Skip to content

Commit

Permalink
Check pending block protocol version before storing
Browse files Browse the repository at this point in the history
  • Loading branch information
IronGauntlets committed Jul 23, 2024
1 parent 2de5992 commit 53df5f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ func removeTxsAndReceipts(txn db.Transaction, blockNumber, numTxs uint64) error

// StorePending stores a pending block given that it is for the next height
func (b *Blockchain) StorePending(pending *Pending) error {
err := checkBlockVersion(pending.Block.ProtocolVersion)
if err != nil {
return err
}
return b.database.View(func(txn db.Transaction) error {
expectedParentHash := new(felt.Felt)
h, err := headsHeader(txn)
Expand Down
5 changes: 5 additions & 0 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ func TestPending(t *testing.T) {
require.Error(t, err)
})

t.Run("cannot store unsupported pending block version", func(t *testing.T) {
pending := &blockchain.Pending{Block: &core.Block{Header: &core.Header{ProtocolVersion: "1.9.0"}}}
require.Error(t, chain.StorePending(pending))
})

t.Run("store genesis as pending", func(t *testing.T) {
pendingGenesis := &blockchain.Pending{
Block: b,
Expand Down

0 comments on commit 53df5f9

Please sign in to comment.