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

Update EthersStateManager to be RpcStateManager under the hood #3167

Merged
merged 18 commits into from
Nov 30, 2023

Conversation

acolytec3
Copy link
Contributor

@acolytec3 acolytec3 commented Nov 27, 2023

Several improvements for EthersStateManager

  • Remove ethers dependency and replace with raw JSON RPC calls similar to Block.fromJsonRpcProvider
  • Adds implementation of minimal blockchain class that mimics existing evm DefaultBlockchain behavior - has benefit of fixing issue where BLOCKHASH opcode wouldn't work right under EthersStateManager
  • Updates EthersStateManager tests with better mocks for JSON-RPC provider
  • Updates readme with revised usage patterns

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

Merging #3167 (d0b4bd6) into master (9d756c2) will decrease coverage by 0.06%.
Report is 2 commits behind head on master.
The diff coverage is 86.36%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 88.80% <ø> (ø)
blockchain 91.61% <ø> (ø)
client 84.91% <ø> (ø)
common 98.19% <ø> (ø)
devp2p 82.09% <ø> (?)
ethash ∅ <ø> (∅)
evm 73.53% <100.00%> (+1.59%) ⬆️
statemanager 90.10% <83.78%> (-0.03%) ⬇️
trie 89.76% <ø> (+0.04%) ⬆️
tx 95.73% <ø> (ø)
util 88.90% <ø> (ø)
vm 81.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@acolytec3 acolytec3 changed the title Experiments with EtherStateManager blockchain supplemental work Update EthersStateManager to be RpcStateManager under the hood Nov 29, 2023
Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

Some minor comments

if (typeof opts.provider === 'string') {
this._provider = new ethers.JsonRpcProvider(opts.provider)
} else if (opts.provider instanceof ethers.JsonRpcProvider) {
if (typeof opts.provider === 'string' && opts.provider.startsWith('http')) {
Copy link
Member

Choose a reason for hiding this comment

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

This is fine, but just noting: we thus do not have websocket support. (Also does not seem that fetchFromProvider accepts this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. This only works over HTTP. If anyone ever asks about websocket support, we can explore it. I'm not sure if node's native fetch instance supports WS anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If ws are added in future you might need to use an isomorphic library or dependency inject it to get it to work in both client and node

@jochem-brouwer
Copy link
Member

I don't understand, tests and linter fail locally (also after a fresh build), but not on CI? 😓

@jochem-brouwer
Copy link
Member

Nvm, did not pull 🤦

@acolytec3 acolytec3 mentioned this pull request Nov 30, 2023
3 tasks
Copy link
Collaborator

@roninjin10 roninjin10 left a comment

Choose a reason for hiding this comment

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

This is amazing! Big improvement from pulling in viem or ethers.js to do something that can be done with this much less code.

I noticed the error handling on fetchFromProvider was less than ideal so I opened a PR to improve it: #3171

if (typeof opts.provider === 'string') {
this._provider = new ethers.JsonRpcProvider(opts.provider)
} else if (opts.provider instanceof ethers.JsonRpcProvider) {
if (typeof opts.provider === 'string' && opts.provider.startsWith('http')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If ws are added in future you might need to use an isomorphic library or dependency inject it to get it to work in both client and node

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

Small nits

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

LGTM, great work 🙏 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants