Skip to content

rpc: add eth_callMany#1

Merged
yiteng-guo merged 3 commits into
hudson-trading:eth_callManyfrom
hrthaowang:callIntraBundleAlpha
Jun 27, 2022
Merged

rpc: add eth_callMany#1
yiteng-guo merged 3 commits into
hudson-trading:eth_callManyfrom
hrthaowang:callIntraBundleAlpha

Conversation

@hrthaowang

Copy link
Copy Markdown

For this PR, I implemented callIntraBundle to simulate bundles at an arbitrary blockchain index and its corresponding testing suite eth_block_test.go.

For a sample python test,

import json
import requests
url = "http://127.0.0.1:8545"
headers = {"content-type": "application/json"}

reserveTx = {
    "from": "0xB283366D2AF84036e76b1166A7395A735435baFD",
    "to": "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc",
    "nonce": "0x0",
    "gas": "0x13880",
    'maxPriorityFeePerGas': "0x59682f00",
    'maxFeePerGas': "0x28ade5e73c",
    "value": "0x0",
    'type': '0x2',
    "data": "0x0902f1ac"
}
params = [
    [{"txs": [reserveTx],"stateOverride" : {
        "0xB283366D2AF84036e76b1166A7395A735435baFD": {
            "balance": "0xde0b6b3a7640000"
        }
    }}],  # bundles  # bundle
    {"BlockNumberOrHash": 14917087, "transactionIndex": 234},  # simulationContxt
    500 * 100,  # timeoff
]
payload = json.dumps(
    {"jsonrpc": "2.0", "id": 2, "method": "eth_callIntraBundle", "params": params}
)
r = requests.post(url, payload, headers=headers)
r.content

Using this testing script, we could obtain the reserves of USD-ETH UNI V2 Pair. Since it's highly liquid, there are multiple sync events in the same block. With the intra-block simulation, we could get the intermediate reserves.

Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So erigon doesn't support eth_call on pending blocks? If that's the case, we can ignore the support for pending blocks.

Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_block.go Outdated
@hrthaowang

Copy link
Copy Markdown
Author

I followed your comment and updated the code correspondingly. Could you review my revision when you're free? Thank you!

@yiteng-guo

Copy link
Copy Markdown

I left some comments on python tests. Could you make changes on this PR accordingly to address those comments?

@yiteng-guo yiteng-guo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove changes that are unrelated tot this PR.

Comment thread 1q Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could you remove this change?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

let's give this a new name since we changed the RPC call name?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment on lines 66 to 77

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can't you just return in the for-loop?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment on lines 96 to 101

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you just slice the array?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you explain what txCtx is used for? This txCtx is still the firstMsg txCtx. Could that be a problem?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

txCtx is for tracking the origin of a certain transaction, so we probably want to initialize a new evm for each transaction.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see. Then we probably want to call transactions.GetEvmContext for each transaction?

@hrthaowang hrthaowang force-pushed the callIntraBundleAlpha branch from 69214f5 to 21b115b Compare June 16, 2022 15:25
Comment on lines +90 to +98
transactionIndex := -1

if simulateContext.TransactionIndex != nil {
transactionIndex = *simulateContext.TransactionIndex
}

if transactionIndex == -1 {
transactionIndex = len(block.Transactions())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's add comments here to document -1 is a speical value?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see. Then we probably want to call transactions.GetEvmContext for each transaction?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment on lines +118 to +123
firstMsg, err := bundles[0].Transactions[0].ToMessage(api.GasCap, nil)
rules := chainConfig.Rules(blockNum)

if len(replayTransactions) > 0 {
firstMsg, err = replayTransactions[0].AsMessage(*signer, nil, rules)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As I mentioned in the other comment, I think a cleaner way to implement this is to call transactions.GetEvmContext for each transaction. Then you don't need to save this firstMsg.

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment on lines +162 to +163
blockCtx, txCtx := transactions.GetEvmContext(firstMsg, parent, simulateContext.BlockNumber.RequireCanonical, tx, contractHasTEVM)
evm = vm.NewEVM(blockCtx, txCtx, st, chainConfig, vm.Config{Debug: false})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Move these to for-loop?

Comment thread cmd/rpcdaemon/commands/eth_callMany.go Outdated
Comment on lines +221 to +230
blockCtx.GetHash = func(i uint64) common.Hash {
if hash, ok := overrideBlockHash[i]; ok {
return hash
}
hash, err := rawdb.ReadCanonicalHash(tx, i)
if err != nil {
log.Debug("Can't get block hash by number", "number", i, "only-canonical", true)
}
return hash
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can't we just set this once before the for-loop?

@yiteng-guo yiteng-guo changed the title add callIntraBundle rpc: add eth_callMany Jun 27, 2022
yiteng-guo pushed a commit that referenced this pull request Jun 27, 2022
* progress #1

* progress #2

* proper file naming

* more mature memory mutation
@yiteng-guo yiteng-guo changed the base branch from devel to eth_callMany June 27, 2022 15:27
@yiteng-guo yiteng-guo merged commit c86d54c into hudson-trading:eth_callMany Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants