Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix condition check for tx key dissemination #149

Merged
merged 5 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions internal/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,11 @@ func (cs *State) fsyncAndCompleteProposal(ctx context.Context, fsyncUponCompleti
cs.handleCompleteProposal(ctx, height, span)
}

// We only used tx key based dissemination if configured to do so and we are a validator
func (cs *State) gossipTransactionKeyOnly() bool {
return cs.config.GossipTransactionKeyOnly && cs.privValidatorPubKey != nil
}

// state transitions on complete-proposal, 2/3-any, 2/3-one
func (cs *State) handleMsg(ctx context.Context, mi msgInfo, fsyncUponCompletion bool) {
cs.mtx.Lock()
Expand All @@ -1047,14 +1052,14 @@ func (cs *State) handleMsg(ctx context.Context, mi msgInfo, fsyncUponCompletion

// will not cause transition.
// once proposal is set, we can receive block parts
err = cs.setProposal(msg.Proposal, mi.ReceiveTime)
// See if we can try creating the proposal block if keys exist
if err != nil && cs.config.GossipTransactionKeyOnly && cs.privValidatorPubKey != nil {
isProposer := cs.isProposer(cs.privValidatorPubKey.Address())
if !isProposer && cs.roundState.ProposalBlock() == nil {
created := cs.tryCreateProposalBlock(spanCtx, msg.Proposal.Height, msg.Proposal.Round, msg.Proposal.Header, msg.Proposal.LastCommit, msg.Proposal.Evidence, msg.Proposal.ProposerAddress)
if created {
cs.fsyncAndCompleteProposal(ctx, fsyncUponCompletion, msg.Proposal.Height, span)
if err = cs.setProposal(msg.Proposal, mi.ReceiveTime); err == nil {
if cs.gossipTransactionKeyOnly() {
isProposer := cs.isProposer(cs.privValidatorPubKey.Address())
if !isProposer && cs.roundState.ProposalBlock() == nil {
created := cs.tryCreateProposalBlock(spanCtx, msg.Proposal.Height, msg.Proposal.Round, msg.Proposal.Header, msg.Proposal.LastCommit, msg.Proposal.Evidence, msg.Proposal.ProposerAddress)
if created {
cs.fsyncAndCompleteProposal(ctx, fsyncUponCompletion, msg.Proposal.Height, span)
}
}
}
}
Expand Down
43 changes: 43 additions & 0 deletions internal/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2924,6 +2924,49 @@ func TestStateOutputsBlockPartsStats(t *testing.T) {

}

func TestGossipTransactionKeyOnlyConfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

config := configSetup(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cs1, vss := makeState(ctx, t, makeStateArgs{config: config, validators: 2})
vs2 := vss[1]
cs1.config.GossipTransactionKeyOnly = true
propBlock, err := cs1.createProposalBlock(ctx)
require.NoError(t, err)
height, round := cs1.roundState.Height(), cs1.roundState.Round()

// make the second validator the proposer by incrementing the round
round++
incrementRound(vss[1:]...)
propBlockParts, err := propBlock.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
pubKey, err := vss[1].PrivValidator.GetPubKey(ctx)
require.NoError(t, err)
proposal := *types.NewProposal(height, round, -1, blockID, propBlock.Time, propBlock.GetTxKeys(), propBlock.Header, propBlock.LastCommit, propBlock.Evidence, pubKey.Address())
p := proposal.ToProto()
err = vs2.SignProposal(ctx, config.ChainID(), p)
require.NoError(t, err)
proposal.Signature = p.Signature

proposalMsg := ProposalMessage{&proposal}
peerID, err := types.NewNodeID("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
startTestRound(ctx, cs1, height, round)
cs1.handleMsg(ctx, msgInfo{&proposalMsg, peerID, time.Now()}, false)
rs := cs1.GetRoundState()
// Proposal, ProposalBlock and ProposalBlockParts sohuld be set since gossip-tx-key is true
if rs.Proposal == nil {
t.Error("rs.Proposal should be set")
}
if rs.ProposalBlock == nil {
t.Error("rs.ProposalBlock should be set")
}
if rs.ProposalBlockParts.Total() == 0 {
t.Error("rs.ProposalBlockParts should be set")
}
}

func TestStateOutputVoteStats(t *testing.T) {
config := configSetup(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down