paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.8k stars 1.06k forks source link

feat req: eth_callBundle #3518

Closed bertmiller closed 9 months ago

bertmiller commented 1 year ago

Describe the feature

Requesting the eth_callBundle API, which is similar to eth_call but takes an ordered list of transactions as an input instead. Here are the args, using the geth type:

type CallBundleArgs struct {
    Txs                    []hexutil.Bytes       `json:"txs"`
    BlockNumber            rpc.BlockNumber       `json:"blockNumber"`
    StateBlockNumberOrHash rpc.BlockNumberOrHash `json:"stateBlockNumber"`
    Coinbase               *string               `json:"coinbase"`
    Timestamp              *uint64               `json:"timestamp"`
    Timeout                *int64                `json:"timeout"`
    GasLimit               *uint64               `json:"gasLimit"`
    Difficulty             *big.Int              `json:"difficulty"`
    BaseFee                *big.Int              `json:"baseFee"`
}

eth_callBundle applies the bundle of transactions (Txs) on top of the state at StateBlockNumberOrHash using block variables that are also passed in. It returns a variety of information about how much gas the bundle used and how much it paid the coinbase address.

Here is the implementation in mev-geth: https://github.com/flashbots/mev-geth/commit/63c86b4cb63906b0a06e00c20b027d384309634d#diff-c426ecd2f7d247753b9ea8c1cc003f21fa412661c1f967d203d4edf8163da344R2067

Additional context

No response

onbjerg commented 1 year ago

Hi @bertmiller! Can you post the return type for completion?

bertmiller commented 1 year ago

CallBundle responds with the following:

type FlashbotsCallBundleResponse struct {
    BundleGasPrice    string                      `json:"bundleGasPrice"`    // "43000001459",
    BundleHash        string                      `json:"bundleHash"`        // "0x2ca9c4d2ba00d8144d8e396a4989374443cb20fb490d800f4f883ad4e1b32158",
    CoinbaseDiff      string                      `json:"coinbaseDiff"`      // "2717471092204423",
    EthSentToCoinbase string                      `json:"ethSentToCoinbase"` // "0",
    GasFees           string                      `json:"gasFees"`           // "2717471092204423",
    Results           []FlashbotsCallBundleResult `json:"results"`           // [],
    StateBlockNumber  int64                       `json:"stateBlockNumber"`  // 12960319,
    TotalGasUsed      int64                       `json:"totalGasUsed"`      // 63197
}

Here is the type used in "Results":

type FlashbotsCallBundleResult struct {
    CoinbaseDiff      string `json:"coinbaseDiff"`      // "2717471092204423",
    EthSentToCoinbase string `json:"ethSentToCoinbase"` // "0",
    FromAddress       string `json:"fromAddress"`       // "0x37ff310ab11d1928BB70F37bC5E3cf62Df09a01c",
    GasFees           string `json:"gasFees"`           // "2717471092204423",
    GasPrice          string `json:"gasPrice"`          // "43000001459",
    GasUsed           int64  `json:"gasUsed"`           // 63197,
    ToAddress         string `json:"toAddress"`         // "0xdAC17F958D2ee523a2206206994597C13D831ec7",
    TxHash            string `json:"txHash"`            // "0xe2df005210bdc204a34ff03211606e5d8036740c686e9fe4e266ae91cf4d12df",
    Value             string `json:"value"`             // "0x"
    Error             string `json:"error"`
    Revert            string `json:"revert"`
}
ameya-deshmukh commented 1 year ago

Hey @onbjerg can I take this up?

mattsse commented 1 year ago

@ameya-deshmukh please go for it,

we just want rust type bindings first, these should go under rpc-types

see for ref:

https://github.com/paradigmxyz/reth/blob/a7f32dbb0b9a297f5df335418e6b8f588426bd7e/crates/rpc/rpc-types/src/eth/transaction/request.rs#L8-L12

ameya-deshmukh commented 1 year ago

Thanks!

bertmiller commented 1 year ago

Hey @ameya-deshmukh did you ever get this over the line?

mattsse commented 1 year ago

fyi @bertmiller we have bindings for mev and eth namespace here

https://github.com/paradigmxyz/mev-share-rs/blob/main/crates/mev-share-rpc-api/src/mev.rs

so we're missing an implementation for this

custom rpc handlers can be plugged into the cli like this

https://github.com/paradigmxyz/reth/blob/main/examples/additional-rpc-namespace-in-cli/src/main.rs

ameya-deshmukh commented 1 year ago

Hey @bertmiller @mattsse I'm actually looking into it, expect a PR soon!

LooterAI commented 1 year ago

Is this going to be implemented anytime soon? @ameya-deshmukh

ameya-deshmukh commented 1 year ago

Hey @LooterAI yes, I'm expecting to raise a PR by the weekend. Thanks :)

chirag-bgh commented 1 year ago

Hey @ameya-deshmukh , do you want to still finish this?

ameya-deshmukh commented 1 year ago

Hey @chirag-bgh yep. Will update on whether or not I can get a PR across this week. If not, please go ahead and pick it up :)

ameya-deshmukh commented 12 months ago

Hey @chirag-bgh I didn't find time to work on this. Please pick it up :)

mattsse commented 9 months ago

we have this now --htp.api eth-call-bundle