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

client: fix libp2p sync and browser example #1588

Merged
merged 18 commits into from
Dec 2, 2021
Merged

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Nov 27, 2021

This PR:

  • Fixes Buffer is not defined from webpack by specifying the polyfill
  • Fixes libp2p sync by removing a premature PEER_CONNECTED in peer:connected
  • Fixes browser IndexedDB cross-session data reloading based on chain name
  • Fixes the browser_sync.png image location and updates to the latest expected output

To help test this PR, please try running through the steps in examples/light-browser-sync.md

* remove premature PEER_CONNECTED
* parse bootnodes, set consistent chainDB
* tidy libp2p files and other small fixes
@codecov
Copy link

codecov bot commented Nov 27, 2021

Codecov Report

Merging #1588 (eef1c14) into master (595f456) will increase coverage by 0.19%.
The diff coverage is 86.84%.

Impacted file tree graph

Flag Coverage Δ
block 84.96% <ø> (ø)
blockchain 85.08% <ø> (ø)
client 70.84% <86.84%> (+0.68%) ⬆️
common 100.00% <ø> (ø)
devp2p 82.89% <ø> (-0.07%) ⬇️
ethash ∅ <ø> (∅)
trie 86.09% <ø> (ø)
tx 88.60% <ø> (ø)
util 91.81% <ø> (ø)
vm 79.32% <ø> (ø)

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

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.

Hi there,
nice that you are tackling this 🙂, have left some first comments.

There is still 1 client test failing here, not sure if you have seen this.

I would be interested to do a production test on this along the browser example lines, not sure if I'll be getting to that though, just as some note.

import PeerId from 'peer-id'
import { Multiaddr } from 'multiaddr'
// types currently unavailable for below libp2p deps,
// tracking issue: https://github.com/libp2p/js-libp2p/issues/659
const LibP2pWebsockets = require('libp2p-websockets')
Copy link
Member

Choose a reason for hiding this comment

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

Just out of interest (without further digging in): the referenced issue here libp2p/js-libp2p#659 is still open, could this nevertheless be resolved?

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 was able to convert a few of the modules to import, the rest are still on require, I think it's obvious at this point that any modules using require are due to missing types, so I thought I'd clean up/remove the comment.

@ryanio
Copy link
Contributor Author

ryanio commented Nov 29, 2021

ok this should be ready for final review/merge unless there are any other suggested changes

Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

This generally looks great to me. Only thing I see is the code coverage missing on some lines. I'll see about adding some tests on the sync pieces to test the new logger warnings.

@@ -33,11 +37,6 @@ const args = yargs(hideBin(process.argv))
choices: networks.map((n) => parseInt(n[0])),
default: undefined,
})
.option('network-id', {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

'network-id' option was defined twice here

@acolytec3
Copy link
Contributor

acolytec3 commented Dec 1, 2021

@ryanio after I spent the time writing them, I'm not so certain the new tests I added for the blockfetcher actually test anything useful. They do help with code coverage but methinks they're kind of pointless since they mock the part of the code that actually triggers the error or not. Thoughts? I guess I could check that the FETCHER_FETCHED event fires but that's probably about the extent of useful testing on these.

@ryanio
Copy link
Contributor Author

ryanio commented Dec 2, 2021

I think that's fine, thanks for adding them! definitely helped with the coverage :)

@acolytec3
Copy link
Contributor

And I think we finally hit the code coverage requirements too. I've spent the last while trying to figure out how to grab the debugger output but can't for the life of me figure out how to redirect it from stderr to something I can actually check. I'm gonna add one more small set of tests around the fetcher since we don't have much coverage there anyway and will then be done.

Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

LGTM

@ryanio ryanio merged commit fcaceaf into master Dec 2, 2021
@ryanio ryanio deleted the fix-client-libp2p branch December 2, 2021 02:59
const client = await runNode(config)
const servers = args.rpc || args.rpcEngine ? runRpcServers(client, config, args) : []
const client = await startClient(config)
const servers = args.rpc || args.rpcEngine ? startRPCServers(client) : []

process.on('SIGINT', async () => {
config.logger.info('Caught interrupt signal. Shutting down...')
Copy link
Member

Choose a reason for hiding this comment

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

Whew.

That's a really great and much needed clean-up on the CLI script!!! 😄 👍

Nice.

🎉

st.pass('store() emitted SYNC_FETCHER_FETCHED event on putting blocks')
)
await fetcher.store([])
})
Copy link
Member

Choose a reason for hiding this comment

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

Nice, all these new test cases are really great as well! 😄

Especially the Fetcher is a beasty thing, so that's nice if we get to better coverage there, also for reproducing things and having certain functionality parts more directly called.

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