[dpos] remove the irrelevent elements from the undo
@@ -8,6 +8,7 @@ import (
"github.com/aergoio/aergo/chain"
"github.com/aergoio/aergo/types"
+ "github.com/davecgh/go-spew/spew"
)
type errLibUpdate struct {
@@ -95,8 +96,25 @@ func (pls *pLibStatus) rollbackStatusTo(block *types.Block) error {
end *list.Element
confirmLow = cInfo(beg).BlockNo
targetHash = block.ID()
+ targetBlockNo = block.BlockNo()
)
+ logger.Debug().
+ Uint64("target no", targetBlockNo).Int("undo len", pls.undo.Len()).
+ Msg("start LIB status rollback")
+
+ // Remove those associated with the blocks reorganized out.
+ removeIf(pls.undo,
+ func(e *list.Element) bool {
+ return cInfo(e).BlockNo > targetBlockNo
+ },
+ )
+
+ logger.Debug().
+ Uint64("target no", targetBlockNo).
+ Int("current undo len", pls.undo.Len()).
+ Msg("irrelevent element removed from undo list")
+
// Check if block is a valid rollback target.
for e := beg; e != nil; e = e.Prev() {
c := cInfo(e)
@@ -485,3 +503,11 @@ func (s *Status) NeedReorganization(rootNo types.BlockNo) bool {
return reorganizable
*/
}
+
+func dumpConfirmInfo(name string, l *list.List) {
+ forEach(l,
+ func(e *list.Element) {
+ logger.Debug().Str("confirm info", spew.Sdump(cInfo(e))).Msg(name)
+ },
+ )
+}
