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

Add p2p.Network component #2283

Merged
merged 39 commits into from
Nov 30, 2023
Merged

Add p2p.Network component #2283

merged 39 commits into from
Nov 30, 2023

Conversation

joshua-kim
Copy link
Contributor

@joshua-kim joshua-kim commented Nov 9, 2023

Why this should be merged

RegisterAppProtocol in the Router currently (and in the future will likely have more) allows the caller to configure the Client to make requests with. Because the Router only knows about user-defined handlers, it doesn't have a great way of offering default values if a Client isn't configured with certain values.

This PR introduces a Network component that wraps a Router and tracks network state. Clients that don't use default options values will have their defaults derived from the Network struct.

How this works

Changes:

  • Router is now un-exported, people should implement p2p networking logic by wrapping Network instead.
  • Peers is now un-exported, it's offered as a default in Network.
  • RegisterAppProtocol now takes in a variadic list of options that can configure a Client instead of allowing callers to pass in nil.

Coreth PR: ava-labs/coreth#384

How this was tested

UTs

@joshua-kim joshua-kim self-assigned this Nov 9, 2023
@joshua-kim joshua-kim added the networking This involves networking label Nov 9, 2023
@joshua-kim joshua-kim marked this pull request as ready for review November 9, 2023 17:18
network/p2p/network.go Outdated Show resolved Hide resolved
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
network/p2p/peers_test.go Outdated Show resolved Hide resolved
network/p2p/peers.go Outdated Show resolved Hide resolved
@@ -22,12 +22,18 @@ var (
)

type ValidatorSet interface {
Has(ctx context.Context, nodeID ids.NodeID) bool
Has(ctx context.Context, nodeID ids.NodeID) bool // TODO return error
Copy link
Contributor Author

@joshua-kim joshua-kim Nov 15, 2023

Choose a reason for hiding this comment

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

In hindsight logging the error instead of bubbling it up was a bad idea.

@@ -71,20 +78,33 @@ func (v *Validators) refresh(ctx context.Context) {
v.lastUpdated = time.Now()
}

// Sample returns a random sample of connected validators
func (v *Validators) Sample(ctx context.Context, limit int) []ids.NodeID {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also consider resampling if the validator we get is disconnected

Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
network/p2p/network.go Outdated Show resolved Hide resolved
network/p2p/network_test.go Outdated Show resolved Hide resolved
network/p2p/network.go Outdated Show resolved Hide resolved
network/p2p/validators.go Outdated Show resolved Hide resolved
network/p2p/network_test.go Outdated Show resolved Hide resolved
network/p2p/validators_test.go Show resolved Hide resolved
network/p2p/validators.go Outdated Show resolved Hide resolved
network/p2p/network.go Outdated Show resolved Hide resolved
@joshua-kim joshua-kim linked an issue Nov 28, 2023 that may be closed by this pull request
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
network/p2p/router.go Outdated Show resolved Hide resolved
network/p2p/validators.go Outdated Show resolved Hide resolved
joshua-kim and others added 3 commits November 29, 2023 15:36
Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
go.mod Outdated Show resolved Hide resolved
joshua-kim and others added 3 commits November 29, 2023 16:36
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
@joshua-kim
Copy link
Contributor Author

Pending approval on coreth: ava-labs/coreth#384

@StephenButtolph StephenButtolph added this to the v1.10.17 milestone Nov 30, 2023
Copy link
Contributor

@marun marun left a comment

Choose a reason for hiding this comment

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

(No action required) I think there may be room for improvement on the testing front - validating corner-cases at this level of abstraction would seem to require too many moving pieces to be easily reasoned about.

@StephenButtolph StephenButtolph added this pull request to the merge queue Nov 30, 2023
Merged via the queue into dev with commit de3b16c Nov 30, 2023
16 checks passed
@StephenButtolph StephenButtolph deleted the network branch November 30, 2023 18:12
joshua-kim added a commit that referenced this pull request Dec 6, 2023
commit b36416d
Author: Alberto Benegiamo <alberto.benegiamo@gmail.com>
Date:   Wed Dec 6 12:12:11 2023 -0700

    Drop Pending Stakers 1 - introduced ScheduledStaker txs (#2323)

    Co-authored-by: Stephen Buttolph <stephen@avalabs.org>

commit 7df1f3a
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Dec 6 13:46:56 2023 -0500

    Restrict GOPROXY (#2434)

commit 21b7ab8
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Dec 5 19:43:00 2023 -0500

    Fix platformvm.SetPreference (#2429)

commit ada692a
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Tue Dec 5 17:40:03 2023 -0500

    Update minimum golang version to v1.20.12 (#2427)

commit 004a23e
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Tue Dec 5 12:56:25 2023 -0500

    `vms/platformvm`: Add `decisionTxs` parameter to `NewBanffProposalBlock` (#2411)

    Co-authored-by: Dan Laine <daniel.laine@avalabs.org>

commit 439dc1e
Author: Alberto Benegiamo <alberto.benegiamo@gmail.com>
Date:   Tue Dec 5 10:46:13 2023 -0700

    ProposerVM Extend windows 0 - Cleanup (#2404)

    Co-authored-by: Stephen Buttolph <stephen@avalabs.org>

commit 477157d
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Tue Dec 5 11:10:56 2023 -0500

    `vms/platformvm`: Cleanup some block tests (#2422)

    Co-authored-by: Dan Laine <daniel.laine@avalabs.org>

commit b6700c9
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Mon Dec 4 22:24:34 2023 -0500

    Update slices dependency to use Compare (#2424)

    Co-authored-by: James Walker <jim.walker@smartcontract.com>

commit 5d9e482
Author: Dan Laine <daniel.laine@avalabs.org>
Date:   Mon Dec 4 19:27:29 2023 -0500

    allow user of `build_fuzz.sh` to specify a directory to fuzz in (#2414)

commit 2e32281
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Mon Dec 4 18:30:41 2023 -0500

    Fix duplicated bootstrapper engine termination (#2334)

    Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
    Co-authored-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>

commit b741c19
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Mon Dec 4 17:49:15 2023 -0500

    `vms/platformvm`: Move `VerifyUniqueInputs` from `verifier` to `backend` (#2410)

commit 6aa20fc
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Mon Dec 4 17:32:07 2023 -0500

    `vms/platformvm`: Initialize txs in `Transactions` field for `BanffProposalBlock` (#2419)

commit c11accd
Author: Alberto Benegiamo <alberto.benegiamo@gmail.com>
Date:   Mon Dec 4 09:16:01 2023 -0700

    Drop Pending Stakers 0 - De-duplicate staking tx verification (#2335)

commit 05ce366
Author: marun <maru.newby@avalabs.org>
Date:   Sat Dec 2 13:33:18 2023 -0800

    testing: Update to latest version of ginkgo (#2390)

commit 04af33e
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Sat Dec 2 16:33:07 2023 -0500

    `vms/platformvm`: Cleanup block builder tests (#2406)

    Co-authored-by: Stephen Buttolph <stephen@avalabs.org>

commit 7623ffd
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Fri Dec 1 19:39:15 2023 -0500

    Update versions for v1.10.17 (#2394)

commit be1a2ad
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Fri Dec 1 13:31:49 2023 -0500

    Add more descriptive formatted error (#2403)

    Co-authored-by: Stephen Buttolph <stephen@avalabs.org>

commit 9b85141
Author: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
Date:   Thu Nov 30 12:42:36 2023 -0800

    `vms/platformvm`: Move `GetRewardUTXOs`, `GetSubnets`, and `GetChains` to `State` interface (#2402)

commit de3b16c
Author: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Date:   Thu Nov 30 12:49:53 2023 -0500

    Add `p2p.Network` component (#2283)

    Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
    Co-authored-by: Stephen Buttolph <stephen@avalabs.org>

commit 0ab2046
Author: marun <maru.newby@avalabs.org>
Date:   Thu Nov 30 09:18:59 2023 -0800

    Rename `testnet` fixture to `tmpnet` (#2307)

commit 907b34c
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Nov 29 21:32:43 2023 -0500

    Update bootstrap IPs (#2396)

commit 96d451d
Author: Stephen Buttolph <stephen@avalabs.org>
Date:   Wed Nov 29 18:15:47 2023 -0500

    Periodically PullGossip only from connected validators (#2399)

commit 0da5bcc
Author: Dan Laine <daniel.laine@avalabs.org>
Date:   Wed Nov 29 16:32:16 2023 -0500

    Remove method `CappedList` from `set.Set` (#2395)

Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
networking This involves networking
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Document p2p.Validators Refactor SDK Clients to accept variadic options parameters
3 participants