Skip to content

Commit

Permalink
fix case where manager would panic when adding v1 transaction after v…
Browse files Browse the repository at this point in the history
…2 require height
  • Loading branch information
chris124567 committed Feb 16, 2024
1 parent 32abe2b commit 2b881e6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chain/manager.go
Expand Up @@ -14,6 +14,9 @@ import (
var (
// ErrFutureBlock is returned when a block's timestamp is too far in the future.
ErrFutureBlock = errors.New("block's timestamp is too far in the future")
// ErrV1AfterV2Required is returned when a v1 transaction is introduced after
// v2 transactions are required.
ErrV1AfterV2Required = errors.New("v1 transaction added after v2 require height")
)

// An ApplyUpdate reflects the changes to the blockchain resulting from the
Expand Down Expand Up @@ -296,6 +299,9 @@ func (m *Manager) applyTip(index types.ChainIndex) error {
panic("applyTip called with non-attaching block")
} else if bs == nil {
bs = new(consensus.V1BlockSupplement)
if cs.Index.Height > cs.Network.HardforkV2.RequireHeight && len(b.Transactions) > 0 {
return ErrV1AfterV2Required
}
*bs = m.store.SupplementTipBlock(b)
if err := consensus.ValidateBlock(m.tipState, b, *bs); err != nil {
m.markBadBlock(index.ID, err)
Expand Down Expand Up @@ -985,6 +991,10 @@ func (m *Manager) AddPoolTransactions(txns []types.Transaction) (known bool, err
return true, m.txpool.invalidTxnSets[setID]
}

if m.tipState.Index.Height > m.tipState.Network.HardforkV2.RequireHeight {
return false, m.markBadTxnSet(setID, fmt.Errorf("transactions are invalid: %w", ErrV1AfterV2Required))
}

// validate as a standalone set
ms := consensus.NewMidState(m.tipState)
for _, txn := range txns {
Expand Down

0 comments on commit 2b881e6

Please sign in to comment.