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

Support pending moves on EVM chains #6

Merged
merged 4 commits into from
Apr 21, 2022
Merged

Support pending moves on EVM chains #6

merged 4 commits into from
Apr 21, 2022

Conversation

domob1812
Copy link
Collaborator

This implements support for pending moves on EVM chains. That is quite non-trivial to do, as there is no direct way to retrieve "predicted" events for pending transactions. To work around this, we use a geth feature for eth_call that allows overriding state for a transaction simulation:

  • We instrument the Xaya accounts contract so that all move events are not only logged, but also saved into an array in storage.
  • We apply a state override to replace the real accounts contract with this intrumented version.
  • We also apply a state override to place a contract at the move sender's EoA address. This contract has a method that performs the actual transaction we want to simulate, and then reads and returns the "move log array" from the call.
  • This way, we can use eth_call to simulate a particular pending transaction and get all emitted move events in return.

Xaya X now has a "whitelist" of contracts that are likely to send move events. Every pending transaction calling one of them will be simulated as described, and all emitted events processed as potential pending moves (that get then fed into the GSP).

This implements Solidity contracts that we will use with an eth_call
state overlay to instrument the XayaAccounts contract, so that we can
extract the moves generated from pending transactions.

The TrackingAccounts contract will be laid over the real XayaAccounts
contract deployed on-chain, and the CallForwarder contract will be
laid over the sender's EOA address.
This adds support for tracking pending moves on EVM chains.

Extracting predicted log events for pending transactions is actually
non-trivial.  The implementation here uses eth_call to simulate each
transaction received (can be limited to just transactions on our
contract in the future).  geth's state overlays with eth_call are
used to instrument the accounts contract so that we can actually
return all moves afterwards from the call.
This introduces a whitelist of contract addresses, where only
transactions to a whitelisted address actually gets simulated with
eth_call to look for pending moves.

While this might miss some moves (e.g. from custom-deployed contracts),
it ensures that the large majority of transactions on the network, which
are not related to Xaya at all, will get quickly ignored.
This adds support for retrieving the mempool content on EVM chains
(as is needed for "getrawmempool", which in turn is used as part of
pending tracking by libxayagame).

We could have used txpool_content to directly mimic Xaya Core's RPC,
but this has two drawbacks:  First it is a geth extension and one that
is not readily available for some interfaces (and not even enabled by
default in geth), and second this is highly inefficient if we expect
most transactions to be unrelated to Xaya.

Thus instead, we keep track of our own "mempool" based on transactions
received from notifications, and we use a batched eth_getTransactionByHash
call to synchronise this with the underlying node whenever needed.
@domob1812
Copy link
Collaborator Author

Note that this needs support for the eth_call extension in Ganache for successful integration tests.

@domob1812 domob1812 merged commit 68db25e into master Apr 21, 2022
domob1812 added a commit that referenced this pull request Apr 21, 2022
Support pending moves on EVM chains
@domob1812 domob1812 deleted the eth-pending branch April 21, 2022 13:01
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.

1 participant