From 45b9df25611796de65b06ce8cf33a61be7f6015c Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 5 Aug 2018 12:06:23 -0400 Subject: [PATCH 01/24] thinking about adapters --- shared/p2p/adapter_example_test.go | 5 +++++ shared/p2p/p2p.go | 27 +++++++++++++++++++++++++++ shared/p2p/service.go | 9 --------- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 shared/p2p/adapter_example_test.go create mode 100644 shared/p2p/p2p.go diff --git a/shared/p2p/adapter_example_test.go b/shared/p2p/adapter_example_test.go new file mode 100644 index 000000000000..3bdd5b7dc074 --- /dev/null +++ b/shared/p2p/adapter_example_test.go @@ -0,0 +1,5 @@ +package p2p + +func ExampleAdapter() { + +} diff --git a/shared/p2p/p2p.go b/shared/p2p/p2p.go new file mode 100644 index 000000000000..2a5492d42d70 --- /dev/null +++ b/shared/p2p/p2p.go @@ -0,0 +1,27 @@ +// Package p2p handles peer-to-peer networking for Ethereum 2.0 clients. +// +// There are three types of p2p communications. +// +// - Direct: two peer communication +// - Floodsub: peer broadcasting to all peers +// - Gossipsub: peer broadcasting to localized peers +// +// Read more about gossipsub at https://github.com/vyzo/gerbil-simsub +// +// Notes: +// Gossip sub topics can be identified by their proto message types. +// +// topic := proto.MessageName(myMsg) +// +// Then we can assume that only these message types are broadcast in that +// gossip subscription. +package p2p + +import "context" + +// Use this file for interfaces only! + +// Adapters are used to create middleware. +type Adapter func(context.Context, Message, Handler) + +type Handler func(context.Context, Message) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 21155e511859..03d5a5918692 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -1,12 +1,3 @@ -// Package p2p handles peer-to-peer networking for the sharding package. -// -// Notes: -// Gossip sub topics can be identified by their proto message types. -// -// topic := proto.MessageName(myMsg) -// -// Then we can assume that only these message types are broadcast in that -// gossip subscription. package p2p import ( From 0fc242a49c37dc27ff4186d2c59658f44f9b4cd5 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 5 Aug 2018 22:16:11 -0400 Subject: [PATCH 02/24] more progress on exploring p2p middleware stack --- shared/p2p/BUILD.bazel | 2 ++ shared/p2p/adapter_example_test.go | 5 --- shared/p2p/p2p.go | 8 ++--- shared/p2p/register_topic_example_test.go | 39 +++++++++++++++++++++++ shared/p2p/service.go | 11 +++++++ 5 files changed, 54 insertions(+), 11 deletions(-) delete mode 100644 shared/p2p/adapter_example_test.go create mode 100644 shared/p2p/register_topic_example_test.go diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index de87fb0e7a31..534540738eed 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -7,6 +7,7 @@ go_library( "feed.go", "message.go", "options.go", + "p2p.go", "peer.go", "service.go", "topics.go", @@ -33,6 +34,7 @@ go_library( go_test( name = "go_default_test", srcs = [ + "adapter_example_test.go", "discovery_test.go", "feed_example_test.go", "feed_test.go", diff --git a/shared/p2p/adapter_example_test.go b/shared/p2p/adapter_example_test.go deleted file mode 100644 index 3bdd5b7dc074..000000000000 --- a/shared/p2p/adapter_example_test.go +++ /dev/null @@ -1,5 +0,0 @@ -package p2p - -func ExampleAdapter() { - -} diff --git a/shared/p2p/p2p.go b/shared/p2p/p2p.go index 2a5492d42d70..2495bb77c1b0 100644 --- a/shared/p2p/p2p.go +++ b/shared/p2p/p2p.go @@ -6,15 +6,11 @@ // - Floodsub: peer broadcasting to all peers // - Gossipsub: peer broadcasting to localized peers // -// Read more about gossipsub at https://github.com/vyzo/gerbil-simsub +// However, this communication is abstracted through the Feed, Broadcast, and Send. // -// Notes: -// Gossip sub topics can be identified by their proto message types. // -// topic := proto.MessageName(myMsg) // -// Then we can assume that only these message types are broadcast in that -// gossip subscription. +// Read more about gossipsub at https://github.com/vyzo/gerbil-simsub package p2p import "context" diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go new file mode 100644 index 000000000000..fe94c9f4a1ee --- /dev/null +++ b/shared/p2p/register_topic_example_test.go @@ -0,0 +1,39 @@ +package p2p_test + +import ( + "context" + "fmt" + + "github.com/prysmaticlabs/prysm/shared/p2p" +) + + +// A basic adapter will complete its logic then call next. Some adapters +// may choose not to call next. For example, in the case of a rate +// limiter or blacklisting condition. +func reqLogger(ctx context.Context, msg p2p.Message, next p2p.Handler) { + fmt.Println("Received message from %s", msg.Peer) + next(ctx, msg) +} + +// Functions can return an adapter in order to capture configuration. +func adapterWithParams(i int) p2p.Adapter { + return func(ctx context.Context, msg p2p.Message, next p2p.Handler) { + fmt.Println("Magic number is %d", i) + i++ + next(ctx, msg) + } +} + +func ExampleServer_RegisterTopic() { + adapters := []p2p.Adapter{reqLogger,adapterWithParams(5)} + + s, _ := p2p.NewServer() + + // TODO: Figure out the topic. Is it a protobuf topic, string, or int? + var topic interface{} + var message interface{} + + s.RegisterTopic(topic, message, adapters) + +} diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 03d5a5918692..e78dfce2e1fe 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -82,6 +82,17 @@ func (s *Server) Stop() error { return nil } +// RegisterTopic, message, and the adapter stack for the given topic. The message type provided +// will be feed selector for emitting messages received on a given topic. +// +// The topics can originate from multiple sources. In other words, messages on TopicA may come +// from direct peer communication or a pub/sub channel. +// +// TODO +func (s *Server) RegisterTopic(topic, message interface{}, adapters ...Adapter) { + // TODO +} + // Subscribe returns a subscription to a feed of msg's Type and adds the channels to the feed. func (s *Server) Subscribe(msg interface{}, channel interface{}) event.Subscription { return s.Feed(msg).Subscribe(channel) From e3ee2caa325f64df240c49da50b4e14d5b7722a4 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Mon, 6 Aug 2018 20:39:31 -0400 Subject: [PATCH 03/24] some more progress on the middleware stack idea --- shared/p2p/BUILD.bazel | 2 +- shared/p2p/p2p.go | 5 ++ shared/p2p/register_topic_example_test.go | 25 ++++---- shared/p2p/service.go | 70 +++++++++++++++++++---- 4 files changed, 78 insertions(+), 24 deletions(-) diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index 534540738eed..a07d7bc1cea3 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -34,11 +34,11 @@ go_library( go_test( name = "go_default_test", srcs = [ - "adapter_example_test.go", "discovery_test.go", "feed_example_test.go", "feed_test.go", "options_test.go", + "register_topic_example_test.go", "service_test.go", "topics_test.go", ], diff --git a/shared/p2p/p2p.go b/shared/p2p/p2p.go index 2495bb77c1b0..4a29e30dcee3 100644 --- a/shared/p2p/p2p.go +++ b/shared/p2p/p2p.go @@ -18,6 +18,11 @@ import "context" // Use this file for interfaces only! // Adapters are used to create middleware. +// +// See http://godoc.org/github.com/prysmaticlabs/prysm/shared/p2p#Server.RegisterTopic type Adapter func(context.Context, Message, Handler) +// Handlers are the callback used in the adapter/middleware stack chain. +// +// See http://godoc.org/github.com/prysmaticlabs/prysm/shared/p2p#Server.RegisterTopic type Handler func(context.Context, Message) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index fe94c9f4a1ee..7ee4d12da1f7 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -3,13 +3,12 @@ package p2p_test import ( "context" "fmt" - + "github.com/prysmaticlabs/prysm/shared/p2p" ) - // A basic adapter will complete its logic then call next. Some adapters -// may choose not to call next. For example, in the case of a rate +// may choose not to call next. For example, in the case of a rate // limiter or blacklisting condition. func reqLogger(ctx context.Context, msg p2p.Message, next p2p.Handler) { fmt.Println("Received message from %s", msg.Peer) @@ -26,14 +25,14 @@ func adapterWithParams(i int) p2p.Adapter { } func ExampleServer_RegisterTopic() { - adapters := []p2p.Adapter{reqLogger,adapterWithParams(5)} - - s, _ := p2p.NewServer() - - // TODO: Figure out the topic. Is it a protobuf topic, string, or int? - var topic interface{} - var message interface{} - - s.RegisterTopic(topic, message, adapters) - + adapters := []p2p.Adapter{reqLogger, adapterWithParams(5)} + + s, _ := p2p.NewServer() + + // TODO: Figure out the topic. Is it a protobuf topic, string, or int? + var topic string + var message interface{} + + s.RegisterTopic(topic, message, adapters) + } diff --git a/shared/p2p/service.go b/shared/p2p/service.go index e78dfce2e1fe..31781e559133 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -66,12 +66,12 @@ func (s *Server) Start() { } // Subscribe to all topics. - for topic, msgType := range topicTypeMapping { - log.WithFields(logrus.Fields{ - "topic": topic, - }).Debug("Subscribing to topic") - go s.subscribeToTopic(topic, msgType) - } + // for topic, msgType := range topicTypeMapping { + // log.WithFields(logrus.Fields{ + // "topic": topic, + // }).Debug("Subscribing to topic") + // go s.subscribeToTopic(topic, msgType) + // } } // Stop the main p2p loop. @@ -86,11 +86,61 @@ func (s *Server) Stop() error { // will be feed selector for emitting messages received on a given topic. // // The topics can originate from multiple sources. In other words, messages on TopicA may come -// from direct peer communication or a pub/sub channel. -// +// from direct peer communication or a pub/sub channel. +// // TODO -func (s *Server) RegisterTopic(topic, message interface{}, adapters ...Adapter) { - // TODO +func (s *Server) RegisterTopic(topic string, message interface{}, adapters []Adapter) { + var msgType reflect.Type // TODO + log.WithFields(logrus.Fields{ + "topic": topic, + }).Debug("Subscribing to topic") + + sub, err := s.gsub.Subscribe(topic) + if err != nil { + log.Errorf("Failed to subscribe to topic: %v", err) + return + } + defer sub.Cancel() + feed := s.Feed(msgType) + + for { + msg, err := sub.Next(s.ctx) + + if s.ctx.Err() != nil { + return // Context closed or something. + } + if err != nil { + log.Errorf("Failed to get next message: %v", err) + return + } + + // TODO: Run the adapter stack. + + s.emit(feed, msg, msgType) + } + +} + +// TODO: rename +func (s *Server) emit(feed *event.Feed, msg *floodsub.Message, msgType reflect.Type) { + + // TODO: reflect.Value.Interface() can panic so we should capture that + // panic so the server doesn't crash. + d, ok := reflect.New(msgType).Interface().(proto.Message) + if !ok { + log.Error("Received message is not a protobuf message") + return + } + if err := proto.Unmarshal(msg.Data, d); err != nil { + log.Errorf("Failed to decode data: %v", err) + return + } + + i := feed.Send(Message{Data: d}) + log.WithFields(logrus.Fields{ + "numSubs": i, + }).Debug("Sent a request to subs") + } // Subscribe returns a subscription to a feed of msg's Type and adds the channels to the feed. From 826afeaad88afde4137de4e0ef38fb2333fd2898 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Mon, 6 Aug 2018 21:01:57 -0400 Subject: [PATCH 04/24] added a bit more to the example --- shared/p2p/register_topic_example_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index 7ee4d12da1f7..09fd055e7297 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -35,4 +35,8 @@ func ExampleServer_RegisterTopic() { s.RegisterTopic(topic, message, adapters) + ch := make(chan p2p.Message) + sub := s.Subscribe(message, ch) + defer sub.Unsubscribe() + // TODO: Show more of how the chan is used. } From 1978ecfdac929f7977b13c7bf7d1754cf7d9980c Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Mon, 6 Aug 2018 21:44:57 -0400 Subject: [PATCH 05/24] working on testing --- shared/p2p/register_topic_example_test.go | 2 +- shared/p2p/service.go | 29 +++++++++++++---------- shared/p2p/service_test.go | 20 ++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index 09fd055e7297..ebc3a98dabdf 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -33,7 +33,7 @@ func ExampleServer_RegisterTopic() { var topic string var message interface{} - s.RegisterTopic(topic, message, adapters) + s.RegisterTopic(topic, message, adapters...) ch := make(chan p2p.Message) sub := s.Subscribe(message, ch) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 31781e559133..b070b3b1dbd5 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -89,7 +89,7 @@ func (s *Server) Stop() error { // from direct peer communication or a pub/sub channel. // // TODO -func (s *Server) RegisterTopic(topic string, message interface{}, adapters []Adapter) { +func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Adapter) { var msgType reflect.Type // TODO log.WithFields(logrus.Fields{ "topic": topic, @@ -103,21 +103,24 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters []Ada defer sub.Cancel() feed := s.Feed(msgType) - for { - msg, err := sub.Next(s.ctx) + // TODO: Run this as the last step in the adapter stack. + go (func() { + for { + msg, err := sub.Next(s.ctx) - if s.ctx.Err() != nil { - return // Context closed or something. - } - if err != nil { - log.Errorf("Failed to get next message: %v", err) - return - } + if s.ctx.Err() != nil { + return // Context closed or something. + } + if err != nil { + log.Errorf("Failed to get next message: %v", err) + return + } - // TODO: Run the adapter stack. + // TODO: Run the adapter stack. - s.emit(feed, msg, msgType) - } + s.emit(feed, msg, msgType) + } + })() } diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index 0c0ce5682b98..e6884ba56d73 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -161,3 +161,23 @@ func testSubscribe(ctx context.Context, t *testing.T, s Server, gsub *floodsub.P t.Error("Context timed out before a message was received!") } } + +func TestRegisterTopic(t *testing.T) { + s, err := NewServer() + if err != nil { + t.Fatalf("Failed to create new server: %v", err) + } + + topic := "test_topic" + + type TestMessage struct{} + + s.RegisterTopic(topic, TestMessage{}) + + // TODO: Publish a message on this topic and expect that it is received from a feed. +} + +func TestRegisterTopic_WithAdapers(t *testing.T) { + // TODO: Test that adapters are called. + // TODO: Use a test suite for different conditions. +} From 393c9b42d21ca3f52c49fccd128fe93e84daf794 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 8 Aug 2018 21:56:46 -0400 Subject: [PATCH 06/24] working a bit more on tests --- shared/p2p/service_test.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index e6884ba56d73..141bb5315409 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -174,7 +174,38 @@ func TestRegisterTopic(t *testing.T) { s.RegisterTopic(topic, TestMessage{}) - // TODO: Publish a message on this topic and expect that it is received from a feed. + ch := make(chan Message) + sub := s.Subscribe(TestMessage{}, ch) + defer sub.Unsubscribe() + + wait := make(chan struct{}) + go (func() { + defer close(wait) + msg := <-ch + _ = msg + })() + + if err := simulateIncomingMessage(s, topic, []byte{}); err != nil { + t.Errorf("Failed to send to topic %s", topic) + } + + select { + case <-wait: + return // OK + case <-time.After(5 * time.Second): + t.Fatal("TestMessage not received within 5 seconds") + } +} + +func simulateIncomingMessage(s *Server, topic string, b []byte) error { + // TODO + // Create a new host + + // Connect to s.Host + + // Use the new connection to Publish msg on topic + + return nil } func TestRegisterTopic_WithAdapers(t *testing.T) { From b02aecc57560ca17b515798cd3b059bc60cd3176 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 19 Aug 2018 14:04:38 -0400 Subject: [PATCH 07/24] more progress on p2p abstraction with adapters --- WORKSPACE | 6 ++ beacon-chain/node/BUILD.bazel | 5 +- beacon-chain/node/node.go | 3 +- beacon-chain/node/p2p_config.go | 21 +++++ proto/README.md | 14 +++- proto/testing/BUILD.bazel | 24 ++++++ proto/testing/test.pb.go | 73 +++++++++++++++++ proto/testing/test.proto | 7 ++ shared/p2p/BUILD.bazel | 3 +- shared/p2p/p2p.go | 11 +-- shared/p2p/register_topic_example_test.go | 18 +++-- shared/p2p/service.go | 42 +++++----- shared/p2p/service_test.go | 99 ++++++++++++++++++----- 13 files changed, 270 insertions(+), 56 deletions(-) create mode 100644 beacon-chain/node/p2p_config.go create mode 100644 proto/testing/BUILD.bazel create mode 100755 proto/testing/test.pb.go create mode 100644 proto/testing/test.proto diff --git a/WORKSPACE b/WORKSPACE index c9156e45f55b..e7edbea14d5f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", +) diff --git a/beacon-chain/node/BUILD.bazel b/beacon-chain/node/BUILD.bazel index 0605ba02a472..1f6243cb7dba 100644 --- a/beacon-chain/node/BUILD.bazel +++ b/beacon-chain/node/BUILD.bazel @@ -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 = [ diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index e38ae52a1cd3..8b440f82630a 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -139,10 +139,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) } diff --git a/beacon-chain/node/p2p_config.go b/beacon-chain/node/p2p_config.go new file mode 100644 index 000000000000..246705aebf3d --- /dev/null +++ b/beacon-chain/node/p2p_config.go @@ -0,0 +1,21 @@ +package node + +import ( + "github.com/prysmaticlabs/prysm/shared/p2p" +) + +func configureP2P() (*p2p.Server, error) { + s, err := p2p.NewServer() + if err != nil { + return nil, err + } + + // Configure adapters + var adapters []p2p.Adapter + type TestInterface struct { + } + + s.RegisterTopic("test_topic", TestInterface{}, adapters...) + + return s, nil +} diff --git a/proto/README.md b/proto/README.md index 14b6695b5ff2..d5466c819820 100644 --- a/proto/README.md +++ b/proto/README.md @@ -12,6 +12,18 @@ proto/ sharding/ p2p/ v1/ + testing/ ``` -We specify messages available for p2p communication common to beacon chain nodes and sharding clients. \ No newline at end of file +We specify messages available for p2p communication common to beacon chain nodes and sharding clients. + +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. \ No newline at end of file diff --git a/proto/testing/BUILD.bazel b/proto/testing/BUILD.bazel new file mode 100644 index 000000000000..f6b385b07741 --- /dev/null +++ b/proto/testing/BUILD.bazel @@ -0,0 +1,24 @@ +package(default_testonly = True) + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +proto_library( + name = "ethereum_testing_proto", + srcs = ["test.proto"], + visibility = ["//visibility:public"], +) + +go_proto_library( + name = "ethereum_testing_go_proto", + importpath = "github.com/prysmaticlabs/prysm/proto/testing", + proto = ":ethereum_testing_proto", + visibility = ["//visibility:public"], +) + +go_library( + name = "go_default_library", + embed = [":ethereum_testing_go_proto"], + importpath = "github.com/prysmaticlabs/prysm/proto/testing", + visibility = ["//visibility:public"], +) diff --git a/proto/testing/test.pb.go b/proto/testing/test.pb.go new file mode 100755 index 000000000000..4a5e82781fb4 --- /dev/null +++ b/proto/testing/test.pb.go @@ -0,0 +1,73 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: proto/testing/test.proto + +package testing + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type TestMessage struct { + Foo string `protobuf:"bytes,1,opt,name=foo" json:"foo,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TestMessage) Reset() { *m = TestMessage{} } +func (m *TestMessage) String() string { return proto.CompactTextString(m) } +func (*TestMessage) ProtoMessage() {} +func (*TestMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_test_45722d484cf957ef, []int{0} +} +func (m *TestMessage) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TestMessage.Unmarshal(m, b) +} +func (m *TestMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TestMessage.Marshal(b, m, deterministic) +} +func (dst *TestMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_TestMessage.Merge(dst, src) +} +func (m *TestMessage) XXX_Size() int { + return xxx_messageInfo_TestMessage.Size(m) +} +func (m *TestMessage) XXX_DiscardUnknown() { + xxx_messageInfo_TestMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_TestMessage proto.InternalMessageInfo + +func (m *TestMessage) GetFoo() string { + if m != nil { + return m.Foo + } + return "" +} + +func init() { + proto.RegisterType((*TestMessage)(nil), "ethereum.testing.TestMessage") +} + +func init() { proto.RegisterFile("proto/testing/test.proto", fileDescriptor_test_45722d484cf957ef) } + +var fileDescriptor_test_45722d484cf957ef = []byte{ + // 92 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x28, 0xca, 0x2f, + 0xc9, 0xd7, 0x2f, 0x49, 0x2d, 0x2e, 0xc9, 0xcc, 0x4b, 0x07, 0xd3, 0x7a, 0x60, 0x21, 0x21, 0x81, + 0xd4, 0x92, 0x8c, 0xd4, 0xa2, 0xd4, 0xd2, 0x5c, 0x3d, 0xa8, 0xa4, 0x92, 0x3c, 0x17, 0x77, 0x48, + 0x6a, 0x71, 0x89, 0x6f, 0x6a, 0x71, 0x71, 0x62, 0x7a, 0xaa, 0x90, 0x00, 0x17, 0x73, 0x5a, 0x7e, + 0xbe, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x88, 0x99, 0xc4, 0x06, 0xd6, 0x69, 0x0c, 0x08, + 0x00, 0x00, 0xff, 0xff, 0xf9, 0x33, 0x23, 0x18, 0x55, 0x00, 0x00, 0x00, +} diff --git a/proto/testing/test.proto b/proto/testing/test.proto new file mode 100644 index 000000000000..c4609e889896 --- /dev/null +++ b/proto/testing/test.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package ethereum.testing; + +message TestMessage { + string foo = 1; +} \ No newline at end of file diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index 57ffe00e9bd9..669cc712a5bd 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -45,11 +45,12 @@ go_test( embed = [":go_default_library"], deps = [ "//proto/sharding/p2p/v1:go_default_library", + "//proto/testing:go_default_library", "//shared:go_default_library", "@com_github_ethereum_go_ethereum//event:go_default_library", "@com_github_golang_protobuf//proto:go_default_library", "@com_github_libp2p_go_floodsub//:go_default_library", - "@com_github_libp2p_go_libp2p//p2p/host/basic:go_default_library", + "@com_github_libp2p_go_libp2p_blankhost//:go_default_library", "@com_github_libp2p_go_libp2p_swarm//testing:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], diff --git a/shared/p2p/p2p.go b/shared/p2p/p2p.go index 4a29e30dcee3..71b28f47ce17 100644 --- a/shared/p2p/p2p.go +++ b/shared/p2p/p2p.go @@ -6,9 +6,10 @@ // - Floodsub: peer broadcasting to all peers // - Gossipsub: peer broadcasting to localized peers // -// However, this communication is abstracted through the Feed, Broadcast, and Send. -// +// This communication is abstracted through the Feed, Broadcast, and Send. // +// Pub/sub topic has a specific message type that is used for that topic. The +// mappings for these topics are outlined here: (TODO). // // Read more about gossipsub at https://github.com/vyzo/gerbil-simsub package p2p @@ -17,12 +18,12 @@ import "context" // Use this file for interfaces only! -// Adapters are used to create middleware. +// Adapter is used to create middleware. // // See http://godoc.org/github.com/prysmaticlabs/prysm/shared/p2p#Server.RegisterTopic -type Adapter func(context.Context, Message, Handler) +type Adapter func(Handler) Handler -// Handlers are the callback used in the adapter/middleware stack chain. +// Handler is a callback used in the adapter/middleware stack chain. // // See http://godoc.org/github.com/prysmaticlabs/prysm/shared/p2p#Server.RegisterTopic type Handler func(context.Context, Message) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index ebc3a98dabdf..00f60ab45566 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -10,17 +10,21 @@ import ( // A basic adapter will complete its logic then call next. Some adapters // may choose not to call next. For example, in the case of a rate // limiter or blacklisting condition. -func reqLogger(ctx context.Context, msg p2p.Message, next p2p.Handler) { - fmt.Println("Received message from %s", msg.Peer) - next(ctx, msg) +func reqLogger(next p2p.Handler) p2p.Handler { + return func(ctx context.Context, msg p2p.Message) { + fmt.Println("Received message from %s", msg.Peer) + next(ctx, msg) + } } // Functions can return an adapter in order to capture configuration. func adapterWithParams(i int) p2p.Adapter { - return func(ctx context.Context, msg p2p.Message, next p2p.Handler) { - fmt.Println("Magic number is %d", i) - i++ - next(ctx, msg) + return func(next p2p.Handler) p2p.Handler { + return func(ctx context.Context, msg p2p.Message) { + fmt.Println("Magic number is %d", i) + i++ + next(ctx, msg) + } } } diff --git a/shared/p2p/service.go b/shared/p2p/service.go index a4f42502c096..dd0f75a8a2e0 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -4,6 +4,7 @@ import ( "context" "reflect" "sync" + "time" "github.com/ethereum/go-ethereum/event" "github.com/golang/protobuf/proto" @@ -64,14 +65,6 @@ func (s *Server) Start() { log.Errorf("Could not start p2p discovery! %v", err) return } - - // Subscribe to all topics. - // for topic, msgType := range topicTypeMapping { - // log.WithFields(logrus.Fields{ - // "topic": topic, - // }).Debug("Subscribing to topic") - // go s.subscribeToTopic(topic, msgType) - // } } // Stop the main p2p loop. @@ -87,10 +80,8 @@ func (s *Server) Stop() error { // // The topics can originate from multiple sources. In other words, messages on TopicA may come // from direct peer communication or a pub/sub channel. -// -// TODO func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Adapter) { - var msgType reflect.Type // TODO + msgType := reflect.TypeOf(message) log.WithFields(logrus.Fields{ "topic": topic, }).Debug("Subscribing to topic") @@ -100,33 +91,48 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad log.Errorf("Failed to subscribe to topic: %v", err) return } - defer sub.Cancel() feed := s.Feed(msgType) - // TODO: Run this as the last step in the adapter stack. go (func() { + defer sub.Cancel() for { msg, err := sub.Next(s.ctx) if s.ctx.Err() != nil { - return // Context closed or something. + log.WithError(s.ctx.Err()).Debug("Context error") + return } + if err != nil { log.Errorf("Failed to get next message: %v", err) return } - // TODO: Run the adapter stack. + // Reverse adapter order + for i := len(adapters)/2 - 1; i >= 0; i-- { + opp := len(adapters) - 1 - i + adapters[i], adapters[opp] = adapters[opp], adapters[i] + } + + var h Handler + h = func(ctx context.Context, pMsg Message) { + s.emit(feed, msg, msgType) + } + + pMsg := Message{} - s.emit(feed, msg, msgType) + for _, adapter := range adapters { + h = adapter(h) + } + + ctx, _ := context.WithTimeout(s.ctx, 10*time.Second) + h(ctx, pMsg) } })() } -// TODO: rename func (s *Server) emit(feed *event.Feed, msg *floodsub.Message, msgType reflect.Type) { - // TODO: reflect.Value.Interface() can panic so we should capture that // panic so the server doesn't crash. d, ok := reflect.New(msgType).Interface().(proto.Message) diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index b2ce1183fbde..d7116de5016c 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -10,12 +10,12 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/golang/protobuf/proto" - "github.com/prysmaticlabs/prysm/shared" - floodsub "github.com/libp2p/go-floodsub" + bhost "github.com/libp2p/go-libp2p-blankhost" swarmt "github.com/libp2p/go-libp2p-swarm/testing" - bhost "github.com/libp2p/go-libp2p/p2p/host/basic" shardpb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" + testpb "github.com/prysmaticlabs/prysm/proto/testing" + "github.com/prysmaticlabs/prysm/shared" "github.com/sirupsen/logrus" ) @@ -42,7 +42,7 @@ func TestBroadcast(t *testing.T) { func TestSubscribeToTopic(t *testing.T) { ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second) defer cancel() - h := bhost.New(swarmt.GenSwarm(t, ctx)) + h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx)) gsub, err := floodsub.NewFloodSub(ctx, h) if err != nil { @@ -68,7 +68,7 @@ func TestSubscribeToTopic(t *testing.T) { func TestSubscribe(t *testing.T) { ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second) defer cancel() - h := bhost.New(swarmt.GenSwarm(t, ctx)) + h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx)) gsub, err := floodsub.NewFloodSub(ctx, h) if err != nil { @@ -133,20 +133,68 @@ func testSubscribe(ctx context.Context, t *testing.T, s Server, gsub *floodsub.P } } -func TestRegisterTopic(t *testing.T) { +func TestRegisterTopic_WithoutAdapters(t *testing.T) { s, err := NewServer() if err != nil { t.Fatalf("Failed to create new server: %v", err) } + topic := "test_topic" + testMessage := testpb.TestMessage{Foo: "bar"} + + s.RegisterTopic(topic, testMessage) + + ch := make(chan Message) + sub := s.Subscribe(testMessage, ch) + defer sub.Unsubscribe() + + wait := make(chan struct{}) + go (func() { + defer close(wait) + msg := <-ch + _ = msg + })() + + if err := simulateIncomingMessage(t, s, topic, []byte{}); err != nil { + t.Errorf("Failed to send to topic %s", topic) + } + + select { + case <-wait: + return // OK + case <-time.After(1 * time.Second): + t.Fatal("TestMessage not received within 1 seconds") + } +} +func TestRegisterTopic_WithAdapers(t *testing.T) { + s, err := NewServer() + if err != nil { + t.Fatalf("Failed to create new server: %v", err) + } topic := "test_topic" + testMessage := testpb.TestMessage{Foo: "bar"} + + i := 0 + var testAdapter Adapter + testAdapter = func(next Handler) Handler { + return func(ctx context.Context, msg Message) { + i++ + next(ctx, msg) + } + } - type TestMessage struct{} + adapters := []Adapter{ + testAdapter, + testAdapter, + testAdapter, + testAdapter, + testAdapter, + } - s.RegisterTopic(topic, TestMessage{}) + s.RegisterTopic(topic, testMessage, adapters...) ch := make(chan Message) - sub := s.Subscribe(TestMessage{}, ch) + sub := s.Subscribe(testMessage, ch) defer sub.Unsubscribe() wait := make(chan struct{}) @@ -156,30 +204,37 @@ func TestRegisterTopic(t *testing.T) { _ = msg })() - if err := simulateIncomingMessage(s, topic, []byte{}); err != nil { + if err := simulateIncomingMessage(t, s, topic, []byte{}); err != nil { t.Errorf("Failed to send to topic %s", topic) } select { case <-wait: + if i != 5 { + t.Errorf("Expected testAdapter to increment i to 5, but was %d", i) + } return // OK - case <-time.After(5 * time.Second): - t.Fatal("TestMessage not received within 5 seconds") + case <-time.After(1 * time.Second): + t.Fatal("TestMessage not received within 1 seconds") } } -func simulateIncomingMessage(s *Server, topic string, b []byte) error { - // TODO - // Create a new host +func simulateIncomingMessage(t *testing.T, s *Server, topic string, b []byte) error { + ctx := context.Background() + h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx)) - // Connect to s.Host + gsub, err := floodsub.NewFloodSub(ctx, h) + if err != nil { + return err + } - // Use the new connection to Publish msg on topic + pinfo := h.Peerstore().PeerInfo(h.ID()) + if err = s.host.Connect(ctx, pinfo); err != nil { + return err + } - return nil -} + // Short timeout to allow libp2p to handle peer connection. + time.Sleep(time.Millisecond * 10) -func TestRegisterTopic_WithAdapers(t *testing.T) { - // TODO: Test that adapters are called. - // TODO: Use a test suite for different conditions. + return gsub.Publish(topic, b) } From 6caaef20f564f62919b164c603e59a908f2b9f06 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 19 Aug 2018 16:12:36 -0400 Subject: [PATCH 08/24] split topics --- proto/beacon/p2p/v1/messages.pb.go | 313 ++++++++++++++++----------- proto/beacon/p2p/v1/messages.proto | 14 ++ proto/sharding/p2p/v1/messages.pb.go | 164 ++++++-------- proto/sharding/p2p/v1/messages.proto | 11 - shared/p2p/BUILD.bazel | 3 - shared/p2p/discovery.go | 31 +-- shared/p2p/discovery_norace_test.go | 18 +- shared/p2p/service.go | 38 ++-- shared/p2p/service_test.go | 2 +- shared/p2p/topics.go | 48 ---- shared/p2p/topics_test.go | 62 ------ 11 files changed, 291 insertions(+), 413 deletions(-) delete mode 100644 shared/p2p/topics.go delete mode 100644 shared/p2p/topics_test.go diff --git a/proto/beacon/p2p/v1/messages.pb.go b/proto/beacon/p2p/v1/messages.pb.go index 5bd6110763e1..c5ea439baba7 100644 --- a/proto/beacon/p2p/v1/messages.pb.go +++ b/proto/beacon/p2p/v1/messages.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: proto/beacon/p2p/v1/messages.proto -package ethereum_beacon_p2p_v1 +package v1 import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -19,6 +19,56 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +type Topic int32 + +const ( + Topic_UNKNOWN Topic = 0 + Topic_BEACON_BLOCK_HASH_ANNOUNCE Topic = 1 + Topic_BEACON_BLOCK_REQUEST Topic = 2 + Topic_BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER Topic = 3 + Topic_BEACON_BLOCK_RESPONSE Topic = 4 + Topic_CRYSTALLIZED_STATE_HASH_ANNOUNCE Topic = 5 + Topic_CRYSTALLIZED_STATE_REQUEST Topic = 6 + Topic_CRYSTALLIZED_STATE_RESPONSE Topic = 7 + Topic_ACTIVE_STATE_HASH_ANNOUNCE Topic = 8 + Topic_ACTIVE_STATE_REQUEST Topic = 9 + Topic_ACTIVE_STATE_RESPONSE Topic = 10 +) + +var Topic_name = map[int32]string{ + 0: "UNKNOWN", + 1: "BEACON_BLOCK_HASH_ANNOUNCE", + 2: "BEACON_BLOCK_REQUEST", + 3: "BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER", + 4: "BEACON_BLOCK_RESPONSE", + 5: "CRYSTALLIZED_STATE_HASH_ANNOUNCE", + 6: "CRYSTALLIZED_STATE_REQUEST", + 7: "CRYSTALLIZED_STATE_RESPONSE", + 8: "ACTIVE_STATE_HASH_ANNOUNCE", + 9: "ACTIVE_STATE_REQUEST", + 10: "ACTIVE_STATE_RESPONSE", +} +var Topic_value = map[string]int32{ + "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, +} + +func (x Topic) String() string { + return proto.EnumName(Topic_name, int32(x)) +} +func (Topic) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{0} +} + type BeaconBlockHashAnnounce struct { Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -30,7 +80,7 @@ func (m *BeaconBlockHashAnnounce) Reset() { *m = BeaconBlockHashAnnounce func (m *BeaconBlockHashAnnounce) String() string { return proto.CompactTextString(m) } func (*BeaconBlockHashAnnounce) ProtoMessage() {} func (*BeaconBlockHashAnnounce) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{0} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{0} } func (m *BeaconBlockHashAnnounce) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BeaconBlockHashAnnounce.Unmarshal(m, b) @@ -68,7 +118,7 @@ func (m *BeaconBlockRequest) Reset() { *m = BeaconBlockRequest{} } func (m *BeaconBlockRequest) String() string { return proto.CompactTextString(m) } func (*BeaconBlockRequest) ProtoMessage() {} func (*BeaconBlockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{1} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{1} } func (m *BeaconBlockRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BeaconBlockRequest.Unmarshal(m, b) @@ -96,7 +146,7 @@ func (m *BeaconBlockRequest) GetHash() []byte { } type BeaconBlockRequestBySlotNumber struct { - SlotNumber uint64 `protobuf:"varint,1,opt,name=slot_number,json=slotNumber,proto3" json:"slot_number,omitempty"` + SlotNumber uint64 `protobuf:"varint,1,opt,name=slot_number,json=slotNumber" json:"slot_number,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -106,7 +156,7 @@ func (m *BeaconBlockRequestBySlotNumber) Reset() { *m = BeaconBlockReque func (m *BeaconBlockRequestBySlotNumber) String() string { return proto.CompactTextString(m) } func (*BeaconBlockRequestBySlotNumber) ProtoMessage() {} func (*BeaconBlockRequestBySlotNumber) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{2} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{2} } func (m *BeaconBlockRequestBySlotNumber) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BeaconBlockRequestBySlotNumber.Unmarshal(m, b) @@ -134,7 +184,7 @@ func (m *BeaconBlockRequestBySlotNumber) GetSlotNumber() uint64 { } type BeaconBlockResponse struct { - Block *BeaconBlock `protobuf:"bytes,1,opt,name=block,proto3" json:"block,omitempty"` + Block *BeaconBlock `protobuf:"bytes,1,opt,name=block" json:"block,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -144,7 +194,7 @@ func (m *BeaconBlockResponse) Reset() { *m = BeaconBlockResponse{} } func (m *BeaconBlockResponse) String() string { return proto.CompactTextString(m) } func (*BeaconBlockResponse) ProtoMessage() {} func (*BeaconBlockResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{3} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{3} } func (m *BeaconBlockResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BeaconBlockResponse.Unmarshal(m, b) @@ -173,13 +223,13 @@ func (m *BeaconBlockResponse) GetBlock() *BeaconBlock { type BeaconBlock struct { ParentHash []byte `protobuf:"bytes,1,opt,name=parent_hash,json=parentHash,proto3" json:"parent_hash,omitempty"` - SlotNumber uint64 `protobuf:"varint,2,opt,name=slot_number,json=slotNumber,proto3" json:"slot_number,omitempty"` + SlotNumber uint64 `protobuf:"varint,2,opt,name=slot_number,json=slotNumber" json:"slot_number,omitempty"` RandaoReveal []byte `protobuf:"bytes,3,opt,name=randao_reveal,json=randaoReveal,proto3" json:"randao_reveal,omitempty"` PowChainRef []byte `protobuf:"bytes,4,opt,name=pow_chain_ref,json=powChainRef,proto3" json:"pow_chain_ref,omitempty"` ActiveStateHash []byte `protobuf:"bytes,5,opt,name=active_state_hash,json=activeStateHash,proto3" json:"active_state_hash,omitempty"` CrystallizedStateHash []byte `protobuf:"bytes,6,opt,name=crystallized_state_hash,json=crystallizedStateHash,proto3" json:"crystallized_state_hash,omitempty"` - Timestamp *timestamp.Timestamp `protobuf:"bytes,7,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - Attestations []*AttestationRecord `protobuf:"bytes,8,rep,name=attestations,proto3" json:"attestations,omitempty"` + Timestamp *timestamp.Timestamp `protobuf:"bytes,7,opt,name=timestamp" json:"timestamp,omitempty"` + Attestations []*AttestationRecord `protobuf:"bytes,8,rep,name=attestations" json:"attestations,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -189,7 +239,7 @@ func (m *BeaconBlock) Reset() { *m = BeaconBlock{} } func (m *BeaconBlock) String() string { return proto.CompactTextString(m) } func (*BeaconBlock) ProtoMessage() {} func (*BeaconBlock) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{4} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{4} } func (m *BeaconBlock) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_BeaconBlock.Unmarshal(m, b) @@ -276,7 +326,7 @@ func (m *CrystallizedStateHashAnnounce) Reset() { *m = CrystallizedState func (m *CrystallizedStateHashAnnounce) String() string { return proto.CompactTextString(m) } func (*CrystallizedStateHashAnnounce) ProtoMessage() {} func (*CrystallizedStateHashAnnounce) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{5} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{5} } func (m *CrystallizedStateHashAnnounce) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CrystallizedStateHashAnnounce.Unmarshal(m, b) @@ -314,7 +364,7 @@ func (m *CrystallizedStateRequest) Reset() { *m = CrystallizedStateReque func (m *CrystallizedStateRequest) String() string { return proto.CompactTextString(m) } func (*CrystallizedStateRequest) ProtoMessage() {} func (*CrystallizedStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{6} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{6} } func (m *CrystallizedStateRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CrystallizedStateRequest.Unmarshal(m, b) @@ -342,7 +392,7 @@ func (m *CrystallizedStateRequest) GetHash() []byte { } type CrystallizedStateResponse struct { - CrystallizedState *CrystallizedState `protobuf:"bytes,1,opt,name=crystallized_state,json=crystallizedState,proto3" json:"crystallized_state,omitempty"` + CrystallizedState *CrystallizedState `protobuf:"bytes,1,opt,name=crystallized_state,json=crystallizedState" json:"crystallized_state,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -352,7 +402,7 @@ func (m *CrystallizedStateResponse) Reset() { *m = CrystallizedStateResp func (m *CrystallizedStateResponse) String() string { return proto.CompactTextString(m) } func (*CrystallizedStateResponse) ProtoMessage() {} func (*CrystallizedStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{7} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{7} } func (m *CrystallizedStateResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CrystallizedStateResponse.Unmarshal(m, b) @@ -380,18 +430,18 @@ func (m *CrystallizedStateResponse) GetCrystallizedState() *CrystallizedState { } type CrystallizedState struct { - LastStateRecalc uint64 `protobuf:"varint,1,opt,name=last_state_recalc,json=lastStateRecalc,proto3" json:"last_state_recalc,omitempty"` - JustifiedStreak uint64 `protobuf:"varint,2,opt,name=justified_streak,json=justifiedStreak,proto3" json:"justified_streak,omitempty"` - LastJustifiedSlot uint64 `protobuf:"varint,3,opt,name=last_justified_slot,json=lastJustifiedSlot,proto3" json:"last_justified_slot,omitempty"` - LastFinalizedSlot uint64 `protobuf:"varint,4,opt,name=last_finalized_slot,json=lastFinalizedSlot,proto3" json:"last_finalized_slot,omitempty"` - CurrentDynasty uint64 `protobuf:"varint,5,opt,name=current_dynasty,json=currentDynasty,proto3" json:"current_dynasty,omitempty"` - CrosslinkingStartShard uint64 `protobuf:"varint,6,opt,name=crosslinking_start_shard,json=crosslinkingStartShard,proto3" json:"crosslinking_start_shard,omitempty"` - TotalDeposits uint64 `protobuf:"varint,7,opt,name=total_deposits,json=totalDeposits,proto3" json:"total_deposits,omitempty"` + LastStateRecalc uint64 `protobuf:"varint,1,opt,name=last_state_recalc,json=lastStateRecalc" json:"last_state_recalc,omitempty"` + JustifiedStreak uint64 `protobuf:"varint,2,opt,name=justified_streak,json=justifiedStreak" json:"justified_streak,omitempty"` + LastJustifiedSlot uint64 `protobuf:"varint,3,opt,name=last_justified_slot,json=lastJustifiedSlot" json:"last_justified_slot,omitempty"` + LastFinalizedSlot uint64 `protobuf:"varint,4,opt,name=last_finalized_slot,json=lastFinalizedSlot" json:"last_finalized_slot,omitempty"` + CurrentDynasty uint64 `protobuf:"varint,5,opt,name=current_dynasty,json=currentDynasty" json:"current_dynasty,omitempty"` + CrosslinkingStartShard uint64 `protobuf:"varint,6,opt,name=crosslinking_start_shard,json=crosslinkingStartShard" json:"crosslinking_start_shard,omitempty"` + TotalDeposits uint64 `protobuf:"varint,7,opt,name=total_deposits,json=totalDeposits" json:"total_deposits,omitempty"` DynastySeed []byte `protobuf:"bytes,8,opt,name=dynasty_seed,json=dynastySeed,proto3" json:"dynasty_seed,omitempty"` - DynastySeedLastReset uint64 `protobuf:"varint,9,opt,name=dynasty_seed_last_reset,json=dynastySeedLastReset,proto3" json:"dynasty_seed_last_reset,omitempty"` - CrosslinkRecords []*CrosslinkRecord `protobuf:"bytes,10,rep,name=crosslink_records,json=crosslinkRecords,proto3" json:"crosslink_records,omitempty"` - Validators []*ValidatorRecord `protobuf:"bytes,11,rep,name=validators,proto3" json:"validators,omitempty"` - IndicesForHeights []*ShardAndCommitteeArray `protobuf:"bytes,12,rep,name=indices_for_heights,json=indicesForHeights,proto3" json:"indices_for_heights,omitempty"` + DynastySeedLastReset uint64 `protobuf:"varint,9,opt,name=dynasty_seed_last_reset,json=dynastySeedLastReset" json:"dynasty_seed_last_reset,omitempty"` + CrosslinkRecords []*CrosslinkRecord `protobuf:"bytes,10,rep,name=crosslink_records,json=crosslinkRecords" json:"crosslink_records,omitempty"` + Validators []*ValidatorRecord `protobuf:"bytes,11,rep,name=validators" json:"validators,omitempty"` + IndicesForHeights []*ShardAndCommitteeArray `protobuf:"bytes,12,rep,name=indices_for_heights,json=indicesForHeights" json:"indices_for_heights,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -401,7 +451,7 @@ func (m *CrystallizedState) Reset() { *m = CrystallizedState{} } func (m *CrystallizedState) String() string { return proto.CompactTextString(m) } func (*CrystallizedState) ProtoMessage() {} func (*CrystallizedState) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{8} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{8} } func (m *CrystallizedState) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CrystallizedState.Unmarshal(m, b) @@ -506,7 +556,7 @@ func (m *CrystallizedState) GetIndicesForHeights() []*ShardAndCommitteeArray { } type ShardAndCommitteeArray struct { - ArrayShardAndCommittee []*ShardAndCommittee `protobuf:"bytes,1,rep,name=array_shard_and_committee,json=arrayShardAndCommittee,proto3" json:"array_shard_and_committee,omitempty"` + ArrayShardAndCommittee []*ShardAndCommittee `protobuf:"bytes,1,rep,name=array_shard_and_committee,json=arrayShardAndCommittee" json:"array_shard_and_committee,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -516,7 +566,7 @@ func (m *ShardAndCommitteeArray) Reset() { *m = ShardAndCommitteeArray{} func (m *ShardAndCommitteeArray) String() string { return proto.CompactTextString(m) } func (*ShardAndCommitteeArray) ProtoMessage() {} func (*ShardAndCommitteeArray) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{9} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{9} } func (m *ShardAndCommitteeArray) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ShardAndCommitteeArray.Unmarshal(m, b) @@ -554,7 +604,7 @@ func (m *ActiveStateHashAnnounce) Reset() { *m = ActiveStateHashAnnounce func (m *ActiveStateHashAnnounce) String() string { return proto.CompactTextString(m) } func (*ActiveStateHashAnnounce) ProtoMessage() {} func (*ActiveStateHashAnnounce) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{10} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{10} } func (m *ActiveStateHashAnnounce) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ActiveStateHashAnnounce.Unmarshal(m, b) @@ -592,7 +642,7 @@ func (m *ActiveStateRequest) Reset() { *m = ActiveStateRequest{} } func (m *ActiveStateRequest) String() string { return proto.CompactTextString(m) } func (*ActiveStateRequest) ProtoMessage() {} func (*ActiveStateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{11} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{11} } func (m *ActiveStateRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ActiveStateRequest.Unmarshal(m, b) @@ -620,8 +670,8 @@ func (m *ActiveStateRequest) GetHash() []byte { } type ShardAndCommittee struct { - ShardId uint64 `protobuf:"varint,1,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"` - Committee []uint32 `protobuf:"varint,2,rep,packed,name=committee,proto3" json:"committee,omitempty"` + ShardId uint64 `protobuf:"varint,1,opt,name=shard_id,json=shardId" json:"shard_id,omitempty"` + Committee []uint32 `protobuf:"varint,2,rep,packed,name=committee" json:"committee,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -631,7 +681,7 @@ func (m *ShardAndCommittee) Reset() { *m = ShardAndCommittee{} } func (m *ShardAndCommittee) String() string { return proto.CompactTextString(m) } func (*ShardAndCommittee) ProtoMessage() {} func (*ShardAndCommittee) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{12} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{12} } func (m *ShardAndCommittee) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ShardAndCommittee.Unmarshal(m, b) @@ -666,7 +716,7 @@ func (m *ShardAndCommittee) GetCommittee() []uint32 { } type ActiveStateResponse struct { - ActiveState *ActiveState `protobuf:"bytes,1,opt,name=active_state,json=activeState,proto3" json:"active_state,omitempty"` + ActiveState *ActiveState `protobuf:"bytes,1,opt,name=active_state,json=activeState" json:"active_state,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -676,7 +726,7 @@ func (m *ActiveStateResponse) Reset() { *m = ActiveStateResponse{} } func (m *ActiveStateResponse) String() string { return proto.CompactTextString(m) } func (*ActiveStateResponse) ProtoMessage() {} func (*ActiveStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{13} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{13} } func (m *ActiveStateResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ActiveStateResponse.Unmarshal(m, b) @@ -704,7 +754,7 @@ func (m *ActiveStateResponse) GetActiveState() *ActiveState { } type ActiveState struct { - PendingAttestations []*AttestationRecord `protobuf:"bytes,1,rep,name=pending_attestations,json=pendingAttestations,proto3" json:"pending_attestations,omitempty"` + PendingAttestations []*AttestationRecord `protobuf:"bytes,1,rep,name=pending_attestations,json=pendingAttestations" json:"pending_attestations,omitempty"` RecentBlockHashes [][]byte `protobuf:"bytes,2,rep,name=recent_block_hashes,json=recentBlockHashes,proto3" json:"recent_block_hashes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -715,7 +765,7 @@ func (m *ActiveState) Reset() { *m = ActiveState{} } func (m *ActiveState) String() string { return proto.CompactTextString(m) } func (*ActiveState) ProtoMessage() {} func (*ActiveState) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{14} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{14} } func (m *ActiveState) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ActiveState.Unmarshal(m, b) @@ -750,13 +800,13 @@ func (m *ActiveState) GetRecentBlockHashes() [][]byte { } type ValidatorRecord struct { - PublicKey uint64 `protobuf:"varint,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` - WithdrawalShard uint64 `protobuf:"varint,2,opt,name=withdrawal_shard,json=withdrawalShard,proto3" json:"withdrawal_shard,omitempty"` + PublicKey uint64 `protobuf:"varint,1,opt,name=public_key,json=publicKey" json:"public_key,omitempty"` + WithdrawalShard uint64 `protobuf:"varint,2,opt,name=withdrawal_shard,json=withdrawalShard" json:"withdrawal_shard,omitempty"` WithdrawalAddress []byte `protobuf:"bytes,3,opt,name=withdrawal_address,json=withdrawalAddress,proto3" json:"withdrawal_address,omitempty"` RandaoCommitment []byte `protobuf:"bytes,4,opt,name=randao_commitment,json=randaoCommitment,proto3" json:"randao_commitment,omitempty"` - Balance uint64 `protobuf:"varint,5,opt,name=balance,proto3" json:"balance,omitempty"` - StartDynasty uint64 `protobuf:"varint,6,opt,name=start_dynasty,json=startDynasty,proto3" json:"start_dynasty,omitempty"` - EndDynasty uint64 `protobuf:"varint,7,opt,name=end_dynasty,json=endDynasty,proto3" json:"end_dynasty,omitempty"` + Balance uint64 `protobuf:"varint,5,opt,name=balance" json:"balance,omitempty"` + StartDynasty uint64 `protobuf:"varint,6,opt,name=start_dynasty,json=startDynasty" json:"start_dynasty,omitempty"` + EndDynasty uint64 `protobuf:"varint,7,opt,name=end_dynasty,json=endDynasty" json:"end_dynasty,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -766,7 +816,7 @@ func (m *ValidatorRecord) Reset() { *m = ValidatorRecord{} } func (m *ValidatorRecord) String() string { return proto.CompactTextString(m) } func (*ValidatorRecord) ProtoMessage() {} func (*ValidatorRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{15} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{15} } func (m *ValidatorRecord) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ValidatorRecord.Unmarshal(m, b) @@ -836,12 +886,12 @@ func (m *ValidatorRecord) GetEndDynasty() uint64 { } type AttestationRecord struct { - Slot uint64 `protobuf:"varint,1,opt,name=slot,proto3" json:"slot,omitempty"` - ShardId uint64 `protobuf:"varint,2,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"` + Slot uint64 `protobuf:"varint,1,opt,name=slot" json:"slot,omitempty"` + ShardId uint64 `protobuf:"varint,2,opt,name=shard_id,json=shardId" json:"shard_id,omitempty"` ShardBlockHash []byte `protobuf:"bytes,3,opt,name=shard_block_hash,json=shardBlockHash,proto3" json:"shard_block_hash,omitempty"` AttesterBitfield []byte `protobuf:"bytes,4,opt,name=attester_bitfield,json=attesterBitfield,proto3" json:"attester_bitfield,omitempty"` ObliqueParentHashes [][]byte `protobuf:"bytes,5,rep,name=oblique_parent_hashes,json=obliqueParentHashes,proto3" json:"oblique_parent_hashes,omitempty"` - AggregateSig []uint64 `protobuf:"varint,6,rep,packed,name=aggregate_sig,json=aggregateSig,proto3" json:"aggregate_sig,omitempty"` + AggregateSig []uint64 `protobuf:"varint,6,rep,packed,name=aggregate_sig,json=aggregateSig" json:"aggregate_sig,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -851,7 +901,7 @@ func (m *AttestationRecord) Reset() { *m = AttestationRecord{} } func (m *AttestationRecord) String() string { return proto.CompactTextString(m) } func (*AttestationRecord) ProtoMessage() {} func (*AttestationRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{16} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{16} } func (m *AttestationRecord) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_AttestationRecord.Unmarshal(m, b) @@ -914,7 +964,7 @@ func (m *AttestationRecord) GetAggregateSig() []uint64 { } type CrosslinkRecord struct { - Dynasty uint64 `protobuf:"varint,1,opt,name=dynasty,proto3" json:"dynasty,omitempty"` + Dynasty uint64 `protobuf:"varint,1,opt,name=dynasty" json:"dynasty,omitempty"` Blockhash []byte `protobuf:"bytes,2,opt,name=blockhash,proto3" json:"blockhash,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -925,7 +975,7 @@ func (m *CrosslinkRecord) Reset() { *m = CrosslinkRecord{} } func (m *CrosslinkRecord) String() string { return proto.CompactTextString(m) } func (*CrosslinkRecord) ProtoMessage() {} func (*CrosslinkRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_a1c78d81bd7dacd5, []int{17} + return fileDescriptor_messages_3e94b77d6a9a1ae2, []int{17} } func (m *CrosslinkRecord) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CrosslinkRecord.Unmarshal(m, b) @@ -978,83 +1028,94 @@ func init() { proto.RegisterType((*ValidatorRecord)(nil), "ethereum.beacon.p2p.v1.ValidatorRecord") proto.RegisterType((*AttestationRecord)(nil), "ethereum.beacon.p2p.v1.AttestationRecord") proto.RegisterType((*CrosslinkRecord)(nil), "ethereum.beacon.p2p.v1.CrosslinkRecord") + proto.RegisterEnum("ethereum.beacon.p2p.v1.Topic", Topic_name, Topic_value) } func init() { - proto.RegisterFile("proto/beacon/p2p/v1/messages.proto", fileDescriptor_messages_a1c78d81bd7dacd5) -} - -var fileDescriptor_messages_a1c78d81bd7dacd5 = []byte{ - // 1127 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x6e, 0xdb, 0xc6, - 0x13, 0x86, 0x6c, 0x39, 0x89, 0x47, 0xb2, 0x65, 0xad, 0x12, 0x9b, 0x0e, 0x7e, 0xf9, 0xd9, 0x65, - 0x50, 0xc4, 0x69, 0x11, 0x0a, 0x71, 0xd0, 0x22, 0x3d, 0xca, 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 0x9a, 0xd1, 0x3c, 0x45, 0x2f, 0x5c, 0xf3, - 0x57, 0xb3, 0xb9, 0x9d, 0x48, 0xcd, 0x85, 0xcd, 0xc9, 0x54, 0xd3, 0x82, 0x73, 0x59, 0x3b, 0x80, - 0x06, 0xe6, 0xac, 0xa4, 0x38, 0x65, 0x02, 0xcc, 0x99, 0x27, 0x84, 0xff, 0xd4, 0xa0, 0xbd, 0xd2, - 0x74, 0x33, 0x8e, 0x56, 0x57, 0x5d, 0x57, 0xec, 0xf3, 0xd2, 0xe4, 0xad, 0x2d, 0x4f, 0xde, 0x11, - 0xec, 0x38, 0xd3, 0xe2, 0x34, 0x7c, 0xf9, 0xdb, 0x16, 0x2f, 0x8f, 0xc2, 0xd4, 0xee, 0xc6, 0x01, - 0x65, 0x32, 0xe0, 0x7a, 0xc8, 0x31, 0x63, 0xf3, 0xda, 0xe7, 0x86, 0x13, 0x8f, 0x93, 0x63, 0x78, - 0x20, 0x06, 0x19, 0xff, 0x30, 0xc5, 0xa4, 0xf2, 0x97, 0x83, 0x2a, 0xd8, 0xb0, 0xe7, 0xdc, 0xf1, - 0xc6, 0x77, 0xe5, 0xef, 0x0e, 0x2a, 0xd3, 0x15, 0x3a, 0x1a, 0x49, 0x1c, 0x99, 0x35, 0xa5, 0xf8, - 0x28, 0xb8, 0x73, 0xb8, 0x6e, 0xba, 0x52, 0x82, 0x7d, 0x3e, 0x0a, 0xdf, 0x40, 0xeb, 0x8a, 0x00, - 0x9a, 0x3e, 0xcf, 0x9b, 0xe4, 0xaf, 0x95, 0x7f, 0x35, 0xd7, 0xca, 0x96, 0x65, 0xab, 0x5a, 0xb3, - 0xa9, 0x2e, 0x80, 0xc1, 0x1d, 0xfb, 0xdf, 0xf1, 0xe2, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, - 0x51, 0x4f, 0xea, 0xe5, 0x0a, 0x00, 0x00, + proto.RegisterFile("proto/beacon/p2p/v1/messages.proto", fileDescriptor_messages_3e94b77d6a9a1ae2) +} + +var fileDescriptor_messages_3e94b77d6a9a1ae2 = []byte{ + // 1294 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xdd, 0x72, 0xdb, 0xb6, + 0x12, 0x3e, 0x96, 0xe5, 0xbf, 0x95, 0x1c, 0x4b, 0x70, 0xe2, 0xd0, 0x39, 0x27, 0xb1, 0x0f, 0xd3, + 0x4e, 0x9c, 0x74, 0x22, 0x4f, 0x9c, 0x69, 0x27, 0xbd, 0x94, 0x14, 0xa5, 0x76, 0xe3, 0xc8, 0x29, + 0x29, 0xa7, 0x4d, 0xa7, 0x2d, 0x07, 0x22, 0x57, 0x12, 0x6b, 0x8a, 0x60, 0x00, 0xc8, 0x1e, 0xf5, + 0xa2, 0x77, 0x7d, 0x86, 0x5e, 0xf4, 0x19, 0xfa, 0x2a, 0x7d, 0x98, 0x3e, 0x41, 0x07, 0x20, 0x24, + 0x51, 0x3f, 0x76, 0xa6, 0x77, 0xe4, 0xf7, 0x7d, 0xbb, 0xdc, 0x5d, 0x2c, 0x76, 0x09, 0x76, 0xc2, + 0x99, 0x64, 0x87, 0x6d, 0xa4, 0x3e, 0x8b, 0x0f, 0x93, 0xa3, 0xe4, 0xf0, 0xf2, 0xd9, 0x61, 0x1f, + 0x85, 0xa0, 0x5d, 0x14, 0x15, 0x4d, 0x92, 0x1d, 0x94, 0x3d, 0xe4, 0x38, 0xe8, 0x57, 0x52, 0x59, + 0x25, 0x39, 0x4a, 0x2a, 0x97, 0xcf, 0xee, 0xed, 0x75, 0x19, 0xeb, 0x46, 0x78, 0xa8, 0x55, 0xed, + 0x41, 0xe7, 0x50, 0x86, 0x7d, 0x14, 0x92, 0xf6, 0x93, 0xd4, 0xd0, 0x7e, 0x0a, 0x77, 0x6b, 0xda, + 0xa2, 0x16, 0x31, 0xff, 0xe2, 0x98, 0x8a, 0x5e, 0x35, 0x8e, 0xd9, 0x20, 0xf6, 0x91, 0x10, 0xc8, + 0xf7, 0xa8, 0xe8, 0x59, 0x4b, 0xfb, 0x4b, 0x07, 0x45, 0x47, 0x3f, 0xdb, 0x07, 0x40, 0x32, 0x72, + 0x07, 0x3f, 0x0c, 0x50, 0xc8, 0x85, 0xca, 0x2a, 0x3c, 0x98, 0x57, 0xd6, 0x86, 0x6e, 0xc4, 0x64, + 0x73, 0xd0, 0x6f, 0x23, 0x27, 0x7b, 0x50, 0x10, 0x11, 0x93, 0x5e, 0xac, 0x5f, 0xb5, 0x71, 0xde, + 0x01, 0x31, 0x16, 0xd8, 0x6f, 0x61, 0x7b, 0xca, 0x85, 0x48, 0x58, 0x2c, 0x90, 0x7c, 0x09, 0x2b, + 0x6d, 0x05, 0x68, 0x8b, 0xc2, 0xd1, 0xc3, 0xca, 0xe2, 0xdc, 0x2b, 0x59, 0xdb, 0xd4, 0xc2, 0xfe, + 0x6d, 0x19, 0x0a, 0x19, 0x58, 0x85, 0x90, 0x50, 0x8e, 0xb1, 0xf4, 0x32, 0xf1, 0x43, 0x0a, 0xa9, + 0x5a, 0xcc, 0xc6, 0x98, 0x9b, 0x8d, 0x91, 0x3c, 0x84, 0x4d, 0x4e, 0xe3, 0x80, 0x32, 0x8f, 0xe3, + 0x25, 0xd2, 0xc8, 0x5a, 0xd6, 0x3e, 0x8a, 0x29, 0xe8, 0x68, 0x8c, 0xd8, 0xb0, 0x99, 0xb0, 0x2b, + 0xcf, 0xef, 0xd1, 0x30, 0xf6, 0x38, 0x76, 0xac, 0xbc, 0x16, 0x15, 0x12, 0x76, 0x55, 0x57, 0x98, + 0x83, 0x1d, 0xf2, 0x04, 0xca, 0xd4, 0x97, 0xe1, 0x25, 0x7a, 0x42, 0x52, 0x89, 0x69, 0x40, 0x2b, + 0x5a, 0xb7, 0x95, 0x12, 0xae, 0xc2, 0x75, 0x54, 0x5f, 0xc0, 0x5d, 0x9f, 0x0f, 0x85, 0xa4, 0x51, + 0x14, 0xfe, 0x82,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 0x3f, 0xe0, 0xfa, 0x86, 0x04, 0xc3, 0x98, + 0x0a, 0x39, 0xd4, 0x3d, 0x99, 0x77, 0x6e, 0x19, 0xf8, 0x65, 0x8a, 0x92, 0x17, 0x60, 0xf9, 0x9c, + 0x09, 0x11, 0x85, 0xf1, 0x45, 0x18, 0x77, 0x55, 0x9e, 0x5c, 0x7a, 0xa2, 0x47, 0x79, 0xa0, 0x7b, + 0x32, 0xef, 0xec, 0x64, 0x79, 0x57, 0xd1, 0xae, 0x62, 0xc9, 0xa7, 0x70, 0x4b, 0x32, 0x49, 0x23, + 0x2f, 0xc0, 0x84, 0x89, 0x50, 0x0a, 0xdd, 0x99, 0x79, 0x67, 0x53, 0xa3, 0x2f, 0x0d, 0x48, 0xfe, + 0x0f, 0x45, 0x13, 0x81, 0x27, 0x10, 0x03, 0x6b, 0x3d, 0xbd, 0x42, 0x06, 0x73, 0x11, 0x03, 0xf2, + 0x39, 0xdc, 0xcd, 0x4a, 0x3c, 0x9d, 0x29, 0x47, 0x81, 0xd2, 0xda, 0xd0, 0x2e, 0x6f, 0x67, 0xd4, + 0xa7, 0x54, 0x48, 0x47, 0x71, 0xa4, 0x05, 0xe5, 0x71, 0x68, 0xea, 0x64, 0x18, 0x0f, 0x84, 0x05, + 0xba, 0xc1, 0x1f, 0x5d, 0xdf, 0x09, 0xc6, 0xc0, 0xb4, 0x77, 0xc9, 0x9f, 0x06, 0x04, 0xf9, 0x0a, + 0xe0, 0x92, 0x46, 0x61, 0x40, 0x25, 0xe3, 0xc2, 0x2a, 0xdc, 0xec, 0xee, 0xdd, 0x48, 0x69, 0xdc, + 0x65, 0x4c, 0xc9, 0x4f, 0xb0, 0x1d, 0xc6, 0x41, 0xe8, 0xa3, 0xf0, 0x3a, 0x8c, 0x7b, 0x3d, 0x0c, + 0xbb, 0x3d, 0x29, 0xac, 0xa2, 0xf6, 0x58, 0xb9, 0xce, 0xa3, 0xae, 0x6d, 0x35, 0x0e, 0xea, 0xac, + 0xdf, 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4, 0x35, 0x0e, 0xd5, 0x10, 0xbb, 0x0a, 0x65, 0x2f, + 0xe0, 0xf4, 0x8a, 0x46, 0x66, 0x10, 0x98, 0x21, 0x36, 0xc1, 0xd3, 0x09, 0xf0, 0x14, 0x48, 0x46, + 0x4a, 0x83, 0x80, 0xa3, 0x10, 0x66, 0x91, 0x96, 0x27, 0x4c, 0x35, 0x25, 0xc8, 0x67, 0x50, 0x36, + 0x2b, 0x37, 0x3d, 0x9d, 0x3e, 0xc6, 0xd2, 0x6c, 0xd4, 0x52, 0x4a, 0xd4, 0xc7, 0x38, 0xb1, 0x60, + 0xad, 0x4d, 0x23, 0x1a, 0xfb, 0x68, 0x06, 0xd7, 0xe8, 0x55, 0x6d, 0xee, 0x74, 0x48, 0x8d, 0x06, + 0x5b, 0x3a, 0xa6, 0x8a, 0x1a, 0x1c, 0x8d, 0xb5, 0x3d, 0x28, 0x60, 0x1c, 0x8c, 0x25, 0xe9, 0x64, + 0x02, 0x8c, 0x03, 0x23, 0xb0, 0xff, 0x5e, 0x82, 0xf2, 0x5c, 0xd1, 0x55, 0x3b, 0xea, 0xb9, 0x9a, + 0x56, 0x45, 0x3f, 0x4f, 0x75, 0x5e, 0x6e, 0xba, 0xf3, 0x0e, 0xa0, 0x94, 0x52, 0x93, 0xd3, 0x30, + 0xe9, 0xdf, 0xd2, 0xf8, 0xf8, 0x28, 0x54, 0xee, 0x69, 0x3b, 0x20, 0xf7, 0xda, 0xa1, 0xec, 0x84, + 0x18, 0x05, 0xa3, 0xdc, 0x47, 0x44, 0xcd, 0xe0, 0xe4, 0x08, 0xee, 0xb0, 0x76, 0x14, 0x7e, 0x18, + 0xa0, 0x97, 0xf9, 0xcb, 0x41, 0x61, 0xad, 0xe8, 0x73, 0xde, 0x36, 0xe4, 0xdb, 0xf1, 0xef, 0x0e, + 0x0a, 0x55, 0x15, 0xda, 0xed, 0x72, 0xec, 0xaa, 0x35, 0x25, 0xc2, 0xae, 0xb5, 0xba, 0xbf, 0xac,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0x91, 0xeb, 0x0d, 0x15, 0xfb, 0x0c, 0x63, 0x9c, 0x42, 0x7b, 0x55, 0xff, 0xc8, 0x3d, + 0xff, 0x27, 0x00, 0x00, 0xff, 0xff, 0xf4, 0xdb, 0x69, 0x34, 0x36, 0x0c, 0x00, 0x00, } diff --git a/proto/beacon/p2p/v1/messages.proto b/proto/beacon/p2p/v1/messages.proto index 6877b9e0cbbc..2a715af309f4 100644 --- a/proto/beacon/p2p/v1/messages.proto +++ b/proto/beacon/p2p/v1/messages.proto @@ -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; } diff --git a/proto/sharding/p2p/v1/messages.pb.go b/proto/sharding/p2p/v1/messages.pb.go index 642b312ccf3c..a60084cb7080 100644 --- a/proto/sharding/p2p/v1/messages.pb.go +++ b/proto/sharding/p2p/v1/messages.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: messages.proto +// source: proto/sharding/p2p/v1/messages.proto -package ethereum_sharding_p2p_v1 +package v1 import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -18,69 +18,38 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package -// TODO: Split the topics into p2p for beacon chain and p2p for sharding. type Topic int32 const ( - Topic_UNKNOWN Topic = 0 - Topic_COLLATION_BODY_REQUEST Topic = 1 - Topic_COLLATION_BODY_RESPONSE Topic = 2 - Topic_TRANSACTIONS Topic = 3 - Topic_BEACON_BLOCK_HASH_ANNOUNCE Topic = 4 - Topic_BEACON_BLOCK_REQUEST Topic = 5 - Topic_BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER Topic = 6 - Topic_BEACON_BLOCK_RESPONSE Topic = 7 - Topic_CRYSTALLIZED_STATE_HASH_ANNOUNCE Topic = 8 - Topic_CRYSTALLIZED_STATE_REQUEST Topic = 9 - Topic_CRYSTALLIZED_STATE_RESPONSE Topic = 10 - Topic_ACTIVE_STATE_HASH_ANNOUNCE Topic = 11 - Topic_ACTIVE_STATE_REQUEST Topic = 12 - Topic_ACTIVE_STATE_RESPONSE Topic = 13 + Topic_UNKNOWN Topic = 0 + Topic_COLLATION_BODY_REQUEST Topic = 1 + Topic_COLLATION_BODY_RESPONSE Topic = 2 + Topic_TRANSACTIONS Topic = 3 ) var Topic_name = map[int32]string{ - 0: "UNKNOWN", - 1: "COLLATION_BODY_REQUEST", - 2: "COLLATION_BODY_RESPONSE", - 3: "TRANSACTIONS", - 4: "BEACON_BLOCK_HASH_ANNOUNCE", - 5: "BEACON_BLOCK_REQUEST", - 6: "BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER", - 7: "BEACON_BLOCK_RESPONSE", - 8: "CRYSTALLIZED_STATE_HASH_ANNOUNCE", - 9: "CRYSTALLIZED_STATE_REQUEST", - 10: "CRYSTALLIZED_STATE_RESPONSE", - 11: "ACTIVE_STATE_HASH_ANNOUNCE", - 12: "ACTIVE_STATE_REQUEST", - 13: "ACTIVE_STATE_RESPONSE", + 0: "UNKNOWN", + 1: "COLLATION_BODY_REQUEST", + 2: "COLLATION_BODY_RESPONSE", + 3: "TRANSACTIONS", } var Topic_value = map[string]int32{ - "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, + "UNKNOWN": 0, + "COLLATION_BODY_REQUEST": 1, + "COLLATION_BODY_RESPONSE": 2, + "TRANSACTIONS": 3, } func (x Topic) String() string { return proto.EnumName(Topic_name, int32(x)) } func (Topic) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_messages_2d61a34a4bdb49bc, []int{0} + return fileDescriptor_messages_8b1affe159ebec96, []int{0} } type CollationBodyRequest struct { - ShardId uint64 `protobuf:"varint,1,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"` - Period uint64 `protobuf:"varint,2,opt,name=period,proto3" json:"period,omitempty"` + ShardId uint64 `protobuf:"varint,1,opt,name=shard_id,json=shardId" json:"shard_id,omitempty"` + Period uint64 `protobuf:"varint,2,opt,name=period" json:"period,omitempty"` ChunkRoot []byte `protobuf:"bytes,3,opt,name=chunk_root,json=chunkRoot,proto3" json:"chunk_root,omitempty"` ProposerAddress []byte `protobuf:"bytes,4,opt,name=proposer_address,json=proposerAddress,proto3" json:"proposer_address,omitempty"` Signature []byte `protobuf:"bytes,5,opt,name=signature,proto3" json:"signature,omitempty"` @@ -93,7 +62,7 @@ func (m *CollationBodyRequest) Reset() { *m = CollationBodyRequest{} } func (m *CollationBodyRequest) String() string { return proto.CompactTextString(m) } func (*CollationBodyRequest) ProtoMessage() {} func (*CollationBodyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_2d61a34a4bdb49bc, []int{0} + return fileDescriptor_messages_8b1affe159ebec96, []int{0} } func (m *CollationBodyRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CollationBodyRequest.Unmarshal(m, b) @@ -160,7 +129,7 @@ func (m *CollationBodyResponse) Reset() { *m = CollationBodyResponse{} } func (m *CollationBodyResponse) String() string { return proto.CompactTextString(m) } func (*CollationBodyResponse) ProtoMessage() {} func (*CollationBodyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_2d61a34a4bdb49bc, []int{1} + return fileDescriptor_messages_8b1affe159ebec96, []int{1} } func (m *CollationBodyResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CollationBodyResponse.Unmarshal(m, b) @@ -195,13 +164,13 @@ func (m *CollationBodyResponse) GetBody() []byte { } type Transaction struct { - Nonce uint64 `protobuf:"varint,1,opt,name=nonce,proto3" json:"nonce,omitempty"` - GasPrice uint64 `protobuf:"varint,2,opt,name=gas_price,json=gasPrice,proto3" json:"gas_price,omitempty"` - GasLimit uint64 `protobuf:"varint,3,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"` + Nonce uint64 `protobuf:"varint,1,opt,name=nonce" json:"nonce,omitempty"` + GasPrice uint64 `protobuf:"varint,2,opt,name=gas_price,json=gasPrice" json:"gas_price,omitempty"` + GasLimit uint64 `protobuf:"varint,3,opt,name=gas_limit,json=gasLimit" json:"gas_limit,omitempty"` Recipient []byte `protobuf:"bytes,4,opt,name=recipient,proto3" json:"recipient,omitempty"` - Value uint64 `protobuf:"varint,5,opt,name=value,proto3" json:"value,omitempty"` + Value uint64 `protobuf:"varint,5,opt,name=value" json:"value,omitempty"` Input []byte `protobuf:"bytes,6,opt,name=input,proto3" json:"input,omitempty"` - Signature *Signature `protobuf:"bytes,7,opt,name=signature,proto3" json:"signature,omitempty"` + Signature *Signature `protobuf:"bytes,7,opt,name=signature" json:"signature,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -211,7 +180,7 @@ func (m *Transaction) Reset() { *m = Transaction{} } func (m *Transaction) String() string { return proto.CompactTextString(m) } func (*Transaction) ProtoMessage() {} func (*Transaction) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_2d61a34a4bdb49bc, []int{2} + return fileDescriptor_messages_8b1affe159ebec96, []int{2} } func (m *Transaction) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Transaction.Unmarshal(m, b) @@ -281,9 +250,9 @@ func (m *Transaction) GetSignature() *Signature { } type Signature struct { - V uint64 `protobuf:"varint,1,opt,name=v,proto3" json:"v,omitempty"` - R uint64 `protobuf:"varint,2,opt,name=r,proto3" json:"r,omitempty"` - S uint64 `protobuf:"varint,3,opt,name=s,proto3" json:"s,omitempty"` + V uint64 `protobuf:"varint,1,opt,name=v" json:"v,omitempty"` + R uint64 `protobuf:"varint,2,opt,name=r" json:"r,omitempty"` + S uint64 `protobuf:"varint,3,opt,name=s" json:"s,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -293,7 +262,7 @@ func (m *Signature) Reset() { *m = Signature{} } func (m *Signature) String() string { return proto.CompactTextString(m) } func (*Signature) ProtoMessage() {} func (*Signature) Descriptor() ([]byte, []int) { - return fileDescriptor_messages_2d61a34a4bdb49bc, []int{3} + return fileDescriptor_messages_8b1affe159ebec96, []int{3} } func (m *Signature) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Signature.Unmarshal(m, b) @@ -342,44 +311,39 @@ func init() { proto.RegisterEnum("ethereum.sharding.p2p.v1.Topic", Topic_name, Topic_value) } -func init() { proto.RegisterFile("messages.proto", fileDescriptor_messages_2d61a34a4bdb49bc) } - -var fileDescriptor_messages_2d61a34a4bdb49bc = []byte{ - // 569 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x53, 0xed, 0x4e, 0xd4, 0x4c, - 0x18, 0x7d, 0x0b, 0xfb, 0xc1, 0x3e, 0xdb, 0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03, 0x00, 0x00, +func init() { + proto.RegisterFile("proto/sharding/p2p/v1/messages.proto", fileDescriptor_messages_8b1affe159ebec96) +} + +var fileDescriptor_messages_8b1affe159ebec96 = []byte{ + // 459 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xdf, 0x6e, 0xd3, 0x30, + 0x14, 0xc6, 0xf1, 0xd6, 0x3f, 0xeb, 0x69, 0x24, 0x22, 0x6b, 0x8c, 0xc0, 0x40, 0x54, 0x85, 0x8b, + 0xc2, 0x45, 0xaa, 0x15, 0xf1, 0x00, 0x59, 0xa9, 0xc4, 0x44, 0x95, 0x8c, 0x24, 0x13, 0xe2, 0x2a, + 0xf2, 0x12, 0x2b, 0xb1, 0x68, 0x6d, 0x63, 0x27, 0x91, 0xf6, 0x58, 0xbc, 0x16, 0x4f, 0x81, 0x62, + 0xa7, 0x63, 0x02, 0x71, 0x97, 0xdf, 0xf7, 0x1d, 0x39, 0xe7, 0xe7, 0x04, 0xde, 0x48, 0x25, 0x6a, + 0xb1, 0xd4, 0x15, 0x51, 0x05, 0xe3, 0xe5, 0x52, 0xae, 0xe4, 0xb2, 0xbd, 0x58, 0xee, 0xa9, 0xd6, + 0xa4, 0xa4, 0xda, 0x37, 0x35, 0xf6, 0x68, 0x5d, 0x51, 0x45, 0x9b, 0xbd, 0x7f, 0x18, 0xf4, 0xe5, + 0x4a, 0xfa, 0xed, 0xc5, 0xfc, 0x27, 0x82, 0xd3, 0xb5, 0xd8, 0xed, 0x48, 0xcd, 0x04, 0xbf, 0x14, + 0xc5, 0x5d, 0x4c, 0x7f, 0x34, 0x54, 0xd7, 0xf8, 0x19, 0x9c, 0x98, 0xd9, 0x8c, 0x15, 0x1e, 0x9a, + 0xa1, 0xc5, 0x20, 0x1e, 0x1b, 0xbe, 0x2a, 0xf0, 0x19, 0x8c, 0x24, 0x55, 0x4c, 0x14, 0xde, 0x91, + 0x29, 0x7a, 0xc2, 0x2f, 0x01, 0xf2, 0xaa, 0xe1, 0xdf, 0x33, 0x25, 0x44, 0xed, 0x1d, 0xcf, 0xd0, + 0xc2, 0x89, 0x27, 0x26, 0x89, 0x85, 0xa8, 0xf1, 0x5b, 0x70, 0xa5, 0x12, 0x52, 0x68, 0xaa, 0x32, + 0x52, 0x14, 0x8a, 0x6a, 0xed, 0x0d, 0xcc, 0xd0, 0xe3, 0x43, 0x1e, 0xd8, 0x18, 0xbf, 0x80, 0x89, + 0x66, 0x25, 0x27, 0x75, 0xa3, 0xa8, 0x37, 0xb4, 0x07, 0xdd, 0x07, 0xf3, 0x2d, 0x3c, 0xf9, 0x6b, + 0x65, 0x2d, 0x05, 0xd7, 0x14, 0xbf, 0x82, 0x69, 0x45, 0x49, 0x41, 0x55, 0x56, 0x11, 0x5d, 0x99, + 0xb5, 0x9d, 0x18, 0x6c, 0xf4, 0x89, 0xe8, 0x0a, 0x63, 0x18, 0xdc, 0x8a, 0xe2, 0xce, 0xec, 0xed, + 0xc4, 0xe6, 0x79, 0xfe, 0x0b, 0xc1, 0x34, 0x55, 0x84, 0x6b, 0x92, 0x77, 0x07, 0xe2, 0x53, 0x18, + 0x72, 0xc1, 0x73, 0xda, 0x5b, 0x5b, 0xc0, 0xe7, 0x30, 0x29, 0x89, 0xce, 0xa4, 0x62, 0x39, 0xed, + 0xb5, 0x4f, 0x4a, 0xa2, 0xaf, 0x3b, 0x3e, 0x94, 0x3b, 0xb6, 0x67, 0xd6, 0xdb, 0x96, 0xdb, 0x8e, + 0x3b, 0x17, 0x45, 0x73, 0x26, 0x19, 0xe5, 0x75, 0xef, 0xfb, 0x27, 0xe8, 0xde, 0xd6, 0x92, 0x5d, + 0x63, 0x2d, 0x07, 0xb1, 0x85, 0x2e, 0x65, 0x5c, 0x36, 0xb5, 0x37, 0x32, 0xf3, 0x16, 0x70, 0xf0, + 0xf0, 0x56, 0xc6, 0x33, 0xb4, 0x98, 0xae, 0x5e, 0xfb, 0xff, 0xfb, 0xb2, 0x7e, 0x72, 0x18, 0x7d, + 0x78, 0x75, 0x1f, 0x60, 0x72, 0x9f, 0x63, 0x07, 0x50, 0xdb, 0x5b, 0xa2, 0xb6, 0x23, 0xd5, 0x9b, + 0x21, 0xd5, 0x91, 0xee, 0x55, 0x90, 0x7e, 0x97, 0xc1, 0x30, 0x15, 0x92, 0xe5, 0x78, 0x0a, 0xe3, + 0x9b, 0xf0, 0x73, 0x18, 0x7d, 0x0d, 0xdd, 0x47, 0xf8, 0x39, 0x9c, 0xad, 0xa3, 0xed, 0x36, 0x48, + 0xaf, 0xa2, 0x30, 0xbb, 0x8c, 0x3e, 0x7e, 0xcb, 0xe2, 0xcd, 0x97, 0x9b, 0x4d, 0x92, 0xba, 0x08, + 0x9f, 0xc3, 0xd3, 0x7f, 0xba, 0xe4, 0x3a, 0x0a, 0x93, 0x8d, 0x7b, 0x84, 0x5d, 0x70, 0xd2, 0x38, + 0x08, 0x93, 0x60, 0xdd, 0xd5, 0x89, 0x7b, 0x7c, 0x3b, 0x32, 0xff, 0xe9, 0xfb, 0xdf, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x1e, 0x58, 0xa9, 0xa1, 0xcf, 0x02, 0x00, 0x00, } diff --git a/proto/sharding/p2p/v1/messages.proto b/proto/sharding/p2p/v1/messages.proto index e9f8761e2fbf..ba5df4caa62c 100644 --- a/proto/sharding/p2p/v1/messages.proto +++ b/proto/sharding/p2p/v1/messages.proto @@ -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 { diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index 669cc712a5bd..8b1034a7a926 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -10,12 +10,10 @@ go_library( "p2p.go", "peer.go", "service.go", - "topics.go", ], importpath = "github.com/prysmaticlabs/prysm/shared/p2p", visibility = ["//visibility:public"], deps = [ - "//proto/beacon/p2p/v1:go_default_library", "//proto/sharding/p2p/v1:go_default_library", "//shared/iputils:go_default_library", "@com_github_ethereum_go_ethereum//event:go_default_library", @@ -40,7 +38,6 @@ go_test( "options_test.go", "register_topic_example_test.go", "service_test.go", - "topics_test.go", ], embed = [":go_default_library"], deps = [ diff --git a/shared/p2p/discovery.go b/shared/p2p/discovery.go index b8e55b268681..fd439462cfbc 100644 --- a/shared/p2p/discovery.go +++ b/shared/p2p/discovery.go @@ -5,10 +5,8 @@ import ( "time" host "github.com/libp2p/go-libp2p-host" - peer "github.com/libp2p/go-libp2p-peer" ps "github.com/libp2p/go-libp2p-peerstore" mdns "github.com/libp2p/go-libp2p/p2p/discovery" - shardpb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" "github.com/sirupsen/logrus" ) @@ -24,30 +22,20 @@ var mDNSTag = mdns.ServiceTag // DNS peer discovery. // // TODO: add other discovery protocols such as DHT, etc. -func startDiscovery(ctx context.Context, host host.Host, gsub topicPeerLister) error { +func startDiscovery(ctx context.Context, host host.Host) error { mdnsService, err := mdns.NewMdnsService(ctx, host, discoveryInterval, mDNSTag) if err != nil { return err } - mdnsService.RegisterNotifee(&discovery{ctx, host, gsub}) - + mdnsService.RegisterNotifee(&discovery{ctx, host}) return nil } -// topicPeerLister has a method to return connected peers on a given topic. -// This is implemented by floodsub.PubSub. -type topicPeerLister interface { - ListPeers(string) []peer.ID -} - // Discovery implements mDNS notifee interface. type discovery struct { ctx context.Context host host.Host - - // Required for helper method. - gsub topicPeerLister } // HandlePeerFound registers the peer with the host. @@ -65,19 +53,4 @@ func (d *discovery) HandlePeerFound(pi ps.PeerInfo) { log.WithFields(logrus.Fields{ "peers": d.host.Peerstore().Peers(), }).Debug("Peers are now") - - log.WithFields(logrus.Fields{ - "peerMap": d.topicPeerMap(), - }).Debug("Gsub has peers") -} - -// topicPeerMap helper function for inspecting which peers are available for -// the p2p topics. -func (d *discovery) topicPeerMap() map[shardpb.Topic][]peer.ID { - m := make(map[shardpb.Topic][]peer.ID) - for topic := range topicTypeMapping { - peers := d.gsub.ListPeers(topic.String()) - m[topic] = peers - } - return m } diff --git a/shared/p2p/discovery_norace_test.go b/shared/p2p/discovery_norace_test.go index 2d42402f111b..772460a05be0 100644 --- a/shared/p2p/discovery_norace_test.go +++ b/shared/p2p/discovery_norace_test.go @@ -5,24 +5,12 @@ import ( "testing" "time" - floodsub "github.com/libp2p/go-floodsub" - peer "github.com/libp2p/go-libp2p-peer" swarmt "github.com/libp2p/go-libp2p-swarm/testing" mdns "github.com/libp2p/go-libp2p/p2p/discovery" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" ) var _ = mdns.Notifee(&discovery{}) -var _ = topicPeerLister(&floodsub.PubSub{}) - -var _ = topicPeerLister(&fakeTopicPeerLister{}) - -type fakeTopicPeerLister struct { -} - -func (f *fakeTopicPeerLister) ListPeers(topic string) []peer.ID { - return nil -} func expectPeers(t *testing.T, h *bhost.BasicHost, n int) { if len(h.Peerstore().Peers()) != n { @@ -42,16 +30,14 @@ func TestStartDiscovery_HandlePeerFound(t *testing.T) { ctx, cancel := context.WithCancel(context.TODO()) defer cancel() - gsub := &fakeTopicPeerLister{} - a := bhost.New(swarmt.GenSwarm(t, ctx)) - err := startDiscovery(ctx, a, gsub) + err := startDiscovery(ctx, a) if err != nil { t.Errorf("Error when starting discovery: %v", err) } b := bhost.New(swarmt.GenSwarm(t, ctx)) - err = startDiscovery(ctx, b, gsub) + err = startDiscovery(ctx, b) if err != nil { t.Errorf("Error when starting discovery: %v", err) } diff --git a/shared/p2p/service.go b/shared/p2p/service.go index dd0f75a8a2e0..69b892774a4f 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -24,12 +24,13 @@ type Sender interface { // Server is a placeholder for a p2p service. To be designed. type Server struct { - ctx context.Context - cancel context.CancelFunc - mutex *sync.Mutex - feeds map[reflect.Type]*event.Feed - host host.Host - gsub *floodsub.PubSub + ctx context.Context + cancel context.CancelFunc + mutex *sync.Mutex + feeds map[reflect.Type]*event.Feed + host host.Host + gsub *floodsub.PubSub + topicMapping map[reflect.Type]string } // NewServer creates a new p2p server instance. @@ -49,19 +50,20 @@ func NewServer() (*Server, error) { } return &Server{ - ctx: ctx, - cancel: cancel, - feeds: make(map[reflect.Type]*event.Feed), - host: host, - gsub: gsub, - mutex: &sync.Mutex{}, + ctx: ctx, + cancel: cancel, + feeds: make(map[reflect.Type]*event.Feed), + host: host, + gsub: gsub, + mutex: &sync.Mutex{}, + topicMapping: make(map[reflect.Type]string), }, nil } // Start the main routine for an p2p server. func (s *Server) Start() { log.Info("Starting service") - if err := startDiscovery(s.ctx, s.host, s.gsub); err != nil { + if err := startDiscovery(s.ctx, s.host); err != nil { log.Errorf("Could not start p2p discovery! %v", err) return } @@ -86,6 +88,8 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad "topic": topic, }).Debug("Subscribing to topic") + s.topicMapping[msgType] = topic + sub, err := s.gsub.Subscribe(topic) if err != nil { log.Errorf("Failed to subscribe to topic: %v", err) @@ -173,12 +177,12 @@ func (s *Server) Send(msg interface{}, peer Peer) { // Broadcast a message to the world. func (s *Server) Broadcast(msg interface{}) { // TODO: https://github.com/prysmaticlabs/prysm/issues/176 - topic := topic(msg) + topic := s.topicMapping[reflect.TypeOf(msg)] log.WithFields(logrus.Fields{ "topic": topic, - }).Debugf("Broadcasting msg %T", msg) + }).Debugf("Broadcasting msg %s", msg) - if topic == shardpb.Topic_UNKNOWN { + if topic == "" { log.Warnf("Topic is unknown for message type %T. %v", msg, msg) } @@ -194,7 +198,7 @@ func (s *Server) Broadcast(msg interface{}) { log.Errorf("Failed to marshal data for broadcast: %v", err) return } - if err := s.gsub.Publish(topic.String(), b); err != nil { + if err := s.gsub.Publish(topic, b); err != nil { log.Errorf("Failed to publish to gossipsub topic: %v", err) } } diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index d7116de5016c..3b13491b8123 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -92,7 +92,7 @@ func TestSubscribe(t *testing.T) { func testSubscribe(ctx context.Context, t *testing.T, s Server, gsub *floodsub.PubSub, ch chan Message) { topic := shardpb.Topic_COLLATION_BODY_REQUEST - msgType := topicTypeMapping[topic] + msgType := reflect.TypeOf(shardpb.CollationBodyRequest{}) go s.subscribeToTopic(topic, msgType) // Short delay to let goroutine add subscription. diff --git a/shared/p2p/topics.go b/shared/p2p/topics.go deleted file mode 100644 index 1cacf1ef3499..000000000000 --- a/shared/p2p/topics.go +++ /dev/null @@ -1,48 +0,0 @@ -package p2p - -import ( - "reflect" - - beaconpb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" - shardpb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" -) - -// Mapping of message topic enums to protobuf types. -var topicTypeMapping = map[shardpb.Topic]reflect.Type{ - shardpb.Topic_BEACON_BLOCK_HASH_ANNOUNCE: reflect.TypeOf(beaconpb.BeaconBlockHashAnnounce{}), - shardpb.Topic_BEACON_BLOCK_REQUEST: reflect.TypeOf(beaconpb.BeaconBlockRequest{}), - shardpb.Topic_BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER: reflect.TypeOf(beaconpb.BeaconBlockRequestBySlotNumber{}), - shardpb.Topic_BEACON_BLOCK_RESPONSE: reflect.TypeOf(beaconpb.BeaconBlockResponse{}), - shardpb.Topic_COLLATION_BODY_REQUEST: reflect.TypeOf(shardpb.CollationBodyRequest{}), - shardpb.Topic_COLLATION_BODY_RESPONSE: reflect.TypeOf(shardpb.CollationBodyResponse{}), - shardpb.Topic_TRANSACTIONS: reflect.TypeOf(shardpb.Transaction{}), - shardpb.Topic_CRYSTALLIZED_STATE_HASH_ANNOUNCE: reflect.TypeOf(beaconpb.CrystallizedStateHashAnnounce{}), - shardpb.Topic_CRYSTALLIZED_STATE_REQUEST: reflect.TypeOf(beaconpb.CrystallizedStateRequest{}), - shardpb.Topic_CRYSTALLIZED_STATE_RESPONSE: reflect.TypeOf(beaconpb.CrystallizedStateResponse{}), - shardpb.Topic_ACTIVE_STATE_HASH_ANNOUNCE: reflect.TypeOf(beaconpb.ActiveStateHashAnnounce{}), - shardpb.Topic_ACTIVE_STATE_REQUEST: reflect.TypeOf(beaconpb.ActiveStateRequest{}), - shardpb.Topic_ACTIVE_STATE_RESPONSE: reflect.TypeOf(beaconpb.ActiveStateResponse{}), -} - -// Mapping of message types to topic enums. -var typeTopicMapping = reverseMapping(topicTypeMapping) - -// ReverseMapping from K,V to V,K -func reverseMapping(m map[shardpb.Topic]reflect.Type) map[reflect.Type]shardpb.Topic { - n := make(map[reflect.Type]shardpb.Topic) - for k, v := range m { - n[v] = k - } - return n -} - -// These functions return the given topic for a given interface. This is the preferred -// way to resolve a topic from an value. The msg could be a pointer or value -// argument to resolve to the correct topic. -func topic(msg interface{}) shardpb.Topic { - msgType := reflect.TypeOf(msg) - if msgType.Kind() == reflect.Ptr { - msgType = reflect.Indirect(reflect.ValueOf(msg)).Type() - } - return typeTopicMapping[msgType] -} diff --git a/shared/p2p/topics_test.go b/shared/p2p/topics_test.go deleted file mode 100644 index ca2962d509c0..000000000000 --- a/shared/p2p/topics_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package p2p - -import ( - "reflect" - "testing" - - shardpb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" -) - -type testStruct struct{} - -func TestReverseMapping(t *testing.T) { - tests := []struct { - input map[shardpb.Topic]reflect.Type - want map[reflect.Type]shardpb.Topic - }{ - { - input: map[shardpb.Topic]reflect.Type{ - shardpb.Topic_UNKNOWN: reflect.TypeOf(testStruct{}), - }, - want: map[reflect.Type]shardpb.Topic{ - reflect.TypeOf(testStruct{}): shardpb.Topic_UNKNOWN, - }, - }, - } - - for _, tt := range tests { - got := reverseMapping(tt.input) - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("reverseMapping(%+v) = %+v. Wanted %+v", tt.input, got, tt.want) - } - } -} - -func TestTopic(t *testing.T) { - type CustomStruct struct{} - - tests := []struct { - input interface{} - want shardpb.Topic - }{ - { - input: shardpb.CollationBodyRequest{}, - want: shardpb.Topic_COLLATION_BODY_REQUEST, - }, - { - input: &shardpb.CollationBodyRequest{}, - want: shardpb.Topic_COLLATION_BODY_REQUEST, - }, - { - input: CustomStruct{}, - want: shardpb.Topic_UNKNOWN, - }, - } - - for _, tt := range tests { - got := topic(tt.input) - if got != tt.want { - t.Errorf("topic(%T) = %v. wanted %v", tt.input, got, tt.want) - } - } -} From 1da3adb9fc3a3bc00cde3a8caf680be0ab4e6e2c Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 19 Aug 2018 16:15:21 -0400 Subject: [PATCH 09/24] split topics --- beacon-chain/node/p2p_config.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/beacon-chain/node/p2p_config.go b/beacon-chain/node/p2p_config.go index 246705aebf3d..0685ef866c5a 100644 --- a/beacon-chain/node/p2p_config.go +++ b/beacon-chain/node/p2p_config.go @@ -2,6 +2,8 @@ package node import ( "github.com/prysmaticlabs/prysm/shared/p2p" + + pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" ) func configureP2P() (*p2p.Server, error) { @@ -10,12 +12,9 @@ func configureP2P() (*p2p.Server, error) { return nil, err } - // Configure adapters var adapters []p2p.Adapter - type TestInterface struct { - } - s.RegisterTopic("test_topic", TestInterface{}, adapters...) + s.RegisterTopic(v1.Topic_BEACON_BLOCK_HASH_ANNOUNCE.String(), pb.BeaconBlockHashAnnounce{}, adapters...) return s, nil -} +} \ No newline at end of file From 7bced19bb6c1eab72305c21f6e1f8bcf7c01ebe2 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 19 Aug 2018 16:23:14 -0400 Subject: [PATCH 10/24] split topics --- beacon-chain/node/BUILD.bazel | 1 + beacon-chain/node/p2p_config.go | 21 ++++++++++++++++++--- client/node/BUILD.bazel | 6 +++++- client/node/node.go | 2 +- shared/p2p/BUILD.bazel | 1 - 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/beacon-chain/node/BUILD.bazel b/beacon-chain/node/BUILD.bazel index 1f6243cb7dba..d06aa6a34bf6 100644 --- a/beacon-chain/node/BUILD.bazel +++ b/beacon-chain/node/BUILD.bazel @@ -15,6 +15,7 @@ go_library( "//beacon-chain/simulator:go_default_library", "//beacon-chain/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", diff --git a/beacon-chain/node/p2p_config.go b/beacon-chain/node/p2p_config.go index 0685ef866c5a..bb1de4bc7587 100644 --- a/beacon-chain/node/p2p_config.go +++ b/beacon-chain/node/p2p_config.go @@ -6,15 +6,30 @@ import ( 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: Define default adaptors for logging, monitoring, etc. var adapters []p2p.Adapter - - s.RegisterTopic(v1.Topic_BEACON_BLOCK_HASH_ANNOUNCE.String(), pb.BeaconBlockHashAnnounce{}, adapters...) + for k, v := range topicMappings { + s.RegisterTopic(k.String(), v, adapters...) + } return s, nil -} \ No newline at end of file +} diff --git a/client/node/BUILD.bazel b/client/node/BUILD.bazel index a1d43c8805fa..9559534a9c83 100644 --- a/client/node/BUILD.bazel +++ b/client/node/BUILD.bazel @@ -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/client/node", visibility = ["//client:__subpackages__"], deps = [ @@ -12,6 +15,7 @@ go_library( "//client/rpcclient:go_default_library", "//client/txpool:go_default_library", "//client/types:go_default_library", + "//proto/sharding/p2p/v1:go_default_library", "//shared:go_default_library", "//shared/cmd:go_default_library", "//shared/database:go_default_library", diff --git a/client/node/node.go b/client/node/node.go index c56529d93e65..7503ad7d3471 100644 --- a/client/node/node.go +++ b/client/node/node.go @@ -137,7 +137,7 @@ func (s *ShardEthereum) startDB(ctx *cli.Context) error { // registerP2P attaches a p2p server to the ShardEthereum instance. func (s *ShardEthereum) registerP2P() error { - shardp2p, err := p2p.NewServer() + shardp2p, err := configureP2P() if err != nil { return fmt.Errorf("could not register shardp2p service: %v", err) } diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index 8b1034a7a926..968fac16bead 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -23,7 +23,6 @@ go_library( "@com_github_libp2p_go_libp2p//p2p/discovery:go_default_library", "@com_github_libp2p_go_libp2p_crypto//:go_default_library", "@com_github_libp2p_go_libp2p_host//:go_default_library", - "@com_github_libp2p_go_libp2p_peer//:go_default_library", "@com_github_libp2p_go_libp2p_peerstore//:go_default_library", "@com_github_multiformats_go_multiaddr//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", From 80fe715092315b9f4c699b6d7f056f27e7ed7b24 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 19 Aug 2018 16:23:59 -0400 Subject: [PATCH 11/24] add other config --- beacon-chain/node/p2p_config.go | 2 +- client/node/p2p_config.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 client/node/p2p_config.go diff --git a/beacon-chain/node/p2p_config.go b/beacon-chain/node/p2p_config.go index bb1de4bc7587..d362986f06e4 100644 --- a/beacon-chain/node/p2p_config.go +++ b/beacon-chain/node/p2p_config.go @@ -25,7 +25,7 @@ func configureP2P() (*p2p.Server, error) { return nil, err } - // TODO: Define default adaptors for logging, monitoring, etc. + // TODO: Define default adapters for logging, monitoring, etc. var adapters []p2p.Adapter for k, v := range topicMappings { s.RegisterTopic(k.String(), v, adapters...) diff --git a/client/node/p2p_config.go b/client/node/p2p_config.go new file mode 100644 index 000000000000..e2960923d1ef --- /dev/null +++ b/client/node/p2p_config.go @@ -0,0 +1,28 @@ +package node + +import ( + "github.com/prysmaticlabs/prysm/shared/p2p" + + pb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" +) + +var topicMappings = map[pb.Topic]interface{}{ + pb.Topic_COLLATION_BODY_REQUEST: pb.CollationBodyRequest{}, + pb.Topic_COLLATION_BODY_RESPONSE: pb.CollationBodyResponse{}, + pb.Topic_TRANSACTIONS: pb.Transaction{}, +} + +func configureP2P() (*p2p.Server, error) { + s, err := p2p.NewServer() + if err != nil { + return nil, err + } + + // TODO: 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 +} From e6c32f3be0d1b90b1ba0975ee1aa9b4587f87245 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 19 Aug 2018 15:53:02 -0700 Subject: [PATCH 12/24] fix example --- beacon-chain/sync/BUILD.bazel | 1 + shared/p2p/register_topic_example_test.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index f388870b1d13..363c7c4fbaaa 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -17,6 +17,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 = [ "//beacon-chain/types:go_default_library", "//proto/beacon/p2p/v1:go_default_library", diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index 00f60ab45566..0f7fa1b737af 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -12,7 +12,7 @@ import ( // limiter or blacklisting condition. func reqLogger(next p2p.Handler) p2p.Handler { return func(ctx context.Context, msg p2p.Message) { - fmt.Println("Received message from %s", msg.Peer) + fmt.Printf("Received message from %s\n", msg.Peer) next(ctx, msg) } } @@ -21,7 +21,7 @@ func reqLogger(next p2p.Handler) p2p.Handler { func adapterWithParams(i int) p2p.Adapter { return func(next p2p.Handler) p2p.Handler { return func(ctx context.Context, msg p2p.Message) { - fmt.Println("Magic number is %d", i) + fmt.Printf("Magic number is %d\n", i) i++ next(ctx, msg) } From 558139be2bee8d403028e6bec93ff7205b834a97 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 22 Aug 2018 20:44:08 -0400 Subject: [PATCH 13/24] newline --- proto/testing/test.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/testing/test.proto b/proto/testing/test.proto index c4609e889896..a9ddff46d9f5 100644 --- a/proto/testing/test.proto +++ b/proto/testing/test.proto @@ -4,4 +4,4 @@ package ethereum.testing; message TestMessage { string foo = 1; -} \ No newline at end of file +} From fe95160353cfc15902b1ccfe4f85872843e4f986 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 22 Aug 2018 20:53:25 -0400 Subject: [PATCH 14/24] fix merge --- beacon-chain/sync/BUILD.bazel | 2 +- validator/node/BUILD.bazel | 31 +++++++------------------------ 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 363c7c4fbaaa..163e62012ae8 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -17,7 +17,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. + race = "off", # TODO(#377): fix issues with race detection testing. deps = [ "//beacon-chain/types:go_default_library", "//proto/beacon/p2p/v1:go_default_library", diff --git a/validator/node/BUILD.bazel b/validator/node/BUILD.bazel index 6525224c2b29..6c4866d47586 100644 --- a/validator/node/BUILD.bazel +++ b/validator/node/BUILD.bazel @@ -1,28 +1,18 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +go_test( + name = "go_default_test", + srcs = ["node_test.go"], + embed = [":go_default_library"], + deps = ["@com_github_urfave_cli//:go_default_library"], +) + go_library( name = "go_default_library", -<<<<<<< HEAD:client/node/BUILD.bazel - srcs = [ - "node.go", - "p2p_config.go", - ], - importpath = "github.com/prysmaticlabs/prysm/client/node", - visibility = ["//client:__subpackages__"], - deps = [ - "//client/attester:go_default_library", - "//client/beacon:go_default_library", - "//client/proposer:go_default_library", - "//client/rpcclient:go_default_library", - "//client/txpool:go_default_library", - "//client/types:go_default_library", - "//proto/sharding/p2p/v1:go_default_library", -======= srcs = ["node.go"], importpath = "github.com/prysmaticlabs/prysm/validator/node", visibility = ["//validator:__subpackages__"], deps = [ ->>>>>>> master:validator/node/BUILD.bazel "//shared:go_default_library", "//shared/cmd:go_default_library", "//shared/database:go_default_library", @@ -38,10 +28,3 @@ go_library( "@com_github_urfave_cli//:go_default_library", ], ) - -go_test( - name = "go_default_test", - srcs = ["node_test.go"], - embed = [":go_default_library"], - deps = ["@com_github_urfave_cli//:go_default_library"], -) From 3d8646d1d3e41977b406384d0c1d326279a1ce01 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 22 Aug 2018 20:57:21 -0400 Subject: [PATCH 15/24] move more after merge --- validator/node/BUILD.bazel | 6 +++++- {client => validator}/node/p2p_config.go | 0 2 files changed, 5 insertions(+), 1 deletion(-) rename {client => validator}/node/p2p_config.go (100%) diff --git a/validator/node/BUILD.bazel b/validator/node/BUILD.bazel index 6c4866d47586..d7a4d2a8acd9 100644 --- a/validator/node/BUILD.bazel +++ b/validator/node/BUILD.bazel @@ -9,10 +9,14 @@ go_test( go_library( name = "go_default_library", - srcs = ["node.go"], + srcs = [ + "node.go", + "p2p_config.go", + ], importpath = "github.com/prysmaticlabs/prysm/validator/node", visibility = ["//validator:__subpackages__"], deps = [ + "//proto/sharding/p2p/v1:go_default_library", "//shared:go_default_library", "//shared/cmd:go_default_library", "//shared/database:go_default_library", diff --git a/client/node/p2p_config.go b/validator/node/p2p_config.go similarity index 100% rename from client/node/p2p_config.go rename to validator/node/p2p_config.go From 55cc0c360c77c535949b536187ea68c10ba741da Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Thu, 23 Aug 2018 21:56:40 -0400 Subject: [PATCH 16/24] fix godoc --- shared/p2p/service.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 69b892774a4f..a3d1308c63bc 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -77,11 +77,12 @@ func (s *Server) Stop() error { return nil } -// RegisterTopic, message, and the adapter stack for the given topic. The message type provided -// will be feed selector for emitting messages received on a given topic. +// RegisterTopic with a message and the adapter stack for the given topic. The +// message type provided will be feed selector for emitting messages received +// on a given topic. // -// The topics can originate from multiple sources. In other words, messages on TopicA may come -// from direct peer communication or a pub/sub channel. +// The topics can originate from multiple sources. In other words, messages on +// TopicA may come from direct peer communication or a pub/sub channel. func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Adapter) { msgType := reflect.TypeOf(message) log.WithFields(logrus.Fields{ From 23daf90f292c52edab9b4bab4ebfbaae1707c6eb Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Thu, 23 Aug 2018 22:35:14 -0400 Subject: [PATCH 17/24] a bit more tests --- shared/p2p/BUILD.bazel | 2 ++ shared/p2p/service_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index 968fac16bead..140e54699e20 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -46,9 +46,11 @@ go_test( "@com_github_ethereum_go_ethereum//event:go_default_library", "@com_github_golang_protobuf//proto:go_default_library", "@com_github_libp2p_go_floodsub//:go_default_library", + "@com_github_libp2p_go_floodsub//pb:go_default_library", "@com_github_libp2p_go_libp2p_blankhost//:go_default_library", "@com_github_libp2p_go_libp2p_swarm//testing:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_sirupsen_logrus//hooks/test:go_default_library", ], ) diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index 3b13491b8123..062be4062587 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -4,6 +4,7 @@ import ( "context" "io/ioutil" "reflect" + "strings" "sync" "testing" "time" @@ -11,12 +12,14 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/golang/protobuf/proto" floodsub "github.com/libp2p/go-floodsub" + floodsubPb "github.com/libp2p/go-floodsub/pb" bhost "github.com/libp2p/go-libp2p-blankhost" swarmt "github.com/libp2p/go-libp2p-swarm/testing" shardpb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" testpb "github.com/prysmaticlabs/prysm/proto/testing" "github.com/prysmaticlabs/prysm/shared" "github.com/sirupsen/logrus" + logTest "github.com/sirupsen/logrus/hooks/test" ) // Ensure that server implements service. @@ -39,6 +42,32 @@ func TestBroadcast(t *testing.T) { // TODO: test that topic was published } +func TestEmitFailsNonProtobuf(t *testing.T) { + s, _ := NewServer() + hook := logTest.NewGlobal() + s.emit(nil /*feed*/, nil /*msg*/, reflect.TypeOf("")) + want := "Received message is not a protobuf message" + if hook.LastEntry().Message != want { + t.Errorf("Expected log to contain %s. Got = %s", want, hook.LastEntry().Message) + } +} + +func TestEmitFailsUnmarshal(t *testing.T) { + s, _ := NewServer() + hook := logTest.NewGlobal() + msg := &floodsub.Message{ + &floodsubPb.Message{ + Data: []byte("bogus"), + }, + } + + s.emit(nil /*feed*/, msg, reflect.TypeOf(testpb.TestMessage{})) + want := "Failed to decode data:" + if !strings.Contains(hook.LastEntry().Message, want) { + t.Errorf("Expected log to contain %s. Got = %s", want, hook.LastEntry().Message) + } +} + func TestSubscribeToTopic(t *testing.T) { ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second) defer cancel() From aa77a948ada648ccdcb357759103ae5c9e6f30a3 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Thu, 23 Aug 2018 22:37:17 -0400 Subject: [PATCH 18/24] merge assignment --- shared/p2p/service.go | 3 +-- shared/p2p/service_test.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index a3d1308c63bc..7e0e0fd73de9 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -119,8 +119,7 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad adapters[i], adapters[opp] = adapters[opp], adapters[i] } - var h Handler - h = func(ctx context.Context, pMsg Message) { + var h Handler = func(ctx context.Context, pMsg Message) { s.emit(feed, msg, msgType) } diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index 062be4062587..b54dd7c2773d 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -204,8 +204,7 @@ func TestRegisterTopic_WithAdapers(t *testing.T) { testMessage := testpb.TestMessage{Foo: "bar"} i := 0 - var testAdapter Adapter - testAdapter = func(next Handler) Handler { + var testAdapter Adapter = func(next Handler) Handler { return func(ctx context.Context, msg Message) { i++ next(ctx, msg) From 91f83528b58202b4c93ebc258355059b19378dfb Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 26 Aug 2018 13:53:06 -0400 Subject: [PATCH 19/24] update from PR feedback --- beacon-chain/node/p2p_config.go | 2 +- proto/testing/test.pb.go | 62 ++++++++++++++++++++--- proto/testing/test.proto | 6 +++ shared/p2p/feed_example_test.go | 15 +++--- shared/p2p/message.go | 6 ++- shared/p2p/register_topic_example_test.go | 1 - shared/p2p/service.go | 12 ++--- validator/node/p2p_config.go | 2 +- 8 files changed, 82 insertions(+), 24 deletions(-) diff --git a/beacon-chain/node/p2p_config.go b/beacon-chain/node/p2p_config.go index d362986f06e4..89c4c53f7b34 100644 --- a/beacon-chain/node/p2p_config.go +++ b/beacon-chain/node/p2p_config.go @@ -25,7 +25,7 @@ func configureP2P() (*p2p.Server, error) { return nil, err } - // TODO: Define default adapters for logging, monitoring, etc. + // 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...) diff --git a/proto/testing/test.pb.go b/proto/testing/test.pb.go index 4a5e82781fb4..87c0c517dbd0 100755 --- a/proto/testing/test.pb.go +++ b/proto/testing/test.pb.go @@ -29,7 +29,7 @@ func (m *TestMessage) Reset() { *m = TestMessage{} } func (m *TestMessage) String() string { return proto.CompactTextString(m) } func (*TestMessage) ProtoMessage() {} func (*TestMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_test_45722d484cf957ef, []int{0} + return fileDescriptor_test_efe8e22469748e36, []int{0} } func (m *TestMessage) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TestMessage.Unmarshal(m, b) @@ -56,18 +56,68 @@ func (m *TestMessage) GetFoo() string { return "" } +type Puzzle struct { + Challenge string `protobuf:"bytes,1,opt,name=challenge" json:"challenge,omitempty"` + Answer string `protobuf:"bytes,2,opt,name=answer" json:"answer,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Puzzle) Reset() { *m = Puzzle{} } +func (m *Puzzle) String() string { return proto.CompactTextString(m) } +func (*Puzzle) ProtoMessage() {} +func (*Puzzle) Descriptor() ([]byte, []int) { + return fileDescriptor_test_efe8e22469748e36, []int{1} +} +func (m *Puzzle) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Puzzle.Unmarshal(m, b) +} +func (m *Puzzle) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Puzzle.Marshal(b, m, deterministic) +} +func (dst *Puzzle) XXX_Merge(src proto.Message) { + xxx_messageInfo_Puzzle.Merge(dst, src) +} +func (m *Puzzle) XXX_Size() int { + return xxx_messageInfo_Puzzle.Size(m) +} +func (m *Puzzle) XXX_DiscardUnknown() { + xxx_messageInfo_Puzzle.DiscardUnknown(m) +} + +var xxx_messageInfo_Puzzle proto.InternalMessageInfo + +func (m *Puzzle) GetChallenge() string { + if m != nil { + return m.Challenge + } + return "" +} + +func (m *Puzzle) GetAnswer() string { + if m != nil { + return m.Answer + } + return "" +} + func init() { proto.RegisterType((*TestMessage)(nil), "ethereum.testing.TestMessage") + proto.RegisterType((*Puzzle)(nil), "ethereum.testing.Puzzle") } -func init() { proto.RegisterFile("proto/testing/test.proto", fileDescriptor_test_45722d484cf957ef) } +func init() { proto.RegisterFile("proto/testing/test.proto", fileDescriptor_test_efe8e22469748e36) } -var fileDescriptor_test_45722d484cf957ef = []byte{ - // 92 bytes of a gzipped FileDescriptorProto +var fileDescriptor_test_efe8e22469748e36 = []byte{ + // 135 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, 0x2d, 0x2e, 0xc9, 0xcc, 0x4b, 0x07, 0xd3, 0x7a, 0x60, 0x21, 0x21, 0x81, 0xd4, 0x92, 0x8c, 0xd4, 0xa2, 0xd4, 0xd2, 0x5c, 0x3d, 0xa8, 0xa4, 0x92, 0x3c, 0x17, 0x77, 0x48, 0x6a, 0x71, 0x89, 0x6f, 0x6a, 0x71, 0x71, 0x62, 0x7a, 0xaa, 0x90, 0x00, 0x17, 0x73, 0x5a, 0x7e, - 0xbe, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x88, 0x99, 0xc4, 0x06, 0xd6, 0x69, 0x0c, 0x08, - 0x00, 0x00, 0xff, 0xff, 0xf9, 0x33, 0x23, 0x18, 0x55, 0x00, 0x00, 0x00, + 0xbe, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x88, 0xa9, 0x64, 0xc7, 0xc5, 0x16, 0x50, 0x5a, + 0x55, 0x95, 0x93, 0x2a, 0x24, 0xc3, 0xc5, 0x99, 0x9c, 0x91, 0x98, 0x93, 0x93, 0x9a, 0x97, 0x9e, + 0x0a, 0x55, 0x81, 0x10, 0x10, 0x12, 0xe3, 0x62, 0x4b, 0xcc, 0x2b, 0x2e, 0x4f, 0x2d, 0x92, 0x60, + 0x02, 0x4b, 0x41, 0x79, 0x49, 0x6c, 0x60, 0x9b, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7f, + 0xb3, 0xa3, 0x6b, 0x95, 0x00, 0x00, 0x00, } diff --git a/proto/testing/test.proto b/proto/testing/test.proto index a9ddff46d9f5..73069570f518 100644 --- a/proto/testing/test.proto +++ b/proto/testing/test.proto @@ -5,3 +5,9 @@ package ethereum.testing; message TestMessage { string foo = 1; } + +// Used in shared/p2p/feed_example_test.go +message Puzzle { + string challenge = 1; + string answer = 2; +} \ No newline at end of file diff --git a/shared/p2p/feed_example_test.go b/shared/p2p/feed_example_test.go index a4f634e36246..233e28caf7de 100644 --- a/shared/p2p/feed_example_test.go +++ b/shared/p2p/feed_example_test.go @@ -1,6 +1,10 @@ package p2p -import "fmt" +import ( + "fmt" + + pb "github.com/prysmaticlabs/prysm/proto/testing" +) // Feeds can be use to subscribe to any type of message. func ExampleServer_Feed() { @@ -10,12 +14,7 @@ func ExampleServer_Feed() { } // Let's wait for a puzzle from our peers then try to solve it. - type Puzzle struct { - Challenge string - Answer string - } - - feed := s.Feed(Puzzle{}) + feed := s.Feed(pb.Puzzle{}) ch := make(chan Message, 5) // Small buffer size. I don't expect many puzzles. sub := feed.Subscribe(ch) @@ -26,7 +25,7 @@ func ExampleServer_Feed() { // Wait until we have a puzzle to solve. msg := <-ch - puzzle, ok := msg.Data.(Puzzle) + puzzle, ok := msg.Data.(*pb.Puzzle) if !ok { panic("Received a message that wasn't a puzzle!") diff --git a/shared/p2p/message.go b/shared/p2p/message.go index ad78bf855aec..bf121bc961a1 100644 --- a/shared/p2p/message.go +++ b/shared/p2p/message.go @@ -1,9 +1,13 @@ package p2p +import ( + "github.com/golang/protobuf/proto" +) + // Message represents a message received from an external peer. type Message struct { // Peer represents the sender of the message. Peer Peer // Data can be any type of message found in sharding/p2p/proto package. - Data interface{} + Data proto.Message } diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index 0f7fa1b737af..b8f001776e6b 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -33,7 +33,6 @@ func ExampleServer_RegisterTopic() { s, _ := p2p.NewServer() - // TODO: Figure out the topic. Is it a protobuf topic, string, or int? var topic string var message interface{} diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 7e0e0fd73de9..84867369abf4 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -98,6 +98,12 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad } feed := s.Feed(msgType) + // Reverse adapter order + for i := len(adapters)/2 - 1; i >= 0; i-- { + opp := len(adapters) - 1 - i + adapters[i], adapters[opp] = adapters[opp], adapters[i] + } + go (func() { defer sub.Cancel() for { @@ -113,12 +119,6 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad return } - // Reverse adapter order - for i := len(adapters)/2 - 1; i >= 0; i-- { - opp := len(adapters) - 1 - i - adapters[i], adapters[opp] = adapters[opp], adapters[i] - } - var h Handler = func(ctx context.Context, pMsg Message) { s.emit(feed, msg, msgType) } diff --git a/validator/node/p2p_config.go b/validator/node/p2p_config.go index e2960923d1ef..2fdc39ac8e5f 100644 --- a/validator/node/p2p_config.go +++ b/validator/node/p2p_config.go @@ -18,7 +18,7 @@ func configureP2P() (*p2p.Server, error) { return nil, err } - // TODO: Define default adapters for logging, monitoring, etc. + // 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...) From 287839fb940f13edfe2c860def50f67edd2b731d Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 28 Aug 2018 20:44:52 -0400 Subject: [PATCH 20/24] PR feedback --- shared/p2p/register_topic_example_test.go | 3 +- shared/p2p/service.go | 47 +---------------------- shared/p2p/service_test.go | 24 ++++++------ 3 files changed, 15 insertions(+), 59 deletions(-) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index b8f001776e6b..9d77eba0bdaf 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/golang/protobuf/proto" "github.com/prysmaticlabs/prysm/shared/p2p" ) @@ -34,7 +35,7 @@ func ExampleServer_RegisterTopic() { s, _ := p2p.NewServer() var topic string - var message interface{} + var message proto.Message s.RegisterTopic(topic, message, adapters...) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 84867369abf4..e60162403ada 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -4,7 +4,6 @@ import ( "context" "reflect" "sync" - "time" "github.com/ethereum/go-ethereum/event" "github.com/golang/protobuf/proto" @@ -13,7 +12,6 @@ import ( floodsub "github.com/libp2p/go-floodsub" libp2p "github.com/libp2p/go-libp2p" host "github.com/libp2p/go-libp2p-host" - shardpb "github.com/prysmaticlabs/prysm/proto/sharding/p2p/v1" ) // Sender represents a struct that is able to relay information via p2p. @@ -129,16 +127,13 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad h = adapter(h) } - ctx, _ := context.WithTimeout(s.ctx, 10*time.Second) - h(ctx, pMsg) + h(s.ctx, pMsg) } })() } func (s *Server) emit(feed *event.Feed, msg *floodsub.Message, msgType reflect.Type) { - // TODO: reflect.Value.Interface() can panic so we should capture that - // panic so the server doesn't crash. d, ok := reflect.New(msgType).Interface().(proto.Message) if !ok { log.Error("Received message is not a protobuf message") @@ -202,43 +197,3 @@ func (s *Server) Broadcast(msg interface{}) { log.Errorf("Failed to publish to gossipsub topic: %v", err) } } - -func (s *Server) subscribeToTopic(topic shardpb.Topic, msgType reflect.Type) { - sub, err := s.gsub.Subscribe(topic.String()) - if err != nil { - log.Errorf("Failed to subscribe to topic: %v", err) - return - } - defer sub.Cancel() - feed := s.Feed(msgType) - - for { - msg, err := sub.Next(s.ctx) - - if s.ctx.Err() != nil { - return // Context closed or something. - } - if err != nil { - log.Errorf("Failed to get next message: %v", err) - return - } - - // TODO: reflect.Value.Interface() can panic so we should capture that - // panic so the server doesn't crash. - d, ok := reflect.New(msgType).Interface().(proto.Message) - if !ok { - log.Error("Received message is not a protobuf message") - continue - } - err = proto.Unmarshal(msg.Data, d) - if err != nil { - log.Errorf("Failed to decode data: %v", err) - continue - } - - i := feed.Send(Message{Data: d}) - log.WithFields(logrus.Fields{ - "numSubs": i, - }).Debug("Sent a request to subs") - } -} diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index b54dd7c2773d..6382627fbcb6 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -84,6 +84,7 @@ func TestSubscribeToTopic(t *testing.T) { host: h, feeds: make(map[reflect.Type]*event.Feed), mutex: &sync.Mutex{}, + topicMapping: make(map[reflect.Type]string), } feed := s.Feed(shardpb.CollationBodyRequest{}) @@ -110,6 +111,7 @@ func TestSubscribe(t *testing.T) { host: h, feeds: make(map[reflect.Type]*event.Feed), mutex: &sync.Mutex{}, + topicMapping: make(map[reflect.Type]string), } ch := make(chan Message) @@ -121,8 +123,8 @@ func TestSubscribe(t *testing.T) { func testSubscribe(ctx context.Context, t *testing.T, s Server, gsub *floodsub.PubSub, ch chan Message) { topic := shardpb.Topic_COLLATION_BODY_REQUEST - msgType := reflect.TypeOf(shardpb.CollationBodyRequest{}) - go s.subscribeToTopic(topic, msgType) + + go s.RegisterTopic(topic.String(), shardpb.CollationBodyRequest{}) // Short delay to let goroutine add subscription. time.Sleep(time.Millisecond * 10) @@ -170,18 +172,17 @@ func TestRegisterTopic_WithoutAdapters(t *testing.T) { topic := "test_topic" testMessage := testpb.TestMessage{Foo: "bar"} - s.RegisterTopic(topic, testMessage) + s.RegisterTopic(topic, testpb.TestMessage{}) ch := make(chan Message) sub := s.Subscribe(testMessage, ch) defer sub.Unsubscribe() wait := make(chan struct{}) - go (func() { + go func() { defer close(wait) - msg := <-ch - _ = msg - })() + <-ch + }() if err := simulateIncomingMessage(t, s, topic, []byte{}); err != nil { t.Errorf("Failed to send to topic %s", topic) @@ -219,18 +220,17 @@ func TestRegisterTopic_WithAdapers(t *testing.T) { testAdapter, } - s.RegisterTopic(topic, testMessage, adapters...) + s.RegisterTopic(topic, testpb.TestMessage{}, adapters...) ch := make(chan Message) sub := s.Subscribe(testMessage, ch) defer sub.Unsubscribe() wait := make(chan struct{}) - go (func() { + go func() { defer close(wait) - msg := <-ch - _ = msg - })() + <-ch + } () if err := simulateIncomingMessage(t, s, topic, []byte{}); err != nil { t.Errorf("Failed to send to topic %s", topic) From 7f83b6fb86da86225bae9bdb266ced6d444d4486 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 28 Aug 2018 20:46:03 -0400 Subject: [PATCH 21/24] another go (func --- shared/p2p/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index e60162403ada..4443e4a5e4b1 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -102,7 +102,7 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad adapters[i], adapters[opp] = adapters[opp], adapters[i] } - go (func() { + go func() { defer sub.Cancel() for { msg, err := sub.Next(s.ctx) @@ -129,7 +129,7 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad h(s.ctx, pMsg) } - })() + } () } From 7b3e0ff3a2c029a2b38ffe958c23f5219c4a4b47 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 28 Aug 2018 20:47:56 -0400 Subject: [PATCH 22/24] PR feedback that I missed --- shared/p2p/register_topic_example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index 9d77eba0bdaf..a9ad57dc6394 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -13,7 +13,7 @@ import ( // limiter or blacklisting condition. func reqLogger(next p2p.Handler) p2p.Handler { return func(ctx context.Context, msg p2p.Message) { - fmt.Printf("Received message from %s\n", msg.Peer) + fmt.Printf("Received message from %v\n", msg.Peer) next(ctx, msg) } } From 0500af631686127f7be3d050c709ce8fb401fcfa Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 28 Aug 2018 21:07:38 -0400 Subject: [PATCH 23/24] gofmt --- shared/p2p/register_topic_example_test.go | 2 +- shared/p2p/service.go | 2 +- shared/p2p/service_test.go | 24 +++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/shared/p2p/register_topic_example_test.go b/shared/p2p/register_topic_example_test.go index a9ad57dc6394..df91e28a4c10 100644 --- a/shared/p2p/register_topic_example_test.go +++ b/shared/p2p/register_topic_example_test.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" "github.com/prysmaticlabs/prysm/shared/p2p" ) diff --git a/shared/p2p/service.go b/shared/p2p/service.go index 4443e4a5e4b1..b90624fc3a24 100644 --- a/shared/p2p/service.go +++ b/shared/p2p/service.go @@ -129,7 +129,7 @@ func (s *Server) RegisterTopic(topic string, message interface{}, adapters ...Ad h(s.ctx, pMsg) } - } () + }() } diff --git a/shared/p2p/service_test.go b/shared/p2p/service_test.go index 6382627fbcb6..1f5644e2ff8d 100644 --- a/shared/p2p/service_test.go +++ b/shared/p2p/service_test.go @@ -79,11 +79,11 @@ func TestSubscribeToTopic(t *testing.T) { } s := Server{ - ctx: ctx, - gsub: gsub, - host: h, - feeds: make(map[reflect.Type]*event.Feed), - mutex: &sync.Mutex{}, + ctx: ctx, + gsub: gsub, + host: h, + feeds: make(map[reflect.Type]*event.Feed), + mutex: &sync.Mutex{}, topicMapping: make(map[reflect.Type]string), } @@ -106,11 +106,11 @@ func TestSubscribe(t *testing.T) { } s := Server{ - ctx: ctx, - gsub: gsub, - host: h, - feeds: make(map[reflect.Type]*event.Feed), - mutex: &sync.Mutex{}, + ctx: ctx, + gsub: gsub, + host: h, + feeds: make(map[reflect.Type]*event.Feed), + mutex: &sync.Mutex{}, topicMapping: make(map[reflect.Type]string), } @@ -123,7 +123,7 @@ func TestSubscribe(t *testing.T) { func testSubscribe(ctx context.Context, t *testing.T, s Server, gsub *floodsub.PubSub, ch chan Message) { topic := shardpb.Topic_COLLATION_BODY_REQUEST - + go s.RegisterTopic(topic.String(), shardpb.CollationBodyRequest{}) // Short delay to let goroutine add subscription. @@ -230,7 +230,7 @@ func TestRegisterTopic_WithAdapers(t *testing.T) { go func() { defer close(wait) <-ch - } () + }() if err := simulateIncomingMessage(t, s, topic, []byte{}); err != nil { t.Errorf("Failed to send to topic %s", topic) From 3ecf3bd9782ff8ca72ef0af2f1a542cca6cbd4b3 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 28 Aug 2018 21:09:16 -0400 Subject: [PATCH 24/24] gazelle --- shared/p2p/BUILD.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index 140e54699e20..5999b66f9395 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -14,7 +14,6 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/shared/p2p", visibility = ["//visibility:public"], deps = [ - "//proto/sharding/p2p/v1:go_default_library", "//shared/iputils:go_default_library", "@com_github_ethereum_go_ethereum//event:go_default_library", "@com_github_golang_protobuf//proto:go_default_library",