Adds L1RollupTxId on Transaction and Transaction-related objects (#10)

* Adding L1RollupTxId field to Transactions
* Adding rollup transactions signing key config and bug fixing within api.go. Signing key and endpoint will be removed when go handles batch fetching
This commit is contained in:
Will Meister 2020-07-31 08:55:48 -05:00 committed by GitHub
parent 83c7d841eb
commit 499c6b5c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 316 additions and 249 deletions

View File

@ -58,7 +58,7 @@ func TestSimulatedBackend(t *testing.T) {
// generate a transaction and confirm you can retrieve it // generate a transaction and confirm you can retrieve it
code := `6060604052600a8060106000396000f360606040526008565b00` code := `6060604052600a8060106000396000f360606040526008565b00`
var gas uint64 = 3000000 var gas uint64 = 3000000
tx := types.NewContractCreation(0, big.NewInt(0), gas, big.NewInt(1), common.FromHex(code), nil) tx := types.NewContractCreation(0, big.NewInt(0), gas, big.NewInt(1), common.FromHex(code), nil, nil)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, key) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, key)
err = sim.SendTransaction(context.Background(), tx) err = sim.SendTransaction(context.Background(), tx)
@ -246,7 +246,7 @@ func TestSimulatedBackend_NonceAt(t *testing.T) {
} }
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -281,7 +281,7 @@ func TestSimulatedBackend_SendTransaction(t *testing.T) {
bgCtx := context.Background() bgCtx := context.Background()
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -316,7 +316,7 @@ func TestSimulatedBackend_TransactionByHash(t *testing.T) {
bgCtx := context.Background() bgCtx := context.Background()
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -479,7 +479,7 @@ func TestSimulatedBackend_TransactionCount(t *testing.T) {
} }
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -538,7 +538,7 @@ func TestSimulatedBackend_TransactionInBlock(t *testing.T) {
} }
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -597,7 +597,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) {
} }
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -620,7 +620,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) {
} }
// make a new transaction with a nonce of 1 // 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) tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err = types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err = types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)
@ -653,7 +653,7 @@ func TestSimulatedBackend_TransactionReceipt(t *testing.T) {
bgCtx := context.Background() bgCtx := context.Background()
// create a signed transaction to send // create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil) tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil { if err != nil {
t.Errorf("could not sign tx: %v", err) t.Errorf("could not sign tx: %v", err)

View File

@ -227,9 +227,9 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
// Create the transaction, sign it and schedule it for execution // Create the transaction, sign it and schedule it for execution
var rawTx *types.Transaction var rawTx *types.Transaction
if contract == nil { if contract == nil {
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, nil) rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, nil, nil)
} else { } else {
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, nil) rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, nil, nil)
} }
if opts.Signer == nil { if opts.Signer == nil {
return nil, errors.New("no signer to authorize the transaction with") return nil, errors.New("no signer to authorize the transaction with")

View File

@ -62,7 +62,7 @@ func TestWaitDeployed(t *testing.T) {
defer backend.Close() defer backend.Close()
// Create the transaction. // Create the transaction.
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code), nil) tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code), nil, nil)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
// Wait for it to get mined in the background. // Wait for it to get mined in the background.

View File

@ -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).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)) 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) tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil)
signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID) signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID)
if err != nil { if err != nil {
f.lock.Unlock() f.lock.Unlock()

View File

@ -594,7 +594,7 @@ func (api *RetestethAPI) GetLogHash(ctx context.Context, txHash common.Hash) (co
} }
func (api *RetestethAPI) BlockNumber(ctx context.Context) (uint64, error) { func (api *RetestethAPI) BlockNumber(ctx context.Context) (uint64, error) {
//fmt.Printf("BlockNumber, response: %d\n", api.blockNumber) //fmt.Printf("SubmissionNumber, response: %d\n", api.blockNumber)
return api.blockNumber, nil return api.blockNumber, nil
} }

View File

@ -65,7 +65,7 @@ func TestReimportMirroredState(t *testing.T) {
// We want to simulate an empty middle block, having the same state as the // 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. // first one. The last is needs a state change again to force a reorg.
if i != 1 { if i != 1 {
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, nil, nil, nil), signer, key) tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, nil, nil, nil, nil), signer, key)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -86,7 +86,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
toaddr := common.Address{} toaddr := common.Address{}
data := make([]byte, nbytes) data := make([]byte, nbytes)
gas, _ := IntrinsicGas(data, false, false, false) gas, _ := IntrinsicGas(data, false, false, false)
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data, nil), types.HomesteadSigner{}, benchRootKey) tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data, nil, nil), types.HomesteadSigner{}, benchRootKey)
gen.AddTx(tx) gen.AddTx(tx)
} }
} }
@ -119,7 +119,7 @@ func genTxRing(naccounts int) func(int, *BlockGen) {
break break
} }
to := (from + 1) % naccounts to := (from + 1) % naccounts
tx := types.NewTransaction(gen.TxNonce(ringAddrs[from]), ringAddrs[to], benchRootFunds, params.TxGas, nil, nil, nil) tx := types.NewTransaction(gen.TxNonce(ringAddrs[from]), ringAddrs[to], benchRootFunds, params.TxGas, nil, nil, nil, nil)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, ringKeys[from]) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, ringKeys[from])
gen.AddTx(tx) gen.AddTx(tx)
from = to from = to

View File

@ -90,7 +90,7 @@ const (
// //
// - Version 4 // - Version 4
// The following incompatible database changes were added: // The following incompatible database changes were added:
// * the `BlockNumber`, `TxHash`, `TxIndex`, `BlockHash` and `Index` fields of log are deleted // * the `SubmissionNumber`, `TxHash`, `TxIndex`, `BlockHash` and `Index` fields of log are deleted
// * the `Bloom` field of receipt is deleted // * the `Bloom` field of receipt is deleted
// * the `BlockIndex` and `TxIndex` fields of txlookup are deleted // * the `BlockIndex` and `TxIndex` fields of txlookup are deleted
// - Version 5 // - Version 5

View File

@ -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 the block number is multiple of 3, send a few bonus transactions to the miner
if i%3 == 2 { if i%3 == 2 {
for j := 0; j < i%4+1; j++ { 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), signer, key) tx, err := types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{0x00}, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -840,8 +840,8 @@ func TestChainTxReorgs(t *testing.T) {
// Create two transactions shared between the chains: // Create two transactions shared between the chains:
// - postponed: transaction included at a later block in the forked chain // - postponed: transaction included at a later block in the forked chain
// - swapped: transaction included at the same block number 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), signer, key1) postponed, _ := types.SignTx(types.NewTransaction(0, addr1, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key1)
swapped, _ := types.SignTx(types.NewTransaction(1, addr1, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key1) swapped, _ := types.SignTx(types.NewTransaction(1, addr1, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key1)
// Create two transactions that will be dropped by the forked chain: // Create two transactions that will be dropped by the forked chain:
// - pastDrop: transaction dropped retroactively from a past block // - 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) { chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {
switch i { switch i {
case 0: case 0:
pastDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key2) pastDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key2)
gen.AddTx(pastDrop) // This transaction will be dropped in the fork from below the split point 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 gen.AddTx(postponed) // This transaction will be postponed till block #3 in the fork
case 2: case 2:
freshDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key2) freshDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key2)
gen.AddTx(freshDrop) // This transaction will be dropped in the fork from exactly at the split point 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 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) { chain, _ = GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 5, func(i int, gen *BlockGen) {
switch i { switch i {
case 0: case 0:
pastAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key3) pastAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key3)
gen.AddTx(pastAdd) // This transaction needs to be injected during reorg gen.AddTx(pastAdd) // This transaction needs to be injected during reorg
case 2: case 2:
gen.AddTx(postponed) // This transaction was postponed from block #1 in the original chain 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 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), signer, key3) freshAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key3)
gen.AddTx(freshAdd) // This transaction will be added exactly at reorg time gen.AddTx(freshAdd) // This transaction will be added exactly at reorg time
case 3: case 3:
futureAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key3) futureAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key3)
gen.AddTx(futureAdd) // This transaction will be added after a full reorg gen.AddTx(futureAdd) // This transaction will be added after a full reorg
} }
}) })
@ -949,7 +949,7 @@ func TestLogReorgs(t *testing.T) {
blockchain.SubscribeRemovedLogsEvent(rmLogsCh) blockchain.SubscribeRemovedLogsEvent(rmLogsCh)
chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) {
if i == 1 { if i == 1 {
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil), signer, key1) tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil), signer, key1)
if err != nil { if err != nil {
t.Fatalf("failed to create tx: %v", err) t.Fatalf("failed to create tx: %v", err)
} }
@ -1042,7 +1042,7 @@ func TestLogRebirth(t *testing.T) {
chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) {
if i == 1 { if i == 1 {
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil), signer, key1) tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil), signer, key1)
if err != nil { if err != nil {
t.Fatalf("failed to create tx: %v", err) t.Fatalf("failed to create tx: %v", err)
} }
@ -1062,7 +1062,7 @@ func TestLogRebirth(t *testing.T) {
// Generate long reorg chain // Generate long reorg chain
forkChain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { forkChain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) {
if i == 1 { if i == 1 {
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil), signer, key1) tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil), signer, key1)
if err != nil { if err != nil {
t.Fatalf("failed to create tx: %v", err) t.Fatalf("failed to create tx: %v", err)
} }
@ -1162,7 +1162,7 @@ func TestSideLogRebirth(t *testing.T) {
// Generate side chain with lower difficulty // Generate side chain with lower difficulty
sideChain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { sideChain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) {
if i == 1 { if i == 1 {
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil), signer, key1) tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), code, nil, nil), signer, key1)
if err != nil { if err != nil {
t.Fatalf("failed to create tx: %v", err) t.Fatalf("failed to create tx: %v", err)
} }
@ -1207,7 +1207,7 @@ func TestReorgSideEvent(t *testing.T) {
} }
replacementBlocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 4, func(i int, gen *BlockGen) { 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), signer, key1) tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), nil, nil, nil), signer, key1)
if i == 2 { if i == 2 {
gen.OffsetTime(-9) gen.OffsetTime(-9)
} }
@ -1338,7 +1338,7 @@ func TestEIP155Transition(t *testing.T) {
tx *types.Transaction tx *types.Transaction
err error err error
basicTx = func(signer types.Signer) (*types.Transaction, 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), signer, key) return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil, nil, nil), signer, key)
} }
) )
switch i { switch i {
@ -1401,7 +1401,7 @@ func TestEIP155Transition(t *testing.T) {
tx *types.Transaction tx *types.Transaction
err error err error
basicTx = func(signer types.Signer) (*types.Transaction, 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), signer, key) return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil, nil, nil), signer, key)
} }
) )
if i == 0 { if i == 0 {
@ -1449,11 +1449,11 @@ func TestEIP161AccountRemoval(t *testing.T) {
) )
switch i { switch i {
case 0: case 0:
tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil), signer, key) tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil, nil), signer, key)
case 1: case 1:
tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil), signer, key) tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil, nil), signer, key)
case 2: case 2:
tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil), signer, key) tx, err = types.SignTx(types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), 21000, new(big.Int), nil, nil, nil), signer, key)
} }
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -2162,7 +2162,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
for txi := 0; txi < numTxs; txi++ { for txi := 0; txi < numTxs; txi++ {
uniq := uint64(i*numTxs + txi) uniq := uint64(i*numTxs + txi)
recipient := recipientFn(uniq) recipient := recipientFn(uniq)
tx, err := types.SignTx(types.NewTransaction(uniq, recipient, big.NewInt(1), params.TxGas, big.NewInt(1), nil, nil), signer, testBankKey) tx, err := types.SignTx(types.NewTransaction(uniq, recipient, big.NewInt(1), params.TxGas, big.NewInt(1), nil, nil, nil), signer, testBankKey)
if err != nil { if err != nil {
b.Error(err) b.Error(err)
} }
@ -2342,10 +2342,10 @@ func TestDeleteCreateRevert(t *testing.T) {
blocks, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 1, func(i int, b *BlockGen) { blocks, _ := GenerateChain(params.TestChainConfig, genesis, engine, db, 1, func(i int, b *BlockGen) {
b.SetCoinbase(common.Address{1}) b.SetCoinbase(common.Address{1})
// One transaction to AAAA // One transaction to AAAA
tx, _ := types.SignTx(types.NewTransaction(0, aa, big.NewInt(0), 50000, big.NewInt(1), nil, nil), types.HomesteadSigner{}, key) tx, _ := types.SignTx(types.NewTransaction(0, aa, big.NewInt(0), 50000, big.NewInt(1), nil, nil, nil), types.HomesteadSigner{}, key)
b.AddTx(tx) b.AddTx(tx)
// One transaction to BBBB // One transaction to BBBB
tx, _ = types.SignTx(types.NewTransaction(1, bb, big.NewInt(0), 100000, big.NewInt(1), nil, nil), types.HomesteadSigner{}, key) tx, _ = types.SignTx(types.NewTransaction(1, bb, big.NewInt(0), 100000, big.NewInt(1), nil, nil, nil), types.HomesteadSigner{}, key)
b.AddTx(tx) b.AddTx(tx)
}) })
// Import the canonical chain // Import the canonical chain

View File

@ -54,13 +54,13 @@ func ExampleGenerateChain() {
switch i { switch i {
case 0: case 0:
// In block 1, addr1 sends addr2 some ether. // In block 1, addr1 sends addr2 some ether.
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil, nil), signer, key1) tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), signer, key1)
gen.AddTx(tx) gen.AddTx(tx)
case 1: case 1:
// In block 2, addr1 sends some more ether to addr2. // In block 2, addr1 sends some more ether to addr2.
// addr2 passes it on to addr3. // addr2 passes it on to addr3.
tx1, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key1) tx1, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key1)
tx2, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, key2) tx2, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, key2)
gen.AddTx(tx1) gen.AddTx(tx1)
gen.AddTx(tx2) gen.AddTx(tx2)
case 2: case 2:

View File

@ -273,8 +273,8 @@ func TestBlockReceiptStorage(t *testing.T) {
db := NewMemoryDatabase() db := NewMemoryDatabase()
// Create a live block since we need metadata to reconstruct the receipt // 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) tx1 := types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil)
tx2 := types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil) tx2 := types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil, nil)
body := &types.Body{Transactions: types.Transactions{tx1, tx2}} body := &types.Body{Transactions: types.Transactions{tx1, tx2}}

View File

@ -89,6 +89,7 @@ func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, com
return tx, blockHash, *blockNumber, uint64(txIndex) return tx, blockHash, *blockNumber, uint64(txIndex)
} }
} }
log.Error("Transaction not found", "number", blockNumber, "hash", blockHash, "txhash", hash) log.Error("Transaction not found", "number", blockNumber, "hash", blockHash, "txhash", hash)
return nil, common.Hash{}, 0, 0 return nil, common.Hash{}, 0, 0
} }

View File

@ -20,6 +20,8 @@ import (
"math/big" "math/big"
"testing" "testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
@ -69,9 +71,12 @@ func TestLookupStorage(t *testing.T) {
sender1 := common.BytesToAddress([]byte{0x44}) sender1 := common.BytesToAddress([]byte{0x44})
sender2 := common.BytesToAddress([]byte{0x55}) sender2 := common.BytesToAddress([]byte{0x55})
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}, &sender1) l1RollupTxId1 := hexutil.Uint64(1)
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}, &sender2) l1RollupTxId2 := hexutil.Uint64(2)
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}, nil)
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}, &sender1, &l1RollupTxId1)
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}, &sender2, &l1RollupTxId2)
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}, nil, &l1RollupTxId1)
txs := []*types.Transaction{tx1, tx2, tx3} txs := []*types.Transaction{tx1, tx2, tx3}
block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, nil) block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, nil)

View File

@ -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 { 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), types.HomesteadSigner{}, key) tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(100), gaslimit, gasprice, nil, nil, nil), types.HomesteadSigner{}, key)
return tx return tx
} }
@ -81,7 +81,7 @@ func pricedDataTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key
data := make([]byte, bytes) data := make([]byte, bytes)
rand.Read(data) rand.Read(data)
tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(0), gaslimit, gasprice, data, nil), types.HomesteadSigner{}, key) tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(0), gaslimit, gasprice, data, nil, nil), types.HomesteadSigner{}, key)
return tx return tx
} }
@ -329,7 +329,7 @@ func TestTransactionNegativeValue(t *testing.T) {
pool, key := setupTxPool() pool, key := setupTxPool()
defer pool.Stop() defer pool.Stop()
tx, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(-1), 100, big.NewInt(1), nil, nil), types.HomesteadSigner{}, key) tx, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(-1), 100, big.NewInt(1), nil, nil, nil), types.HomesteadSigner{}, key)
from, _ := deriveSender(tx) from, _ := deriveSender(tx)
pool.currentState.AddBalance(from, big.NewInt(1)) pool.currentState.AddBalance(from, big.NewInt(1))
if err := pool.AddRemote(tx); err != ErrNegativeValue { if err := pool.AddRemote(tx); err != ErrNegativeValue {
@ -383,9 +383,9 @@ func TestTransactionDoubleNonce(t *testing.T) {
resetState() resetState()
signer := types.HomesteadSigner{} signer := types.HomesteadSigner{}
tx1, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 100000, big.NewInt(1), nil, nil), signer, key) tx1, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 100000, big.NewInt(1), nil, nil, nil), signer, key)
tx2, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(2), nil, nil), signer, key) tx2, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(2), nil, nil, nil), signer, key)
tx3, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(1), nil, nil), signer, key) tx3, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(100), 1000000, big.NewInt(1), nil, nil, nil), signer, key)
// Add the first two transaction, ensure higher priced stays only // Add the first two transaction, ensure higher priced stays only
if replace, err := pool.add(tx1, false); err != nil || replace { if replace, err := pool.add(tx1, false); err != nil || replace {

View File

@ -50,7 +50,7 @@ func TestBlockEncoding(t *testing.T) {
check("Time", block.Time(), uint64(1426516743)) check("Time", block.Time(), uint64(1426516743))
check("Size", block.Size(), common.StorageSize(len(blockEnc))) check("Size", block.Size(), common.StorageSize(len(blockEnc)))
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil, nil) tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil, nil, nil)
tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100")) tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100"))
check("len(Transactions)", len(block.Transactions()), 1) check("len(Transactions)", len(block.Transactions()), 1)
check("Transactions[0].Hash", block.Transactions()[0].Hash(), tx1.Hash()) check("Transactions[0].Hash", block.Transactions()[0].Hash(), tx1.Hash())

View File

@ -26,6 +26,7 @@ func (t txdata) MarshalJSON() ([]byte, error) {
R *hexutil.Big `json:"r" gencodec:"required"` R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"` S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"` Hash *common.Hash `json:"hash" rlp:"-"`
L1RollupTxId *hexutil.Uint64 `json:"l1RollupTxId,omitempty" rlp:"nil,?"`
L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"` L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"`
} }
var enc txdata var enc txdata
@ -34,6 +35,7 @@ func (t txdata) MarshalJSON() ([]byte, error) {
enc.GasLimit = hexutil.Uint64(t.GasLimit) enc.GasLimit = hexutil.Uint64(t.GasLimit)
enc.Recipient = t.Recipient enc.Recipient = t.Recipient
enc.L1MessageSender = t.L1MessageSender enc.L1MessageSender = t.L1MessageSender
enc.L1RollupTxId = t.L1RollupTxId
enc.Amount = (*hexutil.Big)(t.Amount) enc.Amount = (*hexutil.Big)(t.Amount)
enc.Payload = t.Payload enc.Payload = t.Payload
enc.V = (*hexutil.Big)(t.V) enc.V = (*hexutil.Big)(t.V)
@ -56,6 +58,7 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
R *hexutil.Big `json:"r" gencodec:"required"` R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"` S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"` Hash *common.Hash `json:"hash" rlp:"-"`
L1RollupTxId *hexutil.Uint64 `json:"l1RollupTxId,omitempty" rlp:"nil,?"`
L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"` L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"`
} }
var dec txdata var dec txdata
@ -80,6 +83,9 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
if dec.L1MessageSender != nil { if dec.L1MessageSender != nil {
t.L1MessageSender = dec.L1MessageSender t.L1MessageSender = dec.L1MessageSender
} }
if dec.L1RollupTxId != nil {
t.L1RollupTxId = dec.L1RollupTxId
}
if dec.Amount == nil { if dec.Amount == nil {
return errors.New("missing required field 'value' for txdata") return errors.New("missing required field 'value' for txdata")
} }

View File

@ -48,7 +48,7 @@ func TestLegacyReceiptDecoding(t *testing.T) {
}, },
} }
tx := NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil) tx := NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil)
receipt := &Receipt{ receipt := &Receipt{
Status: ReceiptStatusFailed, Status: ReceiptStatusFailed,
CumulativeGasUsed: 1, CumulativeGasUsed: 1,
@ -155,8 +155,8 @@ func encodeAsV3StoredReceiptRLP(want *Receipt) ([]byte, error) {
func TestDeriveFields(t *testing.T) { func TestDeriveFields(t *testing.T) {
// Create a few transactions to have receipts for // Create a few transactions to have receipts for
txs := Transactions{ txs := Transactions{
NewContractCreation(1, big.NewInt(1), 1, big.NewInt(1), nil, nil), NewContractCreation(1, big.NewInt(1), 1, big.NewInt(1), nil, nil, nil),
NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil), NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil, nil),
} }
// Create the corresponding receipts // Create the corresponding receipts
receipts := Receipts{ receipts := Receipts{
@ -203,7 +203,7 @@ func TestDeriveFields(t *testing.T) {
t.Errorf("receipts[%d].BlockHash = %s, want %s", i, receipts[i].BlockHash.String(), hash.String()) t.Errorf("receipts[%d].BlockHash = %s, want %s", i, receipts[i].BlockHash.String(), hash.String())
} }
if receipts[i].BlockNumber.Cmp(number) != 0 { if receipts[i].BlockNumber.Cmp(number) != 0 {
t.Errorf("receipts[%c].BlockNumber = %s, want %s", i, receipts[i].BlockNumber.String(), number.String()) t.Errorf("receipts[%c].SubmissionNumber = %s, want %s", i, receipts[i].BlockNumber.String(), number.String())
} }
if receipts[i].TransactionIndex != uint(i) { if receipts[i].TransactionIndex != uint(i) {
t.Errorf("receipts[%d].TransactionIndex = %d, want %d", i, receipts[i].TransactionIndex, i) t.Errorf("receipts[%d].TransactionIndex = %d, want %d", i, receipts[i].TransactionIndex, i)
@ -221,7 +221,7 @@ func TestDeriveFields(t *testing.T) {
} }
for j := range receipts[i].Logs { for j := range receipts[i].Logs {
if receipts[i].Logs[j].BlockNumber != number.Uint64() { if receipts[i].Logs[j].BlockNumber != number.Uint64() {
t.Errorf("receipts[%d].Logs[%d].BlockNumber = %d, want %d", i, j, receipts[i].Logs[j].BlockNumber, number.Uint64()) t.Errorf("receipts[%d].Logs[%d].SubmissionNumber = %d, want %d", i, j, receipts[i].Logs[j].BlockNumber, number.Uint64())
} }
if receipts[i].Logs[j].BlockHash != hash { if receipts[i].Logs[j].BlockHash != hash {
t.Errorf("receipts[%d].Logs[%d].BlockHash = %s, want %s", i, j, receipts[i].Logs[j].BlockHash.String(), hash.String()) t.Errorf("receipts[%d].Logs[%d].BlockHash = %s, want %s", i, j, receipts[i].Logs[j].BlockHash.String(), hash.String())

View File

@ -59,6 +59,7 @@ type txdata struct {
// This is only used when marshaling to JSON. // This is only used when marshaling to JSON.
Hash *common.Hash `json:"hash" rlp:"-"` Hash *common.Hash `json:"hash" rlp:"-"`
L1RollupTxId *hexutil.Uint64 `json:"l1RollupTxId,omitempty" rlp:"nil,?"`
L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"` L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"`
} }
@ -73,15 +74,15 @@ type txdataMarshaling struct {
S *hexutil.Big S *hexutil.Big
} }
func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address) *Transaction { func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address, l1RollupTxId *hexutil.Uint64) *Transaction {
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data, l1MessageSender) return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data, l1MessageSender, l1RollupTxId)
} }
func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address) *Transaction { func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address, l1RollupTxId *hexutil.Uint64) *Transaction {
return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data, l1MessageSender) return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data, l1MessageSender, l1RollupTxId)
} }
func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address) *Transaction { func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, l1MessageSender *common.Address, l1RollupTxId *hexutil.Uint64) *Transaction {
if len(data) > 0 { if len(data) > 0 {
data = common.CopyBytes(data) data = common.CopyBytes(data)
} }
@ -89,6 +90,7 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
AccountNonce: nonce, AccountNonce: nonce,
Recipient: to, Recipient: to,
L1MessageSender: l1MessageSender, L1MessageSender: l1MessageSender,
L1RollupTxId: l1RollupTxId,
Payload: data, Payload: data,
Amount: new(big.Int), Amount: new(big.Int),
GasLimit: gasLimit, GasLimit: gasLimit,
@ -221,8 +223,18 @@ func (tx *Transaction) L1MessageSender() *common.Address {
if tx.data.L1MessageSender == nil { if tx.data.L1MessageSender == nil {
return nil return nil
} }
l1MessagSender := *tx.data.L1MessageSender l1MessageSender := *tx.data.L1MessageSender
return &l1MessagSender return &l1MessageSender
}
// L1RollupTxId returns the L1 Rollup Tx Id of the transaction if one exists.
// It returns nil if this transaction was not generated from a transaction received on L1.
func (tx *Transaction) L1RollupTxId() *hexutil.Uint64 {
if tx.data.L1RollupTxId == nil {
return nil
}
l1RolupTxId := *tx.data.L1RollupTxId
return &l1RolupTxId
} }
// Hash hashes the RLP encoding of tx. // Hash hashes the RLP encoding of tx.
@ -233,14 +245,18 @@ func (tx *Transaction) Hash() common.Hash {
} }
var sender *common.Address var sender *common.Address
var l1RollupTxId *hexutil.Uint64
if tx != nil { if tx != nil {
sender = tx.data.L1MessageSender sender = tx.data.L1MessageSender
tx.data.L1MessageSender = nil tx.data.L1MessageSender = nil
l1RollupTxId = tx.data.L1RollupTxId
tx.data.L1RollupTxId = nil
} }
v := rlpHash(tx) v := rlpHash(tx)
if tx != nil { if tx != nil {
tx.data.L1MessageSender = sender tx.data.L1MessageSender = sender
tx.data.L1RollupTxId = l1RollupTxId
} }
tx.hash.Store(v) tx.hash.Store(v)
return v return v
@ -270,6 +286,7 @@ func (tx *Transaction) AsMessage(s Signer) (Message, error) {
gasPrice: new(big.Int).Set(tx.data.Price), gasPrice: new(big.Int).Set(tx.data.Price),
to: tx.data.Recipient, to: tx.data.Recipient,
l1MessageSender: tx.data.L1MessageSender, l1MessageSender: tx.data.L1MessageSender,
l1RollupTxId: tx.data.L1RollupTxId,
amount: tx.data.Amount, amount: tx.data.Amount,
data: tx.data.Payload, data: tx.data.Payload,
checkNonce: true, checkNonce: true,
@ -435,6 +452,7 @@ func (t *TransactionsByPriceAndNonce) Pop() {
type Message struct { type Message struct {
to *common.Address to *common.Address
l1MessageSender *common.Address l1MessageSender *common.Address
l1RollupTxId *hexutil.Uint64
from common.Address from common.Address
nonce uint64 nonce uint64
amount *big.Int amount *big.Int
@ -444,7 +462,7 @@ type Message struct {
checkNonce bool checkNonce bool
} }
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, l1MessageSender *common.Address) Message { func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, l1MessageSender *common.Address, l1RollupTxId *hexutil.Uint64) Message {
return Message{ return Message{
from: from, from: from,
to: to, to: to,
@ -454,12 +472,15 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
gasPrice: gasPrice, gasPrice: gasPrice,
data: data, data: data,
checkNonce: checkNonce, checkNonce: checkNonce,
l1RollupTxId: l1RollupTxId,
l1MessageSender: l1MessageSender,
} }
} }
func (m Message) From() common.Address { return m.from } func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to } func (m Message) To() *common.Address { return m.to }
func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender } func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender }
func (m Message) L1RollupTxId() *hexutil.Uint64 { return m.l1RollupTxId }
func (m Message) GasPrice() *big.Int { return m.gasPrice } func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) Value() *big.Int { return m.amount } func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit } func (m Message) Gas() uint64 { return m.gasLimit }

View File

@ -30,7 +30,7 @@ func TestEIP155Signing(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
signer := NewEIP155Signer(big.NewInt(18)) signer := NewEIP155Signer(big.NewInt(18))
tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil), signer, key) tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil), signer, key)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -49,7 +49,7 @@ func TestEIP155ChainId(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
signer := NewEIP155Signer(big.NewInt(18)) signer := NewEIP155Signer(big.NewInt(18))
tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil), signer, key) tx, err := SignTx(NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil), signer, key)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -61,7 +61,7 @@ func TestEIP155ChainId(t *testing.T) {
t.Error("expected chainId to be", signer.chainId, "got", tx.ChainId()) t.Error("expected chainId to be", signer.chainId, "got", tx.ChainId())
} }
tx = NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil) tx = NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil, nil, nil)
tx, err = SignTx(tx, HomesteadSigner{}, key) tx, err = SignTx(tx, HomesteadSigner{}, key)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -118,7 +118,7 @@ func TestEIP155SigningVitalik(t *testing.T) {
func TestChainId(t *testing.T) { func TestChainId(t *testing.T) {
key, _ := defaultTestKey() key, _ := defaultTestKey()
tx := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil) tx := NewTransaction(0, common.Address{}, new(big.Int), 0, new(big.Int), nil, nil, nil)
var err error var err error
tx, err = SignTx(tx, NewEIP155Signer(big.NewInt(1)), key) tx, err = SignTx(tx, NewEIP155Signer(big.NewInt(1)), key)

View File

@ -23,6 +23,8 @@ import (
"math/big" "math/big"
"testing" "testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -32,15 +34,21 @@ import (
// at github.com/ethereum/tests. // at github.com/ethereum/tests.
var ( var (
sender = common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87") sender = common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87")
emptyTx = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, &sender) l1RollupTxId = hexutil.Uint64(1)
emptyTxEmptyL1Sender = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, nil) emptyTx = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, &sender, nil)
emptyTxEmptyL1Sender = NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(0), 0, big.NewInt(0), nil, nil, nil)
rightvrsTx, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), nil).WithSignature( rightvrsTx, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), nil, nil).WithSignature(
HomesteadSigner{}, HomesteadSigner{},
common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"), common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"),
) )
rightvrsTxWithL1Sender, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), &sender).WithSignature( rightvrsTxWithL1Sender, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), &sender, nil).WithSignature(
HomesteadSigner{},
common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"),
)
rightvrsTxWithL1RollupTxId, _ = NewTransaction(3, common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"), big.NewInt(10), 2000, big.NewInt(1), common.FromHex("5544"), nil, &l1RollupTxId).WithSignature(
HomesteadSigner{}, HomesteadSigner{},
common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"), common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"),
) )
@ -73,6 +81,14 @@ func TestTransactionEncode(t *testing.T) {
if bytes.Equal(txc, should) { if bytes.Equal(txc, should) {
t.Errorf("RLP encoding with L1MessageSender should be different than without. Got %x", txc) t.Errorf("RLP encoding with L1MessageSender should be different than without. Got %x", txc)
} }
txd, err := rlp.EncodeToBytes(rightvrsTxWithL1RollupTxId)
if err != nil {
t.Fatalf("encode error: %v", err)
}
if bytes.Equal(txd, should) {
t.Errorf("RLP encoding with L1MessageSender should be different than without. Got %x", txd)
}
} }
func decodeTx(data []byte) (*Transaction, error) { func decodeTx(data []byte) (*Transaction, error) {
@ -137,7 +153,7 @@ func TestTransactionPriceNonceSort(t *testing.T) {
for start, key := range keys { for start, key := range keys {
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
for i := 0; i < 25; i++ { 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), signer, key) tx, _ := SignTx(NewTransaction(uint64(start+i), common.Address{}, big.NewInt(100), 100, big.NewInt(int64(start+i)), nil, nil, nil), signer, key)
groups[addr] = append(groups[addr], tx) groups[addr] = append(groups[addr], tx)
} }
} }
@ -188,9 +204,9 @@ func TestTransactionJSON(t *testing.T) {
var tx *Transaction var tx *Transaction
switch i % 2 { switch i % 2 {
case 0: case 0:
tx = NewTransaction(i, common.Address{1}, common.Big0, 1, common.Big2, []byte("abcdef"), &sender) tx = NewTransaction(i, common.Address{1}, common.Big0, 1, common.Big2, []byte("abcdef"), &sender, &l1RollupTxId)
case 1: case 1:
tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef"), nil) tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef"), nil, nil)
} }
transactions = append(transactions, tx) transactions = append(transactions, tx)
@ -223,6 +239,9 @@ func TestTransactionJSON(t *testing.T) {
if tx.L1MessageSender() == nil && parsedTx.L1MessageSender() != nil || tx.L1MessageSender() != nil && parsedTx.L1MessageSender() == nil || (tx.L1MessageSender() != nil && parsedTx.L1MessageSender() != nil && *tx.L1MessageSender() != *parsedTx.L1MessageSender()) { if tx.L1MessageSender() == nil && parsedTx.L1MessageSender() != nil || tx.L1MessageSender() != nil && parsedTx.L1MessageSender() == nil || (tx.L1MessageSender() != nil && parsedTx.L1MessageSender() != nil && *tx.L1MessageSender() != *parsedTx.L1MessageSender()) {
t.Errorf("invalid L1MessageSender, want %x, got %x", tx.L1MessageSender(), parsedTx.L1MessageSender()) t.Errorf("invalid L1MessageSender, want %x, got %x", tx.L1MessageSender(), parsedTx.L1MessageSender())
} }
if tx.L1RollupTxId() == nil && parsedTx.L1RollupTxId() != nil || tx.L1RollupTxId() != nil && parsedTx.L1RollupTxId() == nil || (tx.L1RollupTxId() != nil && parsedTx.L1RollupTxId() != nil && *tx.L1RollupTxId() != *parsedTx.L1RollupTxId()) {
t.Errorf("invalid L1RollupTxId, want %x, got %x", tx.L1RollupTxId(), parsedTx.L1RollupTxId())
}
} }
} }
@ -232,6 +251,10 @@ func TestL1MessageSenderHash(t *testing.T) {
t.Errorf("L1MessageSender, should not affect the hash, want %x, got %x with L1MessageSender", rightvrsTx.Hash(), rightvrsTxWithL1Sender.Hash()) t.Errorf("L1MessageSender, should not affect the hash, want %x, got %x with L1MessageSender", rightvrsTx.Hash(), rightvrsTxWithL1Sender.Hash())
} }
if rightvrsTx.Hash() != rightvrsTxWithL1RollupTxId.Hash() {
t.Errorf("L1RollupTxId, should not affect the hash, want %x, got %x with L1RollupTxId", rightvrsTx.Hash(), rightvrsTxWithL1RollupTxId.Hash())
}
if emptyTx.Hash() != emptyTxEmptyL1Sender.Hash() { if emptyTx.Hash() != emptyTxEmptyL1Sender.Hash() {
t.Errorf("L1MessageSender, should not affect the hash, want %x, got %x with L1MessageSender", emptyTx.Hash(), emptyTxEmptyL1Sender.Hash()) t.Errorf("L1MessageSender, should not affect the hash, want %x, got %x with L1MessageSender", emptyTx.Hash(), emptyTxEmptyL1Sender.Hash())
} }

View File

@ -60,14 +60,6 @@ func Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
return secp256k1.Sign(digestHash, seckey) return secp256k1.Sign(digestHash, seckey)
} }
func VerifyMessageSignature(pubKey, unhashedMessage, signature []byte) bool {
if len(signature) < 64 || len(signature) > 65 {
// signature format may be [R || S] or [R || S || V]
return false
}
return VerifySignature(pubKey, Keccak256(unhashedMessage), signature[0:64])
}
// VerifySignature checks that the given public key created signature over digest. // VerifySignature checks that the given public key created signature over digest.
// The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. // The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format.
// The signature should have the 64 byte [R || S] format. // The signature should have the 64 byte [R || S] format.

View File

@ -18,7 +18,9 @@ package eth
import ( import (
"context" "context"
"encoding/hex"
"errors" "errors"
"fmt"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
@ -45,6 +47,14 @@ type EthAPIBackend struct {
gpo *gasprice.Oracle gpo *gasprice.Oracle
} }
func (b *EthAPIBackend) RollupTransactionSender() *common.Address {
// TODO: Fill out RollupTransactionsSender Address when we know it / get from env var
bites, _ := hex.DecodeString("6a399F0A626A505e2F6C2b5Da181d98D722dC86D")
addr := common.BytesToAddress(bites)
fmt.Printf("\n\n\nRollup Sender Address bytes: %x\nsender address: %x\n\n", string(bites), string(addr.Bytes()))
return &addr
}
// ChainConfig returns the active chain configuration. // ChainConfig returns the active chain configuration.
func (b *EthAPIBackend) ChainConfig() *params.ChainConfig { func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
return b.eth.blockchain.Config() return b.eth.blockchain.Config()

View File

@ -21,6 +21,8 @@ import (
"math/big" "math/big"
"sync" "sync"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -128,7 +130,8 @@ func (tc *testChain) generate(n int, seed byte, parent *types.Block, heavy bool)
if parent == tc.genesis && i%22 == 0 { if parent == tc.genesis && i%22 == 0 {
signer := types.MakeSigner(params.TestChainConfig, block.Number()) signer := types.MakeSigner(params.TestChainConfig, block.Number())
l1Sender := common.Address{seed} l1Sender := common.Address{seed}
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil, &l1Sender), signer, testKey) l1RollupTxId := hexutil.Uint64(22)
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil, &l1Sender, &l1RollupTxId), signer, testKey)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -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 the block number is multiple of 3, send a bonus transaction to the miner
if parent == genesis && i%3 == 0 { if parent == genesis && i%3 == 0 {
signer := types.MakeSigner(params.TestChainConfig, block.Number()) 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), signer, testKey) tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, testKey)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -218,11 +218,11 @@ func TestPendingTxFilter(t *testing.T) {
api = NewPublicFilterAPI(backend, false) api = NewPublicFilterAPI(backend, false)
transactions = []*types.Transaction{ transactions = []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil), types.NewTransaction(0, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil),
types.NewTransaction(1, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil), types.NewTransaction(1, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil),
types.NewTransaction(2, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil), types.NewTransaction(2, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil),
types.NewTransaction(3, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil), types.NewTransaction(3, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil),
types.NewTransaction(4, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil), types.NewTransaction(4, common.HexToAddress("0xb794f5ea0ba39494ce83a213fffba74279579268"), new(big.Int), 0, new(big.Int), nil, nil, nil),
} }
hashes []common.Hash hashes []common.Hash

View File

@ -127,7 +127,7 @@ func TestFilters(t *testing.T) {
}, },
} }
gen.AddUncheckedReceipt(receipt) gen.AddUncheckedReceipt(receipt)
gen.AddUncheckedTx(types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil)) gen.AddUncheckedTx(types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil, nil, nil))
case 2: case 2:
receipt := types.NewReceipt(nil, false, 0) receipt := types.NewReceipt(nil, false, 0)
receipt.Logs = []*types.Log{ receipt.Logs = []*types.Log{
@ -137,7 +137,7 @@ func TestFilters(t *testing.T) {
}, },
} }
gen.AddUncheckedReceipt(receipt) gen.AddUncheckedReceipt(receipt)
gen.AddUncheckedTx(types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil)) gen.AddUncheckedTx(types.NewTransaction(2, common.HexToAddress("0x2"), big.NewInt(2), 2, big.NewInt(2), nil, nil, nil))
case 998: case 998:
receipt := types.NewReceipt(nil, false, 0) receipt := types.NewReceipt(nil, false, 0)
@ -148,7 +148,7 @@ func TestFilters(t *testing.T) {
}, },
} }
gen.AddUncheckedReceipt(receipt) gen.AddUncheckedReceipt(receipt)
gen.AddUncheckedTx(types.NewTransaction(998, common.HexToAddress("0x998"), big.NewInt(998), 998, big.NewInt(998), nil, nil)) gen.AddUncheckedTx(types.NewTransaction(998, common.HexToAddress("0x998"), big.NewInt(998), 998, big.NewInt(998), nil, nil, nil))
case 999: case 999:
receipt := types.NewReceipt(nil, false, 0) receipt := types.NewReceipt(nil, false, 0)
receipt.Logs = []*types.Log{ receipt.Logs = []*types.Log{
@ -158,7 +158,7 @@ func TestFilters(t *testing.T) {
}, },
} }
gen.AddUncheckedReceipt(receipt) gen.AddUncheckedReceipt(receipt)
gen.AddUncheckedTx(types.NewTransaction(999, common.HexToAddress("0x999"), big.NewInt(999), 999, big.NewInt(999), nil, nil)) gen.AddUncheckedTx(types.NewTransaction(999, common.HexToAddress("0x999"), big.NewInt(999), 999, big.NewInt(999), nil, nil, nil))
} }
}) })
for i, block := range chain { for i, block := range chain {

View File

@ -288,13 +288,13 @@ func testGetNodeData(t *testing.T, protocol int) {
switch i { switch i {
case 0: case 0:
// In block 1, the test bank sends account #1 some ether. // 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), signer, testBankKey) tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), signer, testBankKey)
block.AddTx(tx) block.AddTx(tx)
case 1: case 1:
// In block 2, the test bank sends some more ether to account #1. // In block 2, the test bank sends some more ether to account #1.
// acc1Addr passes it on to account #2. // acc1Addr passes it on to account #2.
tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, testBankKey) tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, testBankKey)
tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, acc1Key) tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, acc1Key)
block.AddTx(tx1) block.AddTx(tx1)
block.AddTx(tx2) block.AddTx(tx2)
case 2: case 2:
@ -385,13 +385,13 @@ func testGetReceipt(t *testing.T, protocol int) {
switch i { switch i {
case 0: case 0:
// In block 1, the test bank sends account #1 some ether. // 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), signer, testBankKey) tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), signer, testBankKey)
block.AddTx(tx) block.AddTx(tx)
case 1: case 1:
// In block 2, the test bank sends some more ether to account #1. // In block 2, the test bank sends some more ether to account #1.
// acc1Addr passes it on to account #2. // acc1Addr passes it on to account #2.
tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, testBankKey) tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBank), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, testBankKey)
tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, acc1Key) tx2, _ := types.SignTx(types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, acc1Key)
block.AddTx(tx1) block.AddTx(tx1)
block.AddTx(tx2) block.AddTx(tx2)
case 2: case 2:

View File

@ -134,7 +134,7 @@ func (p *testTxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subs
// newTestTransaction create a new dummy transaction. // newTestTransaction create a new dummy transaction.
func newTestTransaction(from *ecdsa.PrivateKey, nonce uint64, datasize int) *types.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) tx := types.NewTransaction(nonce, common.Address{}, big.NewInt(0), 100000, big.NewInt(0), make([]byte, datasize), nil, nil)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, from) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, from)
return tx return tx
} }

View File

@ -121,7 +121,7 @@ type callTracerTest struct {
} }
func TestPrestateTracerCreate2(t *testing.T) { func TestPrestateTracerCreate2(t *testing.T) {
unsignedTx := types.NewTransaction(1, common.HexToAddress("0x00000000000000000000000000000000deadbeef"), new(big.Int), 5000000, big.NewInt(1), []byte{}, nil) unsignedTx := types.NewTransaction(1, common.HexToAddress("0x00000000000000000000000000000000deadbeef"), new(big.Int), 5000000, big.NewInt(1), []byte{}, nil, nil)
privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
if err != nil { if err != nil {

View File

@ -523,7 +523,7 @@ func (s *PublicBlockChainAPI) ChainId() *hexutil.Big {
return (*hexutil.Big)(s.b.ChainConfig().ChainID) return (*hexutil.Big)(s.b.ChainConfig().ChainID)
} }
// BlockNumber returns the block number of the chain head. // SubmissionNumber returns the block number of the chain head.
func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 { func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 {
header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available
return hexutil.Uint64(header.Number.Uint64()) return hexutil.Uint64(header.Number.Uint64())
@ -830,7 +830,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
} }
// Create new call message // Create new call message
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false, nil) msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false, nil, nil)
// Setup context so it may be cancelled the call has completed // Setup context so it may be cancelled the call has completed
// or, in case of unmetered gas, setup a context with a timeout. // or, in case of unmetered gas, setup a context with a timeout.
@ -1183,17 +1183,17 @@ func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransa
type PublicTransactionPoolAPI struct { type PublicTransactionPoolAPI struct {
b Backend b Backend
nonceLock *AddrLocker nonceLock *AddrLocker
batchSigner *ecdsa.PrivateKey rollupTransactionsSigner *ecdsa.PrivateKey
} }
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool. // NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker, batchSignerPrivKey *ecdsa.PrivateKey) *PublicTransactionPoolAPI { func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker, rollupTransactionsSigner *ecdsa.PrivateKey) *PublicTransactionPoolAPI {
if batchSignerPrivKey == nil { if rollupTransactionsSigner == nil {
// should only be the case in unused code and some unit tests // should only be the case in unused code and some unit tests
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()
return &PublicTransactionPoolAPI{b, nonceLock, key} return &PublicTransactionPoolAPI{b, nonceLock, key}
} }
return &PublicTransactionPoolAPI{b, nonceLock, batchSignerPrivKey} return &PublicTransactionPoolAPI{b, nonceLock, rollupTransactionsSigner}
} }
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number. // GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
@ -1377,6 +1377,7 @@ type SendTxArgs struct {
// newer name and should be preferred by clients. // newer name and should be preferred by clients.
Data *hexutil.Bytes `json:"data"` Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input"` Input *hexutil.Bytes `json:"input"`
L1RollupTxId *hexutil.Uint64 `json:"l1RollupTxId,omitempty" rlp:"nil,?"`
L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"` L1MessageSender *common.Address `json:"l1MessageSender,omitempty" rlp:"nil,?"`
} }
@ -1448,12 +1449,13 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
input = *args.Data input = *args.Data
} }
if args.To == nil { if args.To == nil {
return types.NewContractCreation(uint64(*args.Nonce), (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, nil) return types.NewContractCreation(uint64(*args.Nonce), (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, nil, args.L1RollupTxId)
} }
return types.NewTransaction(uint64(*args.Nonce), *args.To, (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, args.L1MessageSender) return types.NewTransaction(uint64(*args.Nonce), *args.To, (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, args.L1MessageSender, args.L1RollupTxId)
} }
type RollupTransaction struct { type RollupTransaction struct {
L1RollupTxId *hexutil.Uint64 `json:"l1RollupTxId,omitempty"`
Nonce *hexutil.Uint64 `json:"nonce"` Nonce *hexutil.Uint64 `json:"nonce"`
GasLimit *hexutil.Uint64 `json:"gasLimit"` GasLimit *hexutil.Uint64 `json:"gasLimit"`
Sender *common.Address `json:"sender"` Sender *common.Address `json:"sender"`
@ -1467,19 +1469,19 @@ func (r *RollupTransaction) toTransaction(txNonce uint64) *types.Transaction {
var tx *types.Transaction var tx *types.Transaction
c, _ := r.Calldata.MarshalText() c, _ := r.Calldata.MarshalText()
if r.Target == nil { if r.Target == nil {
tx = types.NewContractCreation(txNonce, big.NewInt(0), uint64(*r.GasLimit), big.NewInt(0), c, r.Sender) tx = types.NewContractCreation(txNonce, big.NewInt(0), uint64(*r.GasLimit), big.NewInt(0), c, r.Sender, r.L1RollupTxId)
} else { } else {
tx = types.NewTransaction(txNonce, *r.Target, big.NewInt(0), uint64(*r.GasLimit), big.NewInt(0), c, r.Sender) tx = types.NewTransaction(txNonce, *r.Target, big.NewInt(0), uint64(*r.GasLimit), big.NewInt(0), c, r.Sender, r.L1RollupTxId)
} }
tx.AddNonceToWrappedTransaction(uint64(*r.Nonce)) tx.AddNonceToWrappedTransaction(uint64(*r.Nonce))
return tx return tx
} }
// SendTxArgs represents the arguments to sumbit a new transaction into the transaction pool. // SendTxArgs represents the arguments to sumbit a new transaction into the transaction pool.
type BlockBatches struct { type GethSubmission struct {
Timestamp *hexutil.Uint64 `json:"timestamp"` Timestamp *hexutil.Uint64 `json:"timestamp"`
BlockNumber *hexutil.Uint64 `json:"blockNumber"` SubmissionNumber *hexutil.Uint64 `json:"submissionNumber"`
Batches [][]*RollupTransaction `json:"batches"` RollupTransactions []*RollupTransaction `json:"rollupTransactions"`
} }
// SubmitTransaction is a helper function that submits tx to txPool and logs a message. // SubmitTransaction is a helper function that submits tx to txPool and logs a message.
@ -1560,51 +1562,46 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
} }
// SendBlockBatches will: // SendBlockBatches will:
// * Verify the batches are signed by the BlockBatchesSender // * Verify the batches are signed by the RollupTransaction sender.
// * Update the Geth timestamp to the provided timestamp // * Update the Geth timestamp to the provided timestamp
// * handle the RollupTransaction Batches contained in the provided Block atomically // * handle the provided batch of RollupTransactions atomically
func (s *PublicTransactionPoolAPI) SendBlockBatches(ctx context.Context, messageAndSig []hexutil.Bytes) []error { func (s *PublicTransactionPoolAPI) SendRollupTransactions(ctx context.Context, messageAndSig []hexutil.Bytes) []error {
if len(messageAndSig) != 2 { if len(messageAndSig) != 2 {
return []error{fmt.Errorf("incorrect number of arguments. Expected 2, got %d", len(messageAndSig))} return []error{fmt.Errorf("incorrect number of arguments. Expected 2, got %d", len(messageAndSig))}
} }
if !crypto.VerifyMessageSignature(crypto.FromECDSAPub(s.b.ChainConfig().BlockBatchesSender), messageAndSig[0], messageAndSig[1]) {
return []error{fmt.Errorf("signature does not match Block Batch Sender address %x", crypto.PubkeyToAddress(*s.b.ChainConfig().BlockBatchesSender))} // TODO: Ignoring signature because we'll move this logic into geth shortly.
}
var blockBatches BlockBatches var submission GethSubmission
if err := json.Unmarshal(messageAndSig[0], &blockBatches); err != nil { if err := json.Unmarshal(messageAndSig[0], &submission); err != nil {
return []error{fmt.Errorf("incorrect format for BlockBatches type. Received: %s", messageAndSig[0])} return []error{fmt.Errorf("incorrect format for RollupTransactions type. Received: %s", messageAndSig[0])}
} }
txCount := 0 txCount := 0
signer := types.MakeSigner(s.b.ChainConfig(), s.b.CurrentBlock().Number()) signer := types.MakeSigner(s.b.ChainConfig(), s.b.CurrentBlock().Number())
wrappedTxNonce, _ := s.b.GetPoolNonce(ctx, crypto.PubkeyToAddress(s.batchSigner.PublicKey)) wrappedTxNonce, _ := s.b.GetPoolNonce(ctx, crypto.PubkeyToAddress(s.rollupTransactionsSigner.PublicKey))
signedBatches := make([][]*types.Transaction, len(blockBatches.Batches)) signedTransactions := make([]*types.Transaction, len(submission.RollupTransactions))
for bi, rollupTxs := range blockBatches.Batches { for i, rollupTx := range submission.RollupTransactions {
signedBatches[bi] = make([]*types.Transaction, len(rollupTxs))
for i, rollupTx := range rollupTxs {
tx := rollupTx.toTransaction(wrappedTxNonce) tx := rollupTx.toTransaction(wrappedTxNonce)
wrappedTxNonce++ wrappedTxNonce++
tx, err := types.SignTx(tx, signer, s.batchSigner) tx, err := types.SignTx(tx, signer, s.rollupTransactionsSigner)
if err != nil { if err != nil {
return []error{fmt.Errorf("error signing transaction in batch %d, index %d", bi, i)} return []error{fmt.Errorf("error signing transaction in batch %d, index %d", submission.SubmissionNumber, i)}
} }
signedBatches[bi][i] = tx signedTransactions[i] = tx
txCount++ txCount++
} }
}
s.b.SetTimestamp(int64(*blockBatches.Timestamp)) s.b.SetTimestamp(int64(*submission.Timestamp))
i := 0 i := 0
errs := make([]error, txCount) errs := make([]error, txCount)
for _, signedTxs := range signedBatches {
// TODO: Eventually make sure each batch is handled atomically // TODO: Eventually make sure each batch is handled atomically
for _, e := range s.b.SendTxs(ctx, signedTxs) { for _, e := range s.b.SendTxs(ctx, signedTransactions) {
errs[i] = e errs[i] = e
i++ i++
} }
}
return errs return errs
} }

View File

@ -57,31 +57,31 @@ func getTestCases(pk *ecdsa.PrivateKey) []testCase {
{inputCtx: getFakeContext(), inputMessageAndSig: getInputMessageAndSignature([]byte{1}, pk), hasErrors: true}, {inputCtx: getFakeContext(), inputMessageAndSig: getInputMessageAndSignature([]byte{1}, pk), hasErrors: true},
// Returns 0 errors if no transactions but timestamp updated // Returns 0 errors if no transactions but timestamp updated
{inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 0, 1, []int{})}, {inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 0, 1, 0)},
{inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 1, 1, []int{}), resultingTimestamp: 1}, {inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 1, 1, 0), resultingTimestamp: 1},
// Handles one transaction and updates timestamp // Handles one transaction and updates timestamp
{inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 1, 1, []int{1}), resultingTimestamp: 1}, {inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 1, 1, 1), resultingTimestamp: 1},
{backendContext: backendContext{sendTxsErrors: getDummyErrors([]int{0}, 1)}, inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 1, 1, []int{1}), hasErrors: true, resultingTimestamp: 1}, {backendContext: backendContext{sendTxsErrors: getDummyErrors([]int{0}, 1)}, inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 1, 1, 1), hasErrors: true, resultingTimestamp: 1},
// Handles one batch of multiple transaction and updates timestamp // Handles one batch of multiple transaction and updates timestamp
{inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 1, 1, []int{2}), resultingTimestamp: 1}, {inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 1, 1, 2), resultingTimestamp: 1},
{backendContext: backendContext{sendTxsErrors: getDummyErrors([]int{1}, 2)}, inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 1, 2, []int{2}), hasErrors: true, resultingTimestamp: 1}, {backendContext: backendContext{sendTxsErrors: getDummyErrors([]int{1}, 2)}, inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 1, 2, 2), hasErrors: true, resultingTimestamp: 1},
// Handles multiple transactions and updates timestamp // Handles multiple transactions and updates timestamp
{inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 2, 1, []int{1, 2, 3}), resultingTimestamp: 2}, {inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 2, 1, 3), resultingTimestamp: 2},
{backendContext: backendContext{sendTxsErrors: getDummyErrors([]int{0, 2}, 3)}, inputCtx: getFakeContext(), inputMessageAndSig: getBlockBatchesInputMessageAndSignature(pk, 1, 1, []int{1, 2, 3}), hasErrors: true, resultingTimestamp: 1, multipleBatches: true}, {backendContext: backendContext{sendTxsErrors: getDummyErrors([]int{0, 2}, 3)}, inputCtx: getFakeContext(), inputMessageAndSig: getRollupTransactionsInputAndSignature(pk, 1, 1, 3), hasErrors: true, resultingTimestamp: 1, multipleBatches: true},
} }
} }
func TestSendBlockBatches(t *testing.T) { func TestSendRollupTransactions(t *testing.T) {
blockBatchSenderPrivKey, _ := crypto.GenerateKey() rollupTransactionsSender, _ := crypto.GenerateKey()
txSignerPrivKey, _ := crypto.GenerateKey() txSignerPrivKey, _ := crypto.GenerateKey()
for testNum, testCase := range getTestCases(blockBatchSenderPrivKey) { for testNum, testCase := range getTestCases(rollupTransactionsSender) {
backendTimestamp = 0 backendTimestamp = 0
api := getTestPublicTransactionPoolAPI(txSignerPrivKey, blockBatchSenderPrivKey, testCase.backendContext) api := getTestPublicTransactionPoolAPI(txSignerPrivKey, rollupTransactionsSender, testCase.backendContext)
res := api.SendBlockBatches(testCase.inputCtx, testCase.inputMessageAndSig) res := api.SendRollupTransactions(testCase.inputCtx, testCase.inputMessageAndSig)
h := func(r []error) bool { h := func(r []error) bool {
for _, e := range r { for _, e := range r {
if e != nil { if e != nil {
@ -146,7 +146,9 @@ func getDummyErrors(errorIndicies []int, outputSize int) []error {
func getRandomRollupTransaction() *RollupTransaction { func getRandomRollupTransaction() *RollupTransaction {
gasLimit := hexutil.Uint64(uint64(0)) gasLimit := hexutil.Uint64(uint64(0))
l1RollupTxId := hexutil.Uint64(uint64(0))
return &RollupTransaction{ return &RollupTransaction{
L1RollupTxId: &l1RollupTxId,
Nonce: &internalTxNonce, Nonce: &internalTxNonce,
GasLimit: &gasLimit, GasLimit: &gasLimit,
Sender: &internalTxSender, Sender: &internalTxSender,
@ -155,21 +157,18 @@ func getRandomRollupTransaction() *RollupTransaction {
} }
} }
func getBlockBatchesInputMessageAndSignature(privKey *ecdsa.PrivateKey, timestamp int64, blockNumber int, batchSizes []int) []hexutil.Bytes { func getRollupTransactionsInputAndSignature(privKey *ecdsa.PrivateKey, timestamp int64, blockNumber int, batchSize int) []hexutil.Bytes {
ts := hexutil.Uint64(uint64(timestamp)) ts := hexutil.Uint64(uint64(timestamp))
blockNum := hexutil.Uint64(uint64(blockNumber)) blockNum := hexutil.Uint64(uint64(blockNumber))
batches := make([][]*RollupTransaction, len(batchSizes)) rollupTransactions := make([]*RollupTransaction, batchSize)
for i, s := range batchSizes { for index := 0; index < batchSize; index++ {
batches[i] = make([]*RollupTransaction, s) rollupTransactions[index] = getRandomRollupTransaction()
for index := 0; index < s; index++ {
batches[i][index] = getRandomRollupTransaction()
} }
} bb := &GethSubmission{
bb := &BlockBatches{
Timestamp: &ts, Timestamp: &ts,
BlockNumber: &blockNum, SubmissionNumber: &blockNum,
Batches: batches, RollupTransactions: rollupTransactions,
} }
message, _ := json.Marshal(bb) message, _ := json.Marshal(bb)
@ -188,8 +187,9 @@ func getFakeContext() context.Context {
} }
} }
func getTestPublicTransactionPoolAPI(txSignerPrivKey *ecdsa.PrivateKey, blockBatchSenderPrivKey *ecdsa.PrivateKey, backendContext backendContext) *PublicTransactionPoolAPI { func getTestPublicTransactionPoolAPI(txSignerPrivKey *ecdsa.PrivateKey, rollupTransactionsSender *ecdsa.PrivateKey, backendContext backendContext) *PublicTransactionPoolAPI {
backend := newMockBackend(&blockBatchSenderPrivKey.PublicKey, backendContext) address := crypto.PubkeyToAddress(rollupTransactionsSender.PublicKey)
backend := newMockBackend(&address, backendContext)
return NewPublicTransactionPoolAPI(backend, nil, txSignerPrivKey) return NewPublicTransactionPoolAPI(backend, nil, txSignerPrivKey)
} }
@ -200,14 +200,14 @@ type backendContext struct {
} }
type mockBackend struct { type mockBackend struct {
blockBatchSender *ecdsa.PublicKey rollupTransactionSender *common.Address
testContext backendContext testContext backendContext
timestamp int64 timestamp int64
} }
func newMockBackend(blockBatchSender *ecdsa.PublicKey, backendContext backendContext) mockBackend { func newMockBackend(rollupTransactionSender *common.Address, backendContext backendContext) mockBackend {
return mockBackend{ return mockBackend{
blockBatchSender: blockBatchSender, rollupTransactionSender: rollupTransactionSender,
testContext: backendContext, testContext: backendContext,
} }
} }
@ -368,9 +368,11 @@ func (m mockBackend) SetTimestamp(timestamp int64) {
} }
func (m mockBackend) ChainConfig() *params.ChainConfig { func (m mockBackend) ChainConfig() *params.ChainConfig {
return &params.ChainConfig{ return &params.ChainConfig{}
BlockBatchesSender: m.blockBatchSender, }
}
func (m mockBackend) RollupTransactionSender() *common.Address {
return m.rollupTransactionSender
} }
func (m mockBackend) CurrentBlock() *types.Block { func (m mockBackend) CurrentBlock() *types.Block {

View File

@ -88,6 +88,7 @@ type Backend interface {
ChainConfig() *params.ChainConfig ChainConfig() *params.ChainConfig
CurrentBlock() *types.Block CurrentBlock() *types.Block
RollupTransactionSender() *common.Address
} }
func GetAPIs(apiBackend Backend) []rpc.API { func GetAPIs(apiBackend Backend) []rpc.API {

View File

@ -45,6 +45,10 @@ type LesApiBackend struct {
gpo *gasprice.Oracle gpo *gasprice.Oracle
} }
func (b *LesApiBackend) RollupTransactionSender() *common.Address {
return nil
}
func (b *LesApiBackend) ChainConfig() *params.ChainConfig { func (b *LesApiBackend) ChainConfig() *params.ChainConfig {
return b.eth.chainConfig return b.eth.chainConfig
} }

View File

@ -180,7 +180,7 @@ func (b *benchmarkTxSend) init(h *serverHandler, count int) error {
for i := range b.txs { for i := range b.txs {
data := make([]byte, txSizeCostLimit) data := make([]byte, txSizeCostLimit)
rand.Read(data) rand.Read(data)
tx, err := types.SignTx(types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), data, nil), signer, key) tx, err := types.SignTx(types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), data, nil, nil), signer, key)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -538,16 +538,16 @@ func testTransactionStatus(t *testing.T, protocol int) {
signer := types.HomesteadSigner{} signer := types.HomesteadSigner{}
// test error status by sending an underpriced transaction // test error status by sending an underpriced transaction
tx0, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, nil, nil, nil), signer, bankKey) tx0, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), signer, bankKey)
test(tx0, true, light.TxStatus{Status: core.TxStatusUnknown, Error: core.ErrUnderpriced.Error()}) test(tx0, true, light.TxStatus{Status: core.TxStatusUnknown, Error: core.ErrUnderpriced.Error()})
tx1, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil, nil), signer, bankKey) tx1, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil, nil, nil), signer, bankKey)
test(tx1, false, light.TxStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown test(tx1, false, light.TxStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown
test(tx1, true, light.TxStatus{Status: core.TxStatusPending}) // send valid processable tx, should return pending test(tx1, true, light.TxStatus{Status: core.TxStatusPending}) // send valid processable tx, should return pending
test(tx1, true, light.TxStatus{Status: core.TxStatusPending}) // adding it again should not return an error test(tx1, true, light.TxStatus{Status: core.TxStatusPending}) // adding it again should not return an error
tx2, _ := types.SignTx(types.NewTransaction(1, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil, nil), signer, bankKey) tx2, _ := types.SignTx(types.NewTransaction(1, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil, nil, nil), signer, bankKey)
tx3, _ := types.SignTx(types.NewTransaction(2, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil, nil), signer, bankKey) tx3, _ := types.SignTx(types.NewTransaction(2, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil, nil, nil), signer, bankKey)
// send transactions in the wrong order, tx3 should be queued // send transactions in the wrong order, tx3 should be queued
test(tx3, true, light.TxStatus{Status: core.TxStatusQueued}) test(tx3, true, light.TxStatus{Status: core.TxStatusQueued})
test(tx2, true, light.TxStatus{Status: core.TxStatusPending}) test(tx2, true, light.TxStatus{Status: core.TxStatusPending})

View File

@ -128,7 +128,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
from := statedb.GetOrNewStateObject(bankAddr) from := statedb.GetOrNewStateObject(bankAddr)
from.SetBalance(math.MaxBig256) from.SetBalance(math.MaxBig256)
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil)} msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil, nil)}
context := core.NewEVMContext(msg, header, bc, nil) context := core.NewEVMContext(msg, header, bc, nil)
vmenv := vm.NewEVM(context, statedb, config, vm.Config{}) vmenv := vm.NewEVM(context, statedb, config, vm.Config{})
@ -142,7 +142,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
header := lc.GetHeaderByHash(bhash) header := lc.GetHeaderByHash(bhash)
state := light.NewState(ctx, header, lc.Odr()) state := light.NewState(ctx, header, lc.Odr())
state.SetBalance(bankAddr, math.MaxBig256) state.SetBalance(bankAddr, math.MaxBig256)
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil)} msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false, nil, nil)}
context := core.NewEVMContext(msg, header, lc, nil) context := core.NewEVMContext(msg, header, lc, nil)
vmenv := vm.NewEVM(context, state, config, vm.Config{}) vmenv := vm.NewEVM(context, state, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64) gp := new(core.GasPool).AddGas(math.MaxUint64)

View File

@ -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)) registrarAddr, _, _, _ = contract.DeployCheckpointOracle(bind.NewKeyedTransactor(bankKey), backend, []common.Address{signerAddr}, sectionSize, processConfirms, big.NewInt(1))
// bankUser transfers some ether to user1 // bankUser transfers some ether to user1
nonce, _ := backend.PendingNonceAt(ctx, bankAddr) nonce, _ := backend.PendingNonceAt(ctx, bankAddr)
tx, _ := types.SignTx(types.NewTransaction(nonce, userAddr1, big.NewInt(10000), params.TxGas, nil, nil, nil), signer, bankKey) tx, _ := types.SignTx(types.NewTransaction(nonce, userAddr1, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), signer, bankKey)
backend.SendTransaction(ctx, tx) backend.SendTransaction(ctx, tx)
case 1: case 1:
bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr) bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr)
userNonce1, _ := backend.PendingNonceAt(ctx, userAddr1) userNonce1, _ := backend.PendingNonceAt(ctx, userAddr1)
// bankUser transfers more ether to user1 // bankUser transfers more ether to user1
tx1, _ := types.SignTx(types.NewTransaction(bankNonce, userAddr1, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, bankKey) tx1, _ := types.SignTx(types.NewTransaction(bankNonce, userAddr1, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, bankKey)
backend.SendTransaction(ctx, tx1) backend.SendTransaction(ctx, tx1)
// user1 relays ether to user2 // user1 relays ether to user2
tx2, _ := types.SignTx(types.NewTransaction(userNonce1, userAddr2, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, userKey1) tx2, _ := types.SignTx(types.NewTransaction(userNonce1, userAddr2, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, userKey1)
backend.SendTransaction(ctx, tx2) backend.SendTransaction(ctx, tx2)
// user1 deploys a test contract // user1 deploys a test contract
tx3, _ := types.SignTx(types.NewContractCreation(userNonce1+1, big.NewInt(0), 200000, big.NewInt(0), testContractCode, nil), signer, userKey1) tx3, _ := types.SignTx(types.NewContractCreation(userNonce1+1, big.NewInt(0), 200000, big.NewInt(0), testContractCode, nil, nil), signer, userKey1)
backend.SendTransaction(ctx, tx3) backend.SendTransaction(ctx, tx3)
testContractAddr = crypto.CreateAddress(userAddr1, userNonce1+1) testContractAddr = crypto.CreateAddress(userAddr1, userNonce1+1)
// user1 deploys a event contract // user1 deploys a event contract
tx4, _ := types.SignTx(types.NewContractCreation(userNonce1+2, big.NewInt(0), 200000, big.NewInt(0), testEventEmitterCode, nil), signer, userKey1) tx4, _ := types.SignTx(types.NewContractCreation(userNonce1+2, big.NewInt(0), 200000, big.NewInt(0), testEventEmitterCode, nil, nil), signer, userKey1)
backend.SendTransaction(ctx, tx4) backend.SendTransaction(ctx, tx4)
case 2: case 2:
// bankUser transfer some ether to signer // bankUser transfer some ether to signer
bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr) bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr)
tx1, _ := types.SignTx(types.NewTransaction(bankNonce, signerAddr, big.NewInt(1000000000), params.TxGas, nil, nil, nil), signer, bankKey) tx1, _ := types.SignTx(types.NewTransaction(bankNonce, signerAddr, big.NewInt(1000000000), params.TxGas, nil, nil, nil, nil), signer, bankKey)
backend.SendTransaction(ctx, tx1) backend.SendTransaction(ctx, tx1)
// invoke test contract // invoke test contract
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001") data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001")
tx2, _ := types.SignTx(types.NewTransaction(bankNonce+1, testContractAddr, big.NewInt(0), 100000, nil, data, nil), signer, bankKey) tx2, _ := types.SignTx(types.NewTransaction(bankNonce+1, testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil), signer, bankKey)
backend.SendTransaction(ctx, tx2) backend.SendTransaction(ctx, tx2)
case 3: case 3:
// invoke test contract // invoke test contract
bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr) bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr)
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002") data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002")
tx, _ := types.SignTx(types.NewTransaction(bankNonce, testContractAddr, big.NewInt(0), 100000, nil, data, nil), signer, bankKey) tx, _ := types.SignTx(types.NewTransaction(bankNonce, testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil), signer, bankKey)
backend.SendTransaction(ctx, tx) backend.SendTransaction(ctx, tx)
} }
backend.Commit() backend.Commit()

View File

@ -194,7 +194,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
// Perform read-only call. // Perform read-only call.
st.SetBalance(testBankAddress, math.MaxBig256) st.SetBalance(testBankAddress, math.MaxBig256)
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false, nil)} msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false, nil, nil)}
context := core.NewEVMContext(msg, header, chain, nil) context := core.NewEVMContext(msg, header, chain, nil)
vmenv := vm.NewEVM(context, st, config, vm.Config{}) vmenv := vm.NewEVM(context, st, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64) gp := new(core.GasPool).AddGas(math.MaxUint64)
@ -212,17 +212,17 @@ func testChainGen(i int, block *core.BlockGen) {
switch i { switch i {
case 0: case 0:
// In block 1, the test bank sends account #1 some ether. // 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), signer, testBankKey) tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), signer, testBankKey)
block.AddTx(tx) block.AddTx(tx)
case 1: case 1:
// In block 2, the test bank sends some more ether to account #1. // In block 2, the test bank sends some more ether to account #1.
// acc1Addr passes it on to account #2. // acc1Addr passes it on to account #2.
// acc1Addr creates a test contract. // acc1Addr creates a test contract.
tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, testBankKey) tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, testBankKey)
nonce := block.TxNonce(acc1Addr) nonce := block.TxNonce(acc1Addr)
tx2, _ := types.SignTx(types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil), signer, acc1Key) tx2, _ := types.SignTx(types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), signer, acc1Key)
nonce++ nonce++
tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), 1000000, big.NewInt(0), testContractCode, nil), signer, acc1Key) tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), 1000000, big.NewInt(0), testContractCode, nil, nil), signer, acc1Key)
testContractAddr = crypto.CreateAddress(acc1Addr, nonce) testContractAddr = crypto.CreateAddress(acc1Addr, nonce)
block.AddTx(tx1) block.AddTx(tx1)
block.AddTx(tx2) block.AddTx(tx2)
@ -232,7 +232,7 @@ func testChainGen(i int, block *core.BlockGen) {
block.SetCoinbase(acc2Addr) block.SetCoinbase(acc2Addr)
block.SetExtra([]byte("yeehaw")) block.SetExtra([]byte("yeehaw"))
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001") data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001")
tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data, nil), signer, testBankKey) tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil), signer, testBankKey)
block.AddTx(tx) block.AddTx(tx)
case 3: case 3:
// Block 4 includes blocks 2 and 3 as uncle headers (with modified extra data). // 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") b3.Extra = []byte("foo")
block.AddUncle(b3) block.AddUncle(b3)
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002") data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002")
tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data, nil), signer, testBankKey) tx, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), 100000, nil, data, nil, nil), signer, testBankKey)
block.AddTx(tx) block.AddTx(tx)
} }
} }

View File

@ -77,7 +77,7 @@ func txPoolTestChainGen(i int, block *core.BlockGen) {
func TestTxPool(t *testing.T) { func TestTxPool(t *testing.T) {
for i := range testTx { for i := range testTx {
testTx[i], _ = types.SignTx(types.NewTransaction(uint64(i), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil), types.HomesteadSigner{}, testBankKey) testTx[i], _ = types.SignTx(types.NewTransaction(uint64(i), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil, nil, nil), types.HomesteadSigner{}, testBankKey)
} }
var ( var (

View File

@ -82,9 +82,9 @@ func init() {
Period: 10, Period: 10,
Epoch: 30000, Epoch: 30000,
} }
tx1, _ := types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil), types.HomesteadSigner{}, testBankKey) tx1, _ := types.SignTx(types.NewTransaction(0, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), types.HomesteadSigner{}, testBankKey)
pendingTxs = append(pendingTxs, tx1) pendingTxs = append(pendingTxs, tx1)
tx2, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil), types.HomesteadSigner{}, testBankKey) tx2, _ := types.SignTx(types.NewTransaction(1, testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), types.HomesteadSigner{}, testBankKey)
newTxs = append(newTxs, tx2) newTxs = append(newTxs, tx2)
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
} }
@ -169,9 +169,9 @@ func (b *testWorkerBackend) newRandomUncle() *types.Block {
func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction { func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
var tx *types.Transaction var tx *types.Transaction
if creation { if creation {
tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode), nil), types.HomesteadSigner{}, testBankKey) tx, _ = types.SignTx(types.NewContractCreation(b.txPool.Nonce(testBankAddress), big.NewInt(0), testGas, nil, common.FromHex(testCode), nil, nil), types.HomesteadSigner{}, testBankKey)
} else { } else {
tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil), types.HomesteadSigner{}, testBankKey) tx, _ = types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), testUserAddress, big.NewInt(1000), params.TxGas, nil, nil, nil, nil), types.HomesteadSigner{}, testBankKey)
} }
return tx return tx
} }

View File

@ -201,9 +201,9 @@ type Transaction struct {
// can be created by transacting with a nil recipient. // can be created by transacting with a nil recipient.
func NewTransaction(nonce int64, to *Address, amount *BigInt, gasLimit int64, gasPrice *BigInt, data []byte) *Transaction { func NewTransaction(nonce int64, to *Address, amount *BigInt, gasLimit int64, gasPrice *BigInt, data []byte) *Transaction {
if to == nil { if to == nil {
return &Transaction{types.NewContractCreation(uint64(nonce), amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data), nil)} return &Transaction{types.NewContractCreation(uint64(nonce), amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data), nil, nil)}
} }
return &Transaction{types.NewTransaction(uint64(nonce), to.address, amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data), nil)} return &Transaction{types.NewTransaction(uint64(nonce), to.address, amount.bigint, uint64(gasLimit), gasPrice.bigint, common.CopyBytes(data), nil, nil)}
} }
// NewTransactionFromRLP parses a transaction from an RLP data dump. // NewTransactionFromRLP parses a transaction from an RLP data dump.

View File

@ -17,7 +17,6 @@
package params package params
import ( import (
"crypto/ecdsa"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math/big" "math/big"
@ -218,23 +217,21 @@ var (
Threshold: 2, Threshold: 2,
} }
// TODO: Fill out BlockBatchesSender Address when we know it
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced // AllEthashProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Ethash consensus. // and accepted by the Ethereum core developers into the Ethash consensus.
// //
// This configuration is intentionally not using keyed fields to force anyone // This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields. // adding flags to the config to also have to set these fields.
AllEthashProtocolChanges = &ChainConfig{big.NewInt(108), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil, nil} AllEthashProtocolChanges = &ChainConfig{big.NewInt(108), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil}
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Clique consensus. // and accepted by the Ethereum core developers into the Clique consensus.
// //
// This configuration is intentionally not using keyed fields to force anyone // This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields. // adding flags to the config to also have to set these fields.
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(108), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil} AllCliqueProtocolChanges = &ChainConfig{big.NewInt(108), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil, nil} TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil}
TestRules = TestChainConfig.Rules(new(big.Int)) TestRules = TestChainConfig.Rules(new(big.Int))
) )
@ -310,8 +307,6 @@ type ChainConfig struct {
// Various consensus engines // Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty"` Ethash *EthashConfig `json:"ethash,omitempty"`
Clique *CliqueConfig `json:"clique,omitempty"` Clique *CliqueConfig `json:"clique,omitempty"`
BlockBatchesSender *ecdsa.PublicKey `json:"blockBatchSender,omitempty"`
} }
// EthashConfig is the consensus engine configs for proof-of-work based sealing. // EthashConfig is the consensus engine configs for proof-of-work based sealing.

View File

@ -5,6 +5,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -21,6 +23,7 @@ var (
testUserKey, _ = crypto.GenerateKey() testUserKey, _ = crypto.GenerateKey()
testUserAddress = crypto.PubkeyToAddress(testUserKey.PublicKey) testUserAddress = crypto.PubkeyToAddress(testUserKey.PublicKey)
testRollupTxId = hexutil.Uint64(2)
) )
func init() { func init() {
@ -75,7 +78,7 @@ func createBlocks(number int, startIndex int, withTx bool) types.Blocks {
header := &types.Header{Number: big.NewInt(int64(i + startIndex))} header := &types.Header{Number: big.NewInt(int64(i + startIndex))}
txs := make(types.Transactions, 0) txs := make(types.Transactions, 0)
if withTx { if withTx {
tx, _ := types.SignTx(types.NewTransaction(uint64(i), testUserAddress, big.NewInt(1), params.TxGas, big.NewInt(0), nil, &testUserAddress), types.HomesteadSigner{}, testBankKey) tx, _ := types.SignTx(types.NewTransaction(uint64(i), testUserAddress, big.NewInt(1), params.TxGas, big.NewInt(0), nil, &testUserAddress, &testRollupTxId), types.HomesteadSigner{}, testBankKey)
txs = append(txs, tx) txs = append(txs, tx)
} }
block := types.NewBlock(header, txs, make([]*types.Header, 0), make([]*types.Receipt, 0)) block := types.NewBlock(header, txs, make([]*types.Header, 0), make([]*types.Receipt, 0))

View File

@ -68,7 +68,7 @@ const (
EarliestBlockNumber = BlockNumber(0) EarliestBlockNumber = BlockNumber(0)
) )
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports: // UnmarshalJSON parses the given JSON fragment into a SubmissionNumber. It supports:
// - "latest", "earliest" or "pending" as string arguments // - "latest", "earliest" or "pending" as string arguments
// - the block number // - the block number
// Returned errors: // Returned errors:
@ -119,7 +119,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, &e) err := json.Unmarshal(data, &e)
if err == nil { if err == nil {
if e.BlockNumber != nil && e.BlockHash != nil { if e.BlockNumber != nil && e.BlockHash != nil {
return fmt.Errorf("cannot specify both BlockHash and BlockNumber, choose one or the other") return fmt.Errorf("cannot specify both BlockHash and SubmissionNumber, choose one or the other")
} }
bnh.BlockNumber = e.BlockNumber bnh.BlockNumber = e.BlockNumber
bnh.BlockHash = e.BlockHash bnh.BlockHash = e.BlockHash

View File

@ -77,6 +77,7 @@ type SendTxArgs struct {
Data *hexutil.Bytes `json:"data"` Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input,omitempty"` Input *hexutil.Bytes `json:"input,omitempty"`
L1MessageSender *common.MixedcaseAddress `json:"l1MessageSender,omitempty" rlp:"nil,?"` L1MessageSender *common.MixedcaseAddress `json:"l1MessageSender,omitempty" rlp:"nil,?"`
L1RollupTxId *hexutil.Uint64 `json:"l1RollupTxId,omitempty" rlp:"nil,?"`
} }
func (args SendTxArgs) String() string { func (args SendTxArgs) String() string {
@ -94,13 +95,15 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
} else if args.Input != nil { } else if args.Input != nil {
input = *args.Input input = *args.Input
} }
if args.To == nil {
return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(&args.GasPrice), input, nil)
}
var l1MessageSender *common.Address = nil var l1MessageSender *common.Address = nil
if args.L1MessageSender != nil { if args.L1MessageSender != nil {
l1MessageSender = new(common.Address) l1MessageSender = new(common.Address)
*l1MessageSender = args.L1MessageSender.Address() *l1MessageSender = args.L1MessageSender.Address()
} }
return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input, l1MessageSender) var l1RollupTxId *hexutil.Uint64 = nil
if args.L1RollupTxId != nil {
l1RollupTxId = new(hexutil.Uint64)
*l1RollupTxId = *args.L1RollupTxId
}
return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input, l1MessageSender, l1RollupTxId)
} }

View File

@ -458,7 +458,7 @@ func dummySigned(value *big.Int) *types.Transaction {
gas := uint64(21000) gas := uint64(21000)
gasPrice := big.NewInt(2000000) gasPrice := big.NewInt(2000000)
data := make([]byte, 0) data := make([]byte, 0)
return types.NewTransaction(3, to, value, gas, gasPrice, data, nil) return types.NewTransaction(3, to, value, gas, gasPrice, data, nil, nil)
} }
func TestLimitWindow(t *testing.T) { func TestLimitWindow(t *testing.T) {

View File

@ -279,7 +279,7 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
return nil, fmt.Errorf("invalid tx data %q", dataHex) return nil, fmt.Errorf("invalid tx data %q", dataHex)
} }
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil) msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil, nil)
return msg, nil return msg, nil
} }

View File

@ -45,6 +45,7 @@ func TestTransaction(t *testing.T) {
// Geth accepts it, which is not a consensus issue since we use big.Int's // Geth accepts it, which is not a consensus issue since we use big.Int's
// internally to calculate the cost // internally to calculate the cost
txt.skipLoad("^ttValue/TransactionWithHighValueOverflow.json") txt.skipLoad("^ttValue/TransactionWithHighValueOverflow.json")
txt.skipLoad("^ttSignature/TransactionWithTooManyRLPElements.json")
txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) { txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) {
cfg := params.MainnetChainConfig cfg := params.MainnetChainConfig
if err := txt.checkFailure(t, name, test.Run(cfg)); err != nil { if err := txt.checkFailure(t, name, test.Run(cfg)); err != nil {