Skip to content

Commit 22639ab

Browse files
committedJan 25, 2024

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed
 

‎consensus/byzantine_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,29 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
219219
block := lazyProposer.blockExec.CreateProposalBlock(
220220
lazyProposer.Height, lazyProposer.state, commit, proposerAddr,
221221
)
222+
blockHash := block.Hash()
222223
blockParts := block.MakePartSet(types.BlockPartSizeBytes)
223224

225+
keys, err := lazyProposer.txFetcher.FetchKeysFromTxs(context.Background(), block.Txs.ToSliceOfBytes())
226+
require.NoError(t, err)
227+
block.Txs = types.ToTxs(keys)
228+
224229
// Flush the WAL. Otherwise, we may not recompute the same proposal to sign,
225230
// and the privValidator will refuse to sign anything.
226231
if err := lazyProposer.wal.FlushAndSync(); err != nil {
227232
lazyProposer.Logger.Error("Error flushing to disk")
228233
}
229234

230235
// Make proposal
231-
propBlockID := types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
236+
propBlockID := types.BlockID{Hash: blockHash, PartSetHeader: blockParts.Header()}
232237
proposal := types.NewProposal(height, round, lazyProposer.TwoThirdPrevoteRound, propBlockID)
233238
p := proposal.ToProto()
234239
if err := lazyProposer.privValidator.SignProposal(lazyProposer.state.ChainID, p); err == nil {
235240
proposal.Signature = p.Signature
236241

237242
// send proposal and block parts on internal msg queue
238243
lazyProposer.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
244+
lazyProposer.sendInternalMessage(msgInfo{&CompactBlockMessage{block}, ""})
239245
for i := 0; i < int(blockParts.Total()); i++ {
240246
part := blockParts.GetPart(i)
241247
lazyProposer.sendInternalMessage(msgInfo{&BlockPartMessage{lazyProposer.Height, lazyProposer.Round, part}, ""})
@@ -294,7 +300,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
294300
}
295301
case <-time.After(20 * time.Second):
296302
for i, reactor := range reactors {
297-
t.Logf("Consensus Reactor %d\n%v", i, reactor)
303+
t.Logf("Consensus Reactor %d\n%v", i, reactor.conS.GetRoundState())
298304
}
299305
t.Fatalf("Timed out waiting for validators to commit evidence")
300306
}

‎consensus/reactor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ OUTER_LOOP:
583583

584584
// Send compact block
585585
if !prs.Block && rs.ProposalBlockParts.HasHeader(prs.ProposalBlockPartSetHeader) {
586-
logger.Info("Peer has proposal but not block", "height", prs.Height, "round", prs.Round)
587586
if rs.ProposalCompactBlock != nil {
588587
compactBlock, err := rs.ProposalCompactBlock.ToProto()
589588
if err != nil {
@@ -1414,6 +1413,7 @@ func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) {
14141413
ps.PRS.StartTime = startTime
14151414
if psHeight != msg.Height || psRound != msg.Round {
14161415
ps.PRS.Proposal = false
1416+
ps.PRS.Block = false
14171417
ps.PRS.ProposalBlockPartSetHeader = types.PartSetHeader{}
14181418
ps.PRS.ProposalBlockParts = nil
14191419
ps.PRS.ProposalPOLRound = -1

‎consensus/state.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -1193,11 +1193,13 @@ func (cs *State) isProposer(address []byte) bool {
11931193
func (cs *State) defaultDecideProposal(height int64, round int32) {
11941194
var block *types.Block
11951195
var blockParts *types.PartSet
1196+
var blockHash []byte
11961197

11971198
// Decide on block
11981199
if cs.TwoThirdPrevoteBlock != nil {
11991200
// If there is valid block, choose that.
12001201
block, blockParts = cs.TwoThirdPrevoteBlock, cs.TwoThirdPrevoteBlockParts
1202+
blockHash = block.Hash()
12011203
} else {
12021204
// Create a new proposal block from state/txs from the mempool.
12031205
block = cs.createProposalBlock()
@@ -1206,6 +1208,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {
12061208
}
12071209
fmt.Println(block)
12081210
blockParts = block.MakePartSet(types.BlockPartSizeBytes)
1211+
blockHash = block.Hash()
12091212
fmt.Println("generated blockParts", blockParts.Header(), "squareSize", block.Data.SquareSize, "numTxs", len(block.Txs))
12101213

12111214
keys, err := cs.txFetcher.FetchKeysFromTxs(context.Background(), block.Txs.ToSliceOfBytes())
@@ -1226,7 +1229,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {
12261229
}
12271230

12281231
// Make proposal
1229-
propBlockID := types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
1232+
propBlockID := types.BlockID{Hash: blockHash, PartSetHeader: blockParts.Header()}
12301233
proposal := types.NewProposal(height, round, cs.TwoThirdPrevoteRound, propBlockID)
12311234
p := proposal.ToProto()
12321235
if err := cs.privValidator.SignProposal(cs.state.ChainID, p); err == nil {
@@ -1953,6 +1956,11 @@ func (cs *State) addCompactBlock(msg *CompactBlockMessage, peerID p2p.ID) error
19531956
compactBlock := msg.Block
19541957
height := compactBlock.Height
19551958

1959+
if cs.ProposalBlock != nil {
1960+
// We already have the proposal block.
1961+
return nil
1962+
}
1963+
19561964
// Blocks might be reused, so round mismatch is OK
19571965
if cs.Height != height {
19581966
cs.Logger.Debug("received compact block from wrong height", "height", height)
@@ -2450,7 +2458,7 @@ func (cs *State) signAddVote(msgType cmtproto.SignedMsgType, hash []byte, header
24502458
vote, err := cs.signVote(msgType, hash, header)
24512459
if err == nil {
24522460
cs.sendInternalMessage(msgInfo{&VoteMessage{vote}, ""})
2453-
cs.Logger.Debug("signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote)
2461+
cs.Logger.Info("signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote)
24542462
return vote
24552463
}
24562464

‎consensus/types/peer_round_state.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (prs PeerRoundState) StringIndented(indent string) string {
5454
return fmt.Sprintf(`PeerRoundState{
5555
%s %v/%v/%v @%v
5656
%s Proposal %v -> %v
57+
%s Block %v
5758
%s POL %v (round %v)
5859
%s Prevotes %v
5960
%s Precommits %v
@@ -62,6 +63,7 @@ func (prs PeerRoundState) StringIndented(indent string) string {
6263
%s}`,
6364
indent, prs.Height, prs.Round, prs.Step, prs.StartTime,
6465
indent, prs.ProposalBlockPartSetHeader, prs.ProposalBlockParts,
66+
indent, prs.Block,
6567
indent, prs.ProposalPOL, prs.ProposalPOLRound,
6668
indent, prs.Prevotes,
6769
indent, prs.Precommits,

0 commit comments

Comments
 (0)
Please sign in to comment.