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

Bitswap support in Libp2p helper #9626

Merged
merged 21 commits into from
Jan 6, 2022
Merged

Bitswap support in Libp2p helper #9626

merged 21 commits into from
Jan 6, 2022

Conversation

georgeee
Copy link
Member

@georgeee georgeee commented Oct 15, 2021

Explain your changes:

This PR adds support of Bitswap in libp2p helper:

  • It introduces block format to split big data blobs into smaller bitswap blocks
    • Encoding and decoding algorithms for the format are also provided
    • Bitswap support relies heavily on this format to greatly reduce DoS attack surface
  • It integrates with bitswap using LMDB as block storage

Explain how you tested your changes:

There are four layers of testing

  • Testing encoding/decoding of block format
  • Testing small-step semantics of maintaining downloading state of a single resource
  • Testing large-step semantics of maintaining state of multiple resources
  • Testing bitswap in localhost network
    • Network is configured to have maximum 15 connections for each node
    • Testing 500-node network on one run
    • Testing 100-node network on 10 runs
    • Testing 20-node network on 100 runs

Testing on network involves random resource generation and random requesting of the resource by different nodes, deleting some resources from some nodes and then retrying random resource requesting.

Note that testing requires up to 30 GB of RAM and ulimit set to some large value (tested on 100000).

Checklist:

  • Modified the current draft of release notes with details on what is completed or incomplete within this project
  • Document code purpose, how to use it
    • Mention expected invariants, implicit constraints
  • Tests were added for the new behavior
    • Document test purpose, significance of failures
    • Test names should reflect their purpose
  • All tests pass (CI will check this if you didn't)
  • Serialized types are in stable-versioned modules
  • Does this close issues? List them
  • Closes #0000

@georgeee georgeee changed the title Bitswap support [WIP] Bitswap support Oct 15, 2021
@georgeee georgeee force-pushed the georgeee/bitswap branch 2 times, most recently from 1479013 to 1876539 Compare October 21, 2021 19:39
@georgeee georgeee changed the title [WIP] Bitswap support Bitswap support in Libp2p helper Nov 15, 2021
@georgeee georgeee added the ci-build-me Add this label to trigger a circle+buildkite build for this branch label Nov 22, 2021
@georgeee georgeee force-pushed the georgeee/bitswap branch 10 times, most recently from fbf0a5c to 9234741 Compare November 29, 2021 17:20
Copy link
Member

@nholland94 nholland94 left a comment

Choose a reason for hiding this comment

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

Looks great overall, just some small suggestions. I haven't fully reviewed the tests yet, but all of the implementation looks good.

@@ -1,3 +0,0 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
Copy link
Member

Choose a reason for hiding this comment

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

Why were the bazel build related files removed? AFAIK, we have a contractor that's working on bazel support for the repository, so doing this will probably step on their toes.

Copy link
Member Author

@georgeee georgeee Dec 1, 2021

Choose a reason for hiding this comment

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

They are broken now. If someone is working on these, let them commit working build files once they're ready, maybe?

../../libp2p_ipc/libp2p_ipc.capnp.go:
make -C ../../libp2p_ipc libp2p_ipc.capnp.go

libp2p_helper: ../../libp2p_ipc/libp2p_ipc.capnp.go
$(WRAPAPP) ../../../scripts/build-go-helper.sh libp2p_helper

test: ../../libp2p_ipc/libp2p_ipc.capnp.go
$(WRAPAPP) ../../../scripts/build-go-helper.sh --test libp2p_helper
cd src/libp2p_helper && $(GO) test -short -timeout 15m # && $(GO) test -timeout 40m -run "^TestBitswapJumbo$$"
Copy link
Member

Choose a reason for hiding this comment

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

Is the commented version of the test command running different tests? Should we provide multiple Makefile targets for different kinds of tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I will experiment with these a bit more

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't able to run BitswapMedium and BitswapJumbo tests in CI, so left them as make test-large which can be executed on a developer machine.

Other tests are now being executed in CI

Copy link
Member Author

@georgeee georgeee Dec 29, 2021

Choose a reason for hiding this comment

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

P.S. BitswapMedium and BitswapJumbo tests timeout in CI, on my laptop both of them complete in an hour, occupying 90% of 32 GB RAM and a chunk of processor power though.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. These seem like good candidates for nightly CI tests, once we have those setup. Perhaps we can revisit putting them in CI once that infrastructure exists.

}
delete(states, root)
state.allDescedants.ForEach(func(c cid.Cid) error {
np, hasNp := nodeParams[c]
Copy link
Member

Choose a reason for hiding this comment

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

Probably worth noting in a comment that this will need modified when we wish to support shared nodes across Bitswap DAGs (which we will want/need to whenever we put ledger into Bitswap).

Copy link
Member Author

@georgeee georgeee Dec 27, 2021

Choose a reason for hiding this comment

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

@nholland94 could you expand on this please? I'm not following you here.

Shared nodes are already supported or at least were meant to be.

Copy link
Member

Choose a reason for hiding this comment

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

If I understand this algorithm, whenever you clear the download state for a root, you clear that state for all descendants as well. If in the future we have shared nodes across roots, then you would need to keep a refcount for all the descendant nodes and only clear their download state when the refcount reaches 0.

src/app/libp2p_helper/src/libp2p_helper/bitswap.go Outdated Show resolved Hide resolved
src/app/libp2p_helper/src/bitswap_storage.go Outdated Show resolved Hide resolved
src/app/libp2p_helper/src/libp2p_helper/app.go Outdated Show resolved Hide resolved
rootDownloadStates := bs.RootDownloadStates()
depthIndices := bs.DepthIndices()
oldPs, foundRoot := nodeDownloadParams[id]
delete(nodeDownloadParams, id)
Copy link
Member

Choose a reason for hiding this comment

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

What happens if we a processing the same downloaded block in parallel? Is that possible? I'm worried about potential race conditions on accessing the node download params.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can check that Loop is only ran once. All these data structures are accessed only from functions called from within the Loop(). These are most importantly kickStartRootDownload and processDownloadedBlock. You can check that within these functions no new goroutines are produced.

So, basically, the execution is single-threaded by design.

src/app/libp2p_helper/src/libp2p_helper/bitswap.go Outdated Show resolved Hide resolved
@georgeee georgeee force-pushed the georgeee/bitswap branch 5 times, most recently from 3a3e46b to 3116ffc Compare December 29, 2021 08:41
Plus allow to configure Bitswap with Config message
and fix Daemon compilation.
+ abstract block downloading logic from irrelevant implementation
  details
Implement test for big-step semantic of block download
state machine.
Problem: jumbo test is resource-intensive and
is better to be executed separately.

Solution: skip jumbo test in "short" mode.
They fail in CI due to lack of resources currently,
but can be executed on developer's laptop.
Problem: case of non-empty block storage is
not well covered. An existing bug wasn't
caught due to this (was caught only via PR review).

Solution: add test (which fails).
Some stylistic changes + bugfix
Copy link
Member

@bkase bkase left a comment

Choose a reason for hiding this comment

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

Product review is good otherwise

@@ -1,201 +0,0 @@
Apache License
Copy link
Member

Choose a reason for hiding this comment

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

can you un-remove the license?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bkase my intuition was that LICENSE at the root of Mina repository applies here unless specified otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

sounds good 👍

@georgeee georgeee merged commit d653a68 into compatible Jan 6, 2022
@georgeee georgeee deleted the georgeee/bitswap branch January 6, 2022 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-build-me Add this label to trigger a circle+buildkite build for this branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants