block: remove MaxContentsPerBlock

This commit is contained in:
Evgeniy Stratonikov 2021-03-01 16:49:24 +03:00
parent 2f490a3403
commit 4df8a2ad36
4 changed files with 7 additions and 9 deletions

View file

@ -14,10 +14,8 @@ import (
) )
const ( 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 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. // 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) block.Script.DecodeBinary(br)
lenHashes := br.ReadVarUint() lenHashes := br.ReadVarUint()
if lenHashes > MaxContentsPerBlock { if lenHashes > MaxTransactionsPerBlock {
return nil, ErrMaxContentsPerBlock return nil, ErrMaxContentsPerBlock
} }
if lenHashes > 0 { if lenHashes > 0 {
@ -140,7 +138,7 @@ func (b *Block) Trim() ([]byte, error) {
func (b *Block) DecodeBinary(br *io.BinReader) { func (b *Block) DecodeBinary(br *io.BinReader) {
b.Base.DecodeBinary(br) b.Base.DecodeBinary(br)
contentsCount := br.ReadVarUint() contentsCount := br.ReadVarUint()
if contentsCount > MaxContentsPerBlock { if contentsCount > MaxTransactionsPerBlock {
br.Err = ErrMaxContentsPerBlock br.Err = ErrMaxContentsPerBlock
return return
} }

View file

@ -221,7 +221,7 @@ func TestBlockEncodeDecode(t *testing.T) {
t.Run("bad contents count", func(t *testing.T) { t.Run("bad contents count", func(t *testing.T) {
b := newDumbBlock() b := newDumbBlock()
b.Transactions = make([]*transaction.Transaction, MaxContentsPerBlock+1) b.Transactions = make([]*transaction.Transaction, MaxTransactionsPerBlock+1)
for i := range b.Transactions { for i := range b.Transactions {
b.Transactions[i] = &transaction.Transaction{ b.Transactions[i] = &transaction.Transaction{
Script: []byte("my_pretty_script"), Script: []byte("my_pretty_script"),

View file

@ -24,7 +24,7 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) {
m.Base.DecodeBinary(br) m.Base.DecodeBinary(br)
txCount := int(br.ReadVarUint()) txCount := int(br.ReadVarUint())
if txCount > block.MaxContentsPerBlock { if txCount > block.MaxTransactionsPerBlock {
br.Err = block.ErrMaxContentsPerBlock br.Err = block.ErrMaxContentsPerBlock
return return
} }

View file

@ -46,8 +46,8 @@ func TestMerkleBlock_EncodeDecodeBinary(t *testing.T) {
_ = b.Hash() _ = b.Hash()
expected := &MerkleBlock{ expected := &MerkleBlock{
Base: b, Base: b,
TxCount: block.MaxContentsPerBlock + 1, TxCount: block.MaxTransactionsPerBlock + 1,
Hashes: make([]util.Uint256, block.MaxContentsPerBlock), Hashes: make([]util.Uint256, block.MaxTransactionsPerBlock),
Flags: []byte{}, Flags: []byte{},
} }
data, err := testserdes.EncodeBinary(expected) data, err := testserdes.EncodeBinary(expected)