Skip to content

Commit

Permalink
Remove pre-Durango block building logic and verification (#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 7, 2024
1 parent 67b1aa0 commit 1340cce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 58 deletions.
43 changes: 13 additions & 30 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ func buildBlock(
forceAdvanceTime bool,
parentState state.Chain,
) (block.Block, error) {
blockTxs, err := packBlockTxs(
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
targetBlockSize,
)
if err != nil {
return nil, fmt.Errorf("failed to pack block txs: %w", err)
}

// Try rewarding stakers whose staking period ends at the new chain time.
// This is done first to prioritize advancing the timestamp as quickly as
// possible.
Expand All @@ -276,23 +289,6 @@ func buildBlock(
return nil, fmt.Errorf("could not build tx to reward staker: %w", err)
}

var blockTxs []*txs.Tx
// TODO: Cleanup post-Durango
if builder.txExecutorBackend.Config.IsDurangoActivated(timestamp) {
blockTxs, err = packBlockTxs(
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
targetBlockSize,
)
if err != nil {
return nil, fmt.Errorf("failed to pack block txs: %w", err)
}
}

return block.NewBanffProposalBlock(
timestamp,
parentID,
Expand All @@ -302,19 +298,6 @@ func buildBlock(
)
}

blockTxs, err := packBlockTxs(
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
targetBlockSize,
)
if err != nil {
return nil, fmt.Errorf("failed to pack block txs: %w", err)
}

// If there is no reason to build a block, don't.
if len(blockTxs) == 0 && !forceAdvanceTime {
builder.txExecutorBackend.Ctx.Log.Debug("no pending txs to issue into a block")
Expand Down
17 changes: 0 additions & 17 deletions vms/platformvm/block/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,6 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) {
require.ErrorIs(err, executor.ErrAdvanceTimeTxIssuedAfterBanff)
}

{
// include too many transactions
statelessProposalBlock, err := block.NewBanffProposalBlock(
nextStakerTime,
parentID,
banffParentBlk.Height()+1,
blkTx,
[]*txs.Tx{},
)
require.NoError(err)

statelessProposalBlock.Transactions = []*txs.Tx{blkTx}
block := env.blkManager.NewBlock(statelessProposalBlock)
err = block.Verify(context.Background())
require.ErrorIs(err, errBanffProposalBlockWithMultipleTransactions)
}

{
// valid
statelessProposalBlock, err := block.NewBanffProposalBlock(
Expand Down
17 changes: 6 additions & 11 deletions vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ var (

ErrConflictingBlockTxs = errors.New("block contains conflicting transactions")

errApricotBlockIssuedAfterFork = errors.New("apricot block issued after fork")
errBanffProposalBlockWithMultipleTransactions = errors.New("BanffProposalBlock contains multiple transactions")
errBanffStandardBlockWithoutChanges = errors.New("BanffStandardBlock performs no state changes")
errIncorrectBlockHeight = errors.New("incorrect block height")
errChildBlockEarlierThanParent = errors.New("proposed timestamp before current chain time")
errOptionBlockTimestampNotMatchingParent = errors.New("option block proposed timestamp not matching parent block one")
errApricotBlockIssuedAfterFork = errors.New("apricot block issued after fork")
errBanffStandardBlockWithoutChanges = errors.New("BanffStandardBlock performs no state changes")
errIncorrectBlockHeight = errors.New("incorrect block height")
errChildBlockEarlierThanParent = errors.New("proposed timestamp before current chain time")
errOptionBlockTimestampNotMatchingParent = errors.New("option block proposed timestamp not matching parent block one")
)

// verifier handles the logic for verifying a block.
Expand All @@ -51,11 +50,6 @@ func (v *verifier) BanffCommitBlock(b *block.BanffCommitBlock) error {
}

func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
nextChainTime := b.Timestamp()
if !v.txExecutorBackend.Config.IsDurangoActivated(nextChainTime) && len(b.Transactions) != 0 {
return errBanffProposalBlockWithMultipleTransactions
}

if err := v.banffNonOptionBlock(b); err != nil {
return err
}
Expand All @@ -67,6 +61,7 @@ func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
}

// Advance the time to [nextChainTime].
nextChainTime := b.Timestamp()
if _, err := executor.AdvanceTimeTo(v.txExecutorBackend, onDecisionState, nextChainTime); err != nil {
return err
}
Expand Down

0 comments on commit 1340cce

Please sign in to comment.