From 283fedd05b57bbedc8142601ac86e9992b3c12cd Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:16:06 -0800 Subject: [PATCH] chore(cmd): remove `--taiko.preconfirmationForwardingUrl` flag (#362) * remove forwading tx's, as will be fetched from mempool * addtl config --- cmd/geth/config.go | 5 -- cmd/geth/main.go | 2 - cmd/utils/taiko_flags.go | 5 -- eth/api_backend.go | 14 +--- eth/backend.go | 4 +- eth/ethconfig/config.go | 3 - internal/ethapi/api.go | 12 --- internal/ethapi/api_test.go | 5 -- internal/ethapi/backend.go | 3 - internal/ethapi/taiko_preconf.go | 94 ------------------------ internal/ethapi/transaction_args_test.go | 5 -- 11 files changed, 5 insertions(+), 147 deletions(-) delete mode 100644 internal/ethapi/taiko_preconf.go diff --git a/cmd/geth/config.go b/cmd/geth/config.go index ef37a55d70..87481c8050 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -192,11 +192,6 @@ func makeFullNode(ctx *cli.Context) *node.Node { cfg.Eth.OverrideVerkle = &v } - // CHANGE(taiko): set preconfirmation forwarding URL. - if ctx.IsSet(utils.PreconfirmationForwardingURLFlag.Name) { - cfg.Eth.PreconfirmationForwardingURL = ctx.String(utils.PreconfirmationForwardingURLFlag.Name) - } - backend, eth := utils.RegisterEthService(stack, &cfg.Eth) // CHANGE(TAIKO): register Taiko RPC APIs. diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 927368e8bb..7cc11f55a2 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -260,8 +260,6 @@ func init() { debug.Flags, metricsFlags, ) - // CHANGE(taiko): append Taiko flags into the original GETH flags - app.Flags = append(app.Flags, utils.TaikoFlag, utils.PreconfirmationForwardingURLFlag) flags.AutoEnvVars(app.Flags, "GETH") diff --git a/cmd/utils/taiko_flags.go b/cmd/utils/taiko_flags.go index 74de57f2f1..b297aeb013 100644 --- a/cmd/utils/taiko_flags.go +++ b/cmd/utils/taiko_flags.go @@ -18,11 +18,6 @@ var ( Usage: "Taiko network", Category: flags.TaikoCategory, } - PreconfirmationForwardingURLFlag = &cli.StringFlag{ - Name: "taiko.preconfirmationForwardingUrl", - Usage: "URL to forward RPC requests before confirmation", - Category: flags.TaikoCategory, - } ) // RegisterTaikoAPIs initializes and registers the Taiko RPC APIs. diff --git a/eth/api_backend.go b/eth/api_backend.go index 02d05494b2..8a9898b956 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -44,11 +44,10 @@ import ( // EthAPIBackend implements ethapi.Backend and tracers.Backend for full nodes type EthAPIBackend struct { - extRPCEnabled bool - allowUnprotectedTxs bool - eth *Ethereum - gpo *gasprice.Oracle - preconfirmationForwardingURL string // CHANGE(taiko): add preconfirmation forwarding URL + extRPCEnabled bool + allowUnprotectedTxs bool + eth *Ethereum + gpo *gasprice.Oracle } // ChainConfig returns the active chain configuration. @@ -432,8 +431,3 @@ func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, re func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (*types.Transaction, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) { return b.eth.stateAtTransaction(ctx, block, txIndex, reexec) } - -// GetPreconfirmationForwardingURL returns the URL to forward RPC requests before confirmation. -func (b *EthAPIBackend) GetPreconfirmationForwardingURL() string { - return b.preconfirmationForwardingURL -} diff --git a/eth/backend.go b/eth/backend.go index 8dcbfe7628..9b0df6382b 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -96,8 +96,6 @@ 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 - - PreconfirmationForwardingURL string // CHANGE(taiko): add preconfirmation forwarding URL } // New creates a new Ethereum object (including the initialisation of the common Ethereum object), @@ -257,7 +255,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData)) // CHANGE(taiko): set up the pre-confirmation forwarding URL - eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil, config.PreconfirmationForwardingURL} + eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil} if eth.APIBackend.allowUnprotectedTxs { log.Info("Unprotected transactions allowed") } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 12b1415dd1..1fd9b1cf37 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -157,9 +157,6 @@ type Config struct { // OverrideVerkle (TODO: remove after the fork) OverrideVerkle *uint64 `toml:",omitempty"` - - // CHANGE(taiko): add preconfirmation forwarding URL - PreconfirmationForwardingURL string } // CreateConsensusEngine creates a consensus engine for the given chain config. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 8d9d9d1ea0..a502952893 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1974,18 +1974,6 @@ func (api *TransactionAPI) FillTransaction(ctx context.Context, args Transaction // 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) { - // CHANGE(taiko): Forward the request to the preconf node if specified. - if forwardURL := api.b.GetPreconfirmationForwardingURL(); forwardURL != "" { - log.Info("Forwarding SendRawTransaction request", "forwardURL", 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 diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 6f2c00dba7..384ca9f1cc 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -3400,8 +3400,3 @@ func testRPCResponseWithFile(t *testing.T, testid int, result interface{}, rpc s func addressToHash(a common.Address) common.Hash { return common.BytesToHash(a.Bytes()) } - -// CHANGE(taiko): add preconfirmation forwarding URL -func (b testBackend) GetPreconfirmationForwardingURL() string { - return "" -} diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 4e2a9b0cad..0e991592b4 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -96,9 +96,6 @@ type Backend interface { SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription BloomStatus() (uint64, uint64) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) - - // CHANGE(taiko): add preconfirmation forwarding URL - GetPreconfirmationForwardingURL() string } func GetAPIs(apiBackend Backend) []rpc.API { diff --git a/internal/ethapi/taiko_preconf.go b/internal/ethapi/taiko_preconf.go deleted file mode 100644 index e99cd9a40b..0000000000 --- a/internal/ethapi/taiko_preconf.go +++ /dev/null @@ -1,94 +0,0 @@ -package ethapi - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "net/http" - - "github.com/ethereum/go-ethereum/log" -) - -type rpcRequest struct { - Jsonrpc string `json:"jsonrpc"` - Method string `json:"method"` - Params []interface{} `json:"params"` - ID int `json:"id"` -} - -type rpcResponse struct { - Jsonrpc string `json:"jsonrpc"` - ID int `json:"id"` - Result *json.RawMessage `json:"result"` - Error *struct { - Code int `json:"code"` - Message string `json:"message"` - Data string `json:"data"` - } `json:"error,omitempty"` -} - -func forward[T any](forwardURL string, method string, params []interface{}) (*T, error) { - rpcReq := rpcRequest{ - Jsonrpc: "2.0", - Method: method, - Params: params, - ID: 1, - } - - jsonData, err := json.Marshal(rpcReq) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", forwardURL, bytes.NewBuffer(jsonData)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/json") - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("failed to forward transaction, status code: %d", resp.StatusCode) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - var rpcResp rpcResponse - - // Unmarshal the response into the struct - if err := json.Unmarshal(body, &rpcResp); err != nil { - return nil, err - } - - // Check for errors in the response - if rpcResp.Error != nil { - err := fmt.Errorf("RPC error %d: %s", rpcResp.Error.Code, rpcResp.Error.Message) - - log.Error("forwarded request error", "err", err, "method", method, "params", params) - - return nil, fmt.Errorf("RPC error %d: %s", rpcResp.Error.Code, rpcResp.Error.Message) - } - - if rpcResp.Result == nil { - log.Warn("forwarded request result is nil", "method", method) - return nil, nil - } - - // Unmarshal the Result into the desired type - var result T - if err := json.Unmarshal(*rpcResp.Result, &result); err != nil { - return nil, err - } - - return &result, nil -} diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 39787509fa..5317828173 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -405,8 +405,3 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) } func (b *backendMock) Engine() consensus.Engine { return nil } - -// CHANGE(taiko): add preconfirmation forwarding URL -func (b *backendMock) GetPreconfirmationForwardingURL() string { - return "" -}