-
Notifications
You must be signed in to change notification settings - Fork 150
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
feat(all): preconfs #281
Changes from all commits
c8648e9
5c474c0
ed57045
9e91c83
e4147eb
9316c67
3e33107
962c01a
d4ae804
283c866
07d9ac7
8175e6d
0be6e70
c09982c
11547c6
86dc5a9
ca1606a
7c97fef
28837e2
22827b7
239690d
a175b68
e085b23
c8e4db3
9dc9717
002515b
f61e2dd
aeeeda0
d1ebecb
58b373f
ffd909d
4edd506
6a3418e
b138398
139410e
7e281e2
323c733
6cd1f75
f07fe35
9d01948
cd44d64
7391e27
4ccf51d
d1ab2fb
bf451ad
b96e4b7
6674bcf
cd7ecf3
b46389f
9a8241c
c579ad7
6f0827b
c6597c6
a2e96fd
7510e3c
649a1e5
dc64cdf
34d90f5
66e3912
4f349c3
47b52e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ on: | |
branches: [ taiko ] | ||
tags: | ||
- "v*" | ||
pull_request: | ||
branches: [ taiko ] | ||
|
||
jobs: | ||
push-docker-image: | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -190,6 +190,7 @@ var ( | |||||
utils.AllowUnprotectedTxs, | ||||||
utils.BatchRequestLimit, | ||||||
utils.BatchResponseMaxSize, | ||||||
utils.PreconfirmationForwardingURLFlag, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
metricsFlags = []cli.Flag{ | ||||||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||||||
|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil, config.PreconfirmationForwardingURL} | ||||||
if eth.APIBackend.allowUnprotectedTxs { | ||||||
log.Info("Unprotected transactions allowed") | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -157,6 +157,9 @@ type Config struct { | |||||
|
||||||
// OverrideVerkle (TODO: remove after the fork) | ||||||
OverrideVerkle *uint64 `toml:",omitempty"` | ||||||
|
||||||
// change(taiko): preconf url | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
PreconfirmationForwardingURL string | ||||||
} | ||||||
|
||||||
// CreateConsensusEngine creates a consensus engine for the given chain config. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"fmt" | ||
"maps" | ||
"math/big" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -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()) | ||
} | ||
|
@@ -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 | ||
|
@@ -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 | ||
} | ||
|
@@ -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 | ||
} | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
@@ -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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto