From 17f6e67f586e0a96951bd141577827252fa00168 Mon Sep 17 00:00:00 2001 From: Jianrong Date: Sat, 20 Nov 2021 14:35:57 +1100 Subject: [PATCH] review comment improvement --- consensus/XDPoS/engines/engine_v2/engine.go | 8 ++++---- consensus/XDPoS/utils/types.go | 4 ++-- consensus/XDPoS/utils/types_test.go | 4 ++-- tests/consensus/v2_test.go | 6 ++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/consensus/XDPoS/engines/engine_v2/engine.go b/consensus/XDPoS/engines/engine_v2/engine.go index bfaea96f3c..eb13fa02bc 100644 --- a/consensus/XDPoS/engines/engine_v2/engine.go +++ b/consensus/XDPoS/engines/engine_v2/engine.go @@ -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, } } diff --git a/consensus/XDPoS/utils/types.go b/consensus/XDPoS/utils/types.go index 027dd13492..8286f49960 100644 --- a/consensus/XDPoS/utils/types.go +++ b/consensus/XDPoS/utils/types.go @@ -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 diff --git a/consensus/XDPoS/utils/types_test.go b/consensus/XDPoS/utils/types_test.go index 0078b26b02..98fe4ed3a0 100644 --- a/consensus/XDPoS/utils/types_test.go +++ b/consensus/XDPoS/utils/types_test.go @@ -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") } diff --git a/tests/consensus/v2_test.go b/tests/consensus/v2_test.go index 59b53b4c73..cb100e6f69 100644 --- a/tests/consensus/v2_test.go +++ b/tests/consensus/v2_test.go @@ -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},