Skip to content

Commit

Permalink
fix(dpos): remove history by real changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jan 22, 2025
1 parent 7ddf3e3 commit bbf89ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion test/unit/dposkeyframe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func dposCheckPointsEqual(first *state.CheckPoint, second *state.CheckPoint) boo
second.CurrentReward.TotalVotesInRound ||
second.NextReward.TotalVotesInRound !=
second.NextReward.TotalVotesInRound ||
first.ForceChanged != second.ForceChanged {
first.ForceChanged != second.ForceChanged ||
first.NeedNextTurnDPOSInfo != second.NeedNextTurnDPOSInfo {
return false
}

Expand Down Expand Up @@ -366,6 +367,7 @@ func randomDPOSStateKeyFrame() *state.StateKeyFrame {
VersionStartHeight: rand.Uint32(),
VersionEndHeight: rand.Uint32(),
DPoSV2ActiveHeight: rand.Uint32(),
NeedNextTurnDPOSInfo: randomBool(),
}

for i := 0; i < 5; i++ {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/txvalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7623,7 +7623,7 @@ func (s *txValidatorTestSuite) TestArbitersAccumulateReward() {
ownerPubKeyStr := "0306e3deefee78e0e25f88e98f1f3290ccea98f08dd3a890616755f1a066c4b9b8"
nodePubKeyStr := "0250c5019a00f8bb4fd59bb6d613c70a39bb3026b87cfa247fd26f59fd04987855"

_, err := hex.DecodeString(ownerPubKeyStr)
ownerPubKey, err := hex.DecodeString(ownerPubKeyStr)
if err != nil {
fmt.Println("err", err)
}
Expand Down
20 changes: 18 additions & 2 deletions utils/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,25 @@ func (h *History) Commit(height uint32) {
h.changes[i].commit()
}

// same height changes is just one
holdHeight := make(map[uint32]bool, 0)
var lastHeight uint32
lastHeightChangesCount := 0
for i, change := range h.changes {
if i == 0 {
lastHeight = change.height
}
if change.height == lastHeight {
lastHeightChangesCount++
}
_, ok := holdHeight[change.height]
if !ok {
holdHeight[change.height] = true
}
}
// if changes overflows history's capacity, remove the oldest change.
if len(h.changes) >= h.capacity {
h.changes = h.changes[1:]
if len(holdHeight) >= h.capacity {
h.changes = h.changes[lastHeightChangesCount:]
}

// if no cached changes, create an empty height change.
Expand Down

0 comments on commit bbf89ab

Please sign in to comment.