Skip to content

chore: use ethers for ethereum-storage #467

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

Closed
wants to merge 48 commits into from
Closed

Conversation

benjlevesque
Copy link
Contributor

@benjlevesque benjlevesque commented Mar 26, 2021

Motivations

  • ethers is used everywhere in the codebase
  • web3 causes the node to crash if connection breaks
  • types and code readability

Additionally, this allows to remove hd-wallet-provider which limits the number of dependencies to maintain

@benjlevesque benjlevesque changed the base branch from master to bnjs March 27, 2021 00:40
@benjlevesque benjlevesque changed the title eth storage ethers chore: use ethers for ethereum-storage Mar 27, 2021
@benjlevesque benjlevesque force-pushed the bnjs branch 2 times, most recently from 2cb737f to 8122ecc Compare March 29, 2021 15:46
Base automatically changed from bnjs to master March 29, 2021 16:03
@coveralls
Copy link

coveralls commented Aug 19, 2021

Coverage Status

Coverage decreased (-0.3%) to 88.899% when pulling 43c4104 on eth-storage-ethers into 5fbc0b4 on master.

const url = config.getStorageWeb3ProviderUrl();
if (url.match('^wss?://.+')) {
provider = new providers.WebSocketProvider(url);
// FIXME previous WS config
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexandre-abrioux any idea what we should do here?

Copy link
Member

@alexandre-abrioux alexandre-abrioux Dec 2, 2021

Choose a reason for hiding this comment

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

You can do this:

provider = new providers.Web3Provider(
  new Web3WsProvider(url, {
    //  previous WS config
  }),
)

; or, if we want to completely remove web3js dependencies, I can take care of it in another PR, for now just remove the if (wss) block or throw an "unsupported" error in the block, as ethers.js does not handle auto-reconnect, cf. ethers-io/ethers.js#1053

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the point is to remove web3 completely yes

Copy link
Member

Choose a reason for hiding this comment

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

We should use this solution then: ethers-io/ethers.js#1053 (comment) , we just need to abstract the provider in it's own module.

@@ -494,6 +495,31 @@ describe('Request client using a request node', () => {
const requests = await badRequestNetwork.fromTopic(myRandomTopic);
expect(requests).toHaveLength(0);
});

it('can create multiple requests in parallel', async () => {
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 added this test because it seemed that the node wouldn't accespt multiple transactions at once.

} else {
provider = new HDWalletProvider(mnemonic, config.getStorageWeb3ProviderUrl());
provider = new providers.StaticJsonRpcProvider(url);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using a StaticJsonRpcProvider allows to reduce the number of calls (eth_chainId for instance)

Copy link
Contributor

Choose a reason for hiding this comment

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

I discovered it with ct. I should have told you so.

LENGTH_BYTES32_STRING,
const feesParametersAsBytes = utils.hexZeroPad(
utils.hexlify(feesParameters.contentSize),
LENGTH_BYTES32_STRING / 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of the way hexZeroPad works

Copy link
Contributor

@vrolland vrolland left a comment

Choose a reason for hiding this comment

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

Awesome PR ! Well done!

} else {
provider = new HDWalletProvider(mnemonic, config.getStorageWeb3ProviderUrl());
provider = new providers.StaticJsonRpcProvider(url);
Copy link
Contributor

Choose a reason for hiding this comment

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

I discovered it with ct. I should have told you so.

Copy link
Member

@yomarion yomarion left a comment

Choose a reason for hiding this comment

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

Not easy to review but everything looks good to me, nice move !

// Keep the transaction hash for future needs
let transactionHash = '';
const transactionParameters = {
// This boolean is set to true once the ethereum metadata has been created and the promise has been resolved
Copy link
Member

Choose a reason for hiding this comment

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

??

expect(events[0].returnValues.feesParameters).toEqual(realSizeBytes32Hex);
expect(events[0].args.hash).toEqual(hashStr);
expect(events[0].args.hashSubmitter.toLowerCase()).toEqual(addressRequestHashSubmitter);
expect(events[0].args.feesParameters).toEqual(realSizeBytes32Hex);
});

// TODO since the migration to jest, this test fails.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO since the migration to jest, this test fails.

Good one :)

jest
.spyOn(smartContractManager.ethereumBlocks.provider, 'getBlockNumber')
.mockImplementation(() => Promise.resolve(9));
// TODO ? smartContractManager.ethereumBlocks = new EthereumBlocks(mockEth, 1, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

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

reminder

Copy link
Contributor

@bertux bertux left a comment

Choose a reason for hiding this comment

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

big good job 👍
I wondered if renaming eth as provider would make it more confusing later because it's more generic word but it's also the word used by etherjs so it's good for now.

Copy link
Member

@alexandre-abrioux alexandre-abrioux left a comment

Choose a reason for hiding this comment

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

Amazing refacto 💯

@@ -103,34 +104,30 @@ const mockBlocksEthereum = [
9807,
9906,
];
const provider = new providers.JsonRpcProvider('http://localhost:8545');
Copy link
Member

@alexandre-abrioux alexandre-abrioux Dec 9, 2021

Choose a reason for hiding this comment

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

(Idea for later, to think about) We could do this to not depend on any external service for unit tests
(but this would reintroduce some web3 dependencies 😆)

import ganache from "ganache";
const provider = new ethers.providers.Web3Provider(ganache.provider());

@benjlevesque benjlevesque enabled auto-merge (squash) December 9, 2021 11:40
@benjlevesque benjlevesque removed the request for review from kevindavee April 29, 2022 13:35
@benjlevesque benjlevesque marked this pull request as draft May 19, 2022 07:52
auto-merge was automatically disabled May 19, 2022 07:52

Pull request was converted to draft

@MantisClone
Copy link
Member

Is this PR still relevant?

@benjlevesque benjlevesque deleted the eth-storage-ethers branch December 6, 2022 08:47
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.

8 participants