From 0bffbcbe6e5bf3a3a4b181f631f1d0e08075b529 Mon Sep 17 00:00:00 2001 From: Jonathan Downing Date: Fri, 2 Jun 2023 15:27:41 -0500 Subject: [PATCH] Replace common.Address map keys with common.AddresBytes --- common/address.go | 40 ++++++++++++++++++++++++++++++++ core/state/access_list.go | 16 ++++++------- core/state/journal.go | 4 ++-- core/state/statedb.go | 16 +++++++------ core/types/transaction_test.go | 4 ++-- core/vm/access_list_tracer.go | 28 +++++++++++------------ core/vm/contracts.go | 42 +++++++++++++++++----------------- core/vm/contracts_test.go | 28 +++++++++++------------ core/vm/evm.go | 4 ++-- core/vm/logger.go | 18 +++++++-------- eth/api_test.go | 2 +- eth/handler_test.go | 4 ++-- go.mod | 3 +-- go.sum | 3 --- internal/quaiapi/addrlock.go | 10 ++++---- internal/quaiapi/api.go | 4 ++-- 16 files changed, 132 insertions(+), 94 deletions(-) diff --git a/common/address.go b/common/address.go index df31bdf227..49cd190c8a 100644 --- a/common/address.go +++ b/common/address.go @@ -2,6 +2,7 @@ package common import ( "database/sql/driver" + "encoding/hex" "encoding/json" "fmt" "reflect" @@ -11,6 +12,7 @@ import ( "github.com/dominant-strategies/go-quai/common/hexutil" "github.com/dominant-strategies/go-quai/rlp" + "golang.org/x/crypto/sha3" ) type Address struct { @@ -231,3 +233,41 @@ func IsHexAddress(s string) bool { } return len(s) == 2*AddressLength && isHex(s) } + +// Hex returns a hex string representation of the address. +func (a AddressBytes) Hex() string { + return string(a.checksumHex()) +} + +// String implements fmt.Stringer. +func (a AddressBytes) String() string { + return a.Hex() +} + +func (a AddressBytes) checksumHex() []byte { + buf := a.hex() + + // compute checksum + sha := sha3.NewLegacyKeccak256() + sha.Write(buf[2:]) + hash := sha.Sum(nil) + for i := 2; i < len(buf); i++ { + hashByte := hash[(i-2)/2] + if i%2 == 0 { + hashByte = hashByte >> 4 + } else { + hashByte &= 0xf + } + if buf[i] > '9' && hashByte > 7 { + buf[i] -= 32 + } + } + return buf[:] +} + +func (a AddressBytes) hex() []byte { + var buf [len(a)*2 + 2]byte + copy(buf[:2], "0x") + hex.Encode(buf[2:], a[:]) + return buf[:] +} diff --git a/core/state/access_list.go b/core/state/access_list.go index 9c23c4e64a..ab42fd7569 100644 --- a/core/state/access_list.go +++ b/core/state/access_list.go @@ -21,19 +21,19 @@ import ( ) type accessList struct { - addresses map[common.Address]int + addresses map[common.AddressBytes]int slots []map[common.Hash]struct{} } // ContainsAddress returns true if the address is in the access list. -func (al *accessList) ContainsAddress(address common.Address) bool { +func (al *accessList) ContainsAddress(address common.AddressBytes) bool { _, ok := al.addresses[address] return ok } // Contains checks if a slot within an account is present in the access list, returning // separate flags for the presence of the account and the slot respectively. -func (al *accessList) Contains(address common.Address, slot common.Hash) (addressPresent bool, slotPresent bool) { +func (al *accessList) Contains(address common.AddressBytes, slot common.Hash) (addressPresent bool, slotPresent bool) { idx, ok := al.addresses[address] if !ok { // no such address (and hence zero slots) @@ -50,7 +50,7 @@ func (al *accessList) Contains(address common.Address, slot common.Hash) (addres // newAccessList creates a new accessList. func newAccessList() *accessList { return &accessList{ - addresses: make(map[common.Address]int), + addresses: make(map[common.AddressBytes]int), } } @@ -73,7 +73,7 @@ func (a *accessList) Copy() *accessList { // AddAddress adds an address to the access list, and returns 'true' if the operation // caused a change (addr was not previously in the list). -func (al *accessList) AddAddress(address common.Address) bool { +func (al *accessList) AddAddress(address common.AddressBytes) bool { if _, present := al.addresses[address]; present { return false } @@ -86,7 +86,7 @@ func (al *accessList) AddAddress(address common.Address) bool { // - address added // - slot added // For any 'true' value returned, a corresponding journal entry must be made. -func (al *accessList) AddSlot(address common.Address, slot common.Hash) (addrChange bool, slotChange bool) { +func (al *accessList) AddSlot(address common.AddressBytes, slot common.Hash) (addrChange bool, slotChange bool) { idx, addrPresent := al.addresses[address] if !addrPresent || idx == -1 { // Address not present, or addr present but no slots there @@ -110,7 +110,7 @@ func (al *accessList) AddSlot(address common.Address, slot common.Hash) (addrCha // This operation needs to be performed in the same order as the addition happened. // This method is meant to be used by the journal, which maintains ordering of // operations. -func (al *accessList) DeleteSlot(address common.Address, slot common.Hash) { +func (al *accessList) DeleteSlot(address common.AddressBytes, slot common.Hash) { idx, addrOk := al.addresses[address] // There are two ways this can fail if !addrOk { @@ -131,6 +131,6 @@ func (al *accessList) DeleteSlot(address common.Address, slot common.Hash) { // needs to be performed in the same order as the addition happened. // This method is meant to be used by the journal, which maintains ordering of // operations. -func (al *accessList) DeleteAddress(address common.Address) { +func (al *accessList) DeleteAddress(address common.AddressBytes) { delete(al.addresses, address) } diff --git a/core/state/journal.go b/core/state/journal.go index fbd3eca790..e8388f9009 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -132,10 +132,10 @@ type ( } // Changes to the access list accessListAddAccountChange struct { - address *common.Address + address *common.AddressBytes } accessListAddSlotChange struct { - address *common.Address + address *common.AddressBytes slot *common.Hash } ) diff --git a/core/state/statedb.go b/core/state/statedb.go index 37af63ffc3..f1c955e82a 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -992,24 +992,26 @@ func (s *StateDB) PrepareAccessList(sender common.Address, dst *common.Address, // AddAddressToAccessList adds the given address to the access list func (s *StateDB) AddAddressToAccessList(addr common.Address) { - if s.accessList.AddAddress(addr) { - s.journal.append(accessListAddAccountChange{&addr}) + addrBytes := addr.Bytes20() + if s.accessList.AddAddress(addrBytes) { + s.journal.append(accessListAddAccountChange{&addrBytes}) } } // AddSlotToAccessList adds the given (address, slot)-tuple to the access list func (s *StateDB) AddSlotToAccessList(addr common.Address, slot common.Hash) { - addrMod, slotMod := s.accessList.AddSlot(addr, slot) + addrBytes := addr.Bytes20() + addrMod, slotMod := s.accessList.AddSlot(addrBytes, slot) if addrMod { // In practice, this should not happen, since there is no way to enter the // scope of 'address' without having the 'address' become already added // to the access list (via call-variant, create, etc). // Better safe than sorry, though - s.journal.append(accessListAddAccountChange{&addr}) + s.journal.append(accessListAddAccountChange{&addrBytes}) } if slotMod { s.journal.append(accessListAddSlotChange{ - address: &addr, + address: &addrBytes, slot: &slot, }) } @@ -1017,10 +1019,10 @@ func (s *StateDB) AddSlotToAccessList(addr common.Address, slot common.Hash) { // AddressInAccessList returns true if the given address is in the access list. func (s *StateDB) AddressInAccessList(addr common.Address) bool { - return s.accessList.ContainsAddress(addr) + return s.accessList.ContainsAddress(addr.Bytes20()) } // SlotInAccessList returns true if the given (address, slot)-tuple is in the access list. func (s *StateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addressPresent bool, slotPresent bool) { - return s.accessList.Contains(addr, slot) + return s.accessList.Contains(addr.Bytes20(), slot) } diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 6e5b4db6ee..66473ff648 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -186,7 +186,7 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) { signer := LatestSignerForChainID(common.Big1) // Generate a batch of transactions with overlapping values, but shifted nonces - groups := map[common.Address]Transactions{} + groups := map[common.AddressBytes]Transactions{} expectedCount := 0 for start, key := range keys { addr := crypto.PubkeyToAddress(key.PublicKey) @@ -271,7 +271,7 @@ func TestTransactionTimeSort(t *testing.T) { keys[i], _ = crypto.GenerateKey() } // Generate a batch of transactions with overlapping prices, but different creation times - groups := map[common.Address]Transactions{} + groups := map[common.AddressBytes]Transactions{} for start, key := range keys { addr := crypto.PubkeyToAddress(key.PublicKey) diff --git a/core/vm/access_list_tracer.go b/core/vm/access_list_tracer.go index a14f9062cf..fcb3537fdc 100644 --- a/core/vm/access_list_tracer.go +++ b/core/vm/access_list_tracer.go @@ -26,7 +26,7 @@ import ( // accessList is an accumulator for the set of accounts and storage slots an EVM // contract execution touches. -type accessList map[common.Address]accessListSlots +type accessList map[common.AddressBytes]accessListSlots // accessListSlots is an accumulator for the set of storage slots within a single // contract that an EVM contract execution touches. @@ -34,14 +34,14 @@ type accessListSlots map[common.Hash]struct{} // newAccessList creates a new accessList. func newAccessList() accessList { - return make(map[common.Address]accessListSlots) + return make(map[common.AddressBytes]accessListSlots) } // addAddress adds an address to the accesslist. func (al accessList) addAddress(address common.Address) { // Set address if not previously present - if _, present := al[address]; !present { - al[address] = make(map[common.Hash]struct{}) + if _, present := al[address.Bytes20()]; !present { + al[address.Bytes20()] = make(map[common.Hash]struct{}) } } @@ -51,7 +51,7 @@ func (al accessList) addSlot(address common.Address, slot common.Hash) { al.addAddress(address) // Set the slot on the surely existent storage set - al[address][slot] = struct{}{} + al[address.Bytes20()][slot] = struct{}{} } // equal checks if the content of the current access list is the same as the @@ -96,7 +96,7 @@ func (al accessList) equal(other accessList) bool { func (al accessList) accessList() types.AccessList { acl := make(types.AccessList, 0, len(al)) for addr, slots := range al { - tuple := types.AccessTuple{Address: addr, StorageKeys: []common.Hash{}} + tuple := types.AccessTuple{Address: common.Bytes20ToAddress(addr), StorageKeys: []common.Hash{}} for slot := range slots { tuple.StorageKeys = append(tuple.StorageKeys, slot) } @@ -108,23 +108,23 @@ func (al accessList) accessList() types.AccessList { // AccessListTracer is a tracer that accumulates touched accounts and storage // slots into an internal set. type AccessListTracer struct { - excl map[common.Address]struct{} // Set of account to exclude from the list - list accessList // Set of accounts and storage slots touched + excl map[common.AddressBytes]struct{} // Set of account to exclude from the list + list accessList // Set of accounts and storage slots touched } // NewAccessListTracer creates a new tracer that can generate AccessLists. // An optional AccessList can be specified to occupy slots and addresses in // the resulting accesslist. func NewAccessListTracer(acl types.AccessList, from, to common.Address, precompiles []common.Address) *AccessListTracer { - excl := map[common.Address]struct{}{ - from: {}, to: {}, + excl := map[common.AddressBytes]struct{}{ + from.Bytes20(): {}, to.Bytes20(): {}, } for _, addr := range precompiles { - excl[addr] = struct{}{} + excl[addr.Bytes20()] = struct{}{} } list := newAccessList() for _, al := range acl { - if _, ok := excl[al.Address]; !ok { + if _, ok := excl[al.Address.Bytes20()]; !ok { list.addAddress(al.Address) } for _, slot := range al.StorageKeys { @@ -149,13 +149,13 @@ func (a *AccessListTracer) CaptureState(env *EVM, pc uint64, op OpCode, gas, cos } if (op == EXTCODECOPY || op == EXTCODEHASH || op == EXTCODESIZE || op == BALANCE || op == SELFDESTRUCT) && stack.len() >= 1 { addr := common.Bytes20ToAddress(stack.data[stack.len()-1].Bytes20()) - if _, ok := a.excl[addr]; !ok { + if _, ok := a.excl[addr.Bytes20()]; !ok { a.list.addAddress(addr) } } if (op == DELEGATECALL || op == CALL || op == STATICCALL || op == CALLCODE) && stack.len() >= 5 { addr := common.Bytes20ToAddress(stack.data[stack.len()-2].Bytes20()) - if _, ok := a.excl[addr]; !ok { + if _, ok := a.excl[addr.Bytes20()]; !ok { a.list.addAddress(addr) } } diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 595625121d..f105422257 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -41,33 +41,33 @@ type PrecompiledContract interface { Run(input []byte) ([]byte, error) // Run runs the precompiled contract } -var TranslatedAddresses = map[common.Address]int{ - common.BytesToAddress([]byte{1}): 0, - common.BytesToAddress([]byte{2}): 1, - common.BytesToAddress([]byte{3}): 2, - common.BytesToAddress([]byte{4}): 3, - common.BytesToAddress([]byte{5}): 4, - common.BytesToAddress([]byte{6}): 5, - common.BytesToAddress([]byte{7}): 6, - common.BytesToAddress([]byte{8}): 7, - common.BytesToAddress([]byte{9}): 8, +var TranslatedAddresses = map[common.AddressBytes]int{ + common.AddressBytes([20]byte{1}): 0, + common.AddressBytes([20]byte{2}): 1, + common.AddressBytes([20]byte{3}): 2, + common.AddressBytes([20]byte{4}): 3, + common.AddressBytes([20]byte{5}): 4, + common.AddressBytes([20]byte{6}): 5, + common.AddressBytes([20]byte{7}): 6, + common.AddressBytes([20]byte{8}): 7, + common.AddressBytes([20]byte{9}): 8, } var ( - PrecompiledContracts map[common.Address]PrecompiledContract = make(map[common.Address]PrecompiledContract) - PrecompiledAddresses map[string][]common.Address = make(map[string][]common.Address) + PrecompiledContracts map[common.AddressBytes]PrecompiledContract = make(map[common.AddressBytes]PrecompiledContract) + PrecompiledAddresses map[string][]common.Address = make(map[string][]common.Address) ) func InitializePrecompiles() { - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][0]] = &ecrecover{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][1]] = &sha256hash{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][2]] = &ripemd160hash{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][3]] = &dataCopy{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][4]] = &bigModExp{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][5]] = &bn256Add{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][6]] = &bn256ScalarMul{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][7]] = &bn256Pairing{} - PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][8]] = &blake2F{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][0].Bytes20()] = &ecrecover{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][1].Bytes20()] = &sha256hash{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][2].Bytes20()] = &ripemd160hash{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][3].Bytes20()] = &dataCopy{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][4].Bytes20()] = &bigModExp{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][5].Bytes20()] = &bn256Add{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][6].Bytes20()] = &bn256ScalarMul{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][7].Bytes20()] = &bn256Pairing{} + PrecompiledContracts[PrecompiledAddresses[common.NodeLocation.Name()][8].Bytes20()] = &blake2F{} } func init() { diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index e69deb873b..b5aa6a208d 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -45,16 +45,16 @@ type precompiledFailureTest struct { // allPrecompiles does not map to the actual set of precompiles, as it also contains // repriced versions of precompiles at certain slots -var allPrecompiles = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, - common.BytesToAddress([]byte{5}): &bigModExp{}, - common.BytesToAddress([]byte{6}): &bn256Add{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMul{}, - common.BytesToAddress([]byte{8}): &bn256Pairing{}, - common.BytesToAddress([]byte{9}): &blake2F{}, +var allPrecompiles = map[common.AddressBytes]PrecompiledContract{ + common.AddressBytes([]byte{1}): &ecrecover{}, + common.AddressBytes([]byte{2}): &sha256hash{}, + common.AddressBytes([]byte{3}): &ripemd160hash{}, + common.AddressBytes([]byte{4}): &dataCopy{}, + common.AddressBytes([]byte{5}): &bigModExp{}, + common.AddressBytes([]byte{6}): &bn256Add{}, + common.AddressBytes([]byte{7}): &bn256ScalarMul{}, + common.AddressBytes([]byte{8}): &bn256Pairing{}, + common.AddressBytes([]byte{9}): &blake2F{}, } var blake2FMalformedInputTests = []precompiledFailureTest{ @@ -81,7 +81,7 @@ var blake2FMalformedInputTests = []precompiledFailureTest{ } func testPrecompiled(addr string, test precompiledTest, t *testing.T) { - p := allPrecompiles[common.HexToAddress(addr)] + p := allPrecompiles[common.HexToAddress(addr).Bytes20()] in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { @@ -102,7 +102,7 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) { } func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) { - p := allPrecompiles[common.HexToAddress(addr)] + p := allPrecompiles[common.HexToAddress(addr).Bytes20()] in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) - 1 @@ -120,7 +120,7 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) { } func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing.T) { - p := allPrecompiles[common.HexToAddress(addr)] + p := allPrecompiles[common.HexToAddress(addr).Bytes20()] in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) t.Run(test.Name, func(t *testing.T) { @@ -140,7 +140,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { if test.NoBenchmark { return } - p := allPrecompiles[common.HexToAddress(addr)] + p := allPrecompiles[common.HexToAddress(addr).Bytes20()] in := common.Hex2Bytes(test.Input) reqGas := p.RequiredGas(in) diff --git a/core/vm/evm.go b/core/vm/evm.go index ee2dac12c9..705ed890e1 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -45,10 +45,10 @@ type ( ) func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool, common.Address) { - if index, ok := TranslatedAddresses[addr]; ok { + if index, ok := TranslatedAddresses[addr.Bytes20()]; ok { addr = PrecompiledAddresses[common.NodeLocation.Name()][index] } - p, ok := PrecompiledContracts[addr] + p, ok := PrecompiledContracts[addr.Bytes20()] return p, ok, addr } diff --git a/core/vm/logger.go b/core/vm/logger.go index 446e67804c..213fbd0350 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -118,7 +118,7 @@ type Tracer interface { type StructLogger struct { cfg LogConfig - storage map[common.Address]Storage + storage map[common.AddressBytes]Storage logs []StructLog output []byte err error @@ -127,7 +127,7 @@ type StructLogger struct { // NewStructLogger returns a new logger func NewStructLogger(cfg *LogConfig) *StructLogger { logger := &StructLogger{ - storage: make(map[common.Address]Storage), + storage: make(map[common.AddressBytes]Storage), } if cfg != nil { logger.cfg = *cfg @@ -137,7 +137,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger { // Reset clears the data held by the logger. func (l *StructLogger) Reset() { - l.storage = make(map[common.Address]Storage) + l.storage = make(map[common.AddressBytes]Storage) l.output = make([]byte, 0) l.logs = l.logs[:0] l.err = nil @@ -177,8 +177,8 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui if !l.cfg.DisableStorage && (op == SLOAD || op == SSTORE) { // initialise new changed values storage container for this contract // if not present. - if l.storage[contract.Address()] == nil { - l.storage[contract.Address()] = make(Storage) + if l.storage[contract.Address().Bytes20()] == nil { + l.storage[contract.Address().Bytes20()] = make(Storage) } // capture SLOAD opcodes and record the read entry in the local storage if op == SLOAD && stack.len() >= 1 { @@ -191,16 +191,16 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui return } value := env.StateDB.GetState(internalContractAddr, address) - l.storage[contract.Address()][address] = value - storage = l.storage[contract.Address()].Copy() + l.storage[contract.Address().Bytes20()][address] = value + storage = l.storage[contract.Address().Bytes20()].Copy() } else if op == SSTORE && stack.len() >= 2 { // capture SSTORE opcodes and record the written entry in the local storage. var ( value = common.Hash(stack.data[stack.len()-2].Bytes32()) address = common.Hash(stack.data[stack.len()-1].Bytes32()) ) - l.storage[contract.Address()][address] = value - storage = l.storage[contract.Address()].Copy() + l.storage[contract.Address().Bytes20()][address] = value + storage = l.storage[contract.Address().Bytes20()].Copy() } } var rdata []byte diff --git a/eth/api_test.go b/eth/api_test.go index 7064419282..b14676abd2 100644 --- a/eth/api_test.go +++ b/eth/api_test.go @@ -69,7 +69,7 @@ func TestAccountRange(t *testing.T) { statedb = state.NewDatabaseWithConfig(rawdb.NewMemoryDatabase(), nil) state, _ = state.New(common.Hash{}, statedb, nil) addrs = [AccountRangeMaxResults * 2]common.Address{} - m = map[common.Address]bool{} + m = map[common.AddressBytes]bool{} ) for i := range addrs { diff --git a/eth/handler_test.go b/eth/handler_test.go index 20eb29cee2..14e61c42ca 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -91,11 +91,11 @@ func (p *testTxPool) AddRemotes(txs []*types.Transaction) []error { } // Pending returns all the transactions known to the pool -func (p *testTxPool) Pending(enforceTips bool) (map[common.Address]types.Transactions, error) { +func (p *testTxPool) Pending(enforceTips bool) (map[common.AddressBytes]types.Transactions, error) { p.lock.RLock() defer p.lock.RUnlock() - batches := make(map[common.Address]types.Transactions) + batches := make(map[common.AddressBytes]types.Transactions) for _, tx := range p.pool { from, _ := types.Sender(types.LatestSigner(params.RopstenChainConfig), tx) batches[from] = append(batches[from], tx) diff --git a/go.mod b/go.mod index e396d42340..8292dba029 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dominant-strategies/go-quai -go 1.19 +go 1.20 require ( github.com/Azure/azure-storage-blob-go v0.7.0 @@ -12,7 +12,6 @@ require ( github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf github.com/dominant-strategies/bn256 v0.0.0-20220930122411-fbf930a7493d github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 - github.com/go-stack/stack v1.8.1 github.com/golang/snappy v0.0.3 github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 012896b0d9..9f4705dd55 100644 --- a/go.sum +++ b/go.sum @@ -115,10 +115,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= -github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= diff --git a/internal/quaiapi/addrlock.go b/internal/quaiapi/addrlock.go index 1d91cc8ae3..221976dfc0 100644 --- a/internal/quaiapi/addrlock.go +++ b/internal/quaiapi/addrlock.go @@ -24,7 +24,7 @@ import ( type AddrLocker struct { mu sync.Mutex - locks map[common.Address]*sync.Mutex + locks map[common.AddressBytes]*sync.Mutex } // lock returns the lock of the given address. @@ -32,12 +32,12 @@ func (l *AddrLocker) lock(address common.Address) *sync.Mutex { l.mu.Lock() defer l.mu.Unlock() if l.locks == nil { - l.locks = make(map[common.Address]*sync.Mutex) + l.locks = make(map[common.AddressBytes]*sync.Mutex) } - if _, ok := l.locks[address]; !ok { - l.locks[address] = new(sync.Mutex) + if _, ok := l.locks[address.Bytes20()]; !ok { + l.locks[address.Bytes20()] = new(sync.Mutex) } - return l.locks[address] + return l.locks[address.Bytes20()] } // LockAddr locks an account's mutex. This is used to prevent another tx getting the diff --git a/internal/quaiapi/api.go b/internal/quaiapi/api.go index 46e0476377..2b5018571d 100644 --- a/internal/quaiapi/api.go +++ b/internal/quaiapi/api.go @@ -507,7 +507,7 @@ type OverrideAccount struct { } // StateOverride is the collection of overridden accounts. -type StateOverride map[common.Address]OverrideAccount +type StateOverride map[common.AddressBytes]OverrideAccount // Apply overrides the fields of specified accounts into the given state. func (diff *StateOverride) Apply(state *state.StateDB) error { @@ -519,7 +519,7 @@ func (diff *StateOverride) Apply(state *state.StateDB) error { return nil } for addr, account := range *diff { - internal, err := addr.InternalAddress() + internal, err := common.Bytes20ToAddress(addr).InternalAddress() if err != nil { return err }