go-ethereum/eth/taiko_api_backend.go
David 7bf5c0d259
feat(eth): changes based on protocol Pacaya fork (#367)
* chore(taiko_genesis): update devnet Pacaya genesis JSONs

* feat: update ValidateAnchorTx

* feat: update ValidateAnchorTx

* feat: update l1Origin

* Revert "feat: update l1Origin"

This reverts commit 1337b37c051fe06ee87e4b7d6ec2b3857558e218.

* feat: update L1Origin

* feat: update genesis json

* feat: add DepositTxType

* feat: add DepositTxType

* chore: update ci

* feat: new defs

* feat: new defs for op-services

* feat: new defs for op-services

* feat: new defs for op-services

* feat: new defs for op-services

* feat: new defs for op-services

* feat: new defs for op-services

* feat: update L1Origin

* fix: fix lint errors

* add preconf devent configs back in

* Update core/rawdb/taiko_l1_origin.go

Co-authored-by: maskpp <maskpp266@gmail.com>

* feat: two more APIs

* feat: update api backend

* feat: update api backend

* feat: rename an API

* feat: rename an API

* feat: rename an API

* feat: update `BuildPayloadArgs`

* feat: update `BuildPayloadArgs`

* feat: update `BuildPayloadArgs`

* chore: update ci

* update preconf genesis

* build

* feat!: update ci

* feat: update devnet json

---------

Co-authored-by: maskpp <maskpp266@gmail.com>
Co-authored-by: Jeffery Walsh <cyberhorsey@gmail.com>
2025-02-06 05:59:38 +00:00

147 lines
3.7 KiB
Go

package eth
import (
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner"
)
// TaikoAPIBackend handles L2 node related RPC calls.
type TaikoAPIBackend struct {
eth *Ethereum
}
// NewTaikoAPIBackend creates a new TaikoAPIBackend instance.
func NewTaikoAPIBackend(eth *Ethereum) *TaikoAPIBackend {
return &TaikoAPIBackend{
eth: eth,
}
}
// HeadL1Origin returns the latest L2 block's corresponding L1 origin.
func (s *TaikoAPIBackend) HeadL1Origin() (*rawdb.L1Origin, error) {
blockID, err := rawdb.ReadHeadL1Origin(s.eth.ChainDb())
if err != nil {
return nil, err
}
if blockID == nil {
return nil, ethereum.NotFound
}
l1Origin, err := rawdb.ReadL1Origin(s.eth.ChainDb(), blockID)
if err != nil {
return nil, err
}
if l1Origin == nil {
return nil, ethereum.NotFound
}
return l1Origin, nil
}
// L1OriginByID returns the L2 block's corresponding L1 origin.
func (s *TaikoAPIBackend) L1OriginByID(blockID *math.HexOrDecimal256) (*rawdb.L1Origin, error) {
l1Origin, err := rawdb.ReadL1Origin(s.eth.ChainDb(), (*big.Int)(blockID))
if err != nil {
return nil, err
}
if l1Origin == nil {
return nil, ethereum.NotFound
}
return l1Origin, nil
}
// SetHeadL1Origin sets the latest L2 block's corresponding L1 origin.
func (s *TaikoAPIBackend) SetHeadL1Origin(blockID *math.HexOrDecimal256) *big.Int {
rawdb.WriteHeadL1Origin(s.eth.ChainDb(), (*big.Int)(blockID))
return (*big.Int)(blockID)
}
// UpdateL1Origin updates the L2 block's corresponding L1 origin.
func (s *TaikoAPIBackend) UpdateL1Origin(l1Origin *rawdb.L1Origin) *rawdb.L1Origin {
rawdb.WriteL1Origin(s.eth.ChainDb(), l1Origin.BlockID, l1Origin)
return l1Origin
}
// GetSyncMode returns the node sync mode.
func (s *TaikoAPIBackend) GetSyncMode() (string, error) {
return s.eth.config.SyncMode.String(), nil
}
// TaikoAuthAPIBackend handles L2 node related authorized RPC calls.
type TaikoAuthAPIBackend struct {
eth *Ethereum
}
// NewTaikoAuthAPIBackend creates a new TaikoAuthAPIBackend instance.
func NewTaikoAuthAPIBackend(eth *Ethereum) *TaikoAuthAPIBackend {
return &TaikoAuthAPIBackend{eth}
}
// TxPoolContent retrieves the transaction pool content with the given upper limits.
func (a *TaikoAuthAPIBackend) TxPoolContent(
beneficiary common.Address,
baseFee *big.Int,
blockMaxGasLimit uint64,
maxBytesPerTxList uint64,
locals []string,
maxTransactionsLists uint64,
) ([]*miner.PreBuiltTxList, error) {
log.Debug(
"Fetching L2 pending transactions finished",
"baseFee", baseFee,
"blockMaxGasLimit", blockMaxGasLimit,
"maxBytesPerTxList", maxBytesPerTxList,
"maxTransactions", maxTransactionsLists,
"locals", locals,
)
return a.eth.Miner().BuildTransactionsLists(
beneficiary,
baseFee,
blockMaxGasLimit,
maxBytesPerTxList,
locals,
maxTransactionsLists,
)
}
// TxPoolContentWithMinTip retrieves the transaction pool content with the given upper limits and minimum tip.
func (a *TaikoAuthAPIBackend) TxPoolContentWithMinTip(
beneficiary common.Address,
baseFee *big.Int,
blockMaxGasLimit uint64,
maxBytesPerTxList uint64,
locals []string,
maxTransactionsLists uint64,
minTip uint64,
) ([]*miner.PreBuiltTxList, error) {
log.Debug(
"Fetching L2 pending transactions finished",
"baseFee", baseFee,
"blockMaxGasLimit", blockMaxGasLimit,
"maxBytesPerTxList", maxBytesPerTxList,
"maxTransactions", maxTransactionsLists,
"locals", locals,
"minTip", minTip,
)
return a.eth.Miner().BuildTransactionsListsWithMinTip(
beneficiary,
baseFee,
blockMaxGasLimit,
maxBytesPerTxList,
locals,
maxTransactionsLists,
minTip,
)
}