Remove NewKeyedTransactor function (#4472)

* accounts/abi: remove NewKeyedTransactor function

* Remove "imported and not used" package

* Update state.go

* Update statedb_insert_chain_transaction_test.go

* Update statedb_chain_test.go

* Update database_test.go

* lint fixes

Co-authored-by: awskii <artem.tsskiy@gmail.com>
This commit is contained in:
Zachinquarantine 2022-07-13 06:40:39 -04:00 committed by GitHub
parent 36586e52a1
commit 8c27879a6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 54 deletions

View File

@ -24,7 +24,6 @@ import (
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/log/v3"
)
// ErrNoChainID is returned whenever the user failed to specify a chain id.
@ -33,29 +32,6 @@ var ErrNoChainID = errors.New("no chain id specified")
// ErrNotAuthorized is returned when an account is not properly unlocked.
var ErrNotAuthorized = errors.New("not authorized to sign this account")
// NewKeyedTransactor is a utility method to easily create a transaction signer
// from a single private key.
//
// Deprecated: Use NewKeyedTransactorWithChainID instead.
func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
log.Warn("WARNING: NewKeyedTransactor has been deprecated in favour of NewKeyedTransactorWithChainID")
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
signer := types.LatestSignerForChainID(nil)
return &TransactOpts{
From: keyAddr,
Signer: func(address common.Address, tx types.Transaction) (types.Transaction, error) {
if address != keyAddr {
return nil, ErrNotAuthorized
}
signature, err := crypto.Sign(tx.SigningHash(nil).Bytes(), key)
if err != nil {
return nil, err
}
return tx.WithSignature(*signer, signature)
},
}
}
// NewKeyedTransactorWithChainID is a utility method to easily create a transaction signer
// from a single private key.
func NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainID *big.Int) (*TransactOpts, error) {

View File

@ -288,9 +288,18 @@ func initialState1() error {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts1 := bind.NewKeyedTransactor(key1)
transactOpts2 := bind.NewKeyedTransactor(key2)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
if err != nil {
panic(err)
}
transactOpts1, err := bind.NewKeyedTransactorWithChainID(key1, m.ChainConfig.ChainID)
if err != nil {
panic(err)
}
transactOpts2, err := bind.NewKeyedTransactorWithChainID(key2, m.ChainConfig.ChainID)
if err != nil {
panic(err)
}
var tokenContract *contracts.Token
// We generate the blocks without plainstant because it's not supported in core.GenerateChain

View File

@ -72,12 +72,12 @@ func TestCreate2Revive(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
var revive *contracts.Revive
var err error
// Change this address whenever you make any changes in the code of the revive contract in
// contracts/revive.sol
var create2address = common.HexToAddress("e70fd65144383e1189bd710b1e23b61e26315ff4")
@ -263,12 +263,13 @@ func TestCreate2Polymorth(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
var poly *contracts.Poly
var err error
// Change this address whenever you make any changes in the code of the poly contract in
// contracts/poly.sol
var create2address = common.HexToAddress("c66aa74c220476f244b7f45897a124d1a01ca8a8")
@ -509,12 +510,12 @@ func TestReorgOverSelfDestruct(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
var selfDestruct *contracts.Selfdestruct
var err error
// Here we generate 3 blocks, two of which (the one with "Change" invocation and "Destruct" invocation will be reverted during the reorg)
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 3, func(i int, block *core.BlockGen) {
@ -549,7 +550,8 @@ func TestReorgOverSelfDestruct(t *testing.T) {
// Create a longer chain, with 4 blocks (with higher total difficulty) that reverts the change of stroage self-destruction of the contract
contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackendLonger.Close()
transactOptsLonger := bind.NewKeyedTransactor(key)
transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOptsLonger.GasLimit = 1000000
longerChain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 4, func(i int, block *core.BlockGen) {
@ -658,12 +660,12 @@ func TestReorgOverStateChange(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
var selfDestruct *contracts.Selfdestruct
var err error
// Here we generate 3 blocks, two of which (the one with "Change" invocation and "Destruct" invocation will be reverted during the reorg)
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 2, func(i int, block *core.BlockGen) {
@ -692,7 +694,8 @@ func TestReorgOverStateChange(t *testing.T) {
// Create a longer chain, with 4 blocks (with higher total difficulty) that reverts the change of stroage self-destruction of the contract
contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackendLonger.Close()
transactOptsLonger := bind.NewKeyedTransactor(key)
transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOptsLonger.GasLimit = 1000000
longerChain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 3, func(i int, block *core.BlockGen) {
var tx types.Transaction
@ -813,10 +816,8 @@ func TestCreateOnExistingStorage(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, gspec.Config.ChainID)
if err != nil {
t.Fatal(err)
}
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
@ -943,12 +944,12 @@ func TestEip2200Gas(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
var selfDestruct *contracts.Selfdestruct
var err error
// Here we generate 1 block with 2 transactions, first creates a contract with some initial values in the
// It activates the SSTORE pricing rules specific to EIP-2200 (istanbul)
@ -1035,12 +1036,12 @@ func TestWrongIncarnation(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var contractAddress common.Address
var changer *contracts.Changer
var err error
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 2, func(i int, block *core.BlockGen) {
var tx types.Transaction
@ -1151,9 +1152,9 @@ func TestWrongIncarnation2(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var err error
var contractAddress common.Address
@ -1190,7 +1191,8 @@ func TestWrongIncarnation2(t *testing.T) {
// Create a longer chain, with 4 blocks (with higher total difficulty) that reverts the change of stroage self-destruction of the contract
contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
transactOptsLonger := bind.NewKeyedTransactor(key)
transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOptsLonger.GasLimit = 1000000
longerChain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 3, func(i int, block *core.BlockGen) {
var tx types.Transaction
@ -1402,13 +1404,13 @@ func TestRecreateAndRewind(t *testing.T) {
m := stages.MockWithGenesis(t, gspec, key)
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOpts.GasLimit = 1000000
var revive *contracts.Revive2
var phoenix *contracts.Phoenix
var reviveAddress common.Address
var phoenixAddress common.Address
var err error
chain, err1 := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 4, func(i int, block *core.BlockGen) {
var tx types.Transaction
@ -1470,7 +1472,8 @@ func TestRecreateAndRewind(t *testing.T) {
contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackendLonger.Close()
transactOptsLonger := bind.NewKeyedTransactor(key)
transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
transactOptsLonger.GasLimit = 1000000
longerChain, err1 := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 5, func(i int, block *core.BlockGen) {
var tx types.Transaction

View File

@ -22,6 +22,7 @@ import (
"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon/ethdb/olddb"
"github.com/stretchr/testify/require"
"github.com/ledgerwatch/erigon/accounts/abi/bind"
"github.com/ledgerwatch/erigon/accounts/abi/bind/backends"
@ -64,11 +65,11 @@ func TestSelfDestructReceive(t *testing.T) {
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID)
require.NoError(t, err)
var contractAddress common.Address
var selfDestructorContract *contracts.SelfDestructor
var err error
// There are two blocks
// First block deploys a contract, then makes it self-destruct, and then sends 1 wei to the address of the contract,

View File

@ -705,7 +705,11 @@ func getGenesis(funds ...*big.Int) initialData {
for _, key := range keys {
addr := crypto.PubkeyToAddress(key.PublicKey)
addresses = append(addresses, addr)
transactOpts = append(transactOpts, bind.NewKeyedTransactor(key))
to, err := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1))
if err != nil {
panic(err)
}
transactOpts = append(transactOpts, to)
allocs[addr] = core.GenesisAccount{Balance: accountFunds}
}