Skip to content

Commit cdb8de9

Browse files
committed
use epochInfo.Masternodes instead of snap.NextEpochCandidates
1 parent 73061af commit cdb8de9

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

consensus/XDPoS/engines/engine_v2/syncInfo.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func (x *XDPoS_v2) VerifySyncInfoMessage(chain consensus.ChainReader, syncInfo *
3131
return false, nil
3232
}
3333

34-
snapshot, err := x.getSnapshot(chain, qc.GapNumber, true)
34+
epochInfo, err := x.getEpochSwitchInfo(chain, nil, qc.ProposedBlockInfo.Hash)
3535
if err != nil {
36-
log.Error("[VerifySyncInfoMessage] fail to get snapshot for a syncInfo message", "blockNum", qc.ProposedBlockInfo.Number, "blockHash", qc.ProposedBlockInfo.Hash, "error", err)
36+
log.Error("[VerifySyncInfoMessage] fail to get epochInfo for qc syncInfo message", "blockNum", qc.ProposedBlockInfo.Number, "blockHash", qc.ProposedBlockInfo.Hash, "error", err)
3737
return false, err
3838
}
3939

@@ -42,24 +42,24 @@ func (x *XDPoS_v2) VerifySyncInfoMessage(chain consensus.ChainReader, syncInfo *
4242
GapNumber: qc.GapNumber,
4343
})
4444

45-
if err := x.verifySignatures(voteSigHash, qc.Signatures, snapshot.NextEpochCandidates); err != nil {
45+
if err := x.verifySignatures(voteSigHash, qc.Signatures, epochInfo.Masternodes); err != nil {
4646
log.Warn("[VerifySyncInfoMessage] SyncInfo message verification failed due to QC", "blockNum", qc.ProposedBlockInfo.Number, "gapNum", qc.GapNumber, "round", qc.ProposedBlockInfo.Round, "error", err)
4747
return false, err
4848
}
4949

5050
if tc != nil { // tc is optional, when the node is starting up there is no TC at the memory
51-
snapshot, err = x.getSnapshot(chain, tc.GapNumber, true)
51+
epochInfo, err := x.getTCEpochInfo(chain, tc.Round)
5252
if err != nil {
53-
log.Error("[VerifySyncInfoMessage] Fail to get snapshot when verifying TC!", "tcGapNumber", tc.GapNumber)
54-
return false, fmt.Errorf("[VerifySyncInfoMessage] Unable to get snapshot, %s", err)
53+
log.Error("[VerifySyncInfoMessage] Fail to get epochInfo for tc syncInfo message", "tcRound", tc.Round, "error", err)
54+
return false, err
5555
}
5656

5757
signedTimeoutObj := types.TimeoutSigHash(&types.TimeoutForSign{
5858
Round: tc.Round,
5959
GapNumber: tc.GapNumber,
6060
})
6161

62-
if err := x.verifySignatures(signedTimeoutObj, tc.Signatures, snapshot.NextEpochCandidates); err != nil {
62+
if err := x.verifySignatures(signedTimeoutObj, tc.Signatures, epochInfo.Masternodes); err != nil {
6363
log.Warn("[VerifySyncInfoMessage] SyncInfo message verification failed due to TC", "gapNum", tc.GapNumber, "round", tc.Round, "error", err)
6464
return false, err
6565
}

consensus/XDPoS/engines/engine_v2/timeout.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,23 @@ func (x *XDPoS_v2) VerifyTimeoutMessage(chain consensus.ChainReader, timeoutMsg
2222
log.Debug("[VerifyTimeoutMessage] Disqualified timeout message as the proposed round does not match currentRound", "timeoutHash", timeoutMsg.Hash(), "timeoutRound", timeoutMsg.Round, "currentRound", x.currentRound)
2323
return false, nil
2424
}
25-
snap, err := x.getSnapshot(chain, timeoutMsg.GapNumber, true)
26-
if err != nil || snap == nil {
27-
log.Error("[VerifyTimeoutMessage] Fail to get snapshot when verifying timeout message!", "messageGapNumber", timeoutMsg.GapNumber, "err", err)
25+
26+
epochInfo, err := x.getTCEpochInfo(chain, timeoutMsg.Round)
27+
if err != nil {
28+
log.Error("[VerifyTimeoutMessage] Fail to get epochInfo for timeout message", "tcGapNumber", timeoutMsg.GapNumber, "tcRound", timeoutMsg.Round, "error", err)
2829
return false, err
2930
}
30-
if len(snap.NextEpochCandidates) == 0 {
31+
32+
if len(epochInfo.Masternodes) == 0 {
33+
// TODO: why this check is needed here? how about other places for epochInfo.Masternodes?
3134
log.Error("[VerifyTimeoutMessage] cannot find NextEpochCandidates from snapshot", "messageGapNumber", timeoutMsg.GapNumber)
3235
return false, errors.New("empty master node lists from snapshot")
3336
}
3437

3538
verified, signer, err := x.verifyMsgSignature(types.TimeoutSigHash(&types.TimeoutForSign{
3639
Round: timeoutMsg.Round,
3740
GapNumber: timeoutMsg.GapNumber,
38-
}), timeoutMsg.Signature, snap.NextEpochCandidates)
41+
}), timeoutMsg.Signature, epochInfo.Masternodes)
3942

4043
if err != nil {
4144
log.Warn("[VerifyTimeoutMessage] cannot verify timeout signature", "err", err)
@@ -116,7 +119,7 @@ func (x *XDPoS_v2) onTimeoutPoolThresholdReached(blockChainReader consensus.Chai
116119
return nil
117120
}
118121

119-
func (x *XDPoS_v2) getTCEpochInfo(chain consensus.ChainReader, timeoutCert *types.TimeoutCert) (*types.EpochSwitchInfo, error) {
122+
func (x *XDPoS_v2) getTCEpochInfo(chain consensus.ChainReader, timeoutRound types.Round) (*types.EpochSwitchInfo, error) {
120123
epochSwitchInfo, err := x.getEpochSwitchInfo(chain, (chain.CurrentHeader()), (chain.CurrentHeader()).Hash())
121124
if err != nil {
122125
log.Error("[getTCEpochInfo] Error when getting epoch switch info", "error", err)
@@ -131,18 +134,18 @@ func (x *XDPoS_v2) getTCEpochInfo(chain consensus.ChainReader, timeoutCert *type
131134
Round: epochRound,
132135
Number: epochSwitchInfo.EpochSwitchBlockInfo.Number,
133136
}
134-
log.Info("[getTCEpochInfo] Init epochInfo", "number", epochBlockInfo.Number, "round", epochRound, "tcRound", timeoutCert.Round, "tcEpoch", tempTCEpoch)
135-
for epochBlockInfo.Round > timeoutCert.Round {
137+
log.Info("[getTCEpochInfo] Init epochInfo", "number", epochBlockInfo.Number, "round", epochRound, "tcRound", timeoutRound, "tcEpoch", tempTCEpoch)
138+
for epochBlockInfo.Round > timeoutRound {
136139
tempTCEpoch--
137140
epochBlockInfo, err = x.GetBlockByEpochNumber(chain, tempTCEpoch)
138141
if err != nil {
139142
log.Error("[getTCEpochInfo] Error when getting epoch block info by tc round", "error", err)
140143
return nil, fmt.Errorf("fail on getTCEpochInfo due to failure in getting epoch block info tc round, %s", err)
141144
}
142-
log.Debug("[getTCEpochInfo] Loop to get right epochInfo", "number", epochBlockInfo.Number, "round", epochBlockInfo.Round, "tcRound", timeoutCert.Round, "tcEpoch", tempTCEpoch)
145+
log.Debug("[getTCEpochInfo] Loop to get right epochInfo", "number", epochBlockInfo.Number, "round", epochBlockInfo.Round, "tcRound", timeoutRound, "tcEpoch", tempTCEpoch)
143146
}
144147
tcEpoch := tempTCEpoch
145-
log.Info("[getTCEpochInfo] Final TC epochInfo", "number", epochBlockInfo.Number, "round", epochBlockInfo.Round, "tcRound", timeoutCert.Round, "tcEpoch", tcEpoch)
148+
log.Info("[getTCEpochInfo] Final TC epochInfo", "number", epochBlockInfo.Number, "round", epochBlockInfo.Round, "tcRound", timeoutRound, "tcEpoch", tcEpoch)
146149

147150
epochInfo, err := x.getEpochSwitchInfo(chain, nil, epochBlockInfo.Hash)
148151
if err != nil {
@@ -175,7 +178,7 @@ func (x *XDPoS_v2) verifyTC(chain consensus.ChainReader, timeoutCert *types.Time
175178
}
176179
}
177180

178-
epochInfo, err := x.getTCEpochInfo(chain, timeoutCert)
181+
epochInfo, err := x.getTCEpochInfo(chain, timeoutCert.Round)
179182
if err != nil {
180183
return err
181184
}

consensus/XDPoS/engines/engine_v2/vote.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ func (x *XDPoS_v2) VerifyVoteMessage(chain consensus.ChainReader, vote *types.Vo
2222
return false, nil
2323
}
2424

25-
snapshot, err := x.getSnapshot(chain, vote.GapNumber, true)
25+
epochInfo, err := x.getEpochSwitchInfo(chain, chain.CurrentHeader(), chain.CurrentHeader().Hash())
2626
if err != nil {
27-
log.Error("[VerifyVoteMessage] fail to get snapshot for a vote message", "blockNum", vote.ProposedBlockInfo.Number, "blockHash", vote.ProposedBlockInfo.Hash, "voteHash", vote.Hash(), "error", err.Error())
27+
log.Error("[VerifyVoteMessage] Fail to get epochInfo when verifying vote message!", "blockNum", vote.ProposedBlockInfo.Number, "blockHash", vote.ProposedBlockInfo.Hash, "voteHash", vote.Hash(), "voteGapNumber", vote.GapNumber, "err", err)
2828
return false, err
2929
}
30+
3031
verified, signer, err := x.verifyMsgSignature(types.VoteSigHash(&types.VoteForSign{
3132
ProposedBlockInfo: vote.ProposedBlockInfo,
3233
GapNumber: vote.GapNumber,
33-
}), vote.Signature, snapshot.NextEpochCandidates)
34+
}), vote.Signature, epochInfo.Masternodes)
3435
if err != nil {
35-
for i, mn := range snapshot.NextEpochCandidates {
36+
for i, mn := range epochInfo.Masternodes {
3637
log.Warn("[VerifyVoteMessage] Master node list item", "index", i, "Master node", mn.Hex())
3738
}
3839
log.Warn("[VerifyVoteMessage] Error while verifying vote message", "votedBlockNum", vote.ProposedBlockInfo.Number.Uint64(), "votedBlockHash", vote.ProposedBlockInfo.Hash.Hex(), "voteHash", vote.Hash(), "error", err.Error())

0 commit comments

Comments
 (0)