Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(all): preconfs #281

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c8648e9
basisc slot/signature preconfs addition
cyberhorsey Jun 27, 2024
5c474c0
Remove slog and signature, also hijack eth_getTransactionReceipt
cyberhorsey Jun 28, 2024
ed57045
.
cyberhorsey Jun 28, 2024
9e91c83
encode
cyberhorsey Jun 28, 2024
e4147eb
preconfs nework support
cyberhorsey Jul 2, 2024
9316c67
build on pr
cyberhorsey Jul 2, 2024
3e33107
.'
cyberhorsey Jul 2, 2024
962c01a
change image url
cyberhorsey Jul 3, 2024
d4ae804
Merge branch 'taiko' into preconfs
cyberhorsey Jul 3, 2024
283c866
spew
cyberhorsey Jul 7, 2024
07d9ac7
Merge branch 'preconfs' of github.com:taikochain/taiko-geth into prec…
cyberhorsey Jul 7, 2024
8175e6d
log
cyberhorsey Jul 7, 2024
0be6e70
oops
cyberhorsey Jul 7, 2024
c09982c
forward addtl calls
cyberhorsey Jul 8, 2024
11547c6
lint
cyberhorsey Jul 8, 2024
86dc5a9
Merge branch 'taiko' into preconfs
cyberhorsey Jul 8, 2024
ca1606a
typo
cyberhorsey Jul 25, 2024
7c97fef
Merge branch 'preconfs' of github.com:taikochain/taiko-geth into prec…
cyberhorsey Jul 25, 2024
28837e2
str req
cyberhorsey Jul 25, 2024
22827b7
.
cyberhorsey Jul 25, 2024
239690d
logs
cyberhorsey Jul 25, 2024
a175b68
log
cyberhorsey Jul 25, 2024
e085b23
method
cyberhorsey Jul 25, 2024
c8e4db3
.
cyberhorsey Jul 25, 2024
9dc9717
Type log
cyberhorsey Jul 25, 2024
002515b
.
cyberhorsey Jul 25, 2024
f61e2dd
fix
cyberhorsey Jul 25, 2024
aeeeda0
.
cyberhorsey Jul 25, 2024
d1ebecb
.
cyberhorsey Jul 25, 2024
58b373f
balance fix
cyberhorsey Jul 25, 2024
ffd909d
err
cyberhorsey Jul 25, 2024
4edd506
conforms
cyberhorsey Jul 25, 2024
6a3418e
forwarding
cyberhorsey Jul 25, 2024
b138398
.'
cyberhorsey Jul 25, 2024
139410e
.'
cyberhorsey Jul 25, 2024
7e281e2
try this
cyberhorsey Jul 25, 2024
323c733
handle nil
cyberhorsey Jul 25, 2024
6cd1f75
.
cyberhorsey Jul 25, 2024
f07fe35
one more log
cyberhorsey Jul 25, 2024
9d01948
gn
cyberhorsey Jul 25, 2024
cd44d64
.
cyberhorsey Jul 26, 2024
7391e27
forwarding
cyberhorsey Jul 26, 2024
4ccf51d
.
cyberhorsey Jul 26, 2024
d1ab2fb
Log
cyberhorsey Jul 29, 2024
bf451ad
Check local before forwarding
cyberhorsey Jul 29, 2024
b96e4b7
Merge branch 'taiko' into preconfs
davidtaikocha Aug 8, 2024
6674bcf
update genesis for helder
cyberhorsey Aug 21, 2024
cd7ecf3
Merge branch 'preconfs' of github.com:taikochain/taiko-geth into prec…
cyberhorsey Aug 21, 2024
b46389f
ontake block
cyberhorsey Aug 21, 2024
9a8241c
Merge branch 'taiko' into preconfs
cyberhorsey Aug 21, 2024
c579ad7
log
cyberhorsey Aug 21, 2024
6f0827b
log
cyberhorsey Aug 22, 2024
c6597c6
moar logs
cyberhorsey Aug 22, 2024
a2e96fd
genesis
cyberhorsey Aug 23, 2024
7510e3c
Merge branch 'taiko' into preconfs
cyberhorsey Sep 10, 2024
649a1e5
Merge branch 'taiko' into preconfs
cyberhorsey Sep 13, 2024
dc64cdf
genesis
cyberhorsey Sep 13, 2024
34d90f5
Merge branch 'preconfs' of github.com:taikochain/taiko-geth into prec…
cyberhorsey Sep 13, 2024
66e3912
genesis
cyberhorsey Sep 13, 2024
4f349c3
merge taiko branch in
cyberhorsey Oct 8, 2024
47b52e4
return err
cyberhorsey Oct 15, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ taiko ]
tags:
- "v*"
pull_request:
branches: [ taiko ]

jobs:
push-docker-image:
Expand Down
1 change: 1 addition & 0 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
if opts.NoSend {
return signedTx, nil
}
// change(taiko): slot and sig
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if err := c.transactor.SendTransaction(ensureContext(opts.Context), signedTx); err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func makeFullNode(ctx *cli.Context) *node.Node {
v := ctx.Uint64(utils.OverrideVerkle.Name)
cfg.Eth.OverrideVerkle = &v
}
// change(taiko):
if ctx.IsSet(utils.PreconfirmationForwardingURLFlag.Name) {
cfg.Eth.PreconfirmationForwardingURL = ctx.String(utils.PreconfirmationForwardingURLFlag.Name)
}

backend, eth := utils.RegisterEthService(stack, &cfg.Eth)

Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ var (
utils.AllowUnprotectedTxs,
utils.BatchRequestLimit,
utils.BatchResponseMaxSize,
utils.PreconfirmationForwardingURLFlag,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
utils.PreconfirmationForwardingURLFlag,
utils.PreconfirmationForwardingURL,

}

metricsFlags = []cli.Flag{
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,14 @@ var (
Category: flags.APICategory,
}

// CHANGE(taiko): preconf url
PreconfirmationForwardingURLFlag = &cli.StringFlag{
Name: "preconfirmationforwardingurl",
Usage: "URL to forward eth_sendTransaction requests before confirmation",
Category: flags.APICategory,
Value: "",
}

// Gas price oracle settings
GpoBlocksFlag = &cli.IntFlag{
Name: "gpo.blocks",
Expand Down
1 change: 1 addition & 0 deletions consensus/taiko/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (t *Taiko) ValidateAnchorTx(tx *types.Transaction, header *types.Header) (b
}

if tx.GasFeeCap().Cmp(header.BaseFee) != 0 {
log.Info("anchor tx fails validation", "gasFeeCap", tx.GasFeeCap(), "header baseFee", header.BaseFee)
return false, nil
}

Expand Down
5 changes: 5 additions & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)
Expand Down Expand Up @@ -277,6 +278,8 @@ func (st *StateTransition) buyGas() error {
mgval = common.Big0
}
if have, want := st.state.GetBalance(st.msg.From), balanceCheckU256; have.Cmp(want) < 0 {
log.Info("failed to get balance", "have", have, "want", want, "isAnchor", st.msg.IsAnchor)

return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From.Hex(), have, want)
}
if err := st.gp.SubGas(st.msg.GasLimit); err != nil {
Expand Down Expand Up @@ -479,6 +482,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}
effectiveTipU256, _ := uint256.FromBig(effectiveTip)

log.Info("executed transaction", "from", msg.From, "to", msg.To, "gas", st.gasUsed(), "gasPrice", msg.GasPrice, "effectiveTip", effectiveTip, "value", msg.Value, "isAnchor", msg.IsAnchor)

if st.evm.Config.NoBaseFee && msg.GasFeeCap.Sign() == 0 && msg.GasTipCap.Sign() == 0 {
// Skip fee payment when NoBaseFee is set and the fee fields
// are 0. This avoids a negative effectiveTip being applied to
Expand Down
4 changes: 4 additions & 0 deletions core/taiko_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {
chainConfig.ChainID = params.HeklaNetworkID
chainConfig.OntakeBlock = HeklaOntakeBlock
allocJSON = taikoGenesis.HeklaGenesisAllocJSON
case params.PreconfsNetworkID.Uint64():
chainConfig.OntakeBlock = new(big.Int).SetUint64(0)
chainConfig.ChainID = params.PreconfsNetworkID
allocJSON = taikoGenesis.PreconfsGenesisAllocJSON
default:
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
chainConfig.OntakeBlock = InternalDevnetOntakeBlock
Expand Down
3 changes: 3 additions & 0 deletions core/taiko_genesis/genesis_alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ var HeklaGenesisAllocJSON []byte

//go:embed mainnet.json
var MainnetGenesisAllocJSON []byte

//go:embed preconfs.json
var PreconfsGenesisAllocJSON []byte
217 changes: 217 additions & 0 deletions core/taiko_genesis/preconfs.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ type EthAPIBackend struct {
allowUnprotectedTxs bool
eth *Ethereum
gpo *gasprice.Oracle
preconfirmationURL string // change(taiko)
}

// GetPreconfirmationForwardingURL
func (b *EthAPIBackend) GetPreconfirmationForwardingURL() string {
return b.preconfirmationURL
}

// ChainConfig returns the active chain configuration.
Expand Down
6 changes: 5 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type Ethereum struct {
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)

shutdownTracker *shutdowncheck.ShutdownTracker // Tracks if and when the node has shutdown ungracefully

// change(taiko)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

PreconfirmationForwardingURL string
}

// New creates a new Ethereum object (including the initialisation of the common Ethereum object),
Expand Down Expand Up @@ -254,7 +257,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.miner = miner.New(eth, config.Miner, eth.engine)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
// change(TAIKO): preconfirmation URL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// change(TAIKO): preconfirmation URL
// CHANGE(taiko): preconfirmation URL

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil, config.PreconfirmationForwardingURL}
if eth.APIBackend.allowUnprotectedTxs {
log.Info("Unprotected transactions allowed")
}
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ type Config struct {

// OverrideVerkle (TODO: remove after the fork)
OverrideVerkle *uint64 `toml:",omitempty"`

// change(taiko): preconf url
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// change(taiko): preconf url
// CHANGE(taiko): preconf url

PreconfirmationForwardingURL string
}

// CreateConsensusEngine creates a consensus engine for the given chain config.
Expand Down
2 changes: 2 additions & 0 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ func (ec *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64
return uint64(hex), nil
}

// change(taiko): slot / signature for preconfs
// SendTransaction injects a signed transaction into the pending pool for execution.
//
// If the transaction was a contract creation use the TransactionReceipt method to get the
Expand All @@ -628,6 +629,7 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
if err != nil {
return err
}

return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
}

Expand Down
112 changes: 109 additions & 3 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"maps"
"math/big"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -657,6 +658,21 @@ func (api *BlockChainAPI) ChainId() *hexutil.Big {

// BlockNumber returns the block number of the chain head.
func (api *BlockChainAPI) BlockNumber() hexutil.Uint64 {
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding blockNumber request")

// Forward the raw transaction to the specified URL
res, err := forward[string](forwardURL, "eth_blockNumber", nil)

if err == nil && res != nil {
log.Info("forwarded block number request", "res", res)
i, _ := strconv.ParseUint(*res, 0, 64)

log.Info("parsed block number", "bn", hexutil.Uint64(i))
return hexutil.Uint64(i)
}
}

header, _ := api.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available
return hexutil.Uint64(header.Number.Uint64())
}
Expand All @@ -665,6 +681,27 @@ func (api *BlockChainAPI) BlockNumber() hexutil.Uint64 {
// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
// block numbers are also allowed.
func (api *BlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) {
// change(taiko): check to see if it exists from the preconfer.
// Check if PreconfirmationForwardingURL is set
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding balance request", "addr", address.Hex())
if blockNr, ok := blockNrOrHash.Number(); ok {
log.Info("forwarding balance request", "blockNr", blockNr.String())
bal, err := forward[string](forwardURL, "eth_getBalance", []interface{}{address.Hex(), blockNr.String()})
if err == nil && bal != nil {
return (*hexutil.Big)(hexutil.MustDecodeBig(*bal)), nil
}
}

if blockHash, ok := blockNrOrHash.Hash(); ok {
log.Info("forwarding balance request", "blockNr", blockHash.Hex())
bal, err := forward[string](forwardURL, "eth_getBalance", []interface{}{address.Hex(), blockHash.Hex()})
if err == nil && bal != nil {
return (*hexutil.Big)(hexutil.MustDecodeBig(*bal)), nil
}
}
}

state, _, err := api.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state == nil || err != nil {
return nil, err
Expand Down Expand Up @@ -845,7 +882,18 @@ func (api *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.Block
response[field] = nil
}
}
return response, nil
return response, err
} else {
// change(taiko): check to see if it exists from the preconfer.
// Check if PreconfirmationForwardingURL is set
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding getBlockByNumber", "number", number.Int64(), "numberStr", number.String())
// Forward the raw transaction to the specified URL
b, err := forward[map[string]interface{}](forwardURL, "eth_getBlockByNumber", []interface{}{number.String(), fullTx})
if err == nil && b != nil {
return *b, nil
}
}
}
return nil, err
}
Expand All @@ -856,6 +904,16 @@ func (api *BlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash,
block, err := api.b.BlockByHash(ctx, hash)
if block != nil {
return RPCMarshalBlock(block, true, fullTx, api.b.ChainConfig()), nil
} else {
// change(taiko): check to see if it exists from the preconfer.
// Check if PreconfirmationForwardingURL is set
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding getBlockByHash", "hash", hash.Hex())
m, err := forward[map[string]interface{}](forwardURL, "eth_getBlockByHash", []interface{}{hash.Hex(), fullTx})
if err == nil && m != nil {
return *m, nil
}
}
}
return nil, err
}
Expand Down Expand Up @@ -1231,6 +1289,7 @@ func applyMessageWithEVM(ctx context.Context, evm *vm.EVM, msg *core.Message, st
return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout)
}
if err != nil {
log.Info("error executing in doCall", "isAnchor", msg.IsAnchor, "err", err)
return result, fmt.Errorf("err: %w (supplied gas %d)", err, msg.GasLimit)
}
return result, nil
Expand Down Expand Up @@ -1750,6 +1809,26 @@ func (api *TransactionAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Cont

// GetTransactionCount returns the number of transactions the given address has sent for the given block number
func (api *TransactionAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error) {
// change(taiko): check to see if it exists from the preconfer.
// Check if PreconfirmationForwardingURL is set
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding getTransactionCount", "addr", address.Hex())

if blockNr, ok := blockNrOrHash.Number(); ok {
txCount, err := forward[hexutil.Uint64](forwardURL, "eth_getTransactionCount", []interface{}{address.Hex(), blockNr.String()})
if err == nil && txCount != nil {
return txCount, nil
}
}

if blockHash, ok := blockNrOrHash.Hash(); ok {
txCount, err := forward[hexutil.Uint64](forwardURL, "eth_getTransactionCount", []interface{}{address.Hex(), blockHash.Hex()})
if err == nil && txCount != nil {
return txCount, nil
}
}
}

// Ask transaction pool for the nonce which includes pending transactions
if blockNr, ok := blockNrOrHash.Number(); ok && blockNr == rpc.PendingBlockNumber {
nonce, err := api.b.GetPoolNonce(ctx, address)
Expand Down Expand Up @@ -1807,9 +1886,23 @@ func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash com
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
found, tx, blockHash, blockNumber, index, err := api.b.GetTransaction(ctx, hash)
if err != nil {
return nil, NewTxIndexingError() // transaction is not fully indexed
if err != nil || !found {
// change(taiko): check to see if it exists from the preconfer.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// Check if PreconfirmationForwardingURL is set
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding get transaction receipt", "url", forwardURL)
// Forward the raw transaction to the specified URL
m, err := forward[map[string]interface{}](forwardURL, "eth_getTransactionReceipt", []interface{}{hash.Hex()})
if err == nil && m != nil {
return *m, err
}
}

if err != nil {
return nil, NewTxIndexingError() // transaction is not fully indexed
}
}

if !found {
return nil, nil // transaction is not existent or reachable
}
Expand Down Expand Up @@ -1971,9 +2064,22 @@ func (api *TransactionAPI) FillTransaction(ctx context.Context, args Transaction
return &SignTransactionResult{data, tx}, nil
}

// change(taiko): preconf logic
// SendRawTransaction will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
// Check if PreconfirmationForwardingURL is set
if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" {
log.Info("forwarding send raw tx", "url", forwardURL)
// Forward the raw transaction to the specified URL
h, err := forward[string](forwardURL, "eth_sendRawTransaction", []interface{}{input.String()})
if err == nil && h != nil {
return common.HexToHash(*h), nil
} else {
return common.Hash{}, err
}
}

tx := new(types.Transaction)
if err := tx.UnmarshalBinary(input); err != nil {
return common.Hash{}, err
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ func (b *testBackend) setPendingBlock(block *types.Block) {
b.pending = block
}

// change(taiko): get preconf url
func (b testBackend) GetPreconfirmationForwardingURL() string {
return ""
}
func (b testBackend) SyncProgress() ethereum.SyncProgress { return ethereum.SyncProgress{} }
func (b testBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return big.NewInt(0), nil
Expand Down
3 changes: 3 additions & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type Backend interface {
SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64)
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

// change(taiko)
GetPreconfirmationForwardingURL() string
}

func GetAPIs(apiBackend Backend) []rpc.API {
Expand Down
Loading
Loading