From 4df8a2ad36951efdf05c616bcd3c946d931af0d4 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 1 Mar 2021 16:49:24 +0300 Subject: [PATCH] block: remove `MaxContentsPerBlock` --- pkg/core/block/block.go | 8 +++----- pkg/core/block/block_test.go | 2 +- pkg/network/payload/merkleblock.go | 2 +- pkg/network/payload/merkleblock_test.go | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/core/block/block.go b/pkg/core/block/block.go index 5355eda88..9023bbd23 100644 --- a/pkg/core/block/block.go +++ b/pkg/core/block/block.go @@ -14,10 +14,8 @@ import ( ) const ( - // MaxContentsPerBlock is the maximum number of contents (transactions + consensus data) per block. - MaxContentsPerBlock = math.MaxUint16 // MaxTransactionsPerBlock is the maximum number of transactions per block. - MaxTransactionsPerBlock = MaxContentsPerBlock + MaxTransactionsPerBlock = math.MaxUint16 ) // ErrMaxContentsPerBlock is returned when the maximum number of contents per block is reached. @@ -88,7 +86,7 @@ func NewBlockFromTrimmedBytes(network netmode.Magic, stateRootEnabled bool, b [] block.Script.DecodeBinary(br) lenHashes := br.ReadVarUint() - if lenHashes > MaxContentsPerBlock { + if lenHashes > MaxTransactionsPerBlock { return nil, ErrMaxContentsPerBlock } if lenHashes > 0 { @@ -140,7 +138,7 @@ func (b *Block) Trim() ([]byte, error) { func (b *Block) DecodeBinary(br *io.BinReader) { b.Base.DecodeBinary(br) contentsCount := br.ReadVarUint() - if contentsCount > MaxContentsPerBlock { + if contentsCount > MaxTransactionsPerBlock { br.Err = ErrMaxContentsPerBlock return } diff --git a/pkg/core/block/block_test.go b/pkg/core/block/block_test.go index d08acf10d..169e672c0 100644 --- a/pkg/core/block/block_test.go +++ b/pkg/core/block/block_test.go @@ -221,7 +221,7 @@ func TestBlockEncodeDecode(t *testing.T) { t.Run("bad contents count", func(t *testing.T) { b := newDumbBlock() - b.Transactions = make([]*transaction.Transaction, MaxContentsPerBlock+1) + b.Transactions = make([]*transaction.Transaction, MaxTransactionsPerBlock+1) for i := range b.Transactions { b.Transactions[i] = &transaction.Transaction{ Script: []byte("my_pretty_script"), diff --git a/pkg/network/payload/merkleblock.go b/pkg/network/payload/merkleblock.go index b53499085..f1c932599 100644 --- a/pkg/network/payload/merkleblock.go +++ b/pkg/network/payload/merkleblock.go @@ -24,7 +24,7 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) { m.Base.DecodeBinary(br) txCount := int(br.ReadVarUint()) - if txCount > block.MaxContentsPerBlock { + if txCount > block.MaxTransactionsPerBlock { br.Err = block.ErrMaxContentsPerBlock return } diff --git a/pkg/network/payload/merkleblock_test.go b/pkg/network/payload/merkleblock_test.go index 5483fb6b2..8058b9dcf 100644 --- a/pkg/network/payload/merkleblock_test.go +++ b/pkg/network/payload/merkleblock_test.go @@ -46,8 +46,8 @@ func TestMerkleBlock_EncodeDecodeBinary(t *testing.T) { _ = b.Hash() expected := &MerkleBlock{ Base: b, - TxCount: block.MaxContentsPerBlock + 1, - Hashes: make([]util.Uint256, block.MaxContentsPerBlock), + TxCount: block.MaxTransactionsPerBlock + 1, + Hashes: make([]util.Uint256, block.MaxTransactionsPerBlock), Flags: []byte{}, } data, err := testserdes.EncodeBinary(expected)