Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOTFIX] fix leader crosslink issue to not include old cross link in the propo… #4629

Merged
merged 11 commits into from
Feb 13, 2024
2 changes: 1 addition & 1 deletion consensus/view_change_construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (vc *viewChange) InitPayload(
if !inited {
viewIDBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(viewIDBytes, viewID)
vc.getLogger().Info().Uint64("viewID", viewID).Uint64("blockNum", blockNum).Msg("[InitPayload] add my M3 (ViewID) type messaage")
vc.getLogger().Info().Uint64("viewID", viewID).Uint64("blockNum", blockNum).Msg("[InitPayload] add my M3 (ViewID) type message")
for _, key := range privKeys {
if _, ok := vc.viewIDBitmap[viewID]; !ok {
viewIDBitmap := bls_cosi.NewMask(members)
Expand Down
38 changes: 38 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,44 @@ func New(

node.serviceManager = service.NewManager()

// delete old pending crosslinks
if node.Blockchain().ShardID() == shard.BeaconChainShardID {
ten := big.NewInt(10)
crossLinkEpochThreshold := new(big.Int).Sub(node.Blockchain().CurrentHeader().Epoch(), ten)

invalidToDelete := make([]types.CrossLink, 0, 1000)
allPending, err := node.Blockchain().ReadPendingCrossLinks()
if err == nil {
for _, pending := range allPending {
// if pending crosslink is older than 10 epochs, delete it
if pending.EpochF.Cmp(crossLinkEpochThreshold) <= 0 {
invalidToDelete = append(invalidToDelete, pending)
utils.Logger().Info().
Uint32("shard", pending.ShardID()).
Int64("epoch", pending.Epoch().Int64()).
Uint64("blockNum", pending.BlockNum()).
Int64("viewID", pending.ViewID().Int64()).
Interface("hash", pending.Hash()).
Msg("[PendingCrossLinksOnInit] delete old pending cross links")
}
}

if n, err := node.Blockchain().DeleteFromPendingCrossLinks(invalidToDelete); err != nil {
utils.Logger().Error().
Err(err).
Msg("[PendingCrossLinksOnInit] deleting old pending cross links failed")
} else if n > 0 {
utils.Logger().Info().
Int("left-pending", n).
Msg("[PendingCrossLinksOnInit] deleted old pending cross links")
}
} else {
utils.Logger().Error().
Err(err).
Msg("[PendingCrossLinksOnInit] read pending cross links failed")
}
}

return &node
}

Expand Down
19 changes: 18 additions & 1 deletion node/node_newblock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node

import (
"math/big"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -226,11 +227,18 @@ func (node *Node) ProposeNewBlock(commitSigs chan []byte) (*types.Block, error)
utils.AnalysisStart("proposeNewBlockVerifyCrossLinks")
// Prepare cross links and slashing messages
var crossLinksToPropose types.CrossLinks
ten := big.NewInt(10)
crossLinkEpochThreshold := new(big.Int).Sub(currentHeader.Epoch(), ten)
if isBeaconchainInCrossLinkEra {
allPending, err := node.Blockchain().ReadPendingCrossLinks()
invalidToDelete := []types.CrossLink{}
if err == nil {
for _, pending := range allPending {
// if pending crosslink is older than 10 epochs, delete it and continue. this logic is also applied when the node starts
if pending.EpochF.Cmp(crossLinkEpochThreshold) <= 0 {
invalidToDelete = append(invalidToDelete, pending)
continue
}
// ReadCrossLink beacon chain usage.
exist, err := node.Blockchain().ReadCrossLink(pending.ShardID(), pending.BlockNum())
if err == nil || exist != nil {
Expand Down Expand Up @@ -263,7 +271,16 @@ func (node *Node) ProposeNewBlock(commitSigs chan []byte) (*types.Block, error)
len(allPending),
)
}
node.Blockchain().DeleteFromPendingCrossLinks(invalidToDelete)
if n, err := node.Blockchain().DeleteFromPendingCrossLinks(invalidToDelete); err != nil {
utils.Logger().Error().
Err(err).
Msg("[ProposeNewBlock] invalid pending cross links failed")
} else if len(invalidToDelete) > 0 {
utils.Logger().Info().
Int("not-deleted", n).
Int("deleted", len(invalidToDelete)).
Msg("[ProposeNewBlock] deleted invalid pending cross links")
}
}
utils.AnalysisEnd("proposeNewBlockVerifyCrossLinks")

Expand Down