From bd6d46664cab63392f215739b43932039171337d Mon Sep 17 00:00:00 2001 From: IronGauntlets Date: Fri, 26 Apr 2024 01:27:53 +0100 Subject: [PATCH] Check pending block protocol version before storing --- blockchain/blockchain.go | 4 ++++ blockchain/blockchain_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 9957f871b8..85d14e267c 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -978,6 +978,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) diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index a368071366..12368538c5 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -705,6 +705,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,