From bfa3007ea4c6b3fb601efb1ecbc86d7dd91d05db Mon Sep 17 00:00:00 2001 From: Kelvin Fichter Date: Tue, 2 Mar 2021 11:25:41 -0800 Subject: [PATCH] Cleanup usage of NewTransaction (#215) * Cleanup usage of NewTransaction * Fix lint error and cleanup * Fix error in contract creation * Fix error in contract creation * Fix error in contract creation * Fix some errors in rollup client * Minor cleanup * Additional cleanup --- accounts/abi/bind/backends/simulated_test.go | 18 ++--- accounts/abi/bind/base.go | 4 +- accounts/abi/bind/util_test.go | 2 +- cmd/faucet/faucet.go | 2 +- consensus/clique/clique_test.go | 2 +- core/bench_test.go | 4 +- core/blockchain_test.go | 42 ++++++------ core/rawdb/accessors_chain_test.go | 21 +++--- core/rawdb/accessors_indexes_test.go | 15 +++- core/tx_pool_test.go | 12 ++-- core/types/block_test.go | 2 +- core/types/receipt_test.go | 6 +- core/types/transaction.go | 19 ++---- core/types/transaction_meta.go | 4 +- core/types/transaction_meta_test.go | 4 +- core/types/transaction_signing_test.go | 26 ++++--- core/types/transaction_test.go | 19 +++--- eth/api_backend_test.go | 4 +- eth/downloader/testchain_test.go | 3 +- eth/fetcher/fetcher_test.go | 2 +- eth/filters/filter_system_test.go | 10 +-- eth/filters/filter_test.go | 8 +-- eth/handler_test.go | 12 ++-- eth/helper_test.go | 2 +- eth/tracers/tracers_test.go | 2 +- internal/ethapi/api.go | 18 +++-- les/benchmark.go | 2 +- les/test_helper.go | 16 ++--- light/odr_test.go | 12 ++-- light/txpool_test.go | 2 +- miner/worker_test.go | 8 +-- mobile/types.go | 4 +- rollup/client.go | 72 +++++++++----------- rollup/sync_service_test.go | 66 +++++++++--------- signer/core/types.go | 5 +- signer/rules/rules_test.go | 2 +- 36 files changed, 230 insertions(+), 222 deletions(-) diff --git a/accounts/abi/bind/backends/simulated_test.go b/accounts/abi/bind/backends/simulated_test.go index 4ec7c20c6779..884ff9df2ae0 100644 --- a/accounts/abi/bind/backends/simulated_test.go +++ b/accounts/abi/bind/backends/simulated_test.go @@ -58,7 +58,7 @@ func TestSimulatedBackend(t *testing.T) { // generate a transaction and confirm you can retrieve it code := `6060604052600a8060106000396000f360606040526008565b00` var gas uint64 = 3000000 - tx := types.NewContractCreation(0, big.NewInt(0), gas, big.NewInt(1), common.FromHex(code), nil, nil, types.QueueOriginSequencer) + tx := types.NewContractCreation(0, big.NewInt(0), gas, big.NewInt(1), common.FromHex(code)) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, key) err = sim.SendTransaction(context.Background(), tx) @@ -246,7 +246,7 @@ func TestSimulatedBackend_NonceAt(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -281,7 +281,7 @@ func TestSimulatedBackend_SendTransaction(t *testing.T) { bgCtx := context.Background() // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -316,7 +316,7 @@ func TestSimulatedBackend_TransactionByHash(t *testing.T) { bgCtx := context.Background() // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -481,7 +481,7 @@ func TestSimulatedBackend_TransactionCount(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -540,7 +540,7 @@ func TestSimulatedBackend_TransactionInBlock(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -599,7 +599,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -622,7 +622,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) { } // make a new transaction with a nonce of 1 - tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err = types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -655,7 +655,7 @@ func TestSimulatedBackend_TransactionReceipt(t *testing.T) { bgCtx := context.Background() // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index 13326c59970f..499b4bda07d4 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -227,9 +227,9 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i // Create the transaction, sign it and schedule it for execution var rawTx *types.Transaction if contract == nil { - rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, nil, nil, types.QueueOriginSequencer) + rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input) } else { - rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input) } if opts.Signer == nil { return nil, errors.New("no signer to authorize the transaction with") diff --git a/accounts/abi/bind/util_test.go b/accounts/abi/bind/util_test.go index 3868b2a88c60..e0141f46e06f 100644 --- a/accounts/abi/bind/util_test.go +++ b/accounts/abi/bind/util_test.go @@ -62,7 +62,7 @@ func TestWaitDeployed(t *testing.T) { defer backend.Close() // Create the transaction. - tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code), nil, nil, types.QueueOriginSequencer) + tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code)) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey) // Wait for it to get mined in the background. diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index d936e03ced59..77938efabd90 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -490,7 +490,7 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) { amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil)) amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil)) - tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil) signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID) if err != nil { f.lock.Unlock() diff --git a/consensus/clique/clique_test.go b/consensus/clique/clique_test.go index 87e339476d58..710f44805555 100644 --- a/consensus/clique/clique_test.go +++ b/consensus/clique/clique_test.go @@ -65,7 +65,7 @@ func TestReimportMirroredState(t *testing.T) { // We want to simulate an empty middle block, having the same state as the // first one. The last is needs a state change again to force a reorg. if i != 1 { - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, nil, nil), signer, key) if err != nil { panic(err) } diff --git a/core/bench_test.go b/core/bench_test.go index 81d541f6235d..c4ed7fc1210d 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -86,7 +86,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) { toaddr := common.Address{} data := make([]byte, nbytes) gas, _ := IntrinsicGas(data, false, false, false) - tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, benchRootKey) + tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data), types.HomesteadSigner{}, benchRootKey) gen.AddTx(tx) } } @@ -119,7 +119,7 @@ func genTxRing(naccounts int) func(int, *BlockGen) { break } to := (from + 1) % naccounts - tx := types.NewTransaction(gen.TxNonce(ringAddrs[from]), ringAddrs[to], benchRootFunds, params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(gen.TxNonce(ringAddrs[from]), ringAddrs[to], benchRootFunds, params.TxGas, nil, nil) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, ringKeys[from]) gen.AddTx(tx) from = to diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 11daab209541..6538e259b12a 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -607,7 +607,7 @@ func TestFastVsFullChains(t *testing.T) { // If the block number is multiple of 3, send a few bonus transactions to the miner if i%3 == 2 { for j := 0; j < i%4+1; j++ { - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{0x00}, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{0x00}, big.NewInt(1000), params.TxGas, nil, nil), signer, key) if err != nil { panic(err) } @@ -840,8 +840,8 @@ func TestChainTxReorgs(t *testing.T) { // Create two transactions shared between the chains: // - postponed: transaction included at a later block in the forked chain // - swapped: transaction included at the same block number in the forked chain - postponed, _ := types.SignTx(types.NewTransaction(0, addr1, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key1) - swapped, _ := types.SignTx(types.NewTransaction(1, addr1, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key1) + postponed, _ := types.SignTx(types.NewTransaction(0, addr1, big.NewInt(1000), params.TxGas, nil, nil), signer, key1) + swapped, _ := types.SignTx(types.NewTransaction(1, addr1, big.NewInt(1000), params.TxGas, nil, nil), signer, key1) // Create two transactions that will be dropped by the forked chain: // - pastDrop: transaction dropped retroactively from a past block @@ -857,13 +857,13 @@ func TestChainTxReorgs(t *testing.T) { chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) { switch i { case 0: - pastDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key2) + pastDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil), signer, key2) gen.AddTx(pastDrop) // This transaction will be dropped in the fork from below the split point gen.AddTx(postponed) // This transaction will be postponed till block #3 in the fork case 2: - freshDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key2) + freshDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil), signer, key2) gen.AddTx(freshDrop) // This transaction will be dropped in the fork from exactly at the split point gen.AddTx(swapped) // This transaction will be swapped out at the exact height @@ -882,18 +882,18 @@ func TestChainTxReorgs(t *testing.T) { chain, _ = GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 5, func(i int, gen *BlockGen) { switch i { case 0: - pastAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key3) + pastAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil), signer, key3) gen.AddTx(pastAdd) // This transaction needs to be injected during reorg case 2: gen.AddTx(postponed) // This transaction was postponed from block #1 in the original chain gen.AddTx(swapped) // This transaction was swapped from the exact current spot in the original chain - freshAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key3) + freshAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil), signer, key3) gen.AddTx(freshAdd) // This transaction will be added exactly at reorg time case 3: - futureAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key3) + futureAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil), signer, key3) gen.AddTx(futureAdd) // This transaction will be added after a full reorg } }) @@ -949,7 +949,7 @@ func TestLogReorgs(t *testing.T) { blockchain.SubscribeRemovedLogsEvent(rmLogsCh) chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { if i == 1 { - tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil, types.QueueOriginSequencer), signer, key1) + tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code), signer, key1) if err != nil { t.Fatalf("failed to create tx: %v", err) } @@ -1044,7 +1044,7 @@ func TestLogRebirth(t *testing.T) { chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { if i == 1 { - tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil, types.QueueOriginSequencer), signer, key1) + tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code), signer, key1) if err != nil { t.Fatalf("failed to create tx: %v", err) } @@ -1064,7 +1064,7 @@ func TestLogRebirth(t *testing.T) { // Generate long reorg chain forkChain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { if i == 1 { - tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil, types.QueueOriginSequencer), signer, key1) + tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code), signer, key1) if err != nil { t.Fatalf("failed to create tx: %v", err) } @@ -1164,7 +1164,7 @@ func TestSideLogRebirth(t *testing.T) { // Generate side chain with lower difficulty sideChain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { if i == 1 { - tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil, types.QueueOriginSequencer), signer, key1) + tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code), signer, key1) if err != nil { t.Fatalf("failed to create tx: %v", err) } @@ -1209,7 +1209,7 @@ func TestReorgSideEvent(t *testing.T) { } replacementBlocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 4, func(i int, gen *BlockGen) { - tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), nil, nil, nil, types.QueueOriginSequencer), signer, key1) + tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), nil), signer, key1) if i == 2 { gen.OffsetTime(-9) } @@ -1340,7 +1340,7 @@ func TestEIP155Transition(t *testing.T) { tx *types.Transaction err error basicTx = func(signer types.Signer) (*types.Transaction, error) { - return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil), signer, key) } ) switch i { @@ -1403,7 +1403,7 @@ func TestEIP155Transition(t *testing.T) { tx *types.Transaction err error basicTx = func(signer types.Signer) (*types.Transaction, error) { - return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil), signer, key) } ) if i == 0 { @@ -1453,11 +1453,11 @@ func TestEIP161AccountRemoval(t *testing.T) { ) switch i { case 0: - tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil), signer, key) case 1: - tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil), signer, key) case 2: - tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil), signer, key) } if err != nil { t.Fatal(err) @@ -2166,7 +2166,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in for txi := 0; txi < numTxs; txi++ { uniq := uint64(i*numTxs + txi) recipient := recipientFn(uniq) - tx, err := types.SignTx(types.NewTransaction(uniq, recipient, big.NewInt(1), params.TxGas, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx, err := types.SignTx(types.NewTransaction(uniq, recipient, big.NewInt(1), params.TxGas, big.NewInt(1), nil), signer, testBankKey) if err != nil { b.Error(err) } @@ -2346,10 +2346,10 @@ func TestDeleteCreateRevert(t *testing.T) { blocks, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 1, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) // One transaction to AAAA - tx, _ := types.SignTx(types.NewTransaction(0, aa, big.NewInt(0), 50000, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, key) + tx, _ := types.SignTx(types.NewTransaction(0, aa, big.NewInt(0), 50000, big.NewInt(1), nil), types.HomesteadSigner{}, key) b.AddTx(tx) // One transaction to BBBB - tx, _ = types.SignTx(types.NewTransaction(1, bb, big.NewInt(0), 100000, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, key) + tx, _ = types.SignTx(types.NewTransaction(1, bb, big.NewInt(0), 100000, big.NewInt(1), nil), types.HomesteadSigner{}, key) b.AddTx(tx) }) // Import the canonical chain diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index cd59c2df7a5b..c3a7203bcf13 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -273,8 +273,8 @@ func TestBlockReceiptStorage(t *testing.T) { db := NewMemoryDatabase() // Create a live block since we need metadata to reconstruct the receipt - tx1 := types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) - tx2 := types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx1 := types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil) + tx2 := types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil) body := &types.Body{Transactions: types.Transactions{tx1, tx2}} @@ -429,16 +429,9 @@ func TestBlockMetaStorage(t *testing.T) { db := NewMemoryDatabase() index1 := uint64(1) - tx1 := types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) - tx1.SetTransactionMeta(&types.TransactionMeta{ - L1BlockNumber: nil, - L1Timestamp: 0, - L1MessageSender: nil, - SignatureHashType: types.SighashEIP155, - QueueOrigin: big.NewInt(int64(types.QueueOriginSequencer)), - Index: &index1, - QueueIndex: nil, - }) + tx1 := types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil) + tx1Meta := types.NewTransactionMeta(nil, 0, nil, types.SighashEIP155, types.QueueOriginSequencer, &index1, nil) + tx1.SetTransactionMeta(tx1Meta) WriteTransactionMeta(db, index1, tx1.GetMeta()) meta := ReadTransactionMeta(db, index1) @@ -470,7 +463,9 @@ func TestBlockMetaStorage(t *testing.T) { l1BlockNumber := big.NewInt(777) index2 := uint64(2) - tx2 := types.NewTransaction(2, common.HexToAddress("0x02"), big.NewInt(2), 2, big.NewInt(2), nil, &addr, l1BlockNumber, types.QueueOriginSequencer, types.SighashEthSign) + tx2 := types.NewTransaction(2, common.HexToAddress("0x02"), big.NewInt(2), 2, big.NewInt(2), nil) + tx2Meta := types.NewTransactionMeta(l1BlockNumber, 0, &addr, types.SighashEthSign, types.QueueOriginSequencer, nil, nil) + tx2.SetTransactionMeta(tx2Meta) WriteTransactionMeta(db, index2, tx2.GetMeta()) meta2 := ReadTransactionMeta(db, index2) diff --git a/core/rawdb/accessors_indexes_test.go b/core/rawdb/accessors_indexes_test.go index ecff3a31df1a..6c3ddd242c37 100644 --- a/core/rawdb/accessors_indexes_test.go +++ b/core/rawdb/accessors_indexes_test.go @@ -72,9 +72,18 @@ func TestLookupStorage(t *testing.T) { l1BlockNumber1 := big.NewInt(1) l1BlockNumber2 := big.NewInt(2) - tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}, &sender1, l1BlockNumber1, types.QueueOriginSequencer, types.SighashEIP155) - tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}, &sender2, l1BlockNumber2, types.QueueOriginSequencer, types.SighashEIP155) - tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}, nil, l1BlockNumber1, types.QueueOriginSequencer, types.SighashEIP155) + tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}) + tx1Meta := types.NewTransactionMeta(l1BlockNumber1, 0, &sender1, types.SighashEIP155, types.QueueOriginSequencer, nil, nil) + tx1.SetTransactionMeta(tx1Meta) + + tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}) + tx2Meta := types.NewTransactionMeta(l1BlockNumber2, 0, &sender2, types.SighashEIP155, types.QueueOriginSequencer, nil, nil) + tx2.SetTransactionMeta(tx2Meta) + + tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}) + tx3Meta := types.NewTransactionMeta(l1BlockNumber1, 0, nil, types.SighashEIP155, types.QueueOriginSequencer, nil, nil) + tx3.SetTransactionMeta(tx3Meta) + txs := []*types.Transaction{tx1, tx2, tx3} block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, nil) diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index b1d8477a30a9..a1e95c590658 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -73,7 +73,7 @@ func transaction(nonce uint64, gaslimit uint64, key *ecdsa.PrivateKey) *types.Tr } func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ecdsa.PrivateKey) *types.Transaction { - tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(100), gaslimit, gasprice, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, key) + tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(100), gaslimit, gasprice, nil), types.HomesteadSigner{}, key) return tx } @@ -81,7 +81,7 @@ func pricedDataTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key data := make([]byte, bytes) rand.Read(data) - tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(0), gaslimit, gasprice, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, key) + tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(0), gaslimit, gasprice, data), types.HomesteadSigner{}, key) return tx } @@ -329,7 +329,7 @@ func TestTransactionNegativeValue(t *testing.T) { pool, key := setupTxPool() defer pool.Stop() - tx, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(-1), 100, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, key) + tx, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(-1), 100, big.NewInt(1), nil), types.HomesteadSigner{}, key) from, _ := deriveSender(tx) pool.currentState.AddBalance(from, big.NewInt(1)) if err := pool.AddRemote(tx); err != ErrNegativeValue { @@ -383,9 +383,9 @@ func TestTransactionDoubleNonce(t *testing.T) { resetState() signer := types.HomesteadSigner{} - tx1, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 100000, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) - tx2, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(2), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) - tx3, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx1, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 100000, big.NewInt(1), nil), signer, key) + tx2, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(2), nil), signer, key) + tx3, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(1), nil), signer, key) // Add the first two transaction, ensure higher priced stays only if replace, err := pool.add(tx1, false); err != nil || replace { diff --git a/core/types/block_test.go b/core/types/block_test.go index 8856aeb1c632..ff0a641e5ceb 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -50,7 +50,7 @@ func TestBlockEncoding(t *testing.T) { check("Time", block.Time(), uint64(1426516743)) check("Size", block.Size(), common.StorageSize(len(blockEnc))) - tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil) tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100")) check("len(Transactions)", len(block.Transactions()), 1) check("Transactions[0].Hash", block.Transactions()[0].Hash(), tx1.Hash()) diff --git a/core/types/receipt_test.go b/core/types/receipt_test.go index c0e424a767ef..a6e0944c0795 100644 --- a/core/types/receipt_test.go +++ b/core/types/receipt_test.go @@ -48,7 +48,7 @@ func TestLegacyReceiptDecoding(t *testing.T) { }, } - tx := NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + tx := NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil) receipt := &Receipt{ Status: ReceiptStatusFailed, CumulativeGasUsed: 1, @@ -155,8 +155,8 @@ func encodeAsV3StoredReceiptRLP(want *Receipt) ([]byte, error) { func TestDeriveFields(t *testing.T) { // Create a few transactions to have receipts for txs := Transactions{ - NewContractCreation(1, big.NewInt(1), 1, big.NewInt(1), nil, nil, nil, QueueOriginSequencer), - NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil, nil, QueueOriginSequencer, SighashEIP155), + NewContractCreation(1, big.NewInt(1), 1, big.NewInt(1), nil), + NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil), } // Create the corresponding receipts receipts := Receipts{ diff --git a/core/types/transaction.go b/core/types/transaction.go index 99d19dcb7711..16310a3cc5a5 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -81,26 +81,21 @@ type txdataMarshaling struct { S *hexutil.Big } -func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin, sighashType SignatureHashType) *Transaction { - return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data, l1MessageSender, l1BlockNumber, queueOrigin, sighashType) +func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction { + return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data) } // TODO: cannot deploy contracts with SighashEthSign right until SighashEIP155 is no longer hardcoded -func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin) *Transaction { - return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data, l1MessageSender, l1BlockNumber, queueOrigin, SighashEIP155) +func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction { + return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data) } -func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin, sighashType SignatureHashType) *Transaction { +func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction { if len(data) > 0 { data = common.CopyBytes(data) } - meta := TransactionMeta{ - L1BlockNumber: l1BlockNumber, - L1MessageSender: l1MessageSender, - SignatureHashType: sighashType, - QueueOrigin: big.NewInt(int64(queueOrigin)), - } + meta := NewTransactionMeta(nil, 0, nil, SighashEIP155, QueueOriginSequencer, nil, nil) d := txdata{ AccountNonce: nonce, @@ -120,7 +115,7 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit d.Price.Set(gasPrice) } - return &Transaction{data: d, meta: meta} + return &Transaction{data: d, meta: *meta} } func (t *Transaction) SetTransactionMeta(meta *TransactionMeta) { diff --git a/core/types/transaction_meta.go b/core/types/transaction_meta.go index 04569d16cf43..bacd6d86b12d 100644 --- a/core/types/transaction_meta.go +++ b/core/types/transaction_meta.go @@ -35,13 +35,15 @@ type TransactionMeta struct { } // NewTransactionMeta creates a TransactionMeta -func NewTransactionMeta(l1BlockNumber *big.Int, l1timestamp uint64, l1MessageSender *common.Address, sighashType SignatureHashType, queueOrigin QueueOrigin) *TransactionMeta { +func NewTransactionMeta(l1BlockNumber *big.Int, l1timestamp uint64, l1MessageSender *common.Address, sighashType SignatureHashType, queueOrigin QueueOrigin, index *uint64, queueIndex *uint64) *TransactionMeta { return &TransactionMeta{ L1BlockNumber: l1BlockNumber, L1Timestamp: l1timestamp, L1MessageSender: l1MessageSender, SignatureHashType: sighashType, QueueOrigin: big.NewInt(int64(queueOrigin)), + Index: index, + QueueIndex: queueIndex, } } diff --git a/core/types/transaction_meta_test.go b/core/types/transaction_meta_test.go index 9026fbb3e58a..1fc23716ae88 100644 --- a/core/types/transaction_meta_test.go +++ b/core/types/transaction_meta_test.go @@ -81,7 +81,7 @@ var ( func TestTransactionMetaEncode(t *testing.T) { for _, test := range txMetaSerializationTests { - txmeta := NewTransactionMeta(test.l1BlockNumber, test.l1Timestamp, test.msgSender, test.sighashType, test.queueOrigin) + txmeta := NewTransactionMeta(test.l1BlockNumber, test.l1Timestamp, test.msgSender, test.sighashType, test.queueOrigin, nil, nil) encoded := TxMetaEncode(txmeta) decoded, err := TxMetaDecode(encoded) @@ -98,7 +98,7 @@ func TestTransactionMetaEncode(t *testing.T) { func TestTransactionSighashEncode(t *testing.T) { for _, test := range txMetaSighashEncodeTests { - txmeta := NewTransactionMeta(l1BlockNumber, 0, &addr, test.input, QueueOriginSequencer) + txmeta := NewTransactionMeta(l1BlockNumber, 0, &addr, test.input, QueueOriginSequencer, nil, nil) encoded := TxMetaEncode(txmeta) decoded, err := TxMetaDecode(encoded) diff --git a/core/types/transaction_signing_test.go b/core/types/transaction_signing_test.go index aa5029cc6225..42898015a44c 100644 --- a/core/types/transaction_signing_test.go +++ b/core/types/transaction_signing_test.go @@ -30,7 +30,7 @@ func TestEIP155Signing(t *testing.T) { addr := crypto.PubkeyToAddress(key.PublicKey) signer := NewEIP155Signer(big.NewInt(18)) - tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155), signer, key) + tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil), signer, key) if err != nil { t.Fatal(err) } @@ -49,7 +49,7 @@ func TestEIP155ChainId(t *testing.T) { addr := crypto.PubkeyToAddress(key.PublicKey) signer := NewEIP155Signer(big.NewInt(18)) - tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155), signer, key) + tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil), signer, key) if err != nil { t.Fatal(err) } @@ -61,7 +61,7 @@ func TestEIP155ChainId(t *testing.T) { t.Error("expected chainId to be", signer.chainId, "got", tx.ChainId()) } - tx = NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + tx = NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil) tx, err = SignTx(tx, HomesteadSigner{}, key) if err != nil { t.Fatal(err) @@ -118,7 +118,7 @@ func TestEIP155SigningVitalik(t *testing.T) { func TestChainId(t *testing.T) { key, _ := defaultTestKey() - tx := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + tx := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil) var err error tx, err = SignTx(tx, NewEIP155Signer(big.NewInt(1)), key) @@ -140,7 +140,9 @@ func TestChainId(t *testing.T) { func TestOVMSigner(t *testing.T) { key, _ := defaultTestKey() - tx := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEthSign) + tx := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil) + txMeta := NewTransactionMeta(nil, 0, nil, SighashEthSign, QueueOriginSequencer, nil, nil) + tx.SetTransactionMeta(txMeta) var err error tx, err = SignTx(tx, NewOVMSigner(big.NewInt(1)), key) @@ -162,8 +164,8 @@ func TestOVMSigner(t *testing.T) { func TestOVMSignerHash(t *testing.T) { signer := NewOVMSigner(big.NewInt(1)) - txNil := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155) - txEIP155 := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + txNil := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil) + txEIP155 := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil) hashNil := signer.Hash(txNil) hashEIP155 := signer.Hash(txEIP155) @@ -172,7 +174,9 @@ func TestOVMSignerHash(t *testing.T) { } // The signature hash should be different when using `SighashEthSign` - txEthSign := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEthSign) + txEthSign := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil) + txMeta := NewTransactionMeta(nil, 0, nil, SighashEthSign, QueueOriginSequencer, nil, nil) + txEthSign.SetTransactionMeta(txMeta) hashEthSign := signer.Hash(txEthSign) if hashEIP155 == hashEthSign { @@ -193,7 +197,7 @@ func TestOVMSignerSender(t *testing.T) { // Create a transaction with EIP155 signature hash, sign the transaction, // recover the address and assert that the address matches the key. - txEIP155 := NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + txEIP155 := NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil) txEIP155, err = SignTx(txEIP155, signer, key) if err != nil { @@ -211,7 +215,9 @@ func TestOVMSignerSender(t *testing.T) { // Create a transaction with EthSign signature hash, sign the transaction, // recover the address and assert that the address matches the key. - txEthSign := NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil, QueueOriginSequencer, SighashEthSign) + txEthSign := NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil) + txMeta := NewTransactionMeta(nil, 0, nil, SighashEthSign, QueueOriginSequencer, nil, nil) + txEthSign.SetTransactionMeta(txMeta) txEthSign, err = SignTx(txEthSign, signer, key) if err != nil { diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index cebdb2868c26..8ed4da8204c8 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -31,26 +31,25 @@ import ( // The values in those tests are from the Transaction Tests // at github.com/ethereum/tests. var ( - sender = common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87") - emptyTx = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, &sender, nil, QueueOriginSequencer, SighashEIP155) - emptyTxEmptyL1Sender = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, nil, nil, QueueOriginSequencer, SighashEIP155) + emptyTx = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil) + emptyTxEmptyL1Sender = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil) - rightvrsTx, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), nil, nil, QueueOriginSequencer, SighashEIP155).WithSignature( + rightvrsTx, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544")).WithSignature( HomesteadSigner{}, common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"), ) - rightvrsTxWithL1Sender, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), &sender, nil, QueueOriginSequencer, SighashEIP155).WithSignature( + rightvrsTxWithL1Sender, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544")).WithSignature( HomesteadSigner{}, common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"), ) - rightvrsTxWithL1BlockNumber, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), nil, big.NewInt(1), QueueOriginSequencer, SighashEIP155).WithSignature( + rightvrsTxWithL1BlockNumber, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544")).WithSignature( HomesteadSigner{}, common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"), ) - emptyTxSighashEthSign = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, &sender, nil, QueueOriginSequencer, SighashEthSign) + emptyTxSighashEthSign = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil) ) func TestTransactionSigHash(t *testing.T) { @@ -165,7 +164,7 @@ func TestTransactionPriceNonceSort(t *testing.T) { for start, key := range keys { addr := crypto.PubkeyToAddress(key.PublicKey) for i := 0; i < 25; i++ { - tx, _ := SignTx(NewTransaction(uint64(start+i), common.Address{}, big.NewInt(100), 100, big.NewInt(int64(start+i)), nil, nil, nil, QueueOriginSequencer, SighashEIP155), signer, key) + tx, _ := SignTx(NewTransaction(uint64(start+i), common.Address{}, big.NewInt(100), 100, big.NewInt(int64(start+i)), nil), signer, key) groups[addr] = append(groups[addr], tx) } } @@ -216,9 +215,9 @@ func TestTransactionJSON(t *testing.T) { var tx *Transaction switch i % 2 { case 0: - tx = NewTransaction(i, common.Address{1}, common.Big0, 1, common.Big2, []byte("abcdef"), &sender, nil, QueueOriginSequencer, SighashEIP155) + tx = NewTransaction(i, common.Address{1}, common.Big0, 1, common.Big2, []byte("abcdef")) case 1: - tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef"), nil, nil, QueueOriginSequencer) + tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef")) } transactions = append(transactions, tx) diff --git a/eth/api_backend_test.go b/eth/api_backend_test.go index aed9934a14a1..941a6c975323 100644 --- a/eth/api_backend_test.go +++ b/eth/api_backend_test.go @@ -26,13 +26,11 @@ func TestGasLimit(t *testing.T) { value := big.NewInt(0) gasPrice := big.NewInt(0) data := []byte{} - qo := types.QueueOriginSequencer - sighash := types.SighashEIP155 // Set the gas limit to 1 so that the transaction will not be // able to be added. gasLimit := uint64(1) - tx := types.NewTransaction(nonce, to, value, gasLimit, gasPrice, data, nil, nil, qo, sighash) + tx := types.NewTransaction(nonce, to, value, gasLimit, gasPrice, data) err := backend.SendTx(context.Background(), tx) if err == nil { diff --git a/eth/downloader/testchain_test.go b/eth/downloader/testchain_test.go index af6a8b2062a4..f410152f5b00 100644 --- a/eth/downloader/testchain_test.go +++ b/eth/downloader/testchain_test.go @@ -127,8 +127,7 @@ func (tc *testChain) generate(n int, seed byte, parent *types.Block, heavy bool) // Include transactions to the miner to make blocks more interesting. if parent == tc.genesis && i%22 == 0 { signer := types.MakeSigner(params.TestChainConfig, block.Number()) - l1Sender := common.Address{seed} - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil, &l1Sender, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testKey) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil), signer, testKey) if err != nil { panic(err) } diff --git a/eth/fetcher/fetcher_test.go b/eth/fetcher/fetcher_test.go index 282de4c51bd7..83172c5348f4 100644 --- a/eth/fetcher/fetcher_test.go +++ b/eth/fetcher/fetcher_test.go @@ -52,7 +52,7 @@ func makeChain(n int, seed byte, parent *types.Block) ([]common.Hash, map[common // If the block number is multiple of 3, send a bonus transaction to the miner if parent == genesis && i%3 == 0 { signer := types.MakeSigner(params.TestChainConfig, block.Number()) - tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testKey) + tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil), signer, testKey) if err != nil { panic(err) } diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index 2495be420239..c8d1d43abbd8 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -218,11 +218,11 @@ func TestPendingTxFilter(t *testing.T) { api = NewPublicFilterAPI(backend, false) transactions = []*types.Transaction{ - types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), - types.NewTransaction(1, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), - types.NewTransaction(2, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), - types.NewTransaction(3, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), - types.NewTransaction(4, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), + types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), + types.NewTransaction(1, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), + types.NewTransaction(2, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), + types.NewTransaction(3, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), + types.NewTransaction(4, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil), } hashes []common.Hash diff --git a/eth/filters/filter_test.go b/eth/filters/filter_test.go index bd380e910bf0..f45720d5a90f 100644 --- a/eth/filters/filter_test.go +++ b/eth/filters/filter_test.go @@ -127,7 +127,7 @@ func TestFilters(t *testing.T) { }, } gen.AddUncheckedReceipt(receipt) - gen.AddUncheckedTx(types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155)) + gen.AddUncheckedTx(types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil)) case 2: receipt := types.NewReceipt(nil, false, 0) receipt.Logs = []*types.Log{ @@ -137,7 +137,7 @@ func TestFilters(t *testing.T) { }, } gen.AddUncheckedReceipt(receipt) - gen.AddUncheckedTx(types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155)) + gen.AddUncheckedTx(types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil)) case 998: receipt := types.NewReceipt(nil, false, 0) @@ -148,7 +148,7 @@ func TestFilters(t *testing.T) { }, } gen.AddUncheckedReceipt(receipt) - gen.AddUncheckedTx(types.NewTransaction(998, common.HexToAddress("0x998"), big.NewInt(998), 998, big.NewInt(998), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155)) + gen.AddUncheckedTx(types.NewTransaction(998, common.HexToAddress("0x998"), big.NewInt(998), 998, big.NewInt(998), nil)) case 999: receipt := types.NewReceipt(nil, false, 0) receipt.Logs = []*types.Log{ @@ -158,7 +158,7 @@ func TestFilters(t *testing.T) { }, } gen.AddUncheckedReceipt(receipt) - gen.AddUncheckedTx(types.NewTransaction(999, common.HexToAddress("0x999"), big.NewInt(999), 999, big.NewInt(999), nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155)) + gen.AddUncheckedTx(types.NewTransaction(999, common.HexToAddress("0x999"), big.NewInt(999), 999, big.NewInt(999), nil)) } }) for i, block := range chain { diff --git a/eth/handler_test.go b/eth/handler_test.go index 6c80d5771f6e..3934a69aa291 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -288,13 +288,13 @@ func testGetNodeData(t *testing.T, protocol int) { switch i { case 0: // In block 1, the test bank sends account #1 some ether. - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey) block.AddTx(tx) case 1: // In block 2, the test bank sends some more ether to account #1. // acc1Addr passes it on to account #2. - tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) - tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, acc1Key) + tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, testBankKey) + tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, acc1Key) block.AddTx(tx1) block.AddTx(tx2) case 2: @@ -387,13 +387,13 @@ func testGetReceipt(t *testing.T, protocol int) { switch i { case 0: // In block 1, the test bank sends account #1 some ether. - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey) block.AddTx(tx) case 1: // In block 2, the test bank sends some more ether to account #1. // acc1Addr passes it on to account #2. - tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) - tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, acc1Key) + tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, testBankKey) + tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, acc1Key) block.AddTx(tx1) block.AddTx(tx2) case 2: diff --git a/eth/helper_test.go b/eth/helper_test.go index a531fbf8a3d2..e66910334f17 100644 --- a/eth/helper_test.go +++ b/eth/helper_test.go @@ -132,7 +132,7 @@ func (p *testTxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subs // newTestTransaction create a new dummy transaction. func newTestTransaction(from *ecdsa.PrivateKey, nonce uint64, datasize int) *types.Transaction { - tx := types.NewTransaction(nonce, common.Address{}, big.NewInt(0), 100000, big.NewInt(0), make([]byte, datasize), nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + tx := types.NewTransaction(nonce, common.Address{}, big.NewInt(0), 100000, big.NewInt(0), make([]byte, datasize)) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, from) return tx } diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go index a09ef1b7962d..3ff53d62bbaf 100644 --- a/eth/tracers/tracers_test.go +++ b/eth/tracers/tracers_test.go @@ -123,7 +123,7 @@ type callTracerTest struct { func TestPrestateTracerCreate2(t *testing.T) { t.Skip("OVM breaks this with `cannot read property` error, probably related to state manager.") - unsignedTx := types.NewTransaction(1, common.HexToAddress("0x00000000000000000000000000000000deadbeef"), new(big.Int), 5000000, big.NewInt(1), []byte{}, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + unsignedTx := types.NewTransaction(1, common.HexToAddress("0x00000000000000000000000000000000deadbeef"), new(big.Int), 5000000, big.NewInt(1), []byte{}) privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) if err != nil { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 38ff3f1715d8..1779e5b9c51a 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1562,9 +1562,15 @@ func (args *SendTxArgs) toTransaction() *types.Transaction { input = *args.Data } if args.To == nil { - return types.NewContractCreation(uint64(*args.Nonce), (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, nil, args.L1BlockNumber, types.QueueOriginSequencer) + tx := types.NewContractCreation(uint64(*args.Nonce), (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input) + txMeta := types.NewTransactionMeta(args.L1BlockNumber, 0, nil, types.SighashEIP155, types.QueueOriginSequencer, nil, nil) + tx.SetTransactionMeta(txMeta) + return tx } - return types.NewTransaction(uint64(*args.Nonce), *args.To, (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, args.L1MessageSender, args.L1BlockNumber, types.QueueOriginSequencer, args.SignatureHashType) + tx := types.NewTransaction(uint64(*args.Nonce), *args.To, (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input) + txMeta := types.NewTransactionMeta(args.L1BlockNumber, 0, args.L1MessageSender, args.SignatureHashType, types.QueueOriginSequencer, nil, nil) + tx.SetTransactionMeta(txMeta) + return tx } // SubmitTransaction is a helper function that submits tx to txPool and logs a message. @@ -1661,8 +1667,8 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod return common.Hash{}, errors.New("Gas price must be a multiple of 1,000,000 wei") } // L1Timestamp and L1BlockNumber will be set by the miner - meta := types.NewTransactionMeta(nil, 0, nil, types.SighashEIP155, types.QueueOriginSequencer) - tx.SetTransactionMeta(meta) + txMeta := types.NewTransactionMeta(nil, 0, nil, types.SighashEIP155, types.QueueOriginSequencer, nil, nil) + tx.SetTransactionMeta(txMeta) return SubmitTransaction(ctx, s.b, tx) } @@ -1688,8 +1694,8 @@ func (s *PublicTransactionPoolAPI) SendRawEthSignTransaction(ctx context.Context return common.Hash{}, errors.New("Gas price must be a multiple of 1,000,000 wei") } // L1Timestamp and L1BlockNumber will be set by the miner - meta := types.NewTransactionMeta(nil, 0, nil, types.SighashEthSign, types.QueueOriginSequencer) - tx.SetTransactionMeta(meta) + txMeta := types.NewTransactionMeta(nil, 0, nil, types.SighashEthSign, types.QueueOriginSequencer, nil, nil) + tx.SetTransactionMeta(txMeta) return SubmitTransaction(ctx, s.b, tx) } diff --git a/les/benchmark.go b/les/benchmark.go index a6f2075ca4e1..42eeef10f3b8 100644 --- a/les/benchmark.go +++ b/les/benchmark.go @@ -180,7 +180,7 @@ func (b *benchmarkTxSend) init(h *serverHandler, count int) error { for i := range b.txs { data := make([]byte, txSizeCostLimit) rand.Read(data) - tx, err := types.SignTx(types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, key) + tx, err := types.SignTx(types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), data), signer, key) if err != nil { panic(err) } diff --git a/les/test_helper.go b/les/test_helper.go index 8eef1ce22333..fb1965eebe90 100644 --- a/les/test_helper.go +++ b/les/test_helper.go @@ -112,43 +112,43 @@ func prepare(n int, backend *backends.SimulatedBackend) { registrarAddr, _, _, _ = contract.DeployCheckpointOracle(bind.NewKeyedTransactor(bankKey), backend, []common.Address{signerAddr}, sectionSize, processConfirms, big.NewInt(1)) // bankUser transfers some ether to user1 nonce, _ := backend.PendingNonceAt(ctx, bankAddr) - tx, _ := types.SignTx(types.NewTransaction(nonce, userAddr1, big.NewInt(10000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, bankKey) + tx, _ := types.SignTx(types.NewTransaction(nonce, userAddr1, big.NewInt(10000), params.TxGas, nil, nil), signer, bankKey) backend.SendTransaction(ctx, tx) case 1: bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr) userNonce1, _ := backend.PendingNonceAt(ctx, userAddr1) // bankUser transfers more ether to user1 - tx1, _ := types.SignTx(types.NewTransaction(bankNonce, userAddr1, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, bankKey) + tx1, _ := types.SignTx(types.NewTransaction(bankNonce, userAddr1, big.NewInt(1000), params.TxGas, nil, nil), signer, bankKey) backend.SendTransaction(ctx, tx1) // user1 relays ether to user2 - tx2, _ := types.SignTx(types.NewTransaction(userNonce1, userAddr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, userKey1) + tx2, _ := types.SignTx(types.NewTransaction(userNonce1, userAddr2, big.NewInt(1000), params.TxGas, nil, nil), signer, userKey1) backend.SendTransaction(ctx, tx2) // user1 deploys a test contract - tx3, _ := types.SignTx(types.NewContractCreation(userNonce1+1, big.NewInt(0), 200000, big.NewInt(0), testContractCode, nil, nil, types.QueueOriginSequencer), signer, userKey1) + tx3, _ := types.SignTx(types.NewContractCreation(userNonce1+1, big.NewInt(0), 200000, big.NewInt(0), testContractCode), signer, userKey1) backend.SendTransaction(ctx, tx3) testContractAddr = crypto.CreateAddress(userAddr1, userNonce1+1) // user1 deploys a event contract - tx4, _ := types.SignTx(types.NewContractCreation(userNonce1+2, big.NewInt(0), 200000, big.NewInt(0), testEventEmitterCode, nil, nil, types.QueueOriginSequencer), signer, userKey1) + tx4, _ := types.SignTx(types.NewContractCreation(userNonce1+2, big.NewInt(0), 200000, big.NewInt(0), testEventEmitterCode), signer, userKey1) backend.SendTransaction(ctx, tx4) case 2: // bankUser transfer some ether to signer bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr) - tx1, _ := types.SignTx(types.NewTransaction(bankNonce, signerAddr, big.NewInt(1000000000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, bankKey) + tx1, _ := types.SignTx(types.NewTransaction(bankNonce, signerAddr, big.NewInt(1000000000), params.TxGas, nil, nil), signer, bankKey) backend.SendTransaction(ctx, tx1) // invoke test contract data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001") - tx2, _ := types.SignTx(types.NewTransaction(bankNonce+1, testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, bankKey) + tx2, _ := types.SignTx(types.NewTransaction(bankNonce+1, testContractAddr, big.NewInt(0), 100000, nil, data), signer, bankKey) backend.SendTransaction(ctx, tx2) case 3: // invoke test contract bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr) data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002") - tx, _ := types.SignTx(types.NewTransaction(bankNonce, testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, bankKey) + tx, _ := types.SignTx(types.NewTransaction(bankNonce, testContractAddr, big.NewInt(0), 100000, nil, data), signer, bankKey) backend.SendTransaction(ctx, tx) } backend.Commit() diff --git a/light/odr_test.go b/light/odr_test.go index 2a2c1a667149..387f705b0315 100644 --- a/light/odr_test.go +++ b/light/odr_test.go @@ -212,17 +212,17 @@ func testChainGen(i int, block *core.BlockGen) { switch i { case 0: // In block 1, the test bank sends account #1 some ether. - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey) block.AddTx(tx) case 1: // In block 2, the test bank sends some more ether to account #1. // acc1Addr passes it on to account #2. // acc1Addr creates a test contract. - tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, testBankKey) nonce := block.TxNonce(acc1Addr) - tx2, _ := types.SignTx(types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, acc1Key) + tx2, _ := types.SignTx(types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, acc1Key) nonce++ - tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), 1000000, big.NewInt(0), testContractCode, nil, nil, types.QueueOriginSequencer), signer, acc1Key) + tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), 1000000, big.NewInt(0), testContractCode), signer, acc1Key) testContractAddr = crypto.CreateAddress(acc1Addr, nonce) block.AddTx(tx1) block.AddTx(tx2) @@ -232,7 +232,7 @@ func testChainGen(i int, block *core.BlockGen) { block.SetCoinbase(acc2Addr) block.SetExtra([]byte("yeehaw")) data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001") - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data), signer, testBankKey) block.AddTx(tx) case 3: // Block 4 includes blocks 2 and 3 as uncle headers (with modified extra data). @@ -243,7 +243,7 @@ func testChainGen(i int, block *core.BlockGen) { b3.Extra = []byte("foo") block.AddUncle(b3) data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002") - tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), signer, testBankKey) + tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data), signer, testBankKey) block.AddTx(tx) } } diff --git a/light/txpool_test.go b/light/txpool_test.go index 4ea8ca1a456c..0996bd7c9cc0 100644 --- a/light/txpool_test.go +++ b/light/txpool_test.go @@ -77,7 +77,7 @@ func txPoolTestChainGen(i int, block *core.BlockGen) { func TestTxPool(t *testing.T) { for i := range testTx { - testTx[i], _ = types.SignTx(types.NewTransaction(uint64(i), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, testBankKey) + testTx[i], _ = types.SignTx(types.NewTransaction(uint64(i), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) } var ( diff --git a/miner/worker_test.go b/miner/worker_test.go index c00e7da3b7cb..730236eb9b3e 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -83,9 +83,9 @@ func init() { Period: 10, Epoch: 30000, } - tx1, _ := types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, testBankKey) + tx1, _ := types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) pendingTxs = append(pendingTxs, tx1) - tx2, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, testBankKey) + tx2, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) newTxs = append(newTxs, tx2) rand.Seed(time.Now().UnixNano()) } @@ -173,9 +173,9 @@ func (b *testWorkerBackend) newRandomUncle() *types.Block { func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction { var tx *types.Transaction if creation { - tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode), nil, nil, types.QueueOriginSequencer), types.HomesteadSigner{}, testBankKey) + tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode)), types.HomesteadSigner{}, testBankKey) } else { - tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, types.QueueOriginSequencer, types.SighashEIP155), types.HomesteadSigner{}, testBankKey) + tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil), types.HomesteadSigner{}, testBankKey) } return tx } diff --git a/mobile/types.go b/mobile/types.go index 8819c98650af..97ada4d84a68 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -201,9 +201,9 @@ type Transaction struct { // can be created by transacting with a nil recipient. func NewTransaction(nonce int64, to *Address, amount *BigInt, gasLimit int64, gasPrice *BigInt, data []byte) *Transaction { if to == nil { - return &Transaction{types.NewContractCreation(uint64(nonce), amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data), nil, nil, types.QueueOriginSequencer)} + return &Transaction{types.NewContractCreation(uint64(nonce), amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data))} } - return &Transaction{types.NewTransaction(uint64(nonce), to.address, amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data), nil, nil, types.QueueOriginSequencer, types.SighashEIP155)} + return &Transaction{types.NewTransaction(uint64(nonce), to.address, amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data))} } // NewTransactionFromRLP parses a transaction from an RLP data dump. diff --git a/rollup/client.go b/rollup/client.go index 369f623d7961..9704b81c5bd7 100644 --- a/rollup/client.go +++ b/rollup/client.go @@ -179,20 +179,20 @@ func enqueueToTransaction(enqueue *Enqueue) (*types.Transaction, error) { data := *enqueue.Data value := big.NewInt(0) - tx := types.NewTransaction(nonce, target, value, gasLimit, big.NewInt(0), data, &origin, blockNumber, types.QueueOriginL1ToL2, types.SighashEIP155) + tx := types.NewTransaction(nonce, target, value, gasLimit, big.NewInt(0), data) // The index does not get a check as it is allowed to be nil in the context // of an enqueue transaction that has yet to be included into the CTC - meta := types.TransactionMeta{ - L1BlockNumber: blockNumber, - L1Timestamp: timestamp, - L1MessageSender: &origin, - SignatureHashType: types.SighashEIP155, - QueueOrigin: big.NewInt(int64(types.QueueOriginL1ToL2)), - Index: enqueue.Index, - QueueIndex: enqueue.QueueIndex, - } - tx.SetTransactionMeta(&meta) + txMeta := types.NewTransactionMeta( + blockNumber, + timestamp, + &origin, + types.SighashEIP155, + types.QueueOriginL1ToL2, + enqueue.Index, + enqueue.QueueIndex, + ) + tx.SetTransactionMeta(txMeta) return tx, nil } @@ -255,26 +255,24 @@ func transactionResponseToTransaction(res *TransactionResponse, signer *types.OV gasLimit := res.Transaction.Decoded.GasLimit gasPrice := new(big.Int).SetUint64(res.Transaction.Decoded.GasPrice) data := res.Transaction.Decoded.Data - l1MessageSender := res.Transaction.Origin - l1BlockNumber := new(big.Int).SetUint64(res.Transaction.BlockNumber) var tx *types.Transaction if to == (common.Address{}) { - tx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, data, l1MessageSender, l1BlockNumber, queueOrigin) + tx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, data) } else { - tx = types.NewTransaction(nonce, to, value, gasLimit, gasPrice, data, l1MessageSender, l1BlockNumber, queueOrigin, sighashType) + tx = types.NewTransaction(nonce, to, value, gasLimit, gasPrice, data) } - meta := types.TransactionMeta{ - L1BlockNumber: new(big.Int).SetUint64(res.Transaction.BlockNumber), - L1Timestamp: res.Transaction.Timestamp, - L1MessageSender: res.Transaction.Origin, - SignatureHashType: sighashType, - QueueOrigin: big.NewInt(int64(queueOrigin)), - Index: &res.Transaction.Index, - QueueIndex: res.Transaction.QueueIndex, - } - tx.SetTransactionMeta(&meta) + txMeta := types.NewTransactionMeta( + new(big.Int).SetUint64(res.Transaction.BlockNumber), + res.Transaction.Timestamp, + res.Transaction.Origin, + sighashType, + queueOrigin, + &res.Transaction.Index, + res.Transaction.QueueIndex, + ) + tx.SetTransactionMeta(txMeta) r, s := res.Transaction.Decoded.Signature.R, res.Transaction.Decoded.Signature.S sig := make([]byte, crypto.SignatureLength) @@ -303,19 +301,17 @@ func transactionResponseToTransaction(res *TransactionResponse, signer *types.OV gasLimit := res.Transaction.GasLimit data := res.Transaction.Data origin := res.Transaction.Origin - blockNumber := new(big.Int).SetUint64(res.Transaction.BlockNumber) - tx := types.NewTransaction(nonce, target, big.NewInt(0), gasLimit, big.NewInt(0), data, origin, blockNumber, types.QueueOriginL1ToL2, types.SighashEIP155) - - meta := types.TransactionMeta{ - L1BlockNumber: blockNumber, - L1Timestamp: res.Transaction.Timestamp, - L1MessageSender: origin, - SignatureHashType: sighashType, - QueueOrigin: big.NewInt(int64(queueOrigin)), - Index: &res.Transaction.Index, - QueueIndex: res.Transaction.QueueIndex, - } - tx.SetTransactionMeta(&meta) + tx := types.NewTransaction(nonce, target, big.NewInt(0), gasLimit, big.NewInt(0), data) + txMeta := types.NewTransactionMeta( + new(big.Int).SetUint64(res.Transaction.BlockNumber), + res.Transaction.Timestamp, + origin, + types.SighashEIP155, + types.QueueOriginL1ToL2, + &res.Transaction.Index, + res.Transaction.QueueIndex, + ) + tx.SetTransactionMeta(txMeta) return tx, nil } diff --git a/rollup/sync_service_test.go b/rollup/sync_service_test.go index 71a89d82a82d..fcef28bf26a6 100644 --- a/rollup/sync_service_test.go +++ b/rollup/sync_service_test.go @@ -44,17 +44,17 @@ func TestSyncServiceTransactionEnqueued(t *testing.T) { //The index in the ctc index := uint64(120) - tx := types.NewTransaction(0, target, big.NewInt(0), gasLimit, big.NewInt(0), data, &l1TxOrigin, l1BlockNumber, types.QueueOriginL1ToL2, types.SighashEIP155) - meta := types.TransactionMeta{ - L1BlockNumber: l1BlockNumber, - L1Timestamp: timestamp, - L1MessageSender: &l1TxOrigin, - SignatureHashType: types.SighashEIP155, - QueueOrigin: big.NewInt(int64(types.QueueOriginL1ToL2)), - Index: &index, - QueueIndex: &queueIndex, - } - tx.SetTransactionMeta(&meta) + tx := types.NewTransaction(0, target, big.NewInt(0), gasLimit, big.NewInt(0), data) + txMeta := types.NewTransactionMeta( + l1BlockNumber, + timestamp, + &l1TxOrigin, + types.SighashEIP155, + types.QueueOriginL1ToL2, + &index, + &queueIndex, + ) + tx.SetTransactionMeta(txMeta) setupMockClient(service, map[string]interface{}{ "GetEnqueue": []*types.Transaction{ @@ -95,17 +95,17 @@ func TestSyncServiceSync(t *testing.T) { l1BlockNumber := big.NewInt(100) queueIndex := uint64(0) index := uint64(0) - tx := types.NewTransaction(0, target, big.NewInt(0), gasLimit, big.NewInt(0), data, &l1TxOrigin, l1BlockNumber, types.QueueOriginL1ToL2, types.SighashEIP155) - meta := types.TransactionMeta{ - L1BlockNumber: l1BlockNumber, - L1Timestamp: timestamp, - L1MessageSender: &l1TxOrigin, - SignatureHashType: types.SighashEIP155, - QueueOrigin: big.NewInt(int64(types.QueueOriginL1ToL2)), - Index: &index, - QueueIndex: &queueIndex, - } - tx.SetTransactionMeta(&meta) + tx := types.NewTransaction(0, target, big.NewInt(0), gasLimit, big.NewInt(0), data) + txMeta := types.NewTransactionMeta( + l1BlockNumber, + timestamp, + &l1TxOrigin, + types.SighashEIP155, + types.QueueOriginL1ToL2, + &index, + &queueIndex, + ) + tx.SetTransactionMeta(txMeta) setupMockClient(service, map[string]interface{}{ "GetTransaction": []*types.Transaction{ @@ -140,17 +140,17 @@ func TestInitializeL1ContextPostGenesis(t *testing.T) { l1BlockNumber := big.NewInt(100) queueIndex := uint64(100) index := uint64(120) - tx := types.NewTransaction(0, target, big.NewInt(0), gasLimit, big.NewInt(0), data, &l1TxOrigin, l1BlockNumber, types.QueueOriginL1ToL2, types.SighashEIP155) - meta := types.TransactionMeta{ - L1BlockNumber: l1BlockNumber, - L1Timestamp: timestamp, - L1MessageSender: &l1TxOrigin, - SignatureHashType: types.SighashEIP155, - QueueOrigin: big.NewInt(int64(types.QueueOriginL1ToL2)), - Index: &index, - QueueIndex: &queueIndex, - } - tx.SetTransactionMeta(&meta) + tx := types.NewTransaction(0, target, big.NewInt(0), gasLimit, big.NewInt(0), data) + txMeta := types.NewTransactionMeta( + l1BlockNumber, + timestamp, + &l1TxOrigin, + types.SighashEIP155, + types.QueueOriginL1ToL2, + &index, + &queueIndex, + ) + tx.SetTransactionMeta(txMeta) setupMockClient(service, map[string]interface{}{ "GetEnqueue": []*types.Transaction{ diff --git a/signer/core/types.go b/signer/core/types.go index 5c9be493c293..0ab85d2ea53e 100644 --- a/signer/core/types.go +++ b/signer/core/types.go @@ -109,5 +109,8 @@ func (args *SendTxArgs) toTransaction() *types.Transaction { *l1BlockNumber = *args.L1BlockNumber } - return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input, l1MessageSender, l1BlockNumber, args.QueueOrigin, args.SignatureHashType) + tx := types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input) + txMeta := types.NewTransactionMeta(l1BlockNumber, 0, l1MessageSender, args.SignatureHashType, args.QueueOrigin, nil, nil) + tx.SetTransactionMeta(txMeta) + return tx } diff --git a/signer/rules/rules_test.go b/signer/rules/rules_test.go index 0247272db2db..c030ed47ceb1 100644 --- a/signer/rules/rules_test.go +++ b/signer/rules/rules_test.go @@ -458,7 +458,7 @@ func dummySigned(value *big.Int) *types.Transaction { gas := uint64(21000) gasPrice := big.NewInt(2000000) data := make([]byte, 0) - return types.NewTransaction(3, to, value, gas, gasPrice, data, nil, nil, types.QueueOriginSequencer, types.SighashEIP155) + return types.NewTransaction(3, to, value, gas, gasPrice, data) } func TestLimitWindow(t *testing.T) {