Skip to content

Commit bc7e213

Browse files
benjamin202410liam.lai
andauthored
fix syncinfo skip condition (XinFinOrg#1285)
* fix syncinfo skip condition * fix condition * fix condition --------- Co-authored-by: liam.lai <liam.lai@us>
1 parent cd407af commit bc7e213

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

consensus/XDPoS/engines/engine_v2/syncInfo.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import (
1717
// Verify syncInfo and trigger process QC or TC if successful
1818
func (x *XDPoS_v2) VerifySyncInfoMessage(chain consensus.ChainReader, syncInfo *types.SyncInfo) (bool, error) {
1919
qc := syncInfo.HighestQuorumCert
20+
tc := syncInfo.HighestTimeoutCert
21+
2022
if qc == nil {
2123
log.Warn("[VerifySyncInfoMessage] SyncInfo message is missing QC", "highestQC", qc)
2224
return false, nil
2325
}
2426

25-
if x.highestQuorumCert.ProposedBlockInfo.Round >= qc.ProposedBlockInfo.Round {
26-
log.Debug("[VerifySyncInfoMessage] Round from incoming syncInfo message is equal or smaller then local round", "highestQCRound", x.highestQuorumCert.ProposedBlockInfo.Round, "incomingSyncInfoQCRound", qc.ProposedBlockInfo.Round)
27+
if x.highestQuorumCert.ProposedBlockInfo.Round >= qc.ProposedBlockInfo.Round && (tc == nil || x.highestTimeoutCert.Round >= tc.Round) {
28+
log.Debug("[VerifySyncInfoMessage] Local Round is larger or equal than syncinfo round", "highestQCRound", x.highestQuorumCert.ProposedBlockInfo.Round, "highestTCRound", x.highestTimeoutCert.Round, "incomingSyncInfoQCRound", qc.ProposedBlockInfo.Round, "incomingSyncInfoTCRound", tc.Round)
2729
return false, nil
2830
}
2931

@@ -43,7 +45,6 @@ func (x *XDPoS_v2) VerifySyncInfoMessage(chain consensus.ChainReader, syncInfo *
4345
return false, err
4446
}
4547

46-
tc := syncInfo.HighestTimeoutCert
4748
if tc != nil { // tc is optional, when the node is starting up there is no TC at the memory
4849
snapshot, err = x.getSnapshot(chain, tc.GapNumber, true)
4950
if err != nil {
@@ -73,28 +74,31 @@ func (x *XDPoS_v2) SyncInfoHandler(chain consensus.ChainReader, syncInfo *types.
7374
}
7475

7576
func (x *XDPoS_v2) syncInfoHandler(chain consensus.ChainReader, syncInfo *types.SyncInfo) error {
76-
if x.highestQuorumCert.ProposedBlockInfo.Round >= syncInfo.HighestQuorumCert.ProposedBlockInfo.Round {
77-
log.Debug("[syncInfoHandler] Round from incoming syncInfo message is equal or smaller then local round, skip process message", "highestQCRound", x.highestQuorumCert.ProposedBlockInfo.Round, "incomingSyncInfoQCRound", syncInfo.HighestQuorumCert.ProposedBlockInfo.Round)
77+
qc := syncInfo.HighestQuorumCert
78+
tc := syncInfo.HighestTimeoutCert
79+
80+
if x.highestQuorumCert.ProposedBlockInfo.Round >= qc.ProposedBlockInfo.Round && (tc == nil || x.highestTimeoutCert.Round >= tc.Round) {
81+
log.Debug("[syncInfoHandler] Local Round is larger or equal than syncinfo round, skip process message", "highestQCRound", x.highestQuorumCert.ProposedBlockInfo.Round, "highestTCRound", x.highestTimeoutCert.Round, "incomingSyncInfoQCRound", qc.ProposedBlockInfo.Round, "incomingSyncInfoTCRound", tc.Round)
7882
return nil
7983
}
8084

81-
if err := x.verifyQC(chain, syncInfo.HighestQuorumCert, nil); err != nil {
85+
if err := x.verifyQC(chain, qc, nil); err != nil {
8286
return fmt.Errorf("[syncInfoHandler] Failed to verify QC, err %s", err)
8387
}
84-
if err := x.processQC(chain, syncInfo.HighestQuorumCert); err != nil {
88+
if err := x.processQC(chain, qc); err != nil {
8589
return fmt.Errorf("[syncInfoHandler] Failed to process QC, err %s", err)
8690
}
8791

88-
if syncInfo.HighestTimeoutCert != nil {
89-
if x.highestTimeoutCert.Round >= syncInfo.HighestTimeoutCert.Round {
90-
log.Debug("[syncInfoHandler] Round from incoming syncInfo message is equal or smaller then local TC round, skip process message", "highestTCRound", x.highestTimeoutCert.Round, "incomingSyncInfoTCRound", syncInfo.HighestTimeoutCert.Round)
92+
if tc != nil {
93+
if x.highestTimeoutCert.Round >= tc.Round {
94+
log.Debug("[syncInfoHandler] Round from incoming syncInfo message is equal or smaller then local TC round, skip process message", "highestTCRound", x.highestTimeoutCert.Round, "incomingSyncInfoTCRound", tc.Round)
9195
return nil
9296
}
93-
if err := x.verifyTC(chain, syncInfo.HighestTimeoutCert); err != nil {
97+
if err := x.verifyTC(chain, tc); err != nil {
9498
return fmt.Errorf("[syncInfoHandler] Failed to verify TC, err %s", err)
9599
}
96100

97-
if err := x.processTC(chain, syncInfo.HighestTimeoutCert); err != nil {
101+
if err := x.processTC(chain, tc); err != nil {
98102
return fmt.Errorf("[syncInfoHandler] Failed to process TC, err %s", err)
99103
}
100104
}
@@ -105,19 +109,6 @@ func (x *XDPoS_v2) syncInfoHandler(chain consensus.ChainReader, syncInfo *types.
105109
func (x *XDPoS_v2) processSyncInfoPool(chain consensus.ChainReader) {
106110
syncInfo := x.syncInfoPool.PoolObjKeysList()
107111
for _, key := range syncInfo {
108-
// Key format: qcRound:qcGapNum:qcBlockNum:timeoutRound:timeoutGapNum:qcBlockHash
109-
// Get QC Round and needs to lower or equal to x.currentRound
110-
qcRound, qcErr := strconv.ParseInt(strings.Split(key, ":")[0], 10, 64)
111-
if qcErr != nil {
112-
log.Warn("[processSyncInfoPool] Failed to parse QC round", "key", key, "error", qcErr)
113-
continue
114-
}
115-
if int64(x.currentRound) < qcRound {
116-
log.Info("[processSyncInfoPool] Sync QC round is higher than current round, need to sync from other nodes", "qcRound", qcRound, "currentRound", x.currentRound)
117-
continue
118-
}
119-
120-
// Optimize TODO: Check TC Round
121112
log.Debug("[processSyncInfoPool] Processing syncInfo message from pool", "key", key)
122113
for _, obj := range x.syncInfoPool.Get()[key] {
123114
if syncInfoObj, ok := obj.(*types.SyncInfo); ok {

0 commit comments

Comments
 (0)