From e5064680b3f05e7a2fe094c7c985092fbbcc72b3 Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Sun, 26 Apr 2026 11:38:20 +0200 Subject: [PATCH] core/types/bal: make txIndex uint32 --- core/types/bal/bal.go | 28 ++++++++++---------- core/types/bal/bal_encoding.go | 24 ++++++++--------- core/types/bal/bal_encoding_rlp_generated.go | 8 +++--- core/types/bal/bal_test.go | 26 +++++++++--------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/core/types/bal/bal.go b/core/types/bal/bal.go index 506b6b514b..85976bfa1b 100644 --- a/core/types/bal/bal.go +++ b/core/types/bal/bal.go @@ -32,7 +32,7 @@ type ConstructionAccountAccesses struct { // StorageWrites is the post-state values of an account's storage slots // that were modified in a block, keyed by the slot key and the tx index // where the modification occurred. - StorageWrites map[common.Hash]map[uint16]common.Hash + StorageWrites map[common.Hash]map[uint32]common.Hash // StorageReads is the set of slot keys that were accessed during block // execution. @@ -43,18 +43,18 @@ type ConstructionAccountAccesses struct { // BalanceChanges contains the post-transaction balances of an account, // keyed by transaction indices where it was changed. - BalanceChanges map[uint16]*uint256.Int + BalanceChanges map[uint32]*uint256.Int // NonceChanges contains the post-state nonce values of an account keyed // by tx index. - NonceChanges map[uint16]uint64 + NonceChanges map[uint32]uint64 - CodeChanges map[uint16][]byte + CodeChanges map[uint32][]byte } func (c *ConstructionAccountAccesses) Copy() (res ConstructionAccountAccesses) { if c.StorageWrites != nil { - res.StorageWrites = make(map[common.Hash]map[uint16]common.Hash) + res.StorageWrites = make(map[common.Hash]map[uint32]common.Hash) for slot, writes := range c.StorageWrites { res.StorageWrites[slot] = maps.Clone(writes) } @@ -191,33 +191,33 @@ func (c *ConstructionBlockAccessList) addMutations(muts *StateMutations, index i return } // TO - idx := uint16(index) + idx := uint32(index) for addr, mut := range muts.list { if _, exist := c.list[addr]; !exist { c.list[addr] = newConstructionAccountAccesses() } if mut.Nonce != nil { if c.list[addr].NonceChanges == nil { - c.list[addr].NonceChanges = make(map[uint16]uint64) + c.list[addr].NonceChanges = make(map[uint32]uint64) } c.list[addr].NonceChanges[idx] = *mut.Nonce } if mut.Balance != nil { if c.list[addr].BalanceChanges == nil { - c.list[addr].BalanceChanges = make(map[uint16]*uint256.Int) + c.list[addr].BalanceChanges = make(map[uint32]*uint256.Int) } c.list[addr].BalanceChanges[idx] = mut.Balance.Clone() } if mut.Code != nil { if c.list[addr].CodeChanges == nil { - c.list[addr].CodeChanges = make(map[uint16][]byte) + c.list[addr].CodeChanges = make(map[uint32][]byte) } c.list[addr].CodeChanges[idx] = bytes.Clone(mut.Code) } if len(mut.StorageWrites) > 0 { for key, val := range mut.StorageWrites { if c.list[addr].StorageWrites[key] == nil { - c.list[addr].StorageWrites[key] = make(map[uint16]common.Hash) + c.list[addr].StorageWrites[key] = make(map[uint32]common.Hash) } c.list[addr].StorageWrites[key][idx] = val @@ -252,11 +252,11 @@ func (c *ConstructionBlockAccessList) AddAccesses(reads *StateAccessList) { func newConstructionAccountAccesses() *ConstructionAccountAccesses { return &ConstructionAccountAccesses{ - StorageWrites: make(map[common.Hash]map[uint16]common.Hash), + StorageWrites: make(map[common.Hash]map[uint32]common.Hash), StorageReads: make(map[common.Hash]struct{}), - BalanceChanges: make(map[uint16]*uint256.Int), - NonceChanges: make(map[uint16]uint64), - CodeChanges: make(map[uint16][]byte), + BalanceChanges: make(map[uint32]*uint256.Int), + NonceChanges: make(map[uint32]uint64), + CodeChanges: make(map[uint32][]byte), } } diff --git a/core/types/bal/bal_encoding.go b/core/types/bal/bal_encoding.go index 6d248af39c..899d60c501 100644 --- a/core/types/bal/bal_encoding.go +++ b/core/types/bal/bal_encoding.go @@ -180,19 +180,19 @@ func (e *BlockAccessList) Hash() common.Hash { // encodingBalanceChange is the encoding format of BalanceChange. type encodingBalanceChange struct { - TxIdx uint16 `json:"txIndex"` + TxIdx uint32 `json:"txIndex"` Balance *uint256.Int `json:"balance"` } // encodingAccountNonce is the encoding format of NonceChange. type encodingAccountNonce struct { - TxIdx uint16 `json:"txIndex"` + TxIdx uint32 `json:"txIndex"` Nonce uint64 `json:"nonce"` } // encodingStorageWrite is the encoding format of StorageWrites. type encodingStorageWrite struct { - TxIdx uint16 `json:"txIndex"` + TxIdx uint32 `json:"txIndex"` ValueAfter *EncodedStorage `json:"valueAfter"` } @@ -278,7 +278,7 @@ func (e *encodingSlotWrites) validate(blockTxCount int) error { return errors.New("nil slot key") } if !slices.IsSortedFunc(e.Accesses, func(a, b encodingStorageWrite) int { - return cmp.Compare[uint16](a.TxIdx, b.TxIdx) + return cmp.Compare[uint32](a.TxIdx, b.TxIdx) }) { return errors.New("storage write tx indices not in order") } @@ -303,7 +303,7 @@ func (e *encodingSlotWrites) validate(blockTxCount int) error { // encodingCodeChange contains the runtime bytecode deployed at an address // and the transaction index where the deployment took place. type encodingCodeChange struct { - TxIndex uint16 `ssz-size:"2"` + TxIndex uint32 `ssz-size:"4"` Code []byte `ssz-max:"300000"` // TODO(rjl493456442) shall we put the limit here? The limit will be increased gradually } @@ -366,7 +366,7 @@ func (e *AccountAccess) validate(blockTxCount int) error { // Check the balance changes are sorted in order // and that none of them report an index above what is allowed if !slices.IsSortedFunc(e.BalanceChanges, func(a, b encodingBalanceChange) int { - return cmp.Compare[uint16](a.TxIdx, b.TxIdx) + return cmp.Compare[uint32](a.TxIdx, b.TxIdx) }) { return errors.New("balance changes not in ascending order by tx index") } @@ -387,7 +387,7 @@ func (e *AccountAccess) validate(blockTxCount int) error { // Check the nonce changes are sorted in order // and that none of them report an index above what is allowed if !slices.IsSortedFunc(e.NonceChanges, func(a, b encodingAccountNonce) int { - return cmp.Compare[uint16](a.TxIdx, b.TxIdx) + return cmp.Compare[uint32](a.TxIdx, b.TxIdx) }) { return errors.New("nonce changes not in ascending order by tx index") } @@ -403,7 +403,7 @@ func (e *AccountAccess) validate(blockTxCount int) error { // TODO: contact testing team to add a test case which has the code changes out of order, // as it wasn't checked here previously if !slices.IsSortedFunc(e.CodeChanges, func(a, b encodingCodeChange) int { - return cmp.Compare[uint16](a.TxIndex, b.TxIndex) + return cmp.Compare[uint32](a.TxIndex, b.TxIndex) }) { return errors.New("code changes not in ascending order") } @@ -475,7 +475,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account obj.Accesses = make([]encodingStorageWrite, 0, len(slotWrites)) indices := slices.Collect(maps.Keys(slotWrites)) - slices.SortFunc(indices, cmp.Compare[uint16]) + slices.SortFunc(indices, cmp.Compare[uint32]) for _, index := range indices { obj.Accesses = append(obj.Accesses, encodingStorageWrite{ TxIdx: index, @@ -494,7 +494,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account // Convert balance changes balanceIndices := slices.Collect(maps.Keys(a.BalanceChanges)) - slices.SortFunc(balanceIndices, cmp.Compare[uint16]) + slices.SortFunc(balanceIndices, cmp.Compare[uint32]) for _, idx := range balanceIndices { res.BalanceChanges = append(res.BalanceChanges, encodingBalanceChange{ TxIdx: idx, @@ -504,7 +504,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account // Convert nonce changes nonceIndices := slices.Collect(maps.Keys(a.NonceChanges)) - slices.SortFunc(nonceIndices, cmp.Compare[uint16]) + slices.SortFunc(nonceIndices, cmp.Compare[uint32]) for _, idx := range nonceIndices { res.NonceChanges = append(res.NonceChanges, encodingAccountNonce{ TxIdx: idx, @@ -514,7 +514,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account // Convert code change codeChangeIdxs := slices.Collect(maps.Keys(a.CodeChanges)) - slices.SortFunc(codeChangeIdxs, cmp.Compare[uint16]) + slices.SortFunc(codeChangeIdxs, cmp.Compare[uint32]) for _, idx := range codeChangeIdxs { res.CodeChanges = append(res.CodeChanges, encodingCodeChange{ idx, diff --git a/core/types/bal/bal_encoding_rlp_generated.go b/core/types/bal/bal_encoding_rlp_generated.go index f61ebe2675..f65a688929 100644 --- a/core/types/bal/bal_encoding_rlp_generated.go +++ b/core/types/bal/bal_encoding_rlp_generated.go @@ -110,7 +110,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error { return err } // TxIdx: - _tmp7, err := dec.Uint16() + _tmp7, err := dec.Uint32() if err != nil { return err } @@ -169,7 +169,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error { return err } // TxIdx: - _tmp13, err := dec.Uint16() + _tmp13, err := dec.Uint32() if err != nil { return err } @@ -202,7 +202,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error { return err } // TxIdx: - _tmp17, err := dec.Uint16() + _tmp17, err := dec.Uint32() if err != nil { return err } @@ -235,7 +235,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error { return err } // TxIndex: - _tmp21, err := dec.Uint16() + _tmp21, err := dec.Uint32() if err != nil { return err } diff --git a/core/types/bal/bal_test.go b/core/types/bal/bal_test.go index 5d42f3d458..ebf3abf4a2 100644 --- a/core/types/bal/bal_test.go +++ b/core/types/bal/bal_test.go @@ -41,7 +41,7 @@ func makeTestConstructionBAL() ConstructionBlockAccessList { return ConstructionBlockAccessList{ list: map[common.Address]*ConstructionAccountAccesses{ common.BytesToAddress([]byte{0xff, 0xff}): { - StorageWrites: map[common.Hash]map[uint16]common.Hash{ + StorageWrites: map[common.Hash]map[uint32]common.Hash{ common.BytesToHash([]byte{0x01}): { 1: common.BytesToHash([]byte{1, 2, 3, 4}), 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), @@ -53,18 +53,18 @@ func makeTestConstructionBAL() ConstructionBlockAccessList { StorageReads: map[common.Hash]struct{}{ common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {}, }, - BalanceChanges: map[uint16]*uint256.Int{ + BalanceChanges: map[uint32]*uint256.Int{ 1: uint256.NewInt(100), 2: uint256.NewInt(500), }, - NonceChanges: map[uint16]uint64{ + NonceChanges: map[uint32]uint64{ 1: 2, 2: 6, }, - CodeChanges: map[uint16][]byte{0: common.Hex2Bytes("deadbeef")}, + CodeChanges: map[uint32][]byte{0: common.Hex2Bytes("deadbeef")}, }, common.BytesToAddress([]byte{0xff, 0xff, 0xff}): { - StorageWrites: map[common.Hash]map[uint16]common.Hash{ + StorageWrites: map[common.Hash]map[uint32]common.Hash{ common.BytesToHash([]byte{0x01}): { 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), 3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}), @@ -73,11 +73,11 @@ func makeTestConstructionBAL() ConstructionBlockAccessList { StorageReads: map[common.Hash]struct{}{ common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}): {}, }, - BalanceChanges: map[uint16]*uint256.Int{ + BalanceChanges: map[uint32]*uint256.Int{ 2: uint256.NewInt(100), 3: uint256.NewInt(500), }, - NonceChanges: map[uint16]uint64{ + NonceChanges: map[uint32]uint64{ 1: 2, }, }, @@ -121,13 +121,13 @@ func makeTestAccountAccess(sort bool) AccountAccess { } for j := 0; j < 3; j++ { slot.Accesses = append(slot.Accesses, encodingStorageWrite{ - TxIdx: uint16(i*3 + j), + TxIdx: uint32(i*3 + j), ValueAfter: NewEncodedStorageFromHash(testrand.Hash()), }) } if sort { slices.SortFunc(slot.Accesses, func(a, b encodingStorageWrite) int { - return cmp.Compare[uint16](a.TxIdx, b.TxIdx) + return cmp.Compare[uint32](a.TxIdx, b.TxIdx) }) } storageWrites = append(storageWrites, slot) @@ -149,25 +149,25 @@ func makeTestAccountAccess(sort bool) AccountAccess { for i := 0; i < 5; i++ { balances = append(balances, encodingBalanceChange{ - TxIdx: uint16(i), + TxIdx: uint32(i), Balance: new(uint256.Int).SetBytes(testrand.Bytes(32)), }) } if sort { slices.SortFunc(balances, func(a, b encodingBalanceChange) int { - return cmp.Compare[uint16](a.TxIdx, b.TxIdx) + return cmp.Compare[uint32](a.TxIdx, b.TxIdx) }) } for i := 0; i < 5; i++ { nonces = append(nonces, encodingAccountNonce{ - TxIdx: uint16(i), + TxIdx: uint32(i), Nonce: uint64(i + 100), }) } if sort { slices.SortFunc(nonces, func(a, b encodingAccountNonce) int { - return cmp.Compare[uint16](a.TxIdx, b.TxIdx) + return cmp.Compare[uint32](a.TxIdx, b.TxIdx) }) }