Skip to content

Commit

Permalink
fix(consensus): propose locked block when it is available
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Jan 12, 2024
1 parent 5b2a393 commit 6be0eaa
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions internal/consensus/state_proposaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ func (p *Proposaler) Set(proposal *types.Proposal, receivedAt time.Time, rs *cst
}

// Create creates, sings and sends a created proposal to the queue
//
// We prioritize LockedBlock. If it's not set, then we use ValidBlock.
// To create a proposal is used RoundState.ValidBlock if it isn't nil and valid, otherwise create a new one
func (p *Proposaler) Create(ctx context.Context, height int64, round int32, rs *cstypes.RoundState) error {
// If there is valid block, choose that.
block, blockParts := rs.ValidBlock, rs.ValidBlockParts
// Create on block
if !p.checkValidBlock(rs) {
create := false
// If we are locked on some block, propose that.
// We don't check the timestamp in this case, as the block is already valid
block, blockParts := rs.LockedBlock, rs.LockedBlockParts
// when no locked block, use valid block
if block == nil || blockParts == nil {
block, blockParts = rs.ValidBlock, rs.ValidBlockParts
create = !p.checkValidBlock(rs)
}

// Create a block
if create {
var err error
start := time.Now()
block, blockParts, err = p.createProposalBlock(ctx, round, rs)
Expand Down

0 comments on commit 6be0eaa

Please sign in to comment.