diff --git a/blacklist.go b/blacklist.go index c63fae0..53599e9 100644 --- a/blacklist.go +++ b/blacklist.go @@ -315,6 +315,10 @@ func (bl *Blacklist) setNodeRedeemed(orbit uint64, nodeIndex uint16) { sn := &bl.SuspectedNodes[i] // Only increment the count if the orbit is the same. if sn.NodeIndex == nodeIndex { + if sn.OrbitSuspected == orbit { + // It is too early to redeem a node that was suspected in the current orbit. + return + } if sn.OrbitToRedeem == 0 { // This is the first time the node is redeemed. sn.OrbitToRedeem = orbit diff --git a/blacklist_test.go b/blacklist_test.go index ea0983e..4d2f403 100644 --- a/blacklist_test.go +++ b/blacklist_test.go @@ -44,6 +44,21 @@ func TestBlacklistVerifyProposedBlacklist(t *testing.T) { }, expectedErr: errBlacklistInvalidUpdates, }, + { + name: "node redeemed in the same orbit it was suspected in", + blacklist: Blacklist{ + NodeCount: 4, + SuspectedNodes: SuspectedNodes{{NodeIndex: 3, SuspectingCount: 2, OrbitSuspected: 7, RedeemingCount: 0, OrbitToRedeem: 0}}, + }, + nodeCount: 4, + round: 29, + proposedBlacklist: Blacklist{ + NodeCount: 4, + SuspectedNodes: SuspectedNodes{{NodeIndex: 3, SuspectingCount: 2, OrbitSuspected: 7, RedeemingCount: 1, OrbitToRedeem: 7}}, + Updates: []BlacklistUpdate{{Type: BlacklistOpType_NodeRedeemed, NodeIndex: 3}}, + }, + expectedErr: errBlacklistInvalidBlacklist, + }, { name: "blacklist mismatch", blacklist: Blacklist{