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

Split P2P Topics And Introduce Middleware (Adapters) #421

Merged
merged 32 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
45b9df2
thinking about adapters
prestonvanloon Aug 5, 2018
0fc242a
more progress on exploring p2p middleware stack
prestonvanloon Aug 6, 2018
e3ee2ca
some more progress on the middleware stack idea
prestonvanloon Aug 7, 2018
826afea
added a bit more to the example
prestonvanloon Aug 7, 2018
1978ecf
working on testing
prestonvanloon Aug 7, 2018
393c9b4
working a bit more on tests
prestonvanloon Aug 9, 2018
5f4c379
Merge branch 'master' of github.com:prysmaticlabs/prysm into p2p_adap…
prestonvanloon Aug 9, 2018
54c761d
Merge branch 'master' into p2p_adapters
prestonvanloon Aug 19, 2018
daa6014
Merge branch 'p2p_adapters' of github.com:prestonvanloon/prysm into p…
prestonvanloon Aug 19, 2018
b02aecc
more progress on p2p abstraction with adapters
prestonvanloon Aug 19, 2018
6caaef2
split topics
prestonvanloon Aug 19, 2018
1da3adb
split topics
prestonvanloon Aug 19, 2018
7bced19
split topics
prestonvanloon Aug 19, 2018
80fe715
add other config
prestonvanloon Aug 19, 2018
41b03c9
Merge branch 'master' into p2p_adapters
prestonvanloon Aug 19, 2018
e6c32f3
fix example
prestonvanloon Aug 19, 2018
558139b
newline
prestonvanloon Aug 23, 2018
1a0770d
merge master
prestonvanloon Aug 23, 2018
fe95160
fix merge
prestonvanloon Aug 23, 2018
3d8646d
move more after merge
prestonvanloon Aug 23, 2018
55cc0c3
fix godoc
prestonvanloon Aug 24, 2018
23daf90
a bit more tests
prestonvanloon Aug 24, 2018
aa77a94
merge assignment
prestonvanloon Aug 24, 2018
91f8352
update from PR feedback
prestonvanloon Aug 26, 2018
fe49351
merge and conflicts
prestonvanloon Aug 26, 2018
287839f
PR feedback
prestonvanloon Aug 29, 2018
7f83b6f
another go (func
prestonvanloon Aug 29, 2018
7b3e0ff
PR feedback that I missed
prestonvanloon Aug 29, 2018
0500af6
gofmt
prestonvanloon Aug 29, 2018
3ecf3bd
gazelle
prestonvanloon Aug 29, 2018
a683da2
Merge branch 'master' into p2p_adapters
prestonvanloon Aug 29, 2018
e13aa0c
Merge branch 'master' into p2p_adapters
rauljordan Aug 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,9 @@ go_repository(
commit = "c4c61651e9e37fa117f53c5a906d3b63090d8445",
importpath = "github.com/syndtr/goleveldb",
)

go_repository(
name = "com_github_libp2p_go_libp2p_blankhost",
commit = "073f507db72de824e981aa0f15f158175a8d6be1",
importpath = "github.com/libp2p/go-libp2p-blankhost",
)
6 changes: 5 additions & 1 deletion beacon-chain/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["node.go"],
srcs = [
"node.go",
"p2p_config.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/node",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
Expand All @@ -13,6 +16,7 @@ go_library(
"//beacon-chain/sync:go_default_library",
"//beacon-chain/sync/initial-sync:go_default_library",
"//beacon-chain/utils:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared:go_default_library",
"//shared/cmd:go_default_library",
"//shared/database:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ func (b *BeaconNode) startDB(ctx *cli.Context) error {
}

func (b *BeaconNode) registerP2P() error {
beaconp2p, err := p2p.NewServer()
beaconp2p, err := configureP2P()
if err != nil {
return fmt.Errorf("could not register p2p service: %v", err)
}

return b.services.RegisterService(beaconp2p)
}

Expand Down
35 changes: 35 additions & 0 deletions beacon-chain/node/p2p_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package node

import (
"github.com/prysmaticlabs/prysm/shared/p2p"

pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)

var topicMappings = map[pb.Topic]interface{}{
pb.Topic_BEACON_BLOCK_HASH_ANNOUNCE: pb.BeaconBlockHashAnnounce{},
pb.Topic_BEACON_BLOCK_REQUEST: pb.BeaconBlockRequest{},
pb.Topic_BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER: pb.BeaconBlockRequestBySlotNumber{},
pb.Topic_BEACON_BLOCK_RESPONSE: pb.BeaconBlockResponse{},
pb.Topic_CRYSTALLIZED_STATE_HASH_ANNOUNCE: pb.CrystallizedStateHashAnnounce{},
pb.Topic_CRYSTALLIZED_STATE_REQUEST: pb.CrystallizedStateRequest{},
pb.Topic_CRYSTALLIZED_STATE_RESPONSE: pb.CrystallizedStateResponse{},
pb.Topic_ACTIVE_STATE_HASH_ANNOUNCE: pb.ActiveStateHashAnnounce{},
pb.Topic_ACTIVE_STATE_REQUEST: pb.ActiveStateRequest{},
pb.Topic_ACTIVE_STATE_RESPONSE: pb.ActiveStateResponse{},
}

func configureP2P() (*p2p.Server, error) {
s, err := p2p.NewServer()
if err != nil {
return nil, err
}

// TODO(437, 438): Define default adapters for logging, monitoring, etc.
var adapters []p2p.Adapter
for k, v := range topicMappings {
s.RegisterTopic(k.String(), v, adapters...)
}

return s, nil
}
1 change: 1 addition & 0 deletions beacon-chain/sync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
race = "off", # TODO(#377): fix issues with race detection testing.
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/p2p:go_default_library",
Expand Down
14 changes: 13 additions & 1 deletion proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ proto/
sharding/
p2p/
v1/
testing/
```

We specify messages available for p2p communication common to beacon chain nodes and sharding clients.
We specify messages available for p2p communication common to beacon chain nodes and sharding clients.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a few sections here about the p2p middleware stuff for visibility?

Copy link
Member Author

Choose a reason for hiding this comment

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

What does this have to do with protos?


For now, we are checking in all generated code to support native go dependency
management. The generated pb.go files can be derived from bazel's bin
directory.

For example, when we build the testing go proto library
`bazel build //proto/testing:ethereum_testing_go_proto` there is a pb.go
generated at
`bazel-bin/proto/testing/linux_amd64_stripped/ethereum_testing_go_proto\~/github.com/prysmaticlabs/prysm/proto/testing/test.pb.go`.
This generated file can be copied, or you can use you protoc locally if you
prefer.
313 changes: 187 additions & 126 deletions proto/beacon/p2p/v1/messages.pb.go
100644 → 100755

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions proto/beacon/p2p/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ package ethereum.beacon.p2p.v1;

import "google/protobuf/timestamp.proto";

enum Topic {
UNKNOWN = 0;
BEACON_BLOCK_HASH_ANNOUNCE = 1;
BEACON_BLOCK_REQUEST = 2;
BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER = 3;
BEACON_BLOCK_RESPONSE = 4;
CRYSTALLIZED_STATE_HASH_ANNOUNCE = 5;
CRYSTALLIZED_STATE_REQUEST = 6;
CRYSTALLIZED_STATE_RESPONSE = 7;
ACTIVE_STATE_HASH_ANNOUNCE = 8;
ACTIVE_STATE_REQUEST = 9;
ACTIVE_STATE_RESPONSE = 10;
}

message BeaconBlockHashAnnounce {
bytes hash = 1;
}
Expand Down
164 changes: 64 additions & 100 deletions proto/sharding/p2p/v1/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions proto/sharding/p2p/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ syntax = "proto3";

package ethereum.sharding.p2p.v1;

// TODO: Split the topics into p2p for beacon chain and p2p for sharding.
enum Topic {
UNKNOWN = 0;
COLLATION_BODY_REQUEST = 1;
COLLATION_BODY_RESPONSE = 2;
TRANSACTIONS = 3;
BEACON_BLOCK_HASH_ANNOUNCE = 4;
BEACON_BLOCK_REQUEST = 5;
BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER = 6;
BEACON_BLOCK_RESPONSE = 7;
CRYSTALLIZED_STATE_HASH_ANNOUNCE = 8;
CRYSTALLIZED_STATE_REQUEST = 9;
CRYSTALLIZED_STATE_RESPONSE = 10;
ACTIVE_STATE_HASH_ANNOUNCE = 11;
ACTIVE_STATE_REQUEST = 12;
ACTIVE_STATE_RESPONSE = 13;
}

message CollationBodyRequest {
Expand Down
Loading