core/types/bal: make txIndex uint32

This commit is contained in:
MariusVanDerWijden 2026-04-26 11:38:20 +02:00
parent da34c4e267
commit e5064680b3
4 changed files with 43 additions and 43 deletions

View file

@ -32,7 +32,7 @@ type ConstructionAccountAccesses struct {
// StorageWrites is the post-state values of an account's storage slots // 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 // that were modified in a block, keyed by the slot key and the tx index
// where the modification occurred. // 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 // StorageReads is the set of slot keys that were accessed during block
// execution. // execution.
@ -43,18 +43,18 @@ type ConstructionAccountAccesses struct {
// BalanceChanges contains the post-transaction balances of an account, // BalanceChanges contains the post-transaction balances of an account,
// keyed by transaction indices where it was changed. // 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 // NonceChanges contains the post-state nonce values of an account keyed
// by tx index. // 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) { func (c *ConstructionAccountAccesses) Copy() (res ConstructionAccountAccesses) {
if c.StorageWrites != nil { 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 { for slot, writes := range c.StorageWrites {
res.StorageWrites[slot] = maps.Clone(writes) res.StorageWrites[slot] = maps.Clone(writes)
} }
@ -191,33 +191,33 @@ func (c *ConstructionBlockAccessList) addMutations(muts *StateMutations, index i
return return
} }
// TO // TO
idx := uint16(index) idx := uint32(index)
for addr, mut := range muts.list { for addr, mut := range muts.list {
if _, exist := c.list[addr]; !exist { if _, exist := c.list[addr]; !exist {
c.list[addr] = newConstructionAccountAccesses() c.list[addr] = newConstructionAccountAccesses()
} }
if mut.Nonce != nil { if mut.Nonce != nil {
if c.list[addr].NonceChanges == 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 c.list[addr].NonceChanges[idx] = *mut.Nonce
} }
if mut.Balance != nil { if mut.Balance != nil {
if c.list[addr].BalanceChanges == 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() c.list[addr].BalanceChanges[idx] = mut.Balance.Clone()
} }
if mut.Code != nil { if mut.Code != nil {
if c.list[addr].CodeChanges == 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) c.list[addr].CodeChanges[idx] = bytes.Clone(mut.Code)
} }
if len(mut.StorageWrites) > 0 { if len(mut.StorageWrites) > 0 {
for key, val := range mut.StorageWrites { for key, val := range mut.StorageWrites {
if c.list[addr].StorageWrites[key] == nil { 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 c.list[addr].StorageWrites[key][idx] = val
@ -252,11 +252,11 @@ func (c *ConstructionBlockAccessList) AddAccesses(reads *StateAccessList) {
func newConstructionAccountAccesses() *ConstructionAccountAccesses { func newConstructionAccountAccesses() *ConstructionAccountAccesses {
return &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{}), StorageReads: make(map[common.Hash]struct{}),
BalanceChanges: make(map[uint16]*uint256.Int), BalanceChanges: make(map[uint32]*uint256.Int),
NonceChanges: make(map[uint16]uint64), NonceChanges: make(map[uint32]uint64),
CodeChanges: make(map[uint16][]byte), CodeChanges: make(map[uint32][]byte),
} }
} }

View file

@ -180,19 +180,19 @@ func (e *BlockAccessList) Hash() common.Hash {
// encodingBalanceChange is the encoding format of BalanceChange. // encodingBalanceChange is the encoding format of BalanceChange.
type encodingBalanceChange struct { type encodingBalanceChange struct {
TxIdx uint16 `json:"txIndex"` TxIdx uint32 `json:"txIndex"`
Balance *uint256.Int `json:"balance"` Balance *uint256.Int `json:"balance"`
} }
// encodingAccountNonce is the encoding format of NonceChange. // encodingAccountNonce is the encoding format of NonceChange.
type encodingAccountNonce struct { type encodingAccountNonce struct {
TxIdx uint16 `json:"txIndex"` TxIdx uint32 `json:"txIndex"`
Nonce uint64 `json:"nonce"` Nonce uint64 `json:"nonce"`
} }
// encodingStorageWrite is the encoding format of StorageWrites. // encodingStorageWrite is the encoding format of StorageWrites.
type encodingStorageWrite struct { type encodingStorageWrite struct {
TxIdx uint16 `json:"txIndex"` TxIdx uint32 `json:"txIndex"`
ValueAfter *EncodedStorage `json:"valueAfter"` ValueAfter *EncodedStorage `json:"valueAfter"`
} }
@ -278,7 +278,7 @@ func (e *encodingSlotWrites) validate(blockTxCount int) error {
return errors.New("nil slot key") return errors.New("nil slot key")
} }
if !slices.IsSortedFunc(e.Accesses, func(a, b encodingStorageWrite) int { 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") 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 // encodingCodeChange contains the runtime bytecode deployed at an address
// and the transaction index where the deployment took place. // and the transaction index where the deployment took place.
type encodingCodeChange struct { 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 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 // Check the balance changes are sorted in order
// and that none of them report an index above what is allowed // and that none of them report an index above what is allowed
if !slices.IsSortedFunc(e.BalanceChanges, func(a, b encodingBalanceChange) int { 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") 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 // Check the nonce changes are sorted in order
// and that none of them report an index above what is allowed // and that none of them report an index above what is allowed
if !slices.IsSortedFunc(e.NonceChanges, func(a, b encodingAccountNonce) int { 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") 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, // TODO: contact testing team to add a test case which has the code changes out of order,
// as it wasn't checked here previously // as it wasn't checked here previously
if !slices.IsSortedFunc(e.CodeChanges, func(a, b encodingCodeChange) int { 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") 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)) obj.Accesses = make([]encodingStorageWrite, 0, len(slotWrites))
indices := slices.Collect(maps.Keys(slotWrites)) indices := slices.Collect(maps.Keys(slotWrites))
slices.SortFunc(indices, cmp.Compare[uint16]) slices.SortFunc(indices, cmp.Compare[uint32])
for _, index := range indices { for _, index := range indices {
obj.Accesses = append(obj.Accesses, encodingStorageWrite{ obj.Accesses = append(obj.Accesses, encodingStorageWrite{
TxIdx: index, TxIdx: index,
@ -494,7 +494,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account
// Convert balance changes // Convert balance changes
balanceIndices := slices.Collect(maps.Keys(a.BalanceChanges)) balanceIndices := slices.Collect(maps.Keys(a.BalanceChanges))
slices.SortFunc(balanceIndices, cmp.Compare[uint16]) slices.SortFunc(balanceIndices, cmp.Compare[uint32])
for _, idx := range balanceIndices { for _, idx := range balanceIndices {
res.BalanceChanges = append(res.BalanceChanges, encodingBalanceChange{ res.BalanceChanges = append(res.BalanceChanges, encodingBalanceChange{
TxIdx: idx, TxIdx: idx,
@ -504,7 +504,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account
// Convert nonce changes // Convert nonce changes
nonceIndices := slices.Collect(maps.Keys(a.NonceChanges)) nonceIndices := slices.Collect(maps.Keys(a.NonceChanges))
slices.SortFunc(nonceIndices, cmp.Compare[uint16]) slices.SortFunc(nonceIndices, cmp.Compare[uint32])
for _, idx := range nonceIndices { for _, idx := range nonceIndices {
res.NonceChanges = append(res.NonceChanges, encodingAccountNonce{ res.NonceChanges = append(res.NonceChanges, encodingAccountNonce{
TxIdx: idx, TxIdx: idx,
@ -514,7 +514,7 @@ func (a *ConstructionAccountAccesses) toEncodingObj(addr common.Address) Account
// Convert code change // Convert code change
codeChangeIdxs := slices.Collect(maps.Keys(a.CodeChanges)) codeChangeIdxs := slices.Collect(maps.Keys(a.CodeChanges))
slices.SortFunc(codeChangeIdxs, cmp.Compare[uint16]) slices.SortFunc(codeChangeIdxs, cmp.Compare[uint32])
for _, idx := range codeChangeIdxs { for _, idx := range codeChangeIdxs {
res.CodeChanges = append(res.CodeChanges, encodingCodeChange{ res.CodeChanges = append(res.CodeChanges, encodingCodeChange{
idx, idx,

View file

@ -110,7 +110,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error {
return err return err
} }
// TxIdx: // TxIdx:
_tmp7, err := dec.Uint16() _tmp7, err := dec.Uint32()
if err != nil { if err != nil {
return err return err
} }
@ -169,7 +169,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error {
return err return err
} }
// TxIdx: // TxIdx:
_tmp13, err := dec.Uint16() _tmp13, err := dec.Uint32()
if err != nil { if err != nil {
return err return err
} }
@ -202,7 +202,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error {
return err return err
} }
// TxIdx: // TxIdx:
_tmp17, err := dec.Uint16() _tmp17, err := dec.Uint32()
if err != nil { if err != nil {
return err return err
} }
@ -235,7 +235,7 @@ func (obj *AccountAccess) DecodeRLP(dec *rlp.Stream) error {
return err return err
} }
// TxIndex: // TxIndex:
_tmp21, err := dec.Uint16() _tmp21, err := dec.Uint32()
if err != nil { if err != nil {
return err return err
} }

View file

@ -41,7 +41,7 @@ func makeTestConstructionBAL() ConstructionBlockAccessList {
return ConstructionBlockAccessList{ return ConstructionBlockAccessList{
list: map[common.Address]*ConstructionAccountAccesses{ list: map[common.Address]*ConstructionAccountAccesses{
common.BytesToAddress([]byte{0xff, 0xff}): { 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}): { common.BytesToHash([]byte{0x01}): {
1: common.BytesToHash([]byte{1, 2, 3, 4}), 1: common.BytesToHash([]byte{1, 2, 3, 4}),
2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}),
@ -53,18 +53,18 @@ func makeTestConstructionBAL() ConstructionBlockAccessList {
StorageReads: map[common.Hash]struct{}{ StorageReads: map[common.Hash]struct{}{
common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {}, common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {},
}, },
BalanceChanges: map[uint16]*uint256.Int{ BalanceChanges: map[uint32]*uint256.Int{
1: uint256.NewInt(100), 1: uint256.NewInt(100),
2: uint256.NewInt(500), 2: uint256.NewInt(500),
}, },
NonceChanges: map[uint16]uint64{ NonceChanges: map[uint32]uint64{
1: 2, 1: 2,
2: 6, 2: 6,
}, },
CodeChanges: map[uint16][]byte{0: common.Hex2Bytes("deadbeef")}, CodeChanges: map[uint32][]byte{0: common.Hex2Bytes("deadbeef")},
}, },
common.BytesToAddress([]byte{0xff, 0xff, 0xff}): { 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}): { common.BytesToHash([]byte{0x01}): {
2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}),
3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}), 3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
@ -73,11 +73,11 @@ func makeTestConstructionBAL() ConstructionBlockAccessList {
StorageReads: map[common.Hash]struct{}{ StorageReads: map[common.Hash]struct{}{
common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}): {}, 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), 2: uint256.NewInt(100),
3: uint256.NewInt(500), 3: uint256.NewInt(500),
}, },
NonceChanges: map[uint16]uint64{ NonceChanges: map[uint32]uint64{
1: 2, 1: 2,
}, },
}, },
@ -121,13 +121,13 @@ func makeTestAccountAccess(sort bool) AccountAccess {
} }
for j := 0; j < 3; j++ { for j := 0; j < 3; j++ {
slot.Accesses = append(slot.Accesses, encodingStorageWrite{ slot.Accesses = append(slot.Accesses, encodingStorageWrite{
TxIdx: uint16(i*3 + j), TxIdx: uint32(i*3 + j),
ValueAfter: NewEncodedStorageFromHash(testrand.Hash()), ValueAfter: NewEncodedStorageFromHash(testrand.Hash()),
}) })
} }
if sort { if sort {
slices.SortFunc(slot.Accesses, func(a, b encodingStorageWrite) int { 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) storageWrites = append(storageWrites, slot)
@ -149,25 +149,25 @@ func makeTestAccountAccess(sort bool) AccountAccess {
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
balances = append(balances, encodingBalanceChange{ balances = append(balances, encodingBalanceChange{
TxIdx: uint16(i), TxIdx: uint32(i),
Balance: new(uint256.Int).SetBytes(testrand.Bytes(32)), Balance: new(uint256.Int).SetBytes(testrand.Bytes(32)),
}) })
} }
if sort { if sort {
slices.SortFunc(balances, func(a, b encodingBalanceChange) int { 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++ { for i := 0; i < 5; i++ {
nonces = append(nonces, encodingAccountNonce{ nonces = append(nonces, encodingAccountNonce{
TxIdx: uint16(i), TxIdx: uint32(i),
Nonce: uint64(i + 100), Nonce: uint64(i + 100),
}) })
} }
if sort { if sort {
slices.SortFunc(nonces, func(a, b encodingAccountNonce) int { slices.SortFunc(nonces, func(a, b encodingAccountNonce) int {
return cmp.Compare[uint16](a.TxIdx, b.TxIdx) return cmp.Compare[uint32](a.TxIdx, b.TxIdx)
}) })
} }