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

Kick ethers off the block #2633

Merged
merged 11 commits into from
Apr 14, 2023
Merged

Kick ethers off the block #2633

merged 11 commits into from
Apr 14, 2023

Conversation

acolytec3
Copy link
Contributor

@acolytec3 acolytec3 commented Apr 12, 2023

Removes ethers from block and tx libraries as a dependency and replace fromEthersProvider internals with fetch calls to retrieve data from provider

  • Creates new fetchFromProvider utility in util for retrieving data from a generic JSON RPC provider
  • Removes dependency on ethers from both tx and block
  • Fixes various tests
  • Updates testdouble to latest version and fixes td.replace typing in client/devp2p

@codecov
Copy link

codecov bot commented Apr 12, 2023

Codecov Report

Merging #2633 (4dce10c) into master (205dc35) will decrease coverage by 0.03%.
The diff coverage is 77.61%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 90.18% <52.00%> (-0.23%) ⬇️
blockchain 90.40% <ø> (ø)
client 87.12% <ø> (ø)
common 95.74% <ø> (ø)
devp2p 91.75% <ø> (-0.11%) ⬇️
ethash ∅ <ø> (∅)
evm 79.39% <ø> (ø)
rlp ∅ <ø> (∅)
statemanager 89.61% <ø> (ø)
trie 90.02% <ø> (-0.35%) ⬇️
tx 94.43% <100.00%> (+0.04%) ⬆️
util 85.17% <90.62%> (+0.09%) ⬆️
vm 84.54% <ø> (ø)

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

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

looks good, assuming you will substitute micro-ftch

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

One additional review question

}
}

const providerUtils = require('@ethereumjs/util/dist/provider')
Copy link
Member

Choose a reason for hiding this comment

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

Does this needs to be required in such a strange way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to get a concrete reference to the function I want to stub using testdouble and this is the only way I could come up with to do it. I spent several hours trying to stub the fetch calls directly without success when I was using cross-fetch as the backend. I might be able to do more direct stubbing now that we're using micro-ftch so will see if I can make it work correctly.

blockTag: string | bigint,
opts: BlockOptions
) => {
let blockData
const prov =
typeof provider === 'string' ? new ethers.providers.JsonRpcProvider(provider) : provider
const providerUrl = getProvider(provider)
Copy link
Contributor

Choose a reason for hiding this comment

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

so the provider is essentially being stripped out. not sure if this is the right approach as the provider might be providing some wrapper functionality (like proof seeking and verification)

May be we can later revisit this on how to best interface a provider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where would a provider do proof verification? We could put cleanly define the provider interface (at least for the minimal functions we'd need to call) I supposed but that feels like more work than it's worth and very brittle if ethers or web3js (if we support that provider type too in the future) ever change their API. At the end of the day, we're just making an HTTP call to some remote RPC provider to get the json blob back for the blob or the tx. But, that said, happy to discuss further. We need to add a todo on the breaking release to rename the fromEthersProvider functions anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Can we eventually test for the Ethers import to work (in a try/catch block) and only do this stripping out as a fallback solution? Then we might somewhat have best of both worlds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we could but all we were doing before was calling the provider.send method which is just abstracting a raw JSON RPC call. Here again, we weren't using any provider-specific functionality, just a simple wrapper around HTTP requests. As such, I'm not sure what we gain since we'd have to blindly call the provider and hope nothing in the API has changed. I don't think what I've done in this PR is any worse than that.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, good reasoning, then let's merge here.

I would now plan a round of "normal" releases for sometime mid next week, will prepare release notes next Monday or so.

const LesProtocol = td.constructor([] as any)
td.replace('../../lib/net/protocol/lesprotocol', { LesProtocol })
td.replace<any>('../../lib/net/protocol/lesprotocol', { LesProtocol })
Copy link
Contributor

Choose a reason for hiding this comment

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

just wondering why do we have to now explicitly type it to any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testdouble did a minor version upgrade that got picked up when I added it to tx and block as a devDependency and their td.replace function now explicitly returns an object of type unknown instead any if you don't specify the type to return. I can back this version bump out and pin to the previous version if people are concerned about it.

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

two comments/observations, but looks good to me

@holgerd77 holgerd77 marked this pull request as ready for review April 14, 2023 06:38
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

LGTM

@holgerd77 holgerd77 merged commit efc4487 into master Apr 14, 2023
@holgerd77 holgerd77 deleted the kickethersofftheblock branch April 14, 2023 06:40
acolytec3 added a commit that referenced this pull request May 12, 2023
* Make `block.fromEthersProvider` provider agnostic

* Finish block

* Move provider utils to util

* Remove ethers from tx

* skip fetch test in browser context

* Fix tests

* Fix td typing

* more td typing

* Switch fetch dep to micro-ftch

* Add error handling
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.

3 participants