Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.

rpc: debug_ingestTransactions #198

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.IngestTransaction(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 {
Expand Down
55 changes: 55 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,61 @@ 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)
}

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
}
return api.b.IngestTransactions(transactions)
}

// PublicNetAPI offers network related RPC methods
type PublicNetAPI struct {
net *p2p.Server
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down