diff --git a/command/chain.go b/command/chain.go new file mode 100644 index 000000000000..ed8ca9a5f868 --- /dev/null +++ b/command/chain.go @@ -0,0 +1,31 @@ +package main + +import ( + "github.com/mitchellh/cli" +) + +// ChainCommand is the command to group the peers commands +type ChainCommand struct { + UI cli.Ui +} + +// Help implements the cli.Command interface +func (c *ChainCommand) Help() string { + return `Usage: bor chain + + This command groups actions to interact with the chain. + + Set the new head of the chain: + + $ bor chain sethead ` +} + +// Synopsis implements the cli.Command interface +func (c *ChainCommand) Synopsis() string { + return "Interact with the chain" +} + +// Run implements the cli.Command interface +func (c *ChainCommand) Run(args []string) int { + return cli.RunResultHelp +} diff --git a/command/chain_sethead.go b/command/chain_sethead.go new file mode 100644 index 000000000000..0dfed6268bed --- /dev/null +++ b/command/chain_sethead.go @@ -0,0 +1,91 @@ +package main + +import ( + "context" + "fmt" + "strconv" + + "github.com/ethereum/go-ethereum/command/flagset" + "github.com/ethereum/go-ethereum/command/server/proto" +) + +// ChainSetHeadCommand is the command to group the peers commands +type ChainSetHeadCommand struct { + *Meta2 + + yes bool +} + +// Help implements the cli.Command interface +func (c *ChainSetHeadCommand) Help() string { + return `Usage: bor chain sethead [--yes] + + This command sets the current chain to a certain block` +} + +func (c *ChainSetHeadCommand) Flags() *flagset.Flagset { + flags := c.NewFlagSet("chain sethead") + + flags.BoolFlag(&flagset.BoolFlag{ + Name: "yes", + Usage: "Force set head", + Default: false, + Value: &c.yes, + }) + return flags +} + +// Synopsis implements the cli.Command interface +func (c *ChainSetHeadCommand) Synopsis() string { + return "Set the new head of the chain" +} + +// Run implements the cli.Command interface +func (c *ChainSetHeadCommand) Run(args []string) int { + flags := c.Flags() + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + args = flags.Args() + if len(args) != 1 { + c.UI.Error("No number provided") + return 1 + } + + borClt, err := c.BorConn() + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + arg := args[0] + fmt.Println(arg) + + number, err := strconv.Atoi(arg) + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + if !c.yes { + response, err := c.UI.Ask("Are you sure you want to reset the database? (y/n)") + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + if response != "y" { + c.UI.Output("set head aborted") + return 0 + } + } + + if _, err := borClt.ChainSetHead(context.Background(), &proto.ChainSetHeadRequest{Number: uint64(number)}); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + c.UI.Output("Done!") + return 0 +} diff --git a/command/main.go b/command/main.go index fab6f55cedbd..7b276e703bb8 100644 --- a/command/main.go +++ b/command/main.go @@ -64,6 +64,16 @@ func commands() map[string]cli.CommandFactory { Meta2: meta2, }, nil }, + "chain": func() (cli.Command, error) { + return &ChainCommand{ + UI: ui, + }, nil + }, + "chain sethead": func() (cli.Command, error) { + return &ChainSetHeadCommand{ + Meta2: meta2, + }, nil + }, "account": func() (cli.Command, error) { return &Account{ UI: ui, diff --git a/command/server/proto/server.pb.go b/command/server/proto/server.pb.go index a6c13fc7d32d..ab6c06662b9b 100644 --- a/command/server/proto/server.pb.go +++ b/command/server/proto/server.pb.go @@ -71,7 +71,7 @@ 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{9, 0} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{11, 0} } type PeersAddRequest struct { @@ -534,6 +534,91 @@ func (x *Peer) GetStatic() bool { return false } +type ChainSetHeadRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Number uint64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` +} + +func (x *ChainSetHeadRequest) Reset() { + *x = ChainSetHeadRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChainSetHeadRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChainSetHeadRequest) ProtoMessage() {} + +func (x *ChainSetHeadRequest) ProtoReflect() protoreflect.Message { + 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 { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChainSetHeadRequest.ProtoReflect.Descriptor instead. +func (*ChainSetHeadRequest) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{9} +} + +func (x *ChainSetHeadRequest) GetNumber() uint64 { + if x != nil { + return x.Number + } + return 0 +} + +type ChainSetHeadResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ChainSetHeadResponse) Reset() { + *x = ChainSetHeadResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_command_server_proto_server_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ChainSetHeadResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChainSetHeadResponse) ProtoMessage() {} + +func (x *ChainSetHeadResponse) ProtoReflect() protoreflect.Message { + 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 { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChainSetHeadResponse.ProtoReflect.Descriptor instead. +func (*ChainSetHeadResponse) Descriptor() ([]byte, []int) { + return file_command_server_proto_server_proto_rawDescGZIP(), []int{10} +} + type PprofRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -547,7 +632,7 @@ type PprofRequest struct { func (x *PprofRequest) Reset() { *x = PprofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[9] + mi := &file_command_server_proto_server_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -560,7 +645,7 @@ func (x *PprofRequest) String() string { func (*PprofRequest) ProtoMessage() {} func (x *PprofRequest) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[9] + 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 { @@ -573,7 +658,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{9} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{11} } func (x *PprofRequest) GetType() PprofRequest_Type { @@ -609,7 +694,7 @@ type PprofResponse struct { func (x *PprofResponse) Reset() { *x = PprofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_command_server_proto_server_proto_msgTypes[10] + mi := &file_command_server_proto_server_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -622,7 +707,7 @@ func (x *PprofResponse) String() string { func (*PprofResponse) ProtoMessage() {} func (x *PprofResponse) ProtoReflect() protoreflect.Message { - mi := &file_command_server_proto_server_proto_msgTypes[10] + 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 { @@ -635,7 +720,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{10} + return file_command_server_proto_server_proto_rawDescGZIP(), []int{12} } func (x *PprofResponse) GetPayload() string { @@ -689,47 +774,56 @@ var file_command_server_proto_server_proto_rawDesc = []byte{ 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, 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, 0xc2, 0x02, 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, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x17, + 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, 0x8b, 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, 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, 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, } @@ -747,39 +841,43 @@ 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, 12) +var file_command_server_proto_server_proto_msgTypes = make([]protoimpl.MessageInfo, 14) 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 - (*PprofRequest)(nil), // 10: proto.PprofRequest - (*PprofResponse)(nil), // 11: proto.PprofResponse - nil, // 12: proto.PprofResponse.HeadersEntry + (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 } 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 - 12, // 3: proto.PprofResponse.headers:type_name -> proto.PprofResponse.HeadersEntry - 10, // 4: proto.Bor.Pprof:input_type -> proto.PprofRequest + 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 - 11, // 9: proto.Bor.Pprof:output_type -> proto.PprofResponse - 2, // 10: proto.Bor.PeersAdd:output_type -> proto.PeersAddResponse - 4, // 11: proto.Bor.PeersRemove:output_type -> proto.PeersRemoveResponse - 6, // 12: proto.Bor.PeersList:output_type -> proto.PeersListResponse - 8, // 13: proto.Bor.PeersStatus:output_type -> proto.PeersStatusResponse - 9, // [9:14] is the sub-list for method output_type - 4, // [4:9] is the sub-list for method input_type + 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 @@ -900,7 +998,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.(*PprofRequest); i { + switch v := v.(*ChainSetHeadRequest); i { case 0: return &v.state case 1: @@ -912,6 +1010,30 @@ 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 { + 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[11].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[12].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PprofResponse); i { case 0: return &v.state @@ -930,7 +1052,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: 12, + NumMessages: 14, NumExtensions: 0, NumServices: 1, }, diff --git a/command/server/proto/server.proto b/command/server/proto/server.proto index 0d1de7bef61a..535aa3f36952 100644 --- a/command/server/proto/server.proto +++ b/command/server/proto/server.proto @@ -14,6 +14,8 @@ service Bor { rpc PeersList(PeersListRequest) returns (PeersListResponse); rpc PeersStatus(PeersStatusRequest) returns (PeersStatusResponse); + + rpc ChainSetHead(ChainSetHeadRequest) returns (ChainSetHeadResponse); } @@ -58,6 +60,13 @@ message Peer { bool static = 7; } +message ChainSetHeadRequest { + uint64 number = 1; +} + +message ChainSetHeadResponse { +} + message PprofRequest { Type type = 1; diff --git a/command/server/proto/server_grpc.pb.go b/command/server/proto/server_grpc.pb.go index 109911e95811..369419b66fc2 100644 --- a/command/server/proto/server_grpc.pb.go +++ b/command/server/proto/server_grpc.pb.go @@ -23,6 +23,7 @@ type BorClient interface { PeersRemove(ctx context.Context, in *PeersRemoveRequest, opts ...grpc.CallOption) (*PeersRemoveResponse, error) 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) } type borClient struct { @@ -78,6 +79,15 @@ func (c *borClient) PeersStatus(ctx context.Context, in *PeersStatusRequest, opt return out, nil } +func (c *borClient) ChainSetHead(ctx context.Context, in *ChainSetHeadRequest, opts ...grpc.CallOption) (*ChainSetHeadResponse, error) { + out := new(ChainSetHeadResponse) + err := c.cc.Invoke(ctx, "/proto.Bor/ChainSetHead", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // BorServer is the server API for Bor service. // All implementations must embed UnimplementedBorServer // for forward compatibility @@ -87,6 +97,7 @@ type BorServer interface { PeersRemove(context.Context, *PeersRemoveRequest) (*PeersRemoveResponse, error) PeersList(context.Context, *PeersListRequest) (*PeersListResponse, error) PeersStatus(context.Context, *PeersStatusRequest) (*PeersStatusResponse, error) + ChainSetHead(context.Context, *ChainSetHeadRequest) (*ChainSetHeadResponse, error) mustEmbedUnimplementedBorServer() } @@ -109,6 +120,9 @@ func (UnimplementedBorServer) PeersList(context.Context, *PeersListRequest) (*Pe func (UnimplementedBorServer) PeersStatus(context.Context, *PeersStatusRequest) (*PeersStatusResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method PeersStatus not implemented") } +func (UnimplementedBorServer) ChainSetHead(context.Context, *ChainSetHeadRequest) (*ChainSetHeadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ChainSetHead not implemented") +} func (UnimplementedBorServer) mustEmbedUnimplementedBorServer() {} // UnsafeBorServer may be embedded to opt out of forward compatibility for this service. @@ -212,6 +226,24 @@ func _Bor_PeersStatus_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Bor_ChainSetHead_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ChainSetHeadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BorServer).ChainSetHead(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Bor/ChainSetHead", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BorServer).ChainSetHead(ctx, req.(*ChainSetHeadRequest)) + } + return interceptor(ctx, in, info, handler) +} + // 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) @@ -239,6 +271,10 @@ var Bor_ServiceDesc = grpc.ServiceDesc{ MethodName: "PeersStatus", Handler: _Bor_PeersStatus_Handler, }, + { + MethodName: "ChainSetHead", + Handler: _Bor_ChainSetHead_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "command/server/proto/server.proto", diff --git a/command/server/server.go b/command/server/server.go index 437a39b90631..0b3e90365bd9 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -27,6 +27,7 @@ import ( type Server struct { proto.UnimplementedBorServer node *node.Node + backend *eth.Ethereum grpcServer *grpc.Server } @@ -65,6 +66,7 @@ func NewServer(config *Config) (*Server, error) { if err != nil { return nil, err } + srv.backend = backend // debug tracing is enabled by default stack.RegisterAPIs(tracers.APIs(backend.APIBackend)) diff --git a/command/server/service.go b/command/server/service.go index 3b8b4d19e806..0c6c23b6bf51 100644 --- a/command/server/service.go +++ b/command/server/service.go @@ -102,3 +102,8 @@ func peerInfoToPeer(info *p2p.PeerInfo) *proto.Peer { Static: info.Network.Static, } } + +func (s *Server) ChainSetHead(ctx context.Context, req *proto.ChainSetHeadRequest) (*proto.ChainSetHeadResponse, error) { + s.backend.APIBackend.SetHead(req.Number) + return &proto.ChainSetHeadResponse{}, nil +}