From bed33fe6efe78dd07e00a3100ef8812692f5e9f9 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Thu, 21 Jan 2021 15:54:03 -0800 Subject: [PATCH 1/2] rpc: debug_ingestTransactions --- eth/api_backend.go | 10 ++++++++++ internal/ethapi/api.go | 41 ++++++++++++++++++++++++++++++++++++++ internal/ethapi/backend.go | 2 +- les/api_backend.go | 12 +++++++---- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index 9ebc9431c..fad485e01 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -128,6 +128,16 @@ func (b *EthAPIBackend) SetHead(number uint64) { b.eth.syncService.SetLatestL1BlockNumber(blockNumber.Uint64()) } +func (b *EthAPIBackend) IngestTransactions(txs []*types.Transaction) error { + for _, tx := range txs { + err := b.eth.syncService.ApplyTransaction(tx) + if err != nil { + return err + } + } + return nil +} + func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) { // Pending block is only known by the miner if number == rpc.PendingBlockNumber { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 38ff3f171..857cb8b56 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1996,6 +1996,47 @@ func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) { api.b.SetHead(uint64(number)) } +func (api *PrivateDebugAPI) IngestTransactions(txs []*RPCTransaction) error { + transactions := make([]*types.Transaction, len(txs)) + + for i, tx := range txs { + nonce := uint64(tx.Nonce) + value := tx.Value.ToInt() + gasLimit := uint64(tx.Gas) + gasPrice := tx.GasPrice.ToInt() + data := tx.Input + l1BlockNumber := tx.L1BlockNumber.ToInt() + l1Timestamp := uint64(tx.L1Timestamp) + + var sighashType types.SignatureHashType + switch tx.TxType { + case "EthSign": + sighashType = types.SighashEthSign + case "EIP155": + sighashType = types.SighashEIP155 + default: + return fmt.Errorf("Transaction with unknown sighash type: %s", tx.TxType) + } + + var queueOrigin types.QueueOrigin + switch tx.QueueOrigin { + case "sequencer": + queueOrigin = types.QueueOriginSequencer + case "l1": + queueOrigin = types.QueueOriginL1ToL2 + default: + return fmt.Errorf("Transaction with unknown queue origin: %s", tx.TxType) + } + + transaction := types.NewTransaction(nonce, *tx.To, value, gasLimit, gasPrice, data, tx.L1TxOrigin, l1BlockNumber, queueOrigin, sighashType) + transaction.SetL1BlockNumber(l1BlockNumber.Uint64()) + transaction.SetL1Timestamp(l1Timestamp) + + transactions[i] = transaction + } + return api.b.IngestTransactions(transactions) +} + // PublicNetAPI offers network related RPC methods type PublicNetAPI struct { net *p2p.Server diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index d0a4555e0..24c7731ae 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -90,7 +90,7 @@ type Backend interface { GetEthContext() (uint64, uint64) GetRollupContext() (uint64, uint64) GasLimit() uint64 - + IngestTransactions([]*types.Transaction) error ChainConfig() *params.ChainConfig CurrentBlock() *types.Block diff --git a/les/api_backend.go b/les/api_backend.go index d0007cf92..edae67017 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -58,18 +58,22 @@ func (b *LesApiBackend) GetEthContext() (uint64, uint64) { return 0, 0 } -func (b *LesApiBackend) GetRollupContext() (uint64, uint64) { - return 0, 0 -} - func (b *LesApiBackend) IsSyncing() bool { return false } +func (b *LesApiBackend) IngestTransactions([]*types.Transaction) error { + panic("not implemented") +} + func (b *LesApiBackend) GetLatestEth1Data() (common.Hash, uint64) { return common.Hash{}, 0 } +func (b *LesApiBackend) GetRollupContext() (uint64, uint64) { + return 0, 0 +} + func (b *LesApiBackend) ChainConfig() *params.ChainConfig { return b.eth.chainConfig } From 109dbb69e586b89d00f9fa54b80b9ea11406bce3 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Sun, 28 Feb 2021 14:04:34 -0800 Subject: [PATCH 2/2] rpc: ingesttransactions working --- eth/api_backend.go | 2 +- internal/ethapi/api.go | 20 +++++++++++++++++--- rollup/sync_service.go | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index fad485e01..ef75eec3f 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -130,7 +130,7 @@ func (b *EthAPIBackend) SetHead(number uint64) { func (b *EthAPIBackend) IngestTransactions(txs []*types.Transaction) error { for _, tx := range txs { - err := b.eth.syncService.ApplyTransaction(tx) + err := b.eth.syncService.IngestTransaction(tx) if err != nil { return err } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 857cb8b56..b8f189125 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -2028,9 +2028,23 @@ func (api *PrivateDebugAPI) IngestTransactions(txs []*RPCTransaction) error { return fmt.Errorf("Transaction with unknown queue origin: %s", tx.TxType) } - transaction := types.NewTransaction(nonce, *tx.To, value, gasLimit, gasPrice, data, tx.L1TxOrigin, l1BlockNumber, queueOrigin, sighashType) - transaction.SetL1BlockNumber(l1BlockNumber.Uint64()) - transaction.SetL1Timestamp(l1Timestamp) + var transaction *types.Transaction + if tx.To == nil { + transaction = types.NewContractCreation(nonce, value, gasLimit, gasPrice, data, tx.L1TxOrigin, l1BlockNumber, queueOrigin) + } else { + transaction = types.NewTransaction(nonce, *tx.To, value, gasLimit, gasPrice, data, tx.L1TxOrigin, l1BlockNumber, queueOrigin, sighashType) + } + + meta := types.TransactionMeta{ + L1BlockNumber: l1BlockNumber, + L1Timestamp: l1Timestamp, + L1MessageSender: tx.L1TxOrigin, + SignatureHashType: sighashType, + QueueOrigin: big.NewInt(int64(queueOrigin)), + Index: (*uint64)(tx.Index), + QueueIndex: (*uint64)(tx.QueueIndex), + } + transaction.SetTransactionMeta(&meta) transactions[i] = transaction } diff --git a/rollup/sync_service.go b/rollup/sync_service.go index ebbf18fd3..166af8492 100644 --- a/rollup/sync_service.go +++ b/rollup/sync_service.go @@ -601,6 +601,10 @@ func (s *SyncService) applyTransaction(tx *types.Transaction) error { return nil } +func (s *SyncService) IngestTransaction(tx *types.Transaction) error { + return s.applyTransaction(tx) +} + // Higher level API for applying transactions. Should only be called for // queue origin sequencer transactions, as the contracts on L1 manage the same // validity checks that are done here.