review comment improvement

This commit is contained in:
Jianrong 2021-11-20 14:35:57 +11:00
parent 98014936c3
commit 17f6e67f58
4 changed files with 10 additions and 12 deletions

View file

@ -110,12 +110,12 @@ func (x *XDPoS_v2) VerifySyncInfoMessage(syncInfo utils.SyncInfo) error {
- verifyTC
2. Broadcast(Not part of consensus)
*/
err := x.verifyQC(&syncInfo.HighestQuorumCert)
err := x.verifyQC(syncInfo.HighestQuorumCert)
if err != nil {
log.Warn("SyncInfo message verification failed due to QC", err)
return err
}
err = x.verifyTC(&syncInfo.HighestTimeoutCert)
err = x.verifyTC(syncInfo.HighestTimeoutCert)
if err != nil {
log.Warn("SyncInfo message verification failed due to TC", err)
return err
@ -470,7 +470,7 @@ func (x *XDPoS_v2) getCurrentRoundMasterNodes() []common.Address {
func (x *XDPoS_v2) getSyncInfo() utils.SyncInfo {
return utils.SyncInfo{
HighestQuorumCert: *x.highestQuorumCert,
HighestTimeoutCert: *x.highestTimeoutCert,
HighestQuorumCert: x.highestQuorumCert,
HighestTimeoutCert: x.highestTimeoutCert,
}
}

View file

@ -85,8 +85,8 @@ type Timeout struct {
// BFT Sync Info message in XDPoS 2.0
type SyncInfo struct {
HighestQuorumCert QuorumCert
HighestTimeoutCert TimeoutCert
HighestQuorumCert *QuorumCert
HighestTimeoutCert *TimeoutCert
}
// Quorum Certificate struct in XDPoS 2.0

View file

@ -53,8 +53,8 @@ func TestHashAndSigHash(t *testing.T) {
if timeout1.Hash() == timeout2.Hash() {
t.Fatalf("Hash of two timeouts shouldn't equal")
}
syncInfo1 := SyncInfo{HighestQuorumCert: quorumCert1}
syncInfo2 := SyncInfo{HighestQuorumCert: quorumCert2}
syncInfo1 := SyncInfo{HighestQuorumCert: &quorumCert1}
syncInfo2 := SyncInfo{HighestQuorumCert: &quorumCert2}
if syncInfo1.Hash() == syncInfo2.Hash() {
t.Fatalf("Hash of two sync info shouldn't equal")
}

View file

@ -74,13 +74,12 @@ func TestTimeoutMessageHandlerSuccessfullyGenerateTCandSyncInfo(t *testing.T) {
assert.Equal(t, utils.Round(2), engineV2.GetCurrentRound())
}
func TestThrowErrorIfTimeoutMsgRoundLessThanCurrentRound(t *testing.T) {
func TestThrowErrorIfTimeoutMsgRoundNotEqualToCurrentRound(t *testing.T) {
blockchain, _, _, _ := PrepareXDCTestBlockChain(t, 11, params.TestXDPoSMockChainConfigWithV2Engine)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
// Set round to 3
engineV2.SetNewRoundFaker(utils.Round(3), false)
// Create two timeout message which will not reach timeout pool threshold
timeoutMsg := &utils.Timeout{
Round: utils.Round(2),
Signature: []byte{1},
@ -141,7 +140,7 @@ func TestVoteMessageHandlerSuccessfullyGeneratedQC(t *testing.T) {
assert.Equal(t, utils.Round(2), engineV2.GetCurrentRound())
}
func TestThrowErrorIfVoteMsgRoundLessThanCurrentRound(t *testing.T) {
func TestThrowErrorIfVoteMsgRoundNotEqualToCurrentRound(t *testing.T) {
blockchain, _, _, _ := PrepareXDCTestBlockChain(t, 11, params.TestXDPoSMockChainConfigWithV2Engine)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
@ -153,7 +152,6 @@ func TestThrowErrorIfVoteMsgRoundLessThanCurrentRound(t *testing.T) {
// Set round to 3
engineV2.SetNewRoundFaker(utils.Round(3), false)
// Create two timeout message which will not reach timeout pool threshold
voteMsg := &utils.Vote{
ProposedBlockInfo: *blockInfo,
Signature: []byte{1},