From a32322e25cd16d4f187be67a24863c12456d581d Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Mon, 22 Feb 2021 21:18:32 +0900 Subject: [PATCH 1/2] fix: use the proposer address selected by VRF when creating new proposal block --- consensus/state.go | 4 ++-- consensus/state_test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 23103c6b2..72b2cd590 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1096,14 +1096,14 @@ func (cs *State) createProposalBlock(round int) (block *types.Block, blockParts if cs.privValidator == nil { panic("entered createProposalBlock with privValidator being nil") } - pubKey, err := cs.privValidator.GetPubKey() + _, err := cs.privValidator.GetPubKey() if err != nil { // If this node is a validator & proposer in the current round, it will // miss the opportunity to create a block. cs.Logger.Error("Error on retrival of pubkey", "err", err) return } - proposerAddr := pubKey.Address() + proposerAddr := cs.Validators.SelectProposer(cs.state.LastProofHash, cs.Height, round).Address message := cs.state.MakeHashMessage(round) proof, err := cs.privValidator.GenerateVRFProof(message) diff --git a/consensus/state_test.go b/consensus/state_test.go index 9358a0ec1..4fb22d8df 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -1918,6 +1918,11 @@ func proposeBlock(t *testing.T, cs *State, round int, vssMap map[crypto.PubKey]* if err := cs.SetProposalAndBlock(proposal, newBlock, blockParts, "some peer"); err != nil { t.Fatal(err) } + + assert.Equal(t, + cs.Validators.SelectProposer(cs.state.LastProofHash, cs.Height, round).Address, + newBlock.ProposerAddress) + return types.BlockID{Hash: newBlock.Hash(), PartsHeader: blockParts.Header()} } From d9d01ed984278a04d2f91f6310761b4b231477ca Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Wed, 24 Feb 2021 17:54:08 +0900 Subject: [PATCH 2/2] revert: it's correct to create the Proposal Block iff privValidator is Proposer --- consensus/state.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 72b2cd590..23103c6b2 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1096,14 +1096,14 @@ func (cs *State) createProposalBlock(round int) (block *types.Block, blockParts if cs.privValidator == nil { panic("entered createProposalBlock with privValidator being nil") } - _, err := cs.privValidator.GetPubKey() + pubKey, err := cs.privValidator.GetPubKey() if err != nil { // If this node is a validator & proposer in the current round, it will // miss the opportunity to create a block. cs.Logger.Error("Error on retrival of pubkey", "err", err) return } - proposerAddr := cs.Validators.SelectProposer(cs.state.LastProofHash, cs.Height, round).Address + proposerAddr := pubKey.Address() message := cs.state.MakeHashMessage(round) proof, err := cs.privValidator.GenerateVRFProof(message)