From 1253fd5dd07c0f590ca504916b66ed8b2c3ab37e Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 30 Nov 2021 17:30:16 +0100 Subject: [PATCH 01/20] Initial approach --- command/chain_watch.go | 62 ++++ command/main.go | 5 + command/server/proto/server.pb.go | 396 +++++++++++++++++++------ command/server/proto/server.proto | 15 + command/server/proto/server_grpc.pb.go | 66 ++++- command/server/service.go | 16 + core/blockchain.go | 21 ++ 7 files changed, 486 insertions(+), 95 deletions(-) create mode 100644 command/chain_watch.go diff --git a/command/chain_watch.go b/command/chain_watch.go new file mode 100644 index 000000000000..f61a28c8777d --- /dev/null +++ b/command/chain_watch.go @@ -0,0 +1,62 @@ +package main + +import ( + "context" + "fmt" + + "github.com/ethereum/go-ethereum/command/flagset" + "github.com/ethereum/go-ethereum/command/server/proto" +) + +// ChainWatchCommand is the command to group the peers commands +type ChainWatchCommand struct { + *Meta2 +} + +// Help implements the cli.Command interface +func (c *ChainWatchCommand) Help() string { + return `` +} + +func (c *ChainWatchCommand) Flags() *flagset.Flagset { + flags := c.NewFlagSet("chain watch") + + return flags +} + +// Synopsis implements the cli.Command interface +func (c *ChainWatchCommand) Synopsis() string { + return "" +} + +// Run implements the cli.Command interface +func (c *ChainWatchCommand) Run(args []string) int { + flags := c.Flags() + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + borClt, err := c.BorConn() + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + sub, err := borClt.ChainWatch(context.Background(), &proto.ChainWatchRequest{}) + if err != nil { + panic(err) + } + + for { + msg, err := sub.Recv() + if err != nil { + // if err == EOF if finished on the other side + panic(err) + } + fmt.Println("message received") + fmt.Println(msg) + } + + return 0 +} diff --git a/command/main.go b/command/main.go index 7b276e703bb8..494e57f8432f 100644 --- a/command/main.go +++ b/command/main.go @@ -69,6 +69,11 @@ func commands() map[string]cli.CommandFactory { UI: ui, }, nil }, + "chain watch": func() (cli.Command, error) { + return &ChainWatchCommand{ + Meta2: meta2, + }, nil + }, "chain sethead": func() (cli.Command, error) { return &ChainSetHeadCommand{ Meta2: meta2, diff --git a/command/server/proto/server.pb.go b/command/server/proto/server.pb.go index ab6c06662b9b..b58f20a7d765 100644 --- a/command/server/proto/server.pb.go +++ b/command/server/proto/server.pb.go @@ -71,7 +71,155 @@ func (x PprofRequest_Type) Number() protoreflect.EnumNumber { // Deprecated: Use PprofRequest_Type.Descriptor instead. func (PprofRequest_Type) EnumDescriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{11, 0} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{14, 0} +} + +type ChainWatchRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ChainWatchRequest) Reset() { + *x = ChainWatchRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChainWatchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChainWatchRequest) ProtoMessage() {} + +func (x *ChainWatchRequest) ProtoReflect() protoreflect.Message { + mi := &file_command_server_proto_server_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChainWatchRequest.ProtoReflect.Descriptor instead. +func (*ChainWatchRequest) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{0} +} + +type ChainWatchResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Oldchain []*BlockStub `protobuf:"bytes,1,rep,name=oldchain,proto3" json:"oldchain,omitempty"` + Newchain []*BlockStub `protobuf:"bytes,2,rep,name=newchain,proto3" json:"newchain,omitempty"` +} + +func (x *ChainWatchResponse) Reset() { + *x = ChainWatchResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChainWatchResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChainWatchResponse) ProtoMessage() {} + +func (x *ChainWatchResponse) ProtoReflect() protoreflect.Message { + mi := &file_command_server_proto_server_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChainWatchResponse.ProtoReflect.Descriptor instead. +func (*ChainWatchResponse) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{1} +} + +func (x *ChainWatchResponse) GetOldchain() []*BlockStub { + if x != nil { + return x.Oldchain + } + return nil +} + +func (x *ChainWatchResponse) GetNewchain() []*BlockStub { + if x != nil { + return x.Newchain + } + return nil +} + +type BlockStub struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + Number uint64 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` +} + +func (x *BlockStub) Reset() { + *x = BlockStub{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockStub) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockStub) ProtoMessage() {} + +func (x *BlockStub) ProtoReflect() protoreflect.Message { + mi := &file_command_server_proto_server_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockStub.ProtoReflect.Descriptor instead. +func (*BlockStub) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{2} +} + +func (x *BlockStub) GetHash() string { + if x != nil { + return x.Hash + } + return "" +} + +func (x *BlockStub) GetNumber() uint64 { + if x != nil { + return x.Number + } + return 0 } type PeersAddRequest struct { @@ -86,7 +234,7 @@ type PeersAddRequest struct { func (x *PeersAddRequest) Reset() { *x = PeersAddRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[0] + mi := &file_command_server_proto_server_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -99,7 +247,7 @@ func (x *PeersAddRequest) String() string { func (*PeersAddRequest) ProtoMessage() {} func (x *PeersAddRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[0] + mi := &file_command_server_proto_server_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -112,7 +260,7 @@ func (x *PeersAddRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersAddRequest.ProtoReflect.Descriptor instead. func (*PeersAddRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{0} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{3} } func (x *PeersAddRequest) GetEnode() string { @@ -138,7 +286,7 @@ type PeersAddResponse struct { func (x *PeersAddResponse) Reset() { *x = PeersAddResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[1] + mi := &file_command_server_proto_server_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -151,7 +299,7 @@ func (x *PeersAddResponse) String() string { func (*PeersAddResponse) ProtoMessage() {} func (x *PeersAddResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[1] + mi := &file_command_server_proto_server_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -164,7 +312,7 @@ func (x *PeersAddResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersAddResponse.ProtoReflect.Descriptor instead. func (*PeersAddResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{1} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{4} } type PeersRemoveRequest struct { @@ -179,7 +327,7 @@ type PeersRemoveRequest struct { func (x *PeersRemoveRequest) Reset() { *x = PeersRemoveRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[2] + mi := &file_command_server_proto_server_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -192,7 +340,7 @@ func (x *PeersRemoveRequest) String() string { func (*PeersRemoveRequest) ProtoMessage() {} func (x *PeersRemoveRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[2] + mi := &file_command_server_proto_server_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -205,7 +353,7 @@ func (x *PeersRemoveRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersRemoveRequest.ProtoReflect.Descriptor instead. func (*PeersRemoveRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{2} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{5} } func (x *PeersRemoveRequest) GetEnode() string { @@ -231,7 +379,7 @@ type PeersRemoveResponse struct { func (x *PeersRemoveResponse) Reset() { *x = PeersRemoveResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[3] + mi := &file_command_server_proto_server_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -244,7 +392,7 @@ func (x *PeersRemoveResponse) String() string { func (*PeersRemoveResponse) ProtoMessage() {} func (x *PeersRemoveResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[3] + mi := &file_command_server_proto_server_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -257,7 +405,7 @@ func (x *PeersRemoveResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersRemoveResponse.ProtoReflect.Descriptor instead. func (*PeersRemoveResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{3} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{6} } type PeersListRequest struct { @@ -269,7 +417,7 @@ type PeersListRequest struct { func (x *PeersListRequest) Reset() { *x = PeersListRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[4] + mi := &file_command_server_proto_server_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -282,7 +430,7 @@ func (x *PeersListRequest) String() string { func (*PeersListRequest) ProtoMessage() {} func (x *PeersListRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[4] + mi := &file_command_server_proto_server_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -295,7 +443,7 @@ func (x *PeersListRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersListRequest.ProtoReflect.Descriptor instead. func (*PeersListRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{4} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{7} } type PeersListResponse struct { @@ -309,7 +457,7 @@ type PeersListResponse struct { func (x *PeersListResponse) Reset() { *x = PeersListResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[5] + mi := &file_command_server_proto_server_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -322,7 +470,7 @@ func (x *PeersListResponse) String() string { func (*PeersListResponse) ProtoMessage() {} func (x *PeersListResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[5] + mi := &file_command_server_proto_server_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -335,7 +483,7 @@ func (x *PeersListResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersListResponse.ProtoReflect.Descriptor instead. func (*PeersListResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{5} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{8} } func (x *PeersListResponse) GetPeers() []*Peer { @@ -356,7 +504,7 @@ type PeersStatusRequest struct { func (x *PeersStatusRequest) Reset() { *x = PeersStatusRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[6] + mi := &file_command_server_proto_server_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -369,7 +517,7 @@ func (x *PeersStatusRequest) String() string { func (*PeersStatusRequest) ProtoMessage() {} func (x *PeersStatusRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[6] + mi := &file_command_server_proto_server_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -382,7 +530,7 @@ func (x *PeersStatusRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersStatusRequest.ProtoReflect.Descriptor instead. func (*PeersStatusRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{6} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{9} } func (x *PeersStatusRequest) GetEnode() string { @@ -403,7 +551,7 @@ type PeersStatusResponse struct { func (x *PeersStatusResponse) Reset() { *x = PeersStatusResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[7] + mi := &file_command_server_proto_server_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -416,7 +564,7 @@ func (x *PeersStatusResponse) String() string { func (*PeersStatusResponse) ProtoMessage() {} func (x *PeersStatusResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[7] + mi := &file_command_server_proto_server_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -429,7 +577,7 @@ func (x *PeersStatusResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersStatusResponse.ProtoReflect.Descriptor instead. func (*PeersStatusResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{7} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{10} } func (x *PeersStatusResponse) GetPeer() *Peer { @@ -456,7 +604,7 @@ type Peer struct { func (x *Peer) Reset() { *x = Peer{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[8] + mi := &file_command_server_proto_server_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -469,7 +617,7 @@ func (x *Peer) String() string { func (*Peer) ProtoMessage() {} func (x *Peer) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[8] + mi := &file_command_server_proto_server_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -482,7 +630,7 @@ func (x *Peer) ProtoReflect() protoreflect.Message { // Deprecated: Use Peer.ProtoReflect.Descriptor instead. func (*Peer) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{8} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{11} } func (x *Peer) GetId() string { @@ -545,7 +693,7 @@ type ChainSetHeadRequest struct { func (x *ChainSetHeadRequest) Reset() { *x = ChainSetHeadRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[9] + mi := &file_command_server_proto_server_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -558,7 +706,7 @@ func (x *ChainSetHeadRequest) String() string { func (*ChainSetHeadRequest) ProtoMessage() {} func (x *ChainSetHeadRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[9] + mi := &file_command_server_proto_server_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -571,7 +719,7 @@ func (x *ChainSetHeadRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ChainSetHeadRequest.ProtoReflect.Descriptor instead. func (*ChainSetHeadRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{9} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{12} } func (x *ChainSetHeadRequest) GetNumber() uint64 { @@ -590,7 +738,7 @@ type ChainSetHeadResponse struct { func (x *ChainSetHeadResponse) Reset() { *x = ChainSetHeadResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[10] + mi := &file_command_server_proto_server_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -603,7 +751,7 @@ func (x *ChainSetHeadResponse) String() string { func (*ChainSetHeadResponse) ProtoMessage() {} func (x *ChainSetHeadResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[10] + mi := &file_command_server_proto_server_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -616,7 +764,7 @@ func (x *ChainSetHeadResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ChainSetHeadResponse.ProtoReflect.Descriptor instead. func (*ChainSetHeadResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{10} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{13} } type PprofRequest struct { @@ -632,7 +780,7 @@ type PprofRequest struct { func (x *PprofRequest) Reset() { *x = PprofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[11] + mi := &file_command_server_proto_server_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -645,7 +793,7 @@ func (x *PprofRequest) String() string { func (*PprofRequest) ProtoMessage() {} func (x *PprofRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[11] + mi := &file_command_server_proto_server_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -658,7 +806,7 @@ func (x *PprofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PprofRequest.ProtoReflect.Descriptor instead. func (*PprofRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{11} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{14} } func (x *PprofRequest) GetType() PprofRequest_Type { @@ -694,7 +842,7 @@ type PprofResponse struct { func (x *PprofResponse) Reset() { *x = PprofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[12] + mi := &file_command_server_proto_server_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -707,7 +855,7 @@ func (x *PprofResponse) String() string { func (*PprofResponse) ProtoMessage() {} func (x *PprofResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[12] + mi := &file_command_server_proto_server_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -720,7 +868,7 @@ func (x *PprofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PprofResponse.ProtoReflect.Descriptor instead. func (*PprofResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{12} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{15} } func (x *PprofResponse) GetPayload() string { @@ -742,7 +890,19 @@ var File_command_server_proto_server_proto protoreflect.FileDescriptor var file_command_server_proto_server_proto_rawDesc = []byte{ 0x0a, 0x21, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x65, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x13, 0x0a, 0x11, 0x43, 0x68, + 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, + 0x70, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x12, 0x2c, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x12, 0x12, + 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, + 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, @@ -799,7 +959,7 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x32, 0x8b, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x05, 0x50, 0x70, 0x72, 0x6f, + 0x32, 0xd0, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x05, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, @@ -823,9 +983,14 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 0x74, 0x48, 0x65, 0x61, 0x64, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, - 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x17, - 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, + 0x0a, 0x0a, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, + 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x30, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -841,46 +1006,53 @@ func file_command_server_proto_server_proto_rawDescGZIP() []byte { } var file_command_server_proto_server_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_command_server_proto_server_proto_msgTypes = make([]protoimpl.MessageInfo, 14) +var file_command_server_proto_server_proto_msgTypes = make([]protoimpl.MessageInfo, 17) var file_command_server_proto_server_proto_goTypes = []interface{}{ (PprofRequest_Type)(0), // 0: proto.PprofRequest.Type - (*PeersAddRequest)(nil), // 1: proto.PeersAddRequest - (*PeersAddResponse)(nil), // 2: proto.PeersAddResponse - (*PeersRemoveRequest)(nil), // 3: proto.PeersRemoveRequest - (*PeersRemoveResponse)(nil), // 4: proto.PeersRemoveResponse - (*PeersListRequest)(nil), // 5: proto.PeersListRequest - (*PeersListResponse)(nil), // 6: proto.PeersListResponse - (*PeersStatusRequest)(nil), // 7: proto.PeersStatusRequest - (*PeersStatusResponse)(nil), // 8: proto.PeersStatusResponse - (*Peer)(nil), // 9: proto.Peer - (*ChainSetHeadRequest)(nil), // 10: proto.ChainSetHeadRequest - (*ChainSetHeadResponse)(nil), // 11: proto.ChainSetHeadResponse - (*PprofRequest)(nil), // 12: proto.PprofRequest - (*PprofResponse)(nil), // 13: proto.PprofResponse - nil, // 14: proto.PprofResponse.HeadersEntry + (*ChainWatchRequest)(nil), // 1: proto.ChainWatchRequest + (*ChainWatchResponse)(nil), // 2: proto.ChainWatchResponse + (*BlockStub)(nil), // 3: proto.BlockStub + (*PeersAddRequest)(nil), // 4: proto.PeersAddRequest + (*PeersAddResponse)(nil), // 5: proto.PeersAddResponse + (*PeersRemoveRequest)(nil), // 6: proto.PeersRemoveRequest + (*PeersRemoveResponse)(nil), // 7: proto.PeersRemoveResponse + (*PeersListRequest)(nil), // 8: proto.PeersListRequest + (*PeersListResponse)(nil), // 9: proto.PeersListResponse + (*PeersStatusRequest)(nil), // 10: proto.PeersStatusRequest + (*PeersStatusResponse)(nil), // 11: proto.PeersStatusResponse + (*Peer)(nil), // 12: proto.Peer + (*ChainSetHeadRequest)(nil), // 13: proto.ChainSetHeadRequest + (*ChainSetHeadResponse)(nil), // 14: proto.ChainSetHeadResponse + (*PprofRequest)(nil), // 15: proto.PprofRequest + (*PprofResponse)(nil), // 16: proto.PprofResponse + nil, // 17: proto.PprofResponse.HeadersEntry } var file_command_server_proto_server_proto_depIdxs = []int32{ - 9, // 0: proto.PeersListResponse.peers:type_name -> proto.Peer - 9, // 1: proto.PeersStatusResponse.peer:type_name -> proto.Peer - 0, // 2: proto.PprofRequest.type:type_name -> proto.PprofRequest.Type - 14, // 3: proto.PprofResponse.headers:type_name -> proto.PprofResponse.HeadersEntry - 12, // 4: proto.Bor.Pprof:input_type -> proto.PprofRequest - 1, // 5: proto.Bor.PeersAdd:input_type -> proto.PeersAddRequest - 3, // 6: proto.Bor.PeersRemove:input_type -> proto.PeersRemoveRequest - 5, // 7: proto.Bor.PeersList:input_type -> proto.PeersListRequest - 7, // 8: proto.Bor.PeersStatus:input_type -> proto.PeersStatusRequest - 10, // 9: proto.Bor.ChainSetHead:input_type -> proto.ChainSetHeadRequest - 13, // 10: proto.Bor.Pprof:output_type -> proto.PprofResponse - 2, // 11: proto.Bor.PeersAdd:output_type -> proto.PeersAddResponse - 4, // 12: proto.Bor.PeersRemove:output_type -> proto.PeersRemoveResponse - 6, // 13: proto.Bor.PeersList:output_type -> proto.PeersListResponse - 8, // 14: proto.Bor.PeersStatus:output_type -> proto.PeersStatusResponse - 11, // 15: proto.Bor.ChainSetHead:output_type -> proto.ChainSetHeadResponse - 10, // [10:16] is the sub-list for method output_type - 4, // [4:10] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 3, // 0: proto.ChainWatchResponse.oldchain:type_name -> proto.BlockStub + 3, // 1: proto.ChainWatchResponse.newchain:type_name -> proto.BlockStub + 12, // 2: proto.PeersListResponse.peers:type_name -> proto.Peer + 12, // 3: proto.PeersStatusResponse.peer:type_name -> proto.Peer + 0, // 4: proto.PprofRequest.type:type_name -> proto.PprofRequest.Type + 17, // 5: proto.PprofResponse.headers:type_name -> proto.PprofResponse.HeadersEntry + 15, // 6: proto.Bor.Pprof:input_type -> proto.PprofRequest + 4, // 7: proto.Bor.PeersAdd:input_type -> proto.PeersAddRequest + 6, // 8: proto.Bor.PeersRemove:input_type -> proto.PeersRemoveRequest + 8, // 9: proto.Bor.PeersList:input_type -> proto.PeersListRequest + 10, // 10: proto.Bor.PeersStatus:input_type -> proto.PeersStatusRequest + 13, // 11: proto.Bor.ChainSetHead:input_type -> proto.ChainSetHeadRequest + 1, // 12: proto.Bor.ChainWatch:input_type -> proto.ChainWatchRequest + 16, // 13: proto.Bor.Pprof:output_type -> proto.PprofResponse + 5, // 14: proto.Bor.PeersAdd:output_type -> proto.PeersAddResponse + 7, // 15: proto.Bor.PeersRemove:output_type -> proto.PeersRemoveResponse + 9, // 16: proto.Bor.PeersList:output_type -> proto.PeersListResponse + 11, // 17: proto.Bor.PeersStatus:output_type -> proto.PeersStatusResponse + 14, // 18: proto.Bor.ChainSetHead:output_type -> proto.ChainSetHeadResponse + 2, // 19: proto.Bor.ChainWatch:output_type -> proto.ChainWatchResponse + 13, // [13:20] is the sub-list for method output_type + 6, // [6:13] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_command_server_proto_server_proto_init() } @@ -890,7 +1062,7 @@ func file_command_server_proto_server_proto_init() { } if !protoimpl.UnsafeEnabled { file_command_server_proto_server_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersAddRequest); i { + switch v := v.(*ChainWatchRequest); i { case 0: return &v.state case 1: @@ -902,7 +1074,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersAddResponse); i { + switch v := v.(*ChainWatchResponse); i { case 0: return &v.state case 1: @@ -914,7 +1086,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersRemoveRequest); i { + switch v := v.(*BlockStub); i { case 0: return &v.state case 1: @@ -926,7 +1098,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersRemoveResponse); i { + switch v := v.(*PeersAddRequest); i { case 0: return &v.state case 1: @@ -938,7 +1110,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersListRequest); i { + switch v := v.(*PeersAddResponse); i { case 0: return &v.state case 1: @@ -950,7 +1122,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersListResponse); i { + switch v := v.(*PeersRemoveRequest); i { case 0: return &v.state case 1: @@ -962,7 +1134,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersStatusRequest); i { + switch v := v.(*PeersRemoveResponse); i { case 0: return &v.state case 1: @@ -974,7 +1146,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersStatusResponse); i { + switch v := v.(*PeersListRequest); i { case 0: return &v.state case 1: @@ -986,7 +1158,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Peer); i { + switch v := v.(*PeersListResponse); i { case 0: return &v.state case 1: @@ -998,7 +1170,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChainSetHeadRequest); i { + switch v := v.(*PeersStatusRequest); i { case 0: return &v.state case 1: @@ -1010,7 +1182,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChainSetHeadResponse); i { + switch v := v.(*PeersStatusResponse); i { case 0: return &v.state case 1: @@ -1022,7 +1194,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PprofRequest); i { + switch v := v.(*Peer); i { case 0: return &v.state case 1: @@ -1034,6 +1206,42 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ChainSetHeadRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_command_server_proto_server_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ChainSetHeadResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_command_server_proto_server_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PprofRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_command_server_proto_server_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PprofResponse); i { case 0: return &v.state @@ -1052,7 +1260,7 @@ func file_command_server_proto_server_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_command_server_proto_server_proto_rawDesc, NumEnums: 1, - NumMessages: 14, + NumMessages: 17, NumExtensions: 0, NumServices: 1, }, diff --git a/command/server/proto/server.proto b/command/server/proto/server.proto index 535aa3f36952..51276c448304 100644 --- a/command/server/proto/server.proto +++ b/command/server/proto/server.proto @@ -16,8 +16,23 @@ service Bor { rpc PeersStatus(PeersStatusRequest) returns (PeersStatusResponse); rpc ChainSetHead(ChainSetHeadRequest) returns (ChainSetHeadResponse); + + rpc ChainWatch(ChainWatchRequest) returns (stream ChainWatchResponse); +} + +message ChainWatchRequest { + } +message ChainWatchResponse { + repeated BlockStub oldchain = 1; + repeated BlockStub newchain = 2; +} + +message BlockStub { + string hash = 1; + uint64 number = 2; +} message PeersAddRequest { string enode = 1; diff --git a/command/server/proto/server_grpc.pb.go b/command/server/proto/server_grpc.pb.go index 369419b66fc2..6820e2687656 100644 --- a/command/server/proto/server_grpc.pb.go +++ b/command/server/proto/server_grpc.pb.go @@ -24,6 +24,7 @@ type BorClient interface { PeersList(ctx context.Context, in *PeersListRequest, opts ...grpc.CallOption) (*PeersListResponse, error) PeersStatus(ctx context.Context, in *PeersStatusRequest, opts ...grpc.CallOption) (*PeersStatusResponse, error) ChainSetHead(ctx context.Context, in *ChainSetHeadRequest, opts ...grpc.CallOption) (*ChainSetHeadResponse, error) + ChainWatch(ctx context.Context, in *ChainWatchRequest, opts ...grpc.CallOption) (Bor_ChainWatchClient, error) } type borClient struct { @@ -88,6 +89,38 @@ func (c *borClient) ChainSetHead(ctx context.Context, in *ChainSetHeadRequest, o return out, nil } +func (c *borClient) ChainWatch(ctx context.Context, in *ChainWatchRequest, opts ...grpc.CallOption) (Bor_ChainWatchClient, error) { + stream, err := c.cc.NewStream(ctx, &Bor_ServiceDesc.Streams[0], "/proto.Bor/ChainWatch", opts...) + if err != nil { + return nil, err + } + x := &borChainWatchClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Bor_ChainWatchClient interface { + Recv() (*ChainWatchResponse, error) + grpc.ClientStream +} + +type borChainWatchClient struct { + grpc.ClientStream +} + +func (x *borChainWatchClient) Recv() (*ChainWatchResponse, error) { + m := new(ChainWatchResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + // BorServer is the server API for Bor service. // All implementations must embed UnimplementedBorServer // for forward compatibility @@ -98,6 +131,7 @@ type BorServer interface { PeersList(context.Context, *PeersListRequest) (*PeersListResponse, error) PeersStatus(context.Context, *PeersStatusRequest) (*PeersStatusResponse, error) ChainSetHead(context.Context, *ChainSetHeadRequest) (*ChainSetHeadResponse, error) + ChainWatch(*ChainWatchRequest, Bor_ChainWatchServer) error mustEmbedUnimplementedBorServer() } @@ -123,6 +157,9 @@ func (UnimplementedBorServer) PeersStatus(context.Context, *PeersStatusRequest) func (UnimplementedBorServer) ChainSetHead(context.Context, *ChainSetHeadRequest) (*ChainSetHeadResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ChainSetHead not implemented") } +func (UnimplementedBorServer) ChainWatch(*ChainWatchRequest, Bor_ChainWatchServer) error { + return status.Errorf(codes.Unimplemented, "method ChainWatch not implemented") +} func (UnimplementedBorServer) mustEmbedUnimplementedBorServer() {} // UnsafeBorServer may be embedded to opt out of forward compatibility for this service. @@ -244,6 +281,27 @@ func _Bor_ChainSetHead_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Bor_ChainWatch_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ChainWatchRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(BorServer).ChainWatch(m, &borChainWatchServer{stream}) +} + +type Bor_ChainWatchServer interface { + Send(*ChainWatchResponse) error + grpc.ServerStream +} + +type borChainWatchServer struct { + grpc.ServerStream +} + +func (x *borChainWatchServer) Send(m *ChainWatchResponse) error { + return x.ServerStream.SendMsg(m) +} + // Bor_ServiceDesc is the grpc.ServiceDesc for Bor service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -276,6 +334,12 @@ var Bor_ServiceDesc = grpc.ServiceDesc{ Handler: _Bor_ChainSetHead_Handler, }, }, - Streams: []grpc.StreamDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "ChainWatch", + Handler: _Bor_ChainWatch_Handler, + ServerStreams: true, + }, + }, Metadata: "command/server/proto/server.proto", } diff --git a/command/server/service.go b/command/server/service.go index 0c6c23b6bf51..f2c8a423b1fc 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/command/server/pprof" "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" ) @@ -107,3 +108,18 @@ func (s *Server) ChainSetHead(ctx context.Context, req *proto.ChainSetHeadReques s.backend.APIBackend.SetHead(req.Number) return &proto.ChainSetHeadResponse{}, nil } + +func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error { + // 1. start the feed to the blcokchain events + // 2. for each event send a proto.ChainWatchResponse + + chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize) + s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh) + + for { + msg := <-chainHeadCh + reply.Send(&proto.ChainWatchResponse{}) + } + + return nil +} diff --git a/core/blockchain.go b/core/blockchain.go index 87cdaded4165..4fd5cd0569ef 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1633,10 +1633,23 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. for _, data := range bc.stateSyncData { bc.stateSyncFeed.Send(StateSyncEvent{Data: data}) } + + // ... + // bc.chain2HeadFeed.Send(ChainHeadEvent2{ + // Type: "head", + // NewChain: []{block} + // }) + // BOR } } else { bc.chainSideFeed.Send(ChainSideEvent{Block: block}) + + // ... + // bc.chain2HeadFeed.Send(ChainHeadEvent2{ + // Type: "fork", + // NewChain: []{block} + // }) } return status, nil } @@ -2257,6 +2270,14 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { } // Ensure the user sees large reorgs if len(oldChain) > 0 && len(newChain) > 0 { + + // ... + // bc.chain2HeadFeed.Send(ChainHeadEvent2{ + // Type: "reorg", + // NewChain: newChain, + // OldChain: oldChain, + // }) + logFn := log.Info msg := "Chain reorg detected" if len(oldChain) > 63 { From 53a35e0d80c5676b8a9b6659573a3c5f219c5bb9 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 1 Dec 2021 16:34:55 +0530 Subject: [PATCH 02/20] Connected chain2head protobuf --- command/server/proto/server.pb.go | 207 ++++++++++++++++-------------- command/server/proto/server.proto | 1 + command/server/server.go | 2 + command/server/service.go | 32 ++++- core/blockchain.go | 53 ++++---- core/events.go | 6 + eth/api_backend.go | 4 + go.sum | 1 - 8 files changed, 175 insertions(+), 131 deletions(-) diff --git a/command/server/proto/server.pb.go b/command/server/proto/server.pb.go index b58f20a7d765..d7c1d671636f 100644 --- a/command/server/proto/server.pb.go +++ b/command/server/proto/server.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.0 +// protoc v3.17.3 // source: command/server/proto/server.proto package proto @@ -119,6 +119,7 @@ type ChainWatchResponse struct { Oldchain []*BlockStub `protobuf:"bytes,1,rep,name=oldchain,proto3" json:"oldchain,omitempty"` Newchain []*BlockStub `protobuf:"bytes,2,rep,name=newchain,proto3" json:"newchain,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` } func (x *ChainWatchResponse) Reset() { @@ -167,6 +168,13 @@ func (x *ChainWatchResponse) GetNewchain() []*BlockStub { return nil } +func (x *ChainWatchResponse) GetType() string { + if x != nil { + return x.Type + } + return "" +} + type BlockStub struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -892,105 +900,106 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x13, 0x0a, 0x11, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, - 0x70, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x12, 0x2c, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, - 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x12, 0x12, - 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, - 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, - 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, - 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x22, 0x12, 0x0a, - 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x44, 0x0a, 0x12, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, - 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, - 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x22, 0x15, 0x0a, 0x13, 0x50, 0x65, 0x65, 0x72, 0x73, - 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x12, - 0x0a, 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x22, 0x36, 0x0a, 0x11, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, - 0x65, 0x65, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0x2a, 0x0a, 0x12, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x22, 0x36, 0x0a, 0x13, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, - 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, 0x65, 0x65, 0x72, 0x22, 0x98, - 0x01, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, - 0x03, 0x65, 0x6e, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x72, 0x12, - 0x12, 0x0a, 0x04, 0x63, 0x61, 0x70, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x63, - 0x61, 0x70, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, - 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, - 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x22, 0x2d, 0x0a, 0x13, 0x43, 0x68, 0x61, - 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x16, 0x0a, 0x14, 0x43, 0x68, 0x61, 0x69, - 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x98, 0x01, 0x0a, 0x0c, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x2c, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, - 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x63, - 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x73, 0x65, 0x63, 0x6f, - 0x6e, 0x64, 0x73, 0x22, 0x26, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x4c, - 0x4f, 0x4f, 0x4b, 0x55, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x43, 0x50, 0x55, 0x10, 0x01, - 0x12, 0x09, 0x0a, 0x05, 0x54, 0x52, 0x41, 0x43, 0x45, 0x10, 0x02, 0x22, 0xa2, 0x01, 0x0a, 0x0d, - 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, - 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3b, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x48, - 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x68, 0x65, 0x61, - 0x64, 0x65, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x32, 0xd0, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x05, 0x50, 0x70, 0x72, 0x6f, - 0x66, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, - 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, - 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, - 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x50, 0x65, 0x65, - 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, - 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x3e, 0x0a, 0x09, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x17, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x44, 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x19, + 0x84, 0x01, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x63, + 0x68, 0x61, 0x69, 0x6e, 0x12, 0x2c, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, + 0x74, 0x75, 0x62, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, + 0x41, 0x0a, 0x0f, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, + 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, + 0x65, 0x64, 0x22, 0x12, 0x0a, 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x44, 0x0a, 0x12, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, + 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x22, 0x15, 0x0a, 0x13, + 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x12, 0x0a, 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x36, 0x0a, 0x11, 0x50, 0x65, 0x65, 0x72, 0x73, + 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, + 0x2a, 0x0a, 0x12, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x22, 0x36, 0x0a, 0x13, 0x50, + 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, + 0x65, 0x65, 0x72, 0x22, 0x98, 0x01, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, + 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x65, 0x6e, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x61, 0x70, 0x73, 0x18, 0x04, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x04, 0x63, 0x61, 0x70, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x22, 0x2d, + 0x0a, 0x13, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x16, 0x0a, + 0x14, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x98, 0x01, 0x0a, 0x0c, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x22, 0x26, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x4f, 0x4f, 0x4b, 0x55, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, + 0x43, 0x50, 0x55, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x54, 0x52, 0x41, 0x43, 0x45, 0x10, 0x02, + 0x22, 0xa2, 0x01, 0x0a, 0x0d, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3b, 0x0a, 0x07, + 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x48, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xd0, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, + 0x05, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, + 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x12, 0x16, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, + 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, + 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x19, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, + 0x74, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, + 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0c, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, - 0x74, 0x48, 0x65, 0x61, 0x64, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, - 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, - 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, - 0x0a, 0x0a, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, - 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x30, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0c, 0x43, 0x68, + 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, + 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x0a, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, + 0x68, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, + 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, + 0x6d, 0x61, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/command/server/proto/server.proto b/command/server/proto/server.proto index 51276c448304..f5b3773bb2df 100644 --- a/command/server/proto/server.proto +++ b/command/server/proto/server.proto @@ -27,6 +27,7 @@ message ChainWatchRequest { message ChainWatchResponse { repeated BlockStub oldchain = 1; repeated BlockStub newchain = 2; + string type = 3; } message BlockStub { diff --git a/command/server/server.go b/command/server/server.go index bab4673214f6..8eb420d41038 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/ethstats" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/graphql" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" @@ -38,6 +39,7 @@ type Server struct { backend *eth.Ethereum grpcServer *grpc.Server tracer *sdktrace.TracerProvider + headSub event.Subscription } func NewServer(config *Config) (*Server, error) { diff --git a/command/server/service.go b/command/server/service.go index f2c8a423b1fc..526d4b66bff1 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/command/server/pprof" "github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" ) @@ -109,17 +110,36 @@ func (s *Server) ChainSetHead(ctx context.Context, req *proto.ChainSetHeadReques return &proto.ChainSetHeadResponse{}, nil } +func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub { + + var blockStubs []*proto.BlockStub + + for _, block := range blocks { + blockStub := &proto.BlockStub{ + Hash: block.Hash().String(), + Number: block.NumberU64(), + } + blockStubs = append(blockStubs, blockStub) + } + + return blockStubs +} + func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error { // 1. start the feed to the blcokchain events // 2. for each event send a proto.ChainWatchResponse - chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize) - s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh) + chain2HeadChanSize := 10 + + chain2HeadCh := make(chan core.Chain2HeadEvent, chain2HeadChanSize) + s.headSub = s.backend.APIBackend.SubscribeChain2HeadEvent(chain2HeadCh) for { - msg := <-chainHeadCh - reply.Send(&proto.ChainWatchResponse{}) + msg := <-chain2HeadCh + fmt.Print(msg) + reply.Send(&proto.ChainWatchResponse{Type: msg.Type, + Newchain: ConvertBlockToBlockStub(msg.NewChain), + Oldchain: ConvertBlockToBlockStub(msg.OldChain), + }) } - - return nil } diff --git a/core/blockchain.go b/core/blockchain.go index 2977008145ef..7e7b7c11432b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -175,15 +175,16 @@ type BlockChain struct { // * nil: disable tx reindexer/deleter, but still index new blocks txLookupLimit uint64 - hc *HeaderChain - rmLogsFeed event.Feed - chainFeed event.Feed - chainSideFeed event.Feed - chainHeadFeed event.Feed - logsFeed event.Feed - blockProcFeed event.Feed - scope event.SubscriptionScope - genesisBlock *types.Block + hc *HeaderChain + rmLogsFeed event.Feed + chainFeed event.Feed + chainSideFeed event.Feed + chainHeadFeed event.Feed + chain2HeadFeed event.Feed + logsFeed event.Feed + blockProcFeed event.Feed + scope event.SubscriptionScope + genesisBlock *types.Block // This mutex synchronizes chain write operations. // Readers don't need to take it, they can just read the database. @@ -1641,22 +1642,20 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. bc.stateSyncFeed.Send(StateSyncEvent{Data: data}) } - // ... - // bc.chain2HeadFeed.Send(ChainHeadEvent2{ - // Type: "head", - // NewChain: []{block} - // }) + bc.chain2HeadFeed.Send(Chain2HeadEvent{ + Type: "head", + NewChain: []*types.Block{block}, + }) // BOR } } else { bc.chainSideFeed.Send(ChainSideEvent{Block: block}) - // ... - // bc.chain2HeadFeed.Send(ChainHeadEvent2{ - // Type: "fork", - // NewChain: []{block} - // }) + bc.chain2HeadFeed.Send(Chain2HeadEvent{ + Type: "fork", + NewChain: []*types.Block{block}, + }) } return status, nil } @@ -2276,12 +2275,11 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { // Ensure the user sees large reorgs if len(oldChain) > 0 && len(newChain) > 0 { - // ... - // bc.chain2HeadFeed.Send(ChainHeadEvent2{ - // Type: "reorg", - // NewChain: newChain, - // OldChain: oldChain, - // }) + bc.chain2HeadFeed.Send(Chain2HeadEvent{ + Type: "reorg", + NewChain: newChain, + OldChain: oldChain, + }) logFn := log.Info msg := "Chain reorg detected" @@ -2591,6 +2589,11 @@ func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Su return bc.scope.Track(bc.chainHeadFeed.Subscribe(ch)) } +// SubscribeChain2HeadEvent registers a subscription of ChainHeadEvent. () +func (bc *BlockChain) SubscribeChain2HeadEvent(ch chan<- Chain2HeadEvent) event.Subscription { + return bc.scope.Track(bc.chain2HeadFeed.Subscribe(ch)) +} + // SubscribeChainSideEvent registers a subscription of ChainSideEvent. func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Subscription { return bc.scope.Track(bc.chainSideFeed.Subscribe(ch)) diff --git a/core/events.go b/core/events.go index ac935a137f5f..648546ea36e9 100644 --- a/core/events.go +++ b/core/events.go @@ -41,3 +41,9 @@ type ChainSideEvent struct { } type ChainHeadEvent struct{ Block *types.Block } + +type Chain2HeadEvent struct { + NewChain []*types.Block + OldChain []*types.Block + Type string +} diff --git a/eth/api_backend.go b/eth/api_backend.go index 01e68f6781dd..7e781e773a1a 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -227,6 +227,10 @@ func (b *EthAPIBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) e return b.eth.BlockChain().SubscribeChainHeadEvent(ch) } +func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { + return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) +} + func (b *EthAPIBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { return b.eth.BlockChain().SubscribeChainSideEvent(ch) } diff --git a/go.sum b/go.sum index 96d83f3fcc92..cec3ce626f67 100644 --- a/go.sum +++ b/go.sum @@ -33,7 +33,6 @@ github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSW github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc= github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= From e6235a8e9beb7104ead6341e207d07c643d38dd0 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 30 Nov 2021 17:30:16 +0100 Subject: [PATCH 03/20] Initial approach --- command/chain_watch.go | 62 ++++ command/main.go | 5 + command/server/proto/server.pb.go | 396 +++++++++++++++++++------ command/server/proto/server.proto | 15 + command/server/proto/server_grpc.pb.go | 66 ++++- command/server/service.go | 16 + core/blockchain.go | 21 ++ 7 files changed, 486 insertions(+), 95 deletions(-) create mode 100644 command/chain_watch.go diff --git a/command/chain_watch.go b/command/chain_watch.go new file mode 100644 index 000000000000..f61a28c8777d --- /dev/null +++ b/command/chain_watch.go @@ -0,0 +1,62 @@ +package main + +import ( + "context" + "fmt" + + "github.com/ethereum/go-ethereum/command/flagset" + "github.com/ethereum/go-ethereum/command/server/proto" +) + +// ChainWatchCommand is the command to group the peers commands +type ChainWatchCommand struct { + *Meta2 +} + +// Help implements the cli.Command interface +func (c *ChainWatchCommand) Help() string { + return `` +} + +func (c *ChainWatchCommand) Flags() *flagset.Flagset { + flags := c.NewFlagSet("chain watch") + + return flags +} + +// Synopsis implements the cli.Command interface +func (c *ChainWatchCommand) Synopsis() string { + return "" +} + +// Run implements the cli.Command interface +func (c *ChainWatchCommand) Run(args []string) int { + flags := c.Flags() + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + borClt, err := c.BorConn() + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + sub, err := borClt.ChainWatch(context.Background(), &proto.ChainWatchRequest{}) + if err != nil { + panic(err) + } + + for { + msg, err := sub.Recv() + if err != nil { + // if err == EOF if finished on the other side + panic(err) + } + fmt.Println("message received") + fmt.Println(msg) + } + + return 0 +} diff --git a/command/main.go b/command/main.go index 7b276e703bb8..494e57f8432f 100644 --- a/command/main.go +++ b/command/main.go @@ -69,6 +69,11 @@ func commands() map[string]cli.CommandFactory { UI: ui, }, nil }, + "chain watch": func() (cli.Command, error) { + return &ChainWatchCommand{ + Meta2: meta2, + }, nil + }, "chain sethead": func() (cli.Command, error) { return &ChainSetHeadCommand{ Meta2: meta2, diff --git a/command/server/proto/server.pb.go b/command/server/proto/server.pb.go index ab6c06662b9b..b58f20a7d765 100644 --- a/command/server/proto/server.pb.go +++ b/command/server/proto/server.pb.go @@ -71,7 +71,155 @@ func (x PprofRequest_Type) Number() protoreflect.EnumNumber { // Deprecated: Use PprofRequest_Type.Descriptor instead. func (PprofRequest_Type) EnumDescriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{11, 0} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{14, 0} +} + +type ChainWatchRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ChainWatchRequest) Reset() { + *x = ChainWatchRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChainWatchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChainWatchRequest) ProtoMessage() {} + +func (x *ChainWatchRequest) ProtoReflect() protoreflect.Message { + mi := &file_command_server_proto_server_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChainWatchRequest.ProtoReflect.Descriptor instead. +func (*ChainWatchRequest) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{0} +} + +type ChainWatchResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Oldchain []*BlockStub `protobuf:"bytes,1,rep,name=oldchain,proto3" json:"oldchain,omitempty"` + Newchain []*BlockStub `protobuf:"bytes,2,rep,name=newchain,proto3" json:"newchain,omitempty"` +} + +func (x *ChainWatchResponse) Reset() { + *x = ChainWatchResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChainWatchResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChainWatchResponse) ProtoMessage() {} + +func (x *ChainWatchResponse) ProtoReflect() protoreflect.Message { + mi := &file_command_server_proto_server_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChainWatchResponse.ProtoReflect.Descriptor instead. +func (*ChainWatchResponse) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{1} +} + +func (x *ChainWatchResponse) GetOldchain() []*BlockStub { + if x != nil { + return x.Oldchain + } + return nil +} + +func (x *ChainWatchResponse) GetNewchain() []*BlockStub { + if x != nil { + return x.Newchain + } + return nil +} + +type BlockStub struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + Number uint64 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` +} + +func (x *BlockStub) Reset() { + *x = BlockStub{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockStub) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockStub) ProtoMessage() {} + +func (x *BlockStub) ProtoReflect() protoreflect.Message { + mi := &file_command_server_proto_server_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockStub.ProtoReflect.Descriptor instead. +func (*BlockStub) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{2} +} + +func (x *BlockStub) GetHash() string { + if x != nil { + return x.Hash + } + return "" +} + +func (x *BlockStub) GetNumber() uint64 { + if x != nil { + return x.Number + } + return 0 } type PeersAddRequest struct { @@ -86,7 +234,7 @@ type PeersAddRequest struct { func (x *PeersAddRequest) Reset() { *x = PeersAddRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[0] + mi := &file_command_server_proto_server_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -99,7 +247,7 @@ func (x *PeersAddRequest) String() string { func (*PeersAddRequest) ProtoMessage() {} func (x *PeersAddRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[0] + mi := &file_command_server_proto_server_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -112,7 +260,7 @@ func (x *PeersAddRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersAddRequest.ProtoReflect.Descriptor instead. func (*PeersAddRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{0} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{3} } func (x *PeersAddRequest) GetEnode() string { @@ -138,7 +286,7 @@ type PeersAddResponse struct { func (x *PeersAddResponse) Reset() { *x = PeersAddResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[1] + mi := &file_command_server_proto_server_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -151,7 +299,7 @@ func (x *PeersAddResponse) String() string { func (*PeersAddResponse) ProtoMessage() {} func (x *PeersAddResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[1] + mi := &file_command_server_proto_server_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -164,7 +312,7 @@ func (x *PeersAddResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersAddResponse.ProtoReflect.Descriptor instead. func (*PeersAddResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{1} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{4} } type PeersRemoveRequest struct { @@ -179,7 +327,7 @@ type PeersRemoveRequest struct { func (x *PeersRemoveRequest) Reset() { *x = PeersRemoveRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[2] + mi := &file_command_server_proto_server_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -192,7 +340,7 @@ func (x *PeersRemoveRequest) String() string { func (*PeersRemoveRequest) ProtoMessage() {} func (x *PeersRemoveRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[2] + mi := &file_command_server_proto_server_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -205,7 +353,7 @@ func (x *PeersRemoveRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersRemoveRequest.ProtoReflect.Descriptor instead. func (*PeersRemoveRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{2} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{5} } func (x *PeersRemoveRequest) GetEnode() string { @@ -231,7 +379,7 @@ type PeersRemoveResponse struct { func (x *PeersRemoveResponse) Reset() { *x = PeersRemoveResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[3] + mi := &file_command_server_proto_server_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -244,7 +392,7 @@ func (x *PeersRemoveResponse) String() string { func (*PeersRemoveResponse) ProtoMessage() {} func (x *PeersRemoveResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[3] + mi := &file_command_server_proto_server_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -257,7 +405,7 @@ func (x *PeersRemoveResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersRemoveResponse.ProtoReflect.Descriptor instead. func (*PeersRemoveResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{3} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{6} } type PeersListRequest struct { @@ -269,7 +417,7 @@ type PeersListRequest struct { func (x *PeersListRequest) Reset() { *x = PeersListRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[4] + mi := &file_command_server_proto_server_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -282,7 +430,7 @@ func (x *PeersListRequest) String() string { func (*PeersListRequest) ProtoMessage() {} func (x *PeersListRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[4] + mi := &file_command_server_proto_server_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -295,7 +443,7 @@ func (x *PeersListRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersListRequest.ProtoReflect.Descriptor instead. func (*PeersListRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{4} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{7} } type PeersListResponse struct { @@ -309,7 +457,7 @@ type PeersListResponse struct { func (x *PeersListResponse) Reset() { *x = PeersListResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[5] + mi := &file_command_server_proto_server_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -322,7 +470,7 @@ func (x *PeersListResponse) String() string { func (*PeersListResponse) ProtoMessage() {} func (x *PeersListResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[5] + mi := &file_command_server_proto_server_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -335,7 +483,7 @@ func (x *PeersListResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersListResponse.ProtoReflect.Descriptor instead. func (*PeersListResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{5} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{8} } func (x *PeersListResponse) GetPeers() []*Peer { @@ -356,7 +504,7 @@ type PeersStatusRequest struct { func (x *PeersStatusRequest) Reset() { *x = PeersStatusRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[6] + mi := &file_command_server_proto_server_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -369,7 +517,7 @@ func (x *PeersStatusRequest) String() string { func (*PeersStatusRequest) ProtoMessage() {} func (x *PeersStatusRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[6] + mi := &file_command_server_proto_server_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -382,7 +530,7 @@ func (x *PeersStatusRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersStatusRequest.ProtoReflect.Descriptor instead. func (*PeersStatusRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{6} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{9} } func (x *PeersStatusRequest) GetEnode() string { @@ -403,7 +551,7 @@ type PeersStatusResponse struct { func (x *PeersStatusResponse) Reset() { *x = PeersStatusResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[7] + mi := &file_command_server_proto_server_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -416,7 +564,7 @@ func (x *PeersStatusResponse) String() string { func (*PeersStatusResponse) ProtoMessage() {} func (x *PeersStatusResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[7] + mi := &file_command_server_proto_server_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -429,7 +577,7 @@ func (x *PeersStatusResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PeersStatusResponse.ProtoReflect.Descriptor instead. func (*PeersStatusResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{7} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{10} } func (x *PeersStatusResponse) GetPeer() *Peer { @@ -456,7 +604,7 @@ type Peer struct { func (x *Peer) Reset() { *x = Peer{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[8] + mi := &file_command_server_proto_server_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -469,7 +617,7 @@ func (x *Peer) String() string { func (*Peer) ProtoMessage() {} func (x *Peer) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[8] + mi := &file_command_server_proto_server_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -482,7 +630,7 @@ func (x *Peer) ProtoReflect() protoreflect.Message { // Deprecated: Use Peer.ProtoReflect.Descriptor instead. func (*Peer) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{8} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{11} } func (x *Peer) GetId() string { @@ -545,7 +693,7 @@ type ChainSetHeadRequest struct { func (x *ChainSetHeadRequest) Reset() { *x = ChainSetHeadRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[9] + mi := &file_command_server_proto_server_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -558,7 +706,7 @@ func (x *ChainSetHeadRequest) String() string { func (*ChainSetHeadRequest) ProtoMessage() {} func (x *ChainSetHeadRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[9] + mi := &file_command_server_proto_server_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -571,7 +719,7 @@ func (x *ChainSetHeadRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ChainSetHeadRequest.ProtoReflect.Descriptor instead. func (*ChainSetHeadRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{9} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{12} } func (x *ChainSetHeadRequest) GetNumber() uint64 { @@ -590,7 +738,7 @@ type ChainSetHeadResponse struct { func (x *ChainSetHeadResponse) Reset() { *x = ChainSetHeadResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[10] + mi := &file_command_server_proto_server_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -603,7 +751,7 @@ func (x *ChainSetHeadResponse) String() string { func (*ChainSetHeadResponse) ProtoMessage() {} func (x *ChainSetHeadResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[10] + mi := &file_command_server_proto_server_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -616,7 +764,7 @@ func (x *ChainSetHeadResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ChainSetHeadResponse.ProtoReflect.Descriptor instead. func (*ChainSetHeadResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{10} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{13} } type PprofRequest struct { @@ -632,7 +780,7 @@ type PprofRequest struct { func (x *PprofRequest) Reset() { *x = PprofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[11] + mi := &file_command_server_proto_server_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -645,7 +793,7 @@ func (x *PprofRequest) String() string { func (*PprofRequest) ProtoMessage() {} func (x *PprofRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[11] + mi := &file_command_server_proto_server_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -658,7 +806,7 @@ func (x *PprofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PprofRequest.ProtoReflect.Descriptor instead. func (*PprofRequest) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{11} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{14} } func (x *PprofRequest) GetType() PprofRequest_Type { @@ -694,7 +842,7 @@ type PprofResponse struct { func (x *PprofResponse) Reset() { *x = PprofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[12] + mi := &file_command_server_proto_server_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -707,7 +855,7 @@ func (x *PprofResponse) String() string { func (*PprofResponse) ProtoMessage() {} func (x *PprofResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[12] + mi := &file_command_server_proto_server_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -720,7 +868,7 @@ func (x *PprofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use PprofResponse.ProtoReflect.Descriptor instead. func (*PprofResponse) Descriptor() ([]byte, []int) { - return file_command_server_proto_server_proto_rawDescGZIP(), []int{12} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{15} } func (x *PprofResponse) GetPayload() string { @@ -742,7 +890,19 @@ var File_command_server_proto_server_proto protoreflect.FileDescriptor var file_command_server_proto_server_proto_rawDesc = []byte{ 0x0a, 0x21, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x65, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x13, 0x0a, 0x11, 0x43, 0x68, + 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, + 0x70, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x12, 0x2c, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x12, 0x12, + 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, + 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, @@ -799,7 +959,7 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x32, 0x8b, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x05, 0x50, 0x70, 0x72, 0x6f, + 0x32, 0xd0, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x05, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, @@ -823,9 +983,14 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 0x74, 0x48, 0x65, 0x61, 0x64, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, - 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x17, - 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, + 0x0a, 0x0a, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, + 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x30, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -841,46 +1006,53 @@ func file_command_server_proto_server_proto_rawDescGZIP() []byte { } var file_command_server_proto_server_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_command_server_proto_server_proto_msgTypes = make([]protoimpl.MessageInfo, 14) +var file_command_server_proto_server_proto_msgTypes = make([]protoimpl.MessageInfo, 17) var file_command_server_proto_server_proto_goTypes = []interface{}{ (PprofRequest_Type)(0), // 0: proto.PprofRequest.Type - (*PeersAddRequest)(nil), // 1: proto.PeersAddRequest - (*PeersAddResponse)(nil), // 2: proto.PeersAddResponse - (*PeersRemoveRequest)(nil), // 3: proto.PeersRemoveRequest - (*PeersRemoveResponse)(nil), // 4: proto.PeersRemoveResponse - (*PeersListRequest)(nil), // 5: proto.PeersListRequest - (*PeersListResponse)(nil), // 6: proto.PeersListResponse - (*PeersStatusRequest)(nil), // 7: proto.PeersStatusRequest - (*PeersStatusResponse)(nil), // 8: proto.PeersStatusResponse - (*Peer)(nil), // 9: proto.Peer - (*ChainSetHeadRequest)(nil), // 10: proto.ChainSetHeadRequest - (*ChainSetHeadResponse)(nil), // 11: proto.ChainSetHeadResponse - (*PprofRequest)(nil), // 12: proto.PprofRequest - (*PprofResponse)(nil), // 13: proto.PprofResponse - nil, // 14: proto.PprofResponse.HeadersEntry + (*ChainWatchRequest)(nil), // 1: proto.ChainWatchRequest + (*ChainWatchResponse)(nil), // 2: proto.ChainWatchResponse + (*BlockStub)(nil), // 3: proto.BlockStub + (*PeersAddRequest)(nil), // 4: proto.PeersAddRequest + (*PeersAddResponse)(nil), // 5: proto.PeersAddResponse + (*PeersRemoveRequest)(nil), // 6: proto.PeersRemoveRequest + (*PeersRemoveResponse)(nil), // 7: proto.PeersRemoveResponse + (*PeersListRequest)(nil), // 8: proto.PeersListRequest + (*PeersListResponse)(nil), // 9: proto.PeersListResponse + (*PeersStatusRequest)(nil), // 10: proto.PeersStatusRequest + (*PeersStatusResponse)(nil), // 11: proto.PeersStatusResponse + (*Peer)(nil), // 12: proto.Peer + (*ChainSetHeadRequest)(nil), // 13: proto.ChainSetHeadRequest + (*ChainSetHeadResponse)(nil), // 14: proto.ChainSetHeadResponse + (*PprofRequest)(nil), // 15: proto.PprofRequest + (*PprofResponse)(nil), // 16: proto.PprofResponse + nil, // 17: proto.PprofResponse.HeadersEntry } var file_command_server_proto_server_proto_depIdxs = []int32{ - 9, // 0: proto.PeersListResponse.peers:type_name -> proto.Peer - 9, // 1: proto.PeersStatusResponse.peer:type_name -> proto.Peer - 0, // 2: proto.PprofRequest.type:type_name -> proto.PprofRequest.Type - 14, // 3: proto.PprofResponse.headers:type_name -> proto.PprofResponse.HeadersEntry - 12, // 4: proto.Bor.Pprof:input_type -> proto.PprofRequest - 1, // 5: proto.Bor.PeersAdd:input_type -> proto.PeersAddRequest - 3, // 6: proto.Bor.PeersRemove:input_type -> proto.PeersRemoveRequest - 5, // 7: proto.Bor.PeersList:input_type -> proto.PeersListRequest - 7, // 8: proto.Bor.PeersStatus:input_type -> proto.PeersStatusRequest - 10, // 9: proto.Bor.ChainSetHead:input_type -> proto.ChainSetHeadRequest - 13, // 10: proto.Bor.Pprof:output_type -> proto.PprofResponse - 2, // 11: proto.Bor.PeersAdd:output_type -> proto.PeersAddResponse - 4, // 12: proto.Bor.PeersRemove:output_type -> proto.PeersRemoveResponse - 6, // 13: proto.Bor.PeersList:output_type -> proto.PeersListResponse - 8, // 14: proto.Bor.PeersStatus:output_type -> proto.PeersStatusResponse - 11, // 15: proto.Bor.ChainSetHead:output_type -> proto.ChainSetHeadResponse - 10, // [10:16] is the sub-list for method output_type - 4, // [4:10] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 3, // 0: proto.ChainWatchResponse.oldchain:type_name -> proto.BlockStub + 3, // 1: proto.ChainWatchResponse.newchain:type_name -> proto.BlockStub + 12, // 2: proto.PeersListResponse.peers:type_name -> proto.Peer + 12, // 3: proto.PeersStatusResponse.peer:type_name -> proto.Peer + 0, // 4: proto.PprofRequest.type:type_name -> proto.PprofRequest.Type + 17, // 5: proto.PprofResponse.headers:type_name -> proto.PprofResponse.HeadersEntry + 15, // 6: proto.Bor.Pprof:input_type -> proto.PprofRequest + 4, // 7: proto.Bor.PeersAdd:input_type -> proto.PeersAddRequest + 6, // 8: proto.Bor.PeersRemove:input_type -> proto.PeersRemoveRequest + 8, // 9: proto.Bor.PeersList:input_type -> proto.PeersListRequest + 10, // 10: proto.Bor.PeersStatus:input_type -> proto.PeersStatusRequest + 13, // 11: proto.Bor.ChainSetHead:input_type -> proto.ChainSetHeadRequest + 1, // 12: proto.Bor.ChainWatch:input_type -> proto.ChainWatchRequest + 16, // 13: proto.Bor.Pprof:output_type -> proto.PprofResponse + 5, // 14: proto.Bor.PeersAdd:output_type -> proto.PeersAddResponse + 7, // 15: proto.Bor.PeersRemove:output_type -> proto.PeersRemoveResponse + 9, // 16: proto.Bor.PeersList:output_type -> proto.PeersListResponse + 11, // 17: proto.Bor.PeersStatus:output_type -> proto.PeersStatusResponse + 14, // 18: proto.Bor.ChainSetHead:output_type -> proto.ChainSetHeadResponse + 2, // 19: proto.Bor.ChainWatch:output_type -> proto.ChainWatchResponse + 13, // [13:20] is the sub-list for method output_type + 6, // [6:13] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_command_server_proto_server_proto_init() } @@ -890,7 +1062,7 @@ func file_command_server_proto_server_proto_init() { } if !protoimpl.UnsafeEnabled { file_command_server_proto_server_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersAddRequest); i { + switch v := v.(*ChainWatchRequest); i { case 0: return &v.state case 1: @@ -902,7 +1074,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersAddResponse); i { + switch v := v.(*ChainWatchResponse); i { case 0: return &v.state case 1: @@ -914,7 +1086,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersRemoveRequest); i { + switch v := v.(*BlockStub); i { case 0: return &v.state case 1: @@ -926,7 +1098,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersRemoveResponse); i { + switch v := v.(*PeersAddRequest); i { case 0: return &v.state case 1: @@ -938,7 +1110,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersListRequest); i { + switch v := v.(*PeersAddResponse); i { case 0: return &v.state case 1: @@ -950,7 +1122,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersListResponse); i { + switch v := v.(*PeersRemoveRequest); i { case 0: return &v.state case 1: @@ -962,7 +1134,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersStatusRequest); i { + switch v := v.(*PeersRemoveResponse); i { case 0: return &v.state case 1: @@ -974,7 +1146,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PeersStatusResponse); i { + switch v := v.(*PeersListRequest); i { case 0: return &v.state case 1: @@ -986,7 +1158,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Peer); i { + switch v := v.(*PeersListResponse); i { case 0: return &v.state case 1: @@ -998,7 +1170,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChainSetHeadRequest); i { + switch v := v.(*PeersStatusRequest); i { case 0: return &v.state case 1: @@ -1010,7 +1182,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChainSetHeadResponse); i { + switch v := v.(*PeersStatusResponse); i { case 0: return &v.state case 1: @@ -1022,7 +1194,7 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PprofRequest); i { + switch v := v.(*Peer); i { case 0: return &v.state case 1: @@ -1034,6 +1206,42 @@ func file_command_server_proto_server_proto_init() { } } file_command_server_proto_server_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ChainSetHeadRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_command_server_proto_server_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ChainSetHeadResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_command_server_proto_server_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PprofRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_command_server_proto_server_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PprofResponse); i { case 0: return &v.state @@ -1052,7 +1260,7 @@ func file_command_server_proto_server_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_command_server_proto_server_proto_rawDesc, NumEnums: 1, - NumMessages: 14, + NumMessages: 17, NumExtensions: 0, NumServices: 1, }, diff --git a/command/server/proto/server.proto b/command/server/proto/server.proto index 535aa3f36952..51276c448304 100644 --- a/command/server/proto/server.proto +++ b/command/server/proto/server.proto @@ -16,8 +16,23 @@ service Bor { rpc PeersStatus(PeersStatusRequest) returns (PeersStatusResponse); rpc ChainSetHead(ChainSetHeadRequest) returns (ChainSetHeadResponse); + + rpc ChainWatch(ChainWatchRequest) returns (stream ChainWatchResponse); +} + +message ChainWatchRequest { + } +message ChainWatchResponse { + repeated BlockStub oldchain = 1; + repeated BlockStub newchain = 2; +} + +message BlockStub { + string hash = 1; + uint64 number = 2; +} message PeersAddRequest { string enode = 1; diff --git a/command/server/proto/server_grpc.pb.go b/command/server/proto/server_grpc.pb.go index 369419b66fc2..6820e2687656 100644 --- a/command/server/proto/server_grpc.pb.go +++ b/command/server/proto/server_grpc.pb.go @@ -24,6 +24,7 @@ type BorClient interface { PeersList(ctx context.Context, in *PeersListRequest, opts ...grpc.CallOption) (*PeersListResponse, error) PeersStatus(ctx context.Context, in *PeersStatusRequest, opts ...grpc.CallOption) (*PeersStatusResponse, error) ChainSetHead(ctx context.Context, in *ChainSetHeadRequest, opts ...grpc.CallOption) (*ChainSetHeadResponse, error) + ChainWatch(ctx context.Context, in *ChainWatchRequest, opts ...grpc.CallOption) (Bor_ChainWatchClient, error) } type borClient struct { @@ -88,6 +89,38 @@ func (c *borClient) ChainSetHead(ctx context.Context, in *ChainSetHeadRequest, o return out, nil } +func (c *borClient) ChainWatch(ctx context.Context, in *ChainWatchRequest, opts ...grpc.CallOption) (Bor_ChainWatchClient, error) { + stream, err := c.cc.NewStream(ctx, &Bor_ServiceDesc.Streams[0], "/proto.Bor/ChainWatch", opts...) + if err != nil { + return nil, err + } + x := &borChainWatchClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Bor_ChainWatchClient interface { + Recv() (*ChainWatchResponse, error) + grpc.ClientStream +} + +type borChainWatchClient struct { + grpc.ClientStream +} + +func (x *borChainWatchClient) Recv() (*ChainWatchResponse, error) { + m := new(ChainWatchResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + // BorServer is the server API for Bor service. // All implementations must embed UnimplementedBorServer // for forward compatibility @@ -98,6 +131,7 @@ type BorServer interface { PeersList(context.Context, *PeersListRequest) (*PeersListResponse, error) PeersStatus(context.Context, *PeersStatusRequest) (*PeersStatusResponse, error) ChainSetHead(context.Context, *ChainSetHeadRequest) (*ChainSetHeadResponse, error) + ChainWatch(*ChainWatchRequest, Bor_ChainWatchServer) error mustEmbedUnimplementedBorServer() } @@ -123,6 +157,9 @@ func (UnimplementedBorServer) PeersStatus(context.Context, *PeersStatusRequest) func (UnimplementedBorServer) ChainSetHead(context.Context, *ChainSetHeadRequest) (*ChainSetHeadResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ChainSetHead not implemented") } +func (UnimplementedBorServer) ChainWatch(*ChainWatchRequest, Bor_ChainWatchServer) error { + return status.Errorf(codes.Unimplemented, "method ChainWatch not implemented") +} func (UnimplementedBorServer) mustEmbedUnimplementedBorServer() {} // UnsafeBorServer may be embedded to opt out of forward compatibility for this service. @@ -244,6 +281,27 @@ func _Bor_ChainSetHead_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Bor_ChainWatch_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ChainWatchRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(BorServer).ChainWatch(m, &borChainWatchServer{stream}) +} + +type Bor_ChainWatchServer interface { + Send(*ChainWatchResponse) error + grpc.ServerStream +} + +type borChainWatchServer struct { + grpc.ServerStream +} + +func (x *borChainWatchServer) Send(m *ChainWatchResponse) error { + return x.ServerStream.SendMsg(m) +} + // Bor_ServiceDesc is the grpc.ServiceDesc for Bor service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -276,6 +334,12 @@ var Bor_ServiceDesc = grpc.ServiceDesc{ Handler: _Bor_ChainSetHead_Handler, }, }, - Streams: []grpc.StreamDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "ChainWatch", + Handler: _Bor_ChainWatch_Handler, + ServerStreams: true, + }, + }, Metadata: "command/server/proto/server.proto", } diff --git a/command/server/service.go b/command/server/service.go index 0c6c23b6bf51..f2c8a423b1fc 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/command/server/pprof" "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" ) @@ -107,3 +108,18 @@ func (s *Server) ChainSetHead(ctx context.Context, req *proto.ChainSetHeadReques s.backend.APIBackend.SetHead(req.Number) return &proto.ChainSetHeadResponse{}, nil } + +func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error { + // 1. start the feed to the blcokchain events + // 2. for each event send a proto.ChainWatchResponse + + chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize) + s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh) + + for { + msg := <-chainHeadCh + reply.Send(&proto.ChainWatchResponse{}) + } + + return nil +} diff --git a/core/blockchain.go b/core/blockchain.go index 05108a9c6bbd..f0f1375763ea 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1640,10 +1640,23 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. for _, data := range bc.stateSyncData { bc.stateSyncFeed.Send(StateSyncEvent{Data: data}) } + + // ... + // bc.chain2HeadFeed.Send(ChainHeadEvent2{ + // Type: "head", + // NewChain: []{block} + // }) + // BOR } } else { bc.chainSideFeed.Send(ChainSideEvent{Block: block}) + + // ... + // bc.chain2HeadFeed.Send(ChainHeadEvent2{ + // Type: "fork", + // NewChain: []{block} + // }) } return status, nil } @@ -2262,6 +2275,14 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { } // Ensure the user sees large reorgs if len(oldChain) > 0 && len(newChain) > 0 { + + // ... + // bc.chain2HeadFeed.Send(ChainHeadEvent2{ + // Type: "reorg", + // NewChain: newChain, + // OldChain: oldChain, + // }) + logFn := log.Info msg := "Chain reorg detected" if len(oldChain) > 63 { From 4488927e1ff62a855afd84d42745e43385d5eff7 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 1 Dec 2021 16:34:55 +0530 Subject: [PATCH 04/20] Connected chain2head protobuf --- command/server/proto/server.pb.go | 207 ++++++++++++++++-------------- command/server/proto/server.proto | 1 + command/server/server.go | 2 + command/server/service.go | 32 ++++- core/blockchain.go | 53 ++++---- core/events.go | 6 + eth/api_backend.go | 4 + go.sum | 1 - 8 files changed, 175 insertions(+), 131 deletions(-) diff --git a/command/server/proto/server.pb.go b/command/server/proto/server.pb.go index b58f20a7d765..d7c1d671636f 100644 --- a/command/server/proto/server.pb.go +++ b/command/server/proto/server.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.12.0 +// protoc v3.17.3 // source: command/server/proto/server.proto package proto @@ -119,6 +119,7 @@ type ChainWatchResponse struct { Oldchain []*BlockStub `protobuf:"bytes,1,rep,name=oldchain,proto3" json:"oldchain,omitempty"` Newchain []*BlockStub `protobuf:"bytes,2,rep,name=newchain,proto3" json:"newchain,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` } func (x *ChainWatchResponse) Reset() { @@ -167,6 +168,13 @@ func (x *ChainWatchResponse) GetNewchain() []*BlockStub { return nil } +func (x *ChainWatchResponse) GetType() string { + if x != nil { + return x.Type + } + return "" +} + type BlockStub struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -892,105 +900,106 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x13, 0x0a, 0x11, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, - 0x70, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x12, 0x2c, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, - 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x12, 0x12, - 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, - 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x41, 0x0a, 0x0f, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, - 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, - 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x22, 0x12, 0x0a, - 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x44, 0x0a, 0x12, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, - 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, - 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x22, 0x15, 0x0a, 0x13, 0x50, 0x65, 0x65, 0x72, 0x73, - 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x12, - 0x0a, 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x22, 0x36, 0x0a, 0x11, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, - 0x65, 0x65, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0x2a, 0x0a, 0x12, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x22, 0x36, 0x0a, 0x13, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, - 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, 0x65, 0x65, 0x72, 0x22, 0x98, - 0x01, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, - 0x03, 0x65, 0x6e, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x72, 0x12, - 0x12, 0x0a, 0x04, 0x63, 0x61, 0x70, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x63, - 0x61, 0x70, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, - 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, - 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x22, 0x2d, 0x0a, 0x13, 0x43, 0x68, 0x61, - 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x16, 0x0a, 0x14, 0x43, 0x68, 0x61, 0x69, - 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x98, 0x01, 0x0a, 0x0c, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x2c, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, - 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x63, - 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x73, 0x65, 0x63, 0x6f, - 0x6e, 0x64, 0x73, 0x22, 0x26, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x4c, - 0x4f, 0x4f, 0x4b, 0x55, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x43, 0x50, 0x55, 0x10, 0x01, - 0x12, 0x09, 0x0a, 0x05, 0x54, 0x52, 0x41, 0x43, 0x45, 0x10, 0x02, 0x22, 0xa2, 0x01, 0x0a, 0x0d, - 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, - 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3b, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x48, - 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x68, 0x65, 0x61, - 0x64, 0x65, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x32, 0xd0, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, 0x05, 0x50, 0x70, 0x72, 0x6f, - 0x66, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, - 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, - 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, - 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x50, 0x65, 0x65, - 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, - 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x3e, 0x0a, 0x09, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x17, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, - 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x44, 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x19, + 0x84, 0x01, 0x0a, 0x12, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x63, + 0x68, 0x61, 0x69, 0x6e, 0x12, 0x2c, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x75, 0x62, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, + 0x74, 0x75, 0x62, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, + 0x41, 0x0a, 0x0f, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, + 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, + 0x65, 0x64, 0x22, 0x12, 0x0a, 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x44, 0x0a, 0x12, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, + 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x22, 0x15, 0x0a, 0x13, + 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x12, 0x0a, 0x10, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x36, 0x0a, 0x11, 0x50, 0x65, 0x65, 0x72, 0x73, + 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x05, + 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, + 0x2a, 0x0a, 0x12, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x22, 0x36, 0x0a, 0x13, 0x50, + 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x70, 0x65, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x52, 0x04, 0x70, + 0x65, 0x65, 0x72, 0x22, 0x98, 0x01, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6e, 0x6f, + 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x65, 0x6e, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x61, 0x70, 0x73, 0x18, 0x04, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x04, 0x63, 0x61, 0x70, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x22, 0x2d, + 0x0a, 0x13, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x16, 0x0a, + 0x14, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x98, 0x01, 0x0a, 0x0c, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x22, 0x26, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x4f, 0x4f, 0x4b, 0x55, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, + 0x43, 0x50, 0x55, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x54, 0x52, 0x41, 0x43, 0x45, 0x10, 0x02, + 0x22, 0xa2, 0x01, 0x0a, 0x0d, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3b, 0x0a, 0x07, + 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x48, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xd0, 0x03, 0x0a, 0x03, 0x42, 0x6f, 0x72, 0x12, 0x32, 0x0a, + 0x05, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, + 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x70, 0x72, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x12, 0x16, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, + 0x65, 0x72, 0x73, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, + 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x19, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, + 0x74, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x44, 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, + 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x73, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0c, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, - 0x74, 0x48, 0x65, 0x61, 0x64, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, - 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, - 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, - 0x0a, 0x0a, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x18, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, - 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x30, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2f, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0c, 0x43, 0x68, + 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, + 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x48, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x0a, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, + 0x68, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, + 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x2f, 0x63, 0x6f, 0x6d, + 0x6d, 0x61, 0x6e, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/command/server/proto/server.proto b/command/server/proto/server.proto index 51276c448304..f5b3773bb2df 100644 --- a/command/server/proto/server.proto +++ b/command/server/proto/server.proto @@ -27,6 +27,7 @@ message ChainWatchRequest { message ChainWatchResponse { repeated BlockStub oldchain = 1; repeated BlockStub newchain = 2; + string type = 3; } message BlockStub { diff --git a/command/server/server.go b/command/server/server.go index bab4673214f6..8eb420d41038 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/ethstats" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/graphql" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" @@ -38,6 +39,7 @@ type Server struct { backend *eth.Ethereum grpcServer *grpc.Server tracer *sdktrace.TracerProvider + headSub event.Subscription } func NewServer(config *Config) (*Server, error) { diff --git a/command/server/service.go b/command/server/service.go index f2c8a423b1fc..526d4b66bff1 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/command/server/pprof" "github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" ) @@ -109,17 +110,36 @@ func (s *Server) ChainSetHead(ctx context.Context, req *proto.ChainSetHeadReques return &proto.ChainSetHeadResponse{}, nil } +func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub { + + var blockStubs []*proto.BlockStub + + for _, block := range blocks { + blockStub := &proto.BlockStub{ + Hash: block.Hash().String(), + Number: block.NumberU64(), + } + blockStubs = append(blockStubs, blockStub) + } + + return blockStubs +} + func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error { // 1. start the feed to the blcokchain events // 2. for each event send a proto.ChainWatchResponse - chainHeadCh := make(chan core.ChainHeadEvent, chainHeadChanSize) - s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh) + chain2HeadChanSize := 10 + + chain2HeadCh := make(chan core.Chain2HeadEvent, chain2HeadChanSize) + s.headSub = s.backend.APIBackend.SubscribeChain2HeadEvent(chain2HeadCh) for { - msg := <-chainHeadCh - reply.Send(&proto.ChainWatchResponse{}) + msg := <-chain2HeadCh + fmt.Print(msg) + reply.Send(&proto.ChainWatchResponse{Type: msg.Type, + Newchain: ConvertBlockToBlockStub(msg.NewChain), + Oldchain: ConvertBlockToBlockStub(msg.OldChain), + }) } - - return nil } diff --git a/core/blockchain.go b/core/blockchain.go index f0f1375763ea..0615b0e84bb2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -175,15 +175,16 @@ type BlockChain struct { // * nil: disable tx reindexer/deleter, but still index new blocks txLookupLimit uint64 - hc *HeaderChain - rmLogsFeed event.Feed - chainFeed event.Feed - chainSideFeed event.Feed - chainHeadFeed event.Feed - logsFeed event.Feed - blockProcFeed event.Feed - scope event.SubscriptionScope - genesisBlock *types.Block + hc *HeaderChain + rmLogsFeed event.Feed + chainFeed event.Feed + chainSideFeed event.Feed + chainHeadFeed event.Feed + chain2HeadFeed event.Feed + logsFeed event.Feed + blockProcFeed event.Feed + scope event.SubscriptionScope + genesisBlock *types.Block // This mutex synchronizes chain write operations. // Readers don't need to take it, they can just read the database. @@ -1641,22 +1642,20 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. bc.stateSyncFeed.Send(StateSyncEvent{Data: data}) } - // ... - // bc.chain2HeadFeed.Send(ChainHeadEvent2{ - // Type: "head", - // NewChain: []{block} - // }) + bc.chain2HeadFeed.Send(Chain2HeadEvent{ + Type: "head", + NewChain: []*types.Block{block}, + }) // BOR } } else { bc.chainSideFeed.Send(ChainSideEvent{Block: block}) - // ... - // bc.chain2HeadFeed.Send(ChainHeadEvent2{ - // Type: "fork", - // NewChain: []{block} - // }) + bc.chain2HeadFeed.Send(Chain2HeadEvent{ + Type: "fork", + NewChain: []*types.Block{block}, + }) } return status, nil } @@ -2276,12 +2275,11 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { // Ensure the user sees large reorgs if len(oldChain) > 0 && len(newChain) > 0 { - // ... - // bc.chain2HeadFeed.Send(ChainHeadEvent2{ - // Type: "reorg", - // NewChain: newChain, - // OldChain: oldChain, - // }) + bc.chain2HeadFeed.Send(Chain2HeadEvent{ + Type: "reorg", + NewChain: newChain, + OldChain: oldChain, + }) logFn := log.Info msg := "Chain reorg detected" @@ -2591,6 +2589,11 @@ func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Su return bc.scope.Track(bc.chainHeadFeed.Subscribe(ch)) } +// SubscribeChain2HeadEvent registers a subscription of ChainHeadEvent. () +func (bc *BlockChain) SubscribeChain2HeadEvent(ch chan<- Chain2HeadEvent) event.Subscription { + return bc.scope.Track(bc.chain2HeadFeed.Subscribe(ch)) +} + // SubscribeChainSideEvent registers a subscription of ChainSideEvent. func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Subscription { return bc.scope.Track(bc.chainSideFeed.Subscribe(ch)) diff --git a/core/events.go b/core/events.go index ac935a137f5f..648546ea36e9 100644 --- a/core/events.go +++ b/core/events.go @@ -41,3 +41,9 @@ type ChainSideEvent struct { } type ChainHeadEvent struct{ Block *types.Block } + +type Chain2HeadEvent struct { + NewChain []*types.Block + OldChain []*types.Block + Type string +} diff --git a/eth/api_backend.go b/eth/api_backend.go index 01e68f6781dd..7e781e773a1a 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -227,6 +227,10 @@ func (b *EthAPIBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) e return b.eth.BlockChain().SubscribeChainHeadEvent(ch) } +func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { + return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) +} + func (b *EthAPIBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { return b.eth.BlockChain().SubscribeChainSideEvent(ch) } diff --git a/go.sum b/go.sum index 96d83f3fcc92..cec3ce626f67 100644 --- a/go.sum +++ b/go.sum @@ -33,7 +33,6 @@ github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSW github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc= github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= From beaf6da26d72973201dfc7531ea97020d17468fe Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 3 Dec 2021 17:28:53 +0530 Subject: [PATCH 05/20] Minor Refactor --- command/chain_watch.go | 13 +++++++++++-- command/server/service.go | 4 ++-- core/blockchain.go | 20 ++++++++++---------- core/bor_events.go | 7 +++++++ core/events.go | 6 ------ 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/command/chain_watch.go b/command/chain_watch.go index f61a28c8777d..2ed37be9f6fc 100644 --- a/command/chain_watch.go +++ b/command/chain_watch.go @@ -54,8 +54,17 @@ func (c *ChainWatchCommand) Run(args []string) int { // if err == EOF if finished on the other side panic(err) } - fmt.Println("message received") - fmt.Println(msg) + if msg.Type == "head" { + fmt.Println("Block Added : ", msg.Newchain) + } else if msg.Type == "fork" { + fmt.Println("New Fork Block :", msg.Newchain) + } else if msg.Type == "reorg" { + fmt.Println("Reorg Detected") + fmt.Println("Added :", msg.Newchain) + fmt.Println("Removed :", msg.Oldchain) + } + + // fmt.Println(msg) } return 0 diff --git a/command/server/service.go b/command/server/service.go index 526d4b66bff1..4c01facf141a 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -126,7 +126,7 @@ func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub { } func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error { - // 1. start the feed to the blcokchain events + // 1. start the feed to the blockchain events // 2. for each event send a proto.ChainWatchResponse chain2HeadChanSize := 10 @@ -136,7 +136,7 @@ func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainW for { msg := <-chain2HeadCh - fmt.Print(msg) + reply.Send(&proto.ChainWatchResponse{Type: msg.Type, Newchain: ConvertBlockToBlockStub(msg.NewChain), Oldchain: ConvertBlockToBlockStub(msg.OldChain), diff --git a/core/blockchain.go b/core/blockchain.go index 22b56dc0b514..a58f94852fc1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -175,16 +175,15 @@ type BlockChain struct { // * nil: disable tx reindexer/deleter, but still index new blocks txLookupLimit uint64 - hc *HeaderChain - rmLogsFeed event.Feed - chainFeed event.Feed - chainSideFeed event.Feed - chainHeadFeed event.Feed - chain2HeadFeed event.Feed - logsFeed event.Feed - blockProcFeed event.Feed - scope event.SubscriptionScope - genesisBlock *types.Block + hc *HeaderChain + rmLogsFeed event.Feed + chainFeed event.Feed + chainSideFeed event.Feed + chainHeadFeed event.Feed + logsFeed event.Feed + blockProcFeed event.Feed + scope event.SubscriptionScope + genesisBlock *types.Block // This mutex synchronizes chain write operations. // Readers don't need to take it, they can just read the database. @@ -218,6 +217,7 @@ type BlockChain struct { borReceiptsCache *lru.Cache // Cache for the most recent bor receipt receipts per block stateSyncData []*types.StateSyncData // State sync data stateSyncFeed event.Feed // State sync feed + chain2HeadFeed event.Feed // Reorg/NewHead/Fork data feed } // NewBlockChain returns a fully initialised block chain using information diff --git a/core/bor_events.go b/core/bor_events.go index d8a5b38d0e9d..e47afba1a54d 100644 --- a/core/bor_events.go +++ b/core/bor_events.go @@ -8,3 +8,10 @@ import ( type StateSyncEvent struct { Data *types.StateSyncData } + +// For tracking reorgs related information +type Chain2HeadEvent struct { + NewChain []*types.Block + OldChain []*types.Block + Type string +} diff --git a/core/events.go b/core/events.go index 648546ea36e9..ac935a137f5f 100644 --- a/core/events.go +++ b/core/events.go @@ -41,9 +41,3 @@ type ChainSideEvent struct { } type ChainHeadEvent struct{ Block *types.Block } - -type Chain2HeadEvent struct { - NewChain []*types.Block - OldChain []*types.Block - Type string -} From a6f014c2c91e377e84bc8ddf3a0f02b95a7bb92b Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Mon, 6 Dec 2021 14:25:33 +0530 Subject: [PATCH 06/20] fixes --- command/chain_watch.go | 40 +++++++++++++++++++++++++++++---------- command/server/server.go | 2 -- command/server/service.go | 8 ++++++-- core/bor_events.go | 6 ++++++ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/command/chain_watch.go b/command/chain_watch.go index 2ed37be9f6fc..05e52d2bc4d2 100644 --- a/command/chain_watch.go +++ b/command/chain_watch.go @@ -3,9 +3,13 @@ package main import ( "context" "fmt" + "os" + "os/signal" + "syscall" "github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/core" ) // ChainWatchCommand is the command to group the peers commands @@ -45,23 +49,39 @@ func (c *ChainWatchCommand) Run(args []string) int { sub, err := borClt.ChainWatch(context.Background(), &proto.ChainWatchRequest{}) if err != nil { - panic(err) + c.UI.Error(err.Error()) + return 1 } + signalCh := make(chan os.Signal, 1) + signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM) + + go func() { + <-signalCh + sub.CloseSend() + }() + for { msg, err := sub.Recv() if err != nil { // if err == EOF if finished on the other side - panic(err) + c.UI.Output(err.Error()) + break } - if msg.Type == "head" { - fmt.Println("Block Added : ", msg.Newchain) - } else if msg.Type == "fork" { - fmt.Println("New Fork Block :", msg.Newchain) - } else if msg.Type == "reorg" { - fmt.Println("Reorg Detected") - fmt.Println("Added :", msg.Newchain) - fmt.Println("Removed :", msg.Oldchain) + if msg.Type == core.Chain2HeadCanonicalEvent { + out := fmt.Sprintf("Block Added : %v", msg.Newchain) + c.UI.Output(out) + } else if msg.Type == core.Chain2HeadForkEvent { + out := fmt.Sprintf("New Fork Block : %v", msg.Newchain) + c.UI.Output(out) + } else if msg.Type == core.Chain2HeadReorgEvent { + c.UI.Output("Reorg Detected") + + out := fmt.Sprintf("Added : %v", msg.Newchain) + c.UI.Output(out) + + out = fmt.Sprintf("Removed : %v", msg.Oldchain) + c.UI.Output(out) } // fmt.Println(msg) diff --git a/command/server/server.go b/command/server/server.go index 8eb420d41038..bab4673214f6 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -15,7 +15,6 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/ethstats" - "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/graphql" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" @@ -39,7 +38,6 @@ type Server struct { backend *eth.Ethereum grpcServer *grpc.Server tracer *sdktrace.TracerProvider - headSub event.Subscription } func NewServer(config *Config) (*Server, error) { diff --git a/command/server/service.go b/command/server/service.go index 4c01facf141a..2a06460bbf2d 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -132,14 +132,18 @@ func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainW chain2HeadChanSize := 10 chain2HeadCh := make(chan core.Chain2HeadEvent, chain2HeadChanSize) - s.headSub = s.backend.APIBackend.SubscribeChain2HeadEvent(chain2HeadCh) + headSub := s.backend.APIBackend.SubscribeChain2HeadEvent(chain2HeadCh) + defer headSub.Unsubscribe() for { msg := <-chain2HeadCh - reply.Send(&proto.ChainWatchResponse{Type: msg.Type, + err := reply.Send(&proto.ChainWatchResponse{Type: msg.Type, Newchain: ConvertBlockToBlockStub(msg.NewChain), Oldchain: ConvertBlockToBlockStub(msg.OldChain), }) + if err != nil { + return err + } } } diff --git a/core/bor_events.go b/core/bor_events.go index e47afba1a54d..68f916fe791c 100644 --- a/core/bor_events.go +++ b/core/bor_events.go @@ -9,6 +9,12 @@ type StateSyncEvent struct { Data *types.StateSyncData } +var ( + Chain2HeadReorgEvent = "reorg" + Chain2HeadCanonicalEvent = "head" + Chain2HeadForkEvent = "fork" +) + // For tracking reorgs related information type Chain2HeadEvent struct { NewChain []*types.Block From 1865f28131dea6cd9f0f7b3fda182fb9ace23d98 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Mon, 6 Dec 2021 16:25:21 +0530 Subject: [PATCH 07/20] Added sypnosis/help + clean code --- command/chain_watch.go | 36 +++++++++++++++++------------------- command/server/service.go | 2 -- core/blockchain.go | 8 ++++---- docs/cli/README.md | 2 ++ docs/cli/chain_watch.md | 3 +++ 5 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 docs/cli/chain_watch.md diff --git a/command/chain_watch.go b/command/chain_watch.go index 05e52d2bc4d2..8e40631ccdc5 100644 --- a/command/chain_watch.go +++ b/command/chain_watch.go @@ -19,7 +19,9 @@ type ChainWatchCommand struct { // Help implements the cli.Command interface func (c *ChainWatchCommand) Help() string { - return `` + return `Usage: bor chain watch + + This command is used to view the chainHead, reorg and fork events in real-time` } func (c *ChainWatchCommand) Flags() *flagset.Flagset { @@ -30,7 +32,19 @@ func (c *ChainWatchCommand) Flags() *flagset.Flagset { // Synopsis implements the cli.Command interface func (c *ChainWatchCommand) Synopsis() string { - return "" + return "Watch the chainHead, reorg and fork events in real-time" +} + +func printEvent(msg *proto.ChainWatchResponse) string { + var out string + if msg.Type == core.Chain2HeadCanonicalEvent { + out = fmt.Sprintf("Block Added : %v", msg.Newchain) + } else if msg.Type == core.Chain2HeadForkEvent { + out = fmt.Sprintf("New Fork Block : %v", msg.Newchain) + } else if msg.Type == core.Chain2HeadReorgEvent { + out = fmt.Sprintf("Reorg Detected \nAdded : %v \nRemoved : %v", msg.Newchain, msg.Oldchain) + } + return out } // Run implements the cli.Command interface @@ -68,23 +82,7 @@ func (c *ChainWatchCommand) Run(args []string) int { c.UI.Output(err.Error()) break } - if msg.Type == core.Chain2HeadCanonicalEvent { - out := fmt.Sprintf("Block Added : %v", msg.Newchain) - c.UI.Output(out) - } else if msg.Type == core.Chain2HeadForkEvent { - out := fmt.Sprintf("New Fork Block : %v", msg.Newchain) - c.UI.Output(out) - } else if msg.Type == core.Chain2HeadReorgEvent { - c.UI.Output("Reorg Detected") - - out := fmt.Sprintf("Added : %v", msg.Newchain) - c.UI.Output(out) - - out = fmt.Sprintf("Removed : %v", msg.Oldchain) - c.UI.Output(out) - } - - // fmt.Println(msg) + c.UI.Output(printEvent(msg)) } return 0 diff --git a/command/server/service.go b/command/server/service.go index 2a06460bbf2d..a2bcd55187c2 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -126,8 +126,6 @@ func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub { } func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error { - // 1. start the feed to the blockchain events - // 2. for each event send a proto.ChainWatchResponse chain2HeadChanSize := 10 diff --git a/core/blockchain.go b/core/blockchain.go index a58f94852fc1..5bd2f9356145 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1643,7 +1643,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. } bc.chain2HeadFeed.Send(Chain2HeadEvent{ - Type: "head", + Type: Chain2HeadCanonicalEvent, NewChain: []*types.Block{block}, }) @@ -1653,7 +1653,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. bc.chainSideFeed.Send(ChainSideEvent{Block: block}) bc.chain2HeadFeed.Send(Chain2HeadEvent{ - Type: "fork", + Type: Chain2HeadForkEvent, NewChain: []*types.Block{block}, }) } @@ -1751,7 +1751,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er bc.chainHeadFeed.Send(ChainHeadEvent{lastCanon}) bc.chain2HeadFeed.Send(Chain2HeadEvent{ - Type: "head", + Type: Chain2HeadCanonicalEvent, NewChain: []*types.Block{lastCanon}, }) } @@ -2281,7 +2281,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { if len(oldChain) > 0 && len(newChain) > 0 { bc.chain2HeadFeed.Send(Chain2HeadEvent{ - Type: "reorg", + Type: Chain2HeadReorgEvent, NewChain: newChain, OldChain: oldChain, }) diff --git a/docs/cli/README.md b/docs/cli/README.md index c82bbbe047fa..052116fde8ad 100644 --- a/docs/cli/README.md +++ b/docs/cli/README.md @@ -15,4 +15,6 @@ - [```account import```](./account_import.md) +- [```chain watch```](./chain_watch.md) + - [```version```](./version.md) diff --git a/docs/cli/chain_watch.md b/docs/cli/chain_watch.md new file mode 100644 index 000000000000..4844bb7618d5 --- /dev/null +++ b/docs/cli/chain_watch.md @@ -0,0 +1,3 @@ +# Chain watch + +The ```chain watch``` command is used to view the chainHead, reorg and fork events in real-time. From 9957d9147f5d941ddb273808937a15207878419c Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Sat, 11 Dec 2021 13:28:50 +0530 Subject: [PATCH 08/20] minor fix --- command/server/service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/server/service.go b/command/server/service.go index a2bcd55187c2..2e188c71d5f6 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -110,7 +110,7 @@ func (s *Server) ChainSetHead(ctx context.Context, req *proto.ChainSetHeadReques return &proto.ChainSetHeadResponse{}, nil } -func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub { +func convertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub { var blockStubs []*proto.BlockStub @@ -137,8 +137,8 @@ func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainW msg := <-chain2HeadCh err := reply.Send(&proto.ChainWatchResponse{Type: msg.Type, - Newchain: ConvertBlockToBlockStub(msg.NewChain), - Oldchain: ConvertBlockToBlockStub(msg.OldChain), + Newchain: convertBlockToBlockStub(msg.NewChain), + Oldchain: convertBlockToBlockStub(msg.OldChain), }) if err != nil { return err From 3a6744785beaa7cf48a39c1760ff2166502e33cb Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 22 Dec 2021 15:36:31 +0530 Subject: [PATCH 09/20] Added chain2head event in Ethstats --- eth/api_backend.go | 4 -- eth/bor_api_backend.go | 5 +++ ethstats/ethstats.go | 81 ++++++++++++++++++++++++++++++++++---- internal/ethapi/backend.go | 2 + les/bor_api_backend.go | 5 +++ light/lightchain.go | 26 +++++++----- 6 files changed, 101 insertions(+), 22 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index 7e781e773a1a..01e68f6781dd 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -227,10 +227,6 @@ func (b *EthAPIBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) e return b.eth.BlockChain().SubscribeChainHeadEvent(ch) } -func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { - return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) -} - func (b *EthAPIBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { return b.eth.BlockChain().SubscribeChainSideEvent(ch) } diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index a6ff090c3f31..bbfc38518574 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -67,3 +67,8 @@ func (b *EthAPIBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, func (b *EthAPIBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription { return b.eth.BlockChain().SubscribeStateSyncEvent(ch) } + +// SubscribeChain2HeadEvent subscribes to reorg/head/fork event +func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { + return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) +} diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 55c0c880f33c..2746f5ad947c 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -57,6 +57,9 @@ const ( txChanSize = 4096 // chainHeadChanSize is the size of channel listening to ChainHeadEvent. chainHeadChanSize = 10 + + // chain2HeadChanSize is the size of channel listening to Chain2HeadEvent. + chain2HeadChanSize = 10 ) // backend encompasses the bare-minimum functionality needed for ethstats reporting @@ -70,10 +73,15 @@ type backend interface { SyncProgress() ethereum.SyncProgress } +type extendedBackend interface { + backend + SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription +} + // fullNodeBackend encompasses the functionality necessary for a full node // reporting to ethstats type fullNodeBackend interface { - backend + extendedBackend Miner() *miner.Miner BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) CurrentBlock() *types.Block @@ -84,7 +92,7 @@ type fullNodeBackend interface { // chain statistics up to a monitoring server. type Service struct { server *p2p.Server // Peer-to-peer server to retrieve networking infos - backend backend + backend extendedBackend engine consensus.Engine // Consensus engine to retrieve variadic block fields node string // Name of the node to display on the monitoring page @@ -96,6 +104,9 @@ type Service struct { headSub event.Subscription txSub event.Subscription + + //bor related sub + chain2headSub event.Subscription } // connWrapper is a wrapper to prevent concurrent-write or concurrent-read on the @@ -168,7 +179,7 @@ func parseEthstatsURL(url string) (parts []string, err error) { } // New returns a monitoring service ready for stats reporting. -func New(node *node.Node, backend backend, engine consensus.Engine, url string) error { +func New(node *node.Node, backend extendedBackend, engine consensus.Engine, url string) error { parts, err := parseEthstatsURL(url) if err != nil { return err @@ -195,7 +206,9 @@ func (s *Service) Start() error { s.headSub = s.backend.SubscribeChainHeadEvent(chainHeadCh) txEventCh := make(chan core.NewTxsEvent, txChanSize) s.txSub = s.backend.SubscribeNewTxsEvent(txEventCh) - go s.loop(chainHeadCh, txEventCh) + chain2HeadCh := make(chan core.Chain2HeadEvent, chain2HeadChanSize) + s.chain2headSub = s.backend.SubscribeChain2HeadEvent(chain2HeadCh) + go s.loop(chainHeadCh, chain2HeadCh, txEventCh) log.Info("Stats daemon started") return nil @@ -211,12 +224,13 @@ func (s *Service) Stop() error { // loop keeps trying to connect to the netstats server, reporting chain events // until termination. -func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core.NewTxsEvent) { +func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, chain2HeadCh chan core.Chain2HeadEvent, txEventCh chan core.NewTxsEvent) { // Start a goroutine that exhausts the subscriptions to avoid events piling up var ( - quitCh = make(chan struct{}) - headCh = make(chan *types.Block, 1) - txCh = make(chan struct{}, 1) + quitCh = make(chan struct{}) + headCh = make(chan *types.Block, 1) + txCh = make(chan struct{}, 1) + head2Ch = make(chan core.Chain2HeadEvent, 1) ) go func() { var lastTx mclock.AbsTime @@ -231,6 +245,13 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core default: } + // Notify of chain2head events, but drop if too frequent + case chain2head := <-chain2HeadCh: + select { + case head2Ch <- chain2head: + default: + } + // Notify of new transaction events, but drop if too frequent case <-txEventCh: if time.Duration(mclock.Now()-lastTx) < time.Second { @@ -333,6 +354,12 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core if err = s.reportPending(conn); err != nil { log.Warn("Post-block transaction stats report failed", "err", err) } + + case chain2head := <-head2Ch: + if err = s.reportChain2Head(conn, &chain2head); err != nil { + log.Warn("Reorg stats report failed", "err", err) + } + case <-txCh: if err = s.reportPending(conn); err != nil { log.Warn("Transaction stats report failed", "err", err) @@ -750,6 +777,44 @@ func (s *Service) reportPending(conn *connWrapper) error { return conn.WriteJSON(report) } +type Chain2HeadStats struct { + NewChain []*blockStats + OldChain []*blockStats + Type string +} + +// reportChain2Head checks for reorg and sends current head to stats server. +func (s *Service) reportChain2Head(conn *connWrapper, chain2HeadData *core.Chain2HeadEvent) error { + + var chain2headStats Chain2HeadStats + + // assemble new chain + for _, block := range chain2HeadData.NewChain { + chain2headStats.NewChain = append(chain2headStats.NewChain, s.assembleBlockStats(block)) + } + + // assemble old chain + for _, block := range chain2HeadData.OldChain { + chain2headStats.OldChain = append(chain2headStats.OldChain, s.assembleBlockStats(block)) + } + + chain2headStats.Type = chain2HeadData.Type + + // Assemble the block report and send it to the server + log.Trace("Reorg Detected", "reorg root block number", chain2headStats.NewChain[0].Number, "block hash", chain2headStats.NewChain[0].Hash) + + stats := map[string]interface{}{ + "id": s.node, + "reorg root block number": chain2headStats.NewChain[0].Number, + "reorg root block hash": chain2headStats.NewChain[0].Hash, + "details": chain2headStats, + } + report := map[string][]interface{}{ + "emit": {"Chain2Head", stats}, + } + return conn.WriteJSON(report) +} + // nodeStats is the information to report about the local node. type nodeStats struct { Active bool `json:"active"` diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 40ac02fccd80..b0b3c88a8b5e 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -99,6 +99,8 @@ type Backend interface { GetBorBlockTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) + SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription + ChainConfig() *params.ChainConfig Engine() consensus.Engine } diff --git a/les/bor_api_backend.go b/les/bor_api_backend.go index 248246810981..3a68bc0ab2e7 100644 --- a/les/bor_api_backend.go +++ b/les/bor_api_backend.go @@ -17,3 +17,8 @@ func (b *LesApiBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end func (b *LesApiBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription { return b.eth.blockchain.SubscribeStateSyncEvent(ch) } + +// SubscribeChain2HeadEvent subscribe head/fork/reorg events. +func (b *LesApiBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { + return b.eth.BlockChain().SubscribeChain2HeadEvent(ch) +} diff --git a/light/lightchain.go b/light/lightchain.go index 92e0e6637f75..e40ae190bfbf 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -49,16 +49,17 @@ var ( // headers, downloading block bodies and receipts on demand through an ODR // interface. It only does header validation during chain insertion. type LightChain struct { - hc *core.HeaderChain - indexerConfig *IndexerConfig - chainDb ethdb.Database - engine consensus.Engine - odr OdrBackend - chainFeed event.Feed - chainSideFeed event.Feed - chainHeadFeed event.Feed - scope event.SubscriptionScope - genesisBlock *types.Block + hc *core.HeaderChain + indexerConfig *IndexerConfig + chainDb ethdb.Database + engine consensus.Engine + odr OdrBackend + chainFeed event.Feed + chainSideFeed event.Feed + chainHeadFeed event.Feed + chain2HeadFeed event.Feed + scope event.SubscriptionScope + genesisBlock *types.Block bodyCache *lru.Cache // Cache for the most recent block bodies bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format @@ -561,6 +562,11 @@ func (lc *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) return lc.scope.Track(new(event.Feed).Subscribe(ch)) } +// SubscribeChain2HeadEvent registers a subscription of Reorg/head/fork events. +func (lc *LightChain) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription { + return lc.scope.Track(lc.chain2HeadFeed.Subscribe(ch)) +} + // DisableCheckFreq disables header validation. This is used for ultralight mode. func (lc *LightChain) DisableCheckFreq() { atomic.StoreInt32(&lc.disableCheckFreq, 1) From 1b9c2ad4199deab6d503c9862e9a7e698e023346 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 22 Dec 2021 12:03:22 +0100 Subject: [PATCH 10/20] Clean ethstats syncer --- command/chain_watch.go | 26 ++++++++++----------- ethstats/ethstats.go | 51 +++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/command/chain_watch.go b/command/chain_watch.go index 8e40631ccdc5..53b76eb86a7d 100644 --- a/command/chain_watch.go +++ b/command/chain_watch.go @@ -35,18 +35,6 @@ func (c *ChainWatchCommand) Synopsis() string { return "Watch the chainHead, reorg and fork events in real-time" } -func printEvent(msg *proto.ChainWatchResponse) string { - var out string - if msg.Type == core.Chain2HeadCanonicalEvent { - out = fmt.Sprintf("Block Added : %v", msg.Newchain) - } else if msg.Type == core.Chain2HeadForkEvent { - out = fmt.Sprintf("New Fork Block : %v", msg.Newchain) - } else if msg.Type == core.Chain2HeadReorgEvent { - out = fmt.Sprintf("Reorg Detected \nAdded : %v \nRemoved : %v", msg.Newchain, msg.Oldchain) - } - return out -} - // Run implements the cli.Command interface func (c *ChainWatchCommand) Run(args []string) int { flags := c.Flags() @@ -82,8 +70,20 @@ func (c *ChainWatchCommand) Run(args []string) int { c.UI.Output(err.Error()) break } - c.UI.Output(printEvent(msg)) + c.UI.Output(formatHeadEvent(msg)) } return 0 } + +func formatHeadEvent(msg *proto.ChainWatchResponse) string { + var out string + if msg.Type == core.Chain2HeadCanonicalEvent { + out = fmt.Sprintf("Block Added : %v", msg.Newchain) + } else if msg.Type == core.Chain2HeadForkEvent { + out = fmt.Sprintf("New Fork Block : %v", msg.Newchain) + } else if msg.Type == core.Chain2HeadReorgEvent { + out = fmt.Sprintf("Reorg Detected \nAdded : %v \nRemoved : %v", msg.Newchain, msg.Oldchain) + } + return out +} diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 2746f5ad947c..c1a5e9cac0d1 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -230,7 +230,7 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, chain2HeadCh chan c quitCh = make(chan struct{}) headCh = make(chan *types.Block, 1) txCh = make(chan struct{}, 1) - head2Ch = make(chan core.Chain2HeadEvent, 1) + head2Ch = make(chan core.Chain2HeadEvent, 100) ) go func() { var lastTx mclock.AbsTime @@ -777,40 +777,45 @@ func (s *Service) reportPending(conn *connWrapper) error { return conn.WriteJSON(report) } -type Chain2HeadStats struct { - NewChain []*blockStats - OldChain []*blockStats - Type string +type blockStub struct { + Hash string `json:"hash"` + Number uint64 `json:"number"` + ParentHash string `json:"parent_hash"` } -// reportChain2Head checks for reorg and sends current head to stats server. -func (s *Service) reportChain2Head(conn *connWrapper, chain2HeadData *core.Chain2HeadEvent) error { +func createStub(b *types.Block) *blockStub { + s := &blockStub{ + Hash: b.Hash().String(), + ParentHash: b.ParentHash().String(), + Number: b.NumberU64(), + } + return s +} - var chain2headStats Chain2HeadStats +type ChainHeadEvent struct { + NewChain []*blockStub `json:"added"` + OldChain []*blockStub `json:"removed"` + Type string `json:"type"` +} - // assemble new chain +// reportChain2Head checks for reorg and sends current head to stats server. +func (s *Service) reportChain2Head(conn *connWrapper, chain2HeadData *core.Chain2HeadEvent) error { + chainHeadEvent := ChainHeadEvent{ + Type: chain2HeadData.Type, + } for _, block := range chain2HeadData.NewChain { - chain2headStats.NewChain = append(chain2headStats.NewChain, s.assembleBlockStats(block)) + chainHeadEvent.NewChain = append(chainHeadEvent.NewChain, createStub(block)) } - - // assemble old chain for _, block := range chain2HeadData.OldChain { - chain2headStats.OldChain = append(chain2headStats.OldChain, s.assembleBlockStats(block)) + chainHeadEvent.OldChain = append(chainHeadEvent.OldChain, createStub(block)) } - chain2headStats.Type = chain2HeadData.Type - - // Assemble the block report and send it to the server - log.Trace("Reorg Detected", "reorg root block number", chain2headStats.NewChain[0].Number, "block hash", chain2headStats.NewChain[0].Hash) - stats := map[string]interface{}{ - "id": s.node, - "reorg root block number": chain2headStats.NewChain[0].Number, - "reorg root block hash": chain2headStats.NewChain[0].Hash, - "details": chain2headStats, + "id": s.node, + "event": chainHeadEvent, } report := map[string][]interface{}{ - "emit": {"Chain2Head", stats}, + "emit": {"headEvent", stats}, } return conn.WriteJSON(report) } From 71bb7157d0f42e586c4c06f91e06fb24628db7f6 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 22 Dec 2021 12:10:32 +0100 Subject: [PATCH 11/20] Move things in lightclient --- light/lightchain.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/light/lightchain.go b/light/lightchain.go index e40ae190bfbf..92fe897d75b1 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -49,17 +49,16 @@ var ( // headers, downloading block bodies and receipts on demand through an ODR // interface. It only does header validation during chain insertion. type LightChain struct { - hc *core.HeaderChain - indexerConfig *IndexerConfig - chainDb ethdb.Database - engine consensus.Engine - odr OdrBackend - chainFeed event.Feed - chainSideFeed event.Feed - chainHeadFeed event.Feed - chain2HeadFeed event.Feed - scope event.SubscriptionScope - genesisBlock *types.Block + hc *core.HeaderChain + indexerConfig *IndexerConfig + chainDb ethdb.Database + engine consensus.Engine + odr OdrBackend + chainFeed event.Feed + chainSideFeed event.Feed + chainHeadFeed event.Feed + scope event.SubscriptionScope + genesisBlock *types.Block bodyCache *lru.Cache // Cache for the most recent block bodies bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format @@ -73,6 +72,9 @@ type LightChain struct { running int32 // whether LightChain is running or stopped procInterrupt int32 // interrupts chain insert disableCheckFreq int32 // disables header verification + + // Bor + chain2HeadFeed event.Feed } // NewLightChain returns a fully initialised light chain using information From bbdd7efcffec4100d0b2b9fc6eaa893be174f911 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Wed, 22 Dec 2021 12:14:14 +0100 Subject: [PATCH 12/20] More cleanup --- ethstats/ethstats.go | 10 ++++------ internal/ethapi/backend.go | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index c1a5e9cac0d1..e699846b7657 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -71,17 +71,15 @@ type backend interface { GetTd(ctx context.Context, hash common.Hash) *big.Int Stats() (pending int, queued int) SyncProgress() ethereum.SyncProgress -} -type extendedBackend interface { - backend + // Bor SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription } // fullNodeBackend encompasses the functionality necessary for a full node // reporting to ethstats type fullNodeBackend interface { - extendedBackend + backend Miner() *miner.Miner BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) CurrentBlock() *types.Block @@ -92,7 +90,7 @@ type fullNodeBackend interface { // chain statistics up to a monitoring server. type Service struct { server *p2p.Server // Peer-to-peer server to retrieve networking infos - backend extendedBackend + backend backend engine consensus.Engine // Consensus engine to retrieve variadic block fields node string // Name of the node to display on the monitoring page @@ -179,7 +177,7 @@ func parseEthstatsURL(url string) (parts []string, err error) { } // New returns a monitoring service ready for stats reporting. -func New(node *node.Node, backend extendedBackend, engine consensus.Engine, url string) error { +func New(node *node.Node, backend backend, engine consensus.Engine, url string) error { parts, err := parseEthstatsURL(url) if err != nil { return err diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index b0b3c88a8b5e..97ce7c24cf68 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -98,7 +98,6 @@ type Backend interface { GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) GetBorBlockTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) - SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription ChainConfig() *params.ChainConfig From 68ea5cd14a8d18ca30d7cb703a55ded23fcf4003 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 19 Jan 2022 12:39:22 +0000 Subject: [PATCH 13/20] minor fixes --- internal/cli/chain_watch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/cli/chain_watch.go b/internal/cli/chain_watch.go index 53b76eb86a7d..9469c1df00ad 100644 --- a/internal/cli/chain_watch.go +++ b/internal/cli/chain_watch.go @@ -1,4 +1,4 @@ -package main +package cli import ( "context" @@ -7,9 +7,9 @@ import ( "os/signal" "syscall" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) // ChainWatchCommand is the command to group the peers commands From 70f9c88a645e45ce71928580702b4f71f110b319 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Thu, 20 Jan 2022 13:31:24 +0000 Subject: [PATCH 14/20] Added Chain2HeadEvent Test --- core/blockchain_bor_test.go | 144 ++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 core/blockchain_bor_test.go diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go new file mode 100644 index 000000000000..c78240b9d865 --- /dev/null +++ b/core/blockchain_bor_test.go @@ -0,0 +1,144 @@ +package core + +import ( + "math/big" + "testing" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/consensus/ethash" + "github.com/ethereum/go-ethereum/core/rawdb" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/params" +) + +func TestChain2HeadEvent(t *testing.T) { + var ( + db = rawdb.NewMemoryDatabase() + key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr1 = crypto.PubkeyToAddress(key1.PublicKey) + gspec = &Genesis{ + Config: params.TestChainConfig, + Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}, + } + genesis = gspec.MustCommit(db) + signer = types.LatestSigner(gspec.Config) + ) + + blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) + defer blockchain.Stop() + + chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {}) + if _, err := blockchain.InsertChain(chain); err != nil { + t.Fatalf("failed to insert chain: %v", err) + } + + replacementBlocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 4, func(i int, gen *BlockGen) { + tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, gen.header.BaseFee, nil), signer, key1) + if i == 2 { + gen.OffsetTime(-9) + } + if err != nil { + t.Fatalf("failed to create tx: %v", err) + } + gen.AddTx(tx) + }) + chain2HeadCh := make(chan Chain2HeadEvent, 64) + blockchain.SubscribeChain2HeadEvent(chain2HeadCh) + if _, err := blockchain.InsertChain(replacementBlocks); err != nil { + t.Fatalf("failed to insert chain: %v", err) + } + + // first two block of the secondary chain are for a brief moment considered + // side chains because up to that point the first one is considered the + // heavier chain. + expectedReorgHashes := map[common.Hash]bool{ + replacementBlocks[0].Hash(): true, + replacementBlocks[1].Hash(): true, + replacementBlocks[2].Hash(): true, + } + + expectedReplacedHashes := map[common.Hash]bool{ + chain[0].Hash(): true, + chain[1].Hash(): true, + chain[2].Hash(): true, + } + + expectedForkHashes := map[common.Hash]bool{ + replacementBlocks[0].Hash(): true, + replacementBlocks[1].Hash(): true, + } + + expectedHeadHashes := map[common.Hash]bool{ + replacementBlocks[3].Hash(): true, + } + i := 0 + + //number of totalEvents are 4 : when the second chain is generated, there are 2 fork events, + //then reorg happens and triggers 1 event, then last head block of Replacement chain triggers 1 event + totalEvents := 4 + + const timeoutDura = 10 * time.Second + timeout := time.NewTimer(timeoutDura) +done: + for { + select { + case ev := <-chain2HeadCh: + if ev.Type == Chain2HeadReorgEvent { + //Reorg Event Sends Chain of Added Blocks in NewChain. So need to check all of them in reorgHashes + for j := 0; j < len(ev.OldChain); j++ { + block := ev.OldChain[j] + if _, ok := expectedReplacedHashes[block.Hash()]; !ok { + t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) + } + + } + //Reorg Event also Sends Chain of Removed Blocks in NewChain. So need to check all of them in replacedHashes + for j := 0; j < len(ev.OldChain); j++ { + block := ev.NewChain[j] + if _, ok := expectedReorgHashes[block.Hash()]; !ok { + t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) + } + + } + + } + + if ev.Type == Chain2HeadForkEvent { + block := ev.NewChain[0] + if _, ok := expectedForkHashes[block.Hash()]; !ok { + t.Errorf("%d: didn't expect %x to be in fork chain", i, block.Hash()) + } + } + + if ev.Type == Chain2HeadCanonicalEvent { + block := ev.NewChain[0] + if _, ok := expectedHeadHashes[block.Hash()]; !ok { + t.Errorf("%d: didn't expect %x to be in head chain", i, block.Hash()) + } + } + + i++ + + if i == (totalEvents) { + timeout.Stop() + + break done + } + timeout.Reset(timeoutDura) + + case <-timeout.C: + t.Fatal("Timeout. Possibly not all blocks were triggered for sideevent") + } + } + + // make sure no more events are fired + select { + case e := <-chain2HeadCh: + t.Errorf("unexpected event fired: %v", e) + case <-time.After(250 * time.Millisecond): + } + +} From 06c9d5cca6617209f783506875fc026e62005bb1 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Thu, 20 Jan 2022 18:23:11 +0100 Subject: [PATCH 15/20] Test each event without for loop --- core/blockchain_bor_test.go | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go index c78240b9d865..9ad2ff4b8484 100644 --- a/core/blockchain_bor_test.go +++ b/core/blockchain_bor_test.go @@ -1,6 +1,7 @@ package core import ( + "fmt" "math/big" "testing" "time" @@ -30,6 +31,9 @@ func TestChain2HeadEvent(t *testing.T) { blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil) defer blockchain.Stop() + chain2HeadCh := make(chan Chain2HeadEvent, 64) + blockchain.SubscribeChain2HeadEvent(chain2HeadCh) + chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {}) if _, err := blockchain.InsertChain(chain); err != nil { t.Fatalf("failed to insert chain: %v", err) @@ -45,12 +49,42 @@ func TestChain2HeadEvent(t *testing.T) { } gen.AddTx(tx) }) - chain2HeadCh := make(chan Chain2HeadEvent, 64) - blockchain.SubscribeChain2HeadEvent(chain2HeadCh) if _, err := blockchain.InsertChain(replacementBlocks); err != nil { t.Fatalf("failed to insert chain: %v", err) } + readEvent := func() *Chain2HeadEvent { + select { + case evnt := <-chain2HeadCh: + return &evnt + case <-time.After(2 * time.Second): + t.Fatal("timeout") + } + return nil + } + + // head event + evnt := readEvent() + fmt.Println(evnt.Type) + + // fork event + evnt = readEvent() + fmt.Println(evnt.Type) + + // fork event + evnt = readEvent() + fmt.Println(evnt.Type) + + // reorg event + evnt = readEvent() + fmt.Println(evnt.Type) + + // head event + evnt = readEvent() + fmt.Println(evnt.Type) + + return + // first two block of the secondary chain are for a brief moment considered // side chains because up to that point the first one is considered the // heavier chain. From 949822c07232f743b70e70f94394d90a1d6993e1 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Jan 2022 06:30:51 +0000 Subject: [PATCH 16/20] some refactor --- core/blockchain_bor_test.go | 82 ++++++++++++------------------------- 1 file changed, 26 insertions(+), 56 deletions(-) diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go index 9ad2ff4b8484..86456d7d075e 100644 --- a/core/blockchain_bor_test.go +++ b/core/blockchain_bor_test.go @@ -1,7 +1,6 @@ package core import ( - "fmt" "math/big" "testing" "time" @@ -49,42 +48,11 @@ func TestChain2HeadEvent(t *testing.T) { } gen.AddTx(tx) }) + if _, err := blockchain.InsertChain(replacementBlocks); err != nil { t.Fatalf("failed to insert chain: %v", err) } - readEvent := func() *Chain2HeadEvent { - select { - case evnt := <-chain2HeadCh: - return &evnt - case <-time.After(2 * time.Second): - t.Fatal("timeout") - } - return nil - } - - // head event - evnt := readEvent() - fmt.Println(evnt.Type) - - // fork event - evnt = readEvent() - fmt.Println(evnt.Type) - - // fork event - evnt = readEvent() - fmt.Println(evnt.Type) - - // reorg event - evnt = readEvent() - fmt.Println(evnt.Type) - - // head event - evnt = readEvent() - fmt.Println(evnt.Type) - - return - // first two block of the secondary chain are for a brief moment considered // side chains because up to that point the first one is considered the // heavier chain. @@ -106,23 +74,22 @@ func TestChain2HeadEvent(t *testing.T) { } expectedHeadHashes := map[common.Hash]bool{ + chain[2].Hash(): true, replacementBlocks[3].Hash(): true, } + i := 0 - //number of totalEvents are 4 : when the second chain is generated, there are 2 fork events, - //then reorg happens and triggers 1 event, then last head block of Replacement chain triggers 1 event - totalEvents := 4 + tot := 0 - const timeoutDura = 10 * time.Second - timeout := time.NewTimer(timeoutDura) -done: - for { + readEvent := func() *Chain2HeadEvent { select { case ev := <-chain2HeadCh: + i++ if ev.Type == Chain2HeadReorgEvent { //Reorg Event Sends Chain of Added Blocks in NewChain. So need to check all of them in reorgHashes for j := 0; j < len(ev.OldChain); j++ { + tot++ block := ev.OldChain[j] if _, ok := expectedReplacedHashes[block.Hash()]; !ok { t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) @@ -131,6 +98,7 @@ done: } //Reorg Event also Sends Chain of Removed Blocks in NewChain. So need to check all of them in replacedHashes for j := 0; j < len(ev.OldChain); j++ { + tot++ block := ev.NewChain[j] if _, ok := expectedReorgHashes[block.Hash()]; !ok { t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) @@ -141,6 +109,7 @@ done: } if ev.Type == Chain2HeadForkEvent { + tot++ block := ev.NewChain[0] if _, ok := expectedForkHashes[block.Hash()]; !ok { t.Errorf("%d: didn't expect %x to be in fork chain", i, block.Hash()) @@ -148,31 +117,32 @@ done: } if ev.Type == Chain2HeadCanonicalEvent { + tot++ block := ev.NewChain[0] if _, ok := expectedHeadHashes[block.Hash()]; !ok { t.Errorf("%d: didn't expect %x to be in head chain", i, block.Hash()) } } - i++ + return nil + case <-time.After(2 * time.Second): + t.Fatal("timeout") + } + return nil + } - if i == (totalEvents) { - timeout.Stop() + // head event + readEvent() - break done - } - timeout.Reset(timeoutDura) + // fork event + readEvent() - case <-timeout.C: - t.Fatal("Timeout. Possibly not all blocks were triggered for sideevent") - } - } + // fork event + readEvent() - // make sure no more events are fired - select { - case e := <-chain2HeadCh: - t.Errorf("unexpected event fired: %v", e) - case <-time.After(250 * time.Millisecond): - } + // reorg event + readEvent() + // head event + readEvent() } From 8f7174fb92daec6c711e38a97b5798237fe616c3 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Jan 2022 08:14:40 +0000 Subject: [PATCH 17/20] Refactor Code --- core/blockchain_bor_test.go | 119 ++++++++++++++---------------------- 1 file changed, 47 insertions(+), 72 deletions(-) diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go index 86456d7d075e..5134d3b22d49 100644 --- a/core/blockchain_bor_test.go +++ b/core/blockchain_bor_test.go @@ -53,78 +53,12 @@ func TestChain2HeadEvent(t *testing.T) { t.Fatalf("failed to insert chain: %v", err) } - // first two block of the secondary chain are for a brief moment considered - // side chains because up to that point the first one is considered the - // heavier chain. - expectedReorgHashes := map[common.Hash]bool{ - replacementBlocks[0].Hash(): true, - replacementBlocks[1].Hash(): true, - replacementBlocks[2].Hash(): true, - } - - expectedReplacedHashes := map[common.Hash]bool{ - chain[0].Hash(): true, - chain[1].Hash(): true, - chain[2].Hash(): true, - } - - expectedForkHashes := map[common.Hash]bool{ - replacementBlocks[0].Hash(): true, - replacementBlocks[1].Hash(): true, - } - - expectedHeadHashes := map[common.Hash]bool{ - chain[2].Hash(): true, - replacementBlocks[3].Hash(): true, - } - i := 0 - - tot := 0 - readEvent := func() *Chain2HeadEvent { select { case ev := <-chain2HeadCh: i++ - if ev.Type == Chain2HeadReorgEvent { - //Reorg Event Sends Chain of Added Blocks in NewChain. So need to check all of them in reorgHashes - for j := 0; j < len(ev.OldChain); j++ { - tot++ - block := ev.OldChain[j] - if _, ok := expectedReplacedHashes[block.Hash()]; !ok { - t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) - } - - } - //Reorg Event also Sends Chain of Removed Blocks in NewChain. So need to check all of them in replacedHashes - for j := 0; j < len(ev.OldChain); j++ { - tot++ - block := ev.NewChain[j] - if _, ok := expectedReorgHashes[block.Hash()]; !ok { - t.Errorf("%d: didn't expect %x to be in side chain", i, block.Hash()) - } - - } - - } - - if ev.Type == Chain2HeadForkEvent { - tot++ - block := ev.NewChain[0] - if _, ok := expectedForkHashes[block.Hash()]; !ok { - t.Errorf("%d: didn't expect %x to be in fork chain", i, block.Hash()) - } - } - - if ev.Type == Chain2HeadCanonicalEvent { - tot++ - block := ev.NewChain[0] - if _, ok := expectedHeadHashes[block.Hash()]; !ok { - t.Errorf("%d: didn't expect %x to be in head chain", i, block.Hash()) - } - } - - return nil + return &ev case <-time.After(2 * time.Second): t.Fatal("timeout") } @@ -132,17 +66,58 @@ func TestChain2HeadEvent(t *testing.T) { } // head event - readEvent() + event1 := readEvent() + if event1.Type != Chain2HeadCanonicalEvent { + t.Fatal("it should be type head") + } + if event1.NewChain[0].Hash() != chain[2].Hash() { + t.Fatalf("%d : Hash Does Not Match", i) + } // fork event - readEvent() + event2 := readEvent() + if event2.Type != Chain2HeadForkEvent { + t.Fatal("it should be type fork") + } + if event2.NewChain[0].Hash() != replacementBlocks[0].Hash() { + t.Fatalf("%d : Hash Does Not Match", i) + } // fork event - readEvent() + event3 := readEvent() + if event3.Type != Chain2HeadForkEvent { + t.Fatal("it should be type fork") + } + if event3.NewChain[0].Hash() != replacementBlocks[1].Hash() { + t.Fatalf("%d : Hash Does Not Match", i) + } // reorg event - readEvent() + //In this event the channel recieves an array of Blocks in NewChain and OldChain + expectedOldChainHashes := [3]common.Hash{0: chain[2].Hash(), 1: chain[1].Hash(), 2: chain[0].Hash()} + expectedNewChainHashes := [3]common.Hash{0: replacementBlocks[2].Hash(), 1: replacementBlocks[1].Hash(), 2: replacementBlocks[0].Hash()} + + event4 := readEvent() + if event4.Type != Chain2HeadReorgEvent { + t.Fatal("it should be type reorg") + } + for j := 0; j < len(event4.OldChain); j++ { + if event4.OldChain[j].Hash() != expectedOldChainHashes[j] { + t.Fatalf("%d : Oldchain hashes Does Not Match", i) + } + } + for j := 0; j < len(event4.NewChain); j++ { + if event4.NewChain[j].Hash() != expectedNewChainHashes[j] { + t.Fatalf("%d : Newchain hashes Does Not Match", i) + } + } // head event - readEvent() + event5 := readEvent() + if event5.Type != Chain2HeadCanonicalEvent { + t.Fatal("it should be type head") + } + if event5.NewChain[0].Hash() != replacementBlocks[3].Hash() { + t.Fatalf("%d : Hash Does Not Match", i) + } } From 2d4ef6784975566c0fca0824233dc1a9da07817b Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Jan 2022 09:49:01 +0000 Subject: [PATCH 18/20] Streamlined code --- core/blockchain_bor_test.go | 103 +++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go index 5134d3b22d49..4e6833ecd3f2 100644 --- a/core/blockchain_bor_test.go +++ b/core/blockchain_bor_test.go @@ -53,71 +53,78 @@ func TestChain2HeadEvent(t *testing.T) { t.Fatalf("failed to insert chain: %v", err) } + type eventTest struct { + Type string + Added []common.Hash + Removed []common.Hash + } + + // To use in fatal log, indicates the readEvent which failed the test. i := 0 - readEvent := func() *Chain2HeadEvent { + + readEvent := func(expect *eventTest) { select { case ev := <-chain2HeadCh: i++ - return &ev + if ev.Type != expect.Type { + t.Fatalf("%d : type mismatch", i) + } + for j := 0; j < len(ev.OldChain); j++ { + if ev.OldChain[j].Hash() != expect.Removed[j] { + t.Fatalf("%d : Oldchain hashes Does Not Match", i) + } + } + for j := 0; j < len(ev.NewChain); j++ { + if ev.NewChain[j].Hash() != expect.Added[j] { + t.Fatalf("%d : Newchain hashes Does Not Match", i) + } + } case <-time.After(2 * time.Second): t.Fatal("timeout") } - return nil } // head event - event1 := readEvent() - if event1.Type != Chain2HeadCanonicalEvent { - t.Fatal("it should be type head") - } - if event1.NewChain[0].Hash() != chain[2].Hash() { - t.Fatalf("%d : Hash Does Not Match", i) - } + readEvent(&eventTest{ + Type: Chain2HeadCanonicalEvent, + Added: []common.Hash{ + chain[2].Hash(), + }}) // fork event - event2 := readEvent() - if event2.Type != Chain2HeadForkEvent { - t.Fatal("it should be type fork") - } - if event2.NewChain[0].Hash() != replacementBlocks[0].Hash() { - t.Fatalf("%d : Hash Does Not Match", i) - } + readEvent(&eventTest{ + Type: Chain2HeadForkEvent, + Added: []common.Hash{ + replacementBlocks[0].Hash(), + }}) // fork event - event3 := readEvent() - if event3.Type != Chain2HeadForkEvent { - t.Fatal("it should be type fork") - } - if event3.NewChain[0].Hash() != replacementBlocks[1].Hash() { - t.Fatalf("%d : Hash Does Not Match", i) - } + readEvent(&eventTest{ + Type: Chain2HeadForkEvent, + Added: []common.Hash{ + replacementBlocks[1].Hash(), + }}) // reorg event //In this event the channel recieves an array of Blocks in NewChain and OldChain - expectedOldChainHashes := [3]common.Hash{0: chain[2].Hash(), 1: chain[1].Hash(), 2: chain[0].Hash()} - expectedNewChainHashes := [3]common.Hash{0: replacementBlocks[2].Hash(), 1: replacementBlocks[1].Hash(), 2: replacementBlocks[0].Hash()} - - event4 := readEvent() - if event4.Type != Chain2HeadReorgEvent { - t.Fatal("it should be type reorg") - } - for j := 0; j < len(event4.OldChain); j++ { - if event4.OldChain[j].Hash() != expectedOldChainHashes[j] { - t.Fatalf("%d : Oldchain hashes Does Not Match", i) - } - } - for j := 0; j < len(event4.NewChain); j++ { - if event4.NewChain[j].Hash() != expectedNewChainHashes[j] { - t.Fatalf("%d : Newchain hashes Does Not Match", i) - } - } + readEvent(&eventTest{ + Type: Chain2HeadReorgEvent, + Added: []common.Hash{ + replacementBlocks[2].Hash(), + replacementBlocks[1].Hash(), + replacementBlocks[0].Hash(), + }, + Removed: []common.Hash{ + chain[2].Hash(), + chain[1].Hash(), + chain[0].Hash(), + }, + }) // head event - event5 := readEvent() - if event5.Type != Chain2HeadCanonicalEvent { - t.Fatal("it should be type head") - } - if event5.NewChain[0].Hash() != replacementBlocks[3].Hash() { - t.Fatalf("%d : Hash Does Not Match", i) - } + readEvent(&eventTest{ + Type: Chain2HeadCanonicalEvent, + Added: []common.Hash{ + replacementBlocks[3].Hash(), + }}) } From 904f8b52ce8020a091fcece883428eac8c629f1b Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Jan 2022 12:54:49 +0000 Subject: [PATCH 19/20] Minor changes --- core/blockchain_bor_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go index 4e6833ecd3f2..a30627675d56 100644 --- a/core/blockchain_bor_test.go +++ b/core/blockchain_bor_test.go @@ -69,6 +69,14 @@ func TestChain2HeadEvent(t *testing.T) { if ev.Type != expect.Type { t.Fatalf("%d : type mismatch", i) } + + if len(ev.NewChain) != len(expect.Added) { + t.Fatalf("%d : Newchain and Added Array Size don't match", i) + } + if len(ev.OldChain) != len(expect.Removed) { + t.Fatalf("%d : Oldchain and Removed Array Size don't match", i) + } + for j := 0; j < len(ev.OldChain); j++ { if ev.OldChain[j].Hash() != expect.Removed[j] { t.Fatalf("%d : Oldchain hashes Does Not Match", i) From 58e4311e632d09b16e2fac8daa2871b90984b458 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Fri, 21 Jan 2022 13:03:02 +0000 Subject: [PATCH 20/20] Minor change --- core/blockchain_bor_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/blockchain_bor_test.go b/core/blockchain_bor_test.go index a30627675d56..52f4f7cd8325 100644 --- a/core/blockchain_bor_test.go +++ b/core/blockchain_bor_test.go @@ -59,32 +59,28 @@ func TestChain2HeadEvent(t *testing.T) { Removed []common.Hash } - // To use in fatal log, indicates the readEvent which failed the test. - i := 0 - readEvent := func(expect *eventTest) { select { case ev := <-chain2HeadCh: - i++ if ev.Type != expect.Type { - t.Fatalf("%d : type mismatch", i) + t.Fatal("Type mismatch") } if len(ev.NewChain) != len(expect.Added) { - t.Fatalf("%d : Newchain and Added Array Size don't match", i) + t.Fatal("Newchain and Added Array Size don't match") } if len(ev.OldChain) != len(expect.Removed) { - t.Fatalf("%d : Oldchain and Removed Array Size don't match", i) + t.Fatal("Oldchain and Removed Array Size don't match") } for j := 0; j < len(ev.OldChain); j++ { if ev.OldChain[j].Hash() != expect.Removed[j] { - t.Fatalf("%d : Oldchain hashes Does Not Match", i) + t.Fatal("Oldchain hashes Do Not Match") } } for j := 0; j < len(ev.NewChain); j++ { if ev.NewChain[j].Hash() != expect.Added[j] { - t.Fatalf("%d : Newchain hashes Does Not Match", i) + t.Fatal("Newchain hashes Do Not Match") } } case <-time.After(2 * time.Second):