From f3d3a5f6833c617d5c1a1bee4bdfe042210376fb Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:24:49 -0400 Subject: [PATCH 1/5] Broadcast vote power. --- api/proto/message/harmonymessage.pb.go | 410 ++++++++++++++++--------- api/proto/message/harmonymessage.proto | 10 + consensus/consensus.go | 15 + consensus/consensus_service.go | 47 +++ consensus/consensus_v2.go | 11 + consensus/fbft_log.go | 1 + hmy/hmy.go | 1 - node/harmony/api.go | 37 +-- node/harmony/node.go | 24 +- rpc/harmony/private_debug.go | 7 - 10 files changed, 373 insertions(+), 190 deletions(-) diff --git a/api/proto/message/harmonymessage.pb.go b/api/proto/message/harmonymessage.pb.go index 314403ccbf..f23cec0de2 100644 --- a/api/proto/message/harmonymessage.pb.go +++ b/api/proto/message/harmonymessage.pb.go @@ -94,6 +94,7 @@ const ( MessageType_DRAND_COMMIT MessageType = 11 // Deprecated: Marked as deprecated in harmonymessage.proto. MessageType_LOTTERY_REQUEST MessageType = 12 // it should be either ENTER or GETPLAYERS but it will be removed later. + MessageType_LAST_SIGN_POWER MessageType = 13 ) // Enum value maps for MessageType. @@ -110,6 +111,7 @@ var ( 10: "DRAND_INIT", 11: "DRAND_COMMIT", 12: "LOTTERY_REQUEST", + 13: "LAST_SIGN_POWER", } MessageType_value = map[string]int32{ "NEWNODE_BEACON_STAKING": 0, @@ -123,6 +125,7 @@ var ( "DRAND_INIT": 10, "DRAND_COMMIT": 11, "LOTTERY_REQUEST": 12, + "LAST_SIGN_POWER": 13, } ) @@ -225,6 +228,7 @@ type Message struct { // *Message_Drand // *Message_Viewchange // *Message_LotteryRequest + // *Message_LastSignPower Request isMessage_Request `protobuf_oneof:"request"` } @@ -326,6 +330,13 @@ func (x *Message) GetLotteryRequest() *LotteryRequest { return nil } +func (x *Message) GetLastSignPower() *LastSignPowerBroadcast { + if x, ok := x.GetRequest().(*Message_LastSignPower); ok { + return x.LastSignPower + } + return nil +} + type isMessage_Request interface { isMessage_Request() } @@ -355,6 +366,10 @@ type Message_LotteryRequest struct { LotteryRequest *LotteryRequest `protobuf:"bytes,8,opt,name=lottery_request,json=lotteryRequest,proto3,oneof"` } +type Message_LastSignPower struct { + LastSignPower *LastSignPowerBroadcast `protobuf:"bytes,9,opt,name=last_sign_power,json=lastSignPower,proto3,oneof"` +} + func (*Message_Staking) isMessage_Request() {} func (*Message_Consensus) isMessage_Request() {} @@ -365,6 +380,8 @@ func (*Message_Viewchange) isMessage_Request() {} func (*Message_LotteryRequest) isMessage_Request() {} +func (*Message_LastSignPower) isMessage_Request() {} + type Response struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -965,12 +982,91 @@ func (x *ViewChangeRequest) GetPreparedBlock() []byte { return nil } +type LastSignPowerBroadcast struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Prepare int64 `protobuf:"varint,1,opt,name=prepare,proto3" json:"prepare,omitempty"` + Commit int64 `protobuf:"varint,2,opt,name=commit,proto3" json:"commit,omitempty"` + Change int64 `protobuf:"varint,3,opt,name=change,proto3" json:"change,omitempty"` + SenderPubkey []byte `protobuf:"bytes,4,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"` + ShardId uint32 `protobuf:"varint,5,opt,name=shard_id,json=shardId,proto3" json:"shard_id,omitempty"` +} + +func (x *LastSignPowerBroadcast) Reset() { + *x = LastSignPowerBroadcast{} + if protoimpl.UnsafeEnabled { + mi := &file_harmonymessage_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LastSignPowerBroadcast) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LastSignPowerBroadcast) ProtoMessage() {} + +func (x *LastSignPowerBroadcast) ProtoReflect() protoreflect.Message { + mi := &file_harmonymessage_proto_msgTypes[8] + 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 LastSignPowerBroadcast.ProtoReflect.Descriptor instead. +func (*LastSignPowerBroadcast) Descriptor() ([]byte, []int) { + return file_harmonymessage_proto_rawDescGZIP(), []int{8} +} + +func (x *LastSignPowerBroadcast) GetPrepare() int64 { + if x != nil { + return x.Prepare + } + return 0 +} + +func (x *LastSignPowerBroadcast) GetCommit() int64 { + if x != nil { + return x.Commit + } + return 0 +} + +func (x *LastSignPowerBroadcast) GetChange() int64 { + if x != nil { + return x.Change + } + return 0 +} + +func (x *LastSignPowerBroadcast) GetSenderPubkey() []byte { + if x != nil { + return x.SenderPubkey + } + return nil +} + +func (x *LastSignPowerBroadcast) GetShardId() uint32 { + if x != nil { + return x.ShardId + } + return 0 +} + var File_harmonymessage_proto protoreflect.FileDescriptor var file_harmonymessage_proto_rawDesc = []byte{ 0x0a, 0x14, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xf3, 0x03, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xc5, 0x04, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, @@ -1001,123 +1097,140 @@ var file_harmonymessage_proto_rawDesc = []byte{ 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x42, 0x02, 0x18, 0x01, 0x48, 0x00, 0x52, 0x0e, 0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x42, 0x09, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xd9, 0x01, 0x0a, - 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x73, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x1b, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0b, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x74, 0x79, 0x70, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, - 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x50, 0x0a, 0x10, 0x6c, 0x6f, - 0x74, 0x74, 0x65, 0x72, 0x79, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x02, 0x18, 0x01, 0x48, 0x00, 0x52, 0x0f, 0x6c, 0x6f, 0x74, - 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0a, 0x0a, 0x08, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x4f, 0x0a, 0x0f, 0x4c, 0x6f, 0x74, 0x74, - 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x07, 0x70, - 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, - 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x1e, 0x0a, 0x08, 0x62, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, - 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x22, 0xca, 0x01, 0x0a, 0x0e, 0x4c, 0x6f, - 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x3b, 0x0a, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x68, 0x61, 0x72, - 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x6f, 0x74, 0x74, - 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x42, - 0x02, 0x18, 0x01, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0b, 0x70, 0x72, 0x69, - 0x76, 0x61, 0x74, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, - 0x18, 0x01, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x1a, - 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x42, 0x02, - 0x18, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x0a, 0x04, 0x54, 0x79, - 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x05, 0x45, 0x4e, 0x54, 0x45, 0x52, 0x10, 0x00, 0x1a, 0x02, 0x08, - 0x01, 0x12, 0x0e, 0x0a, 0x06, 0x52, 0x45, 0x53, 0x55, 0x4c, 0x54, 0x10, 0x01, 0x1a, 0x02, 0x08, - 0x01, 0x12, 0x13, 0x0a, 0x0b, 0x50, 0x49, 0x43, 0x4b, 0x5f, 0x57, 0x49, 0x4e, 0x4e, 0x45, 0x52, - 0x10, 0x02, 0x1a, 0x02, 0x08, 0x01, 0x22, 0x53, 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, - 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x6e, - 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x02, 0x18, - 0x01, 0x52, 0x0b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1b, - 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, - 0x02, 0x18, 0x01, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x22, 0x89, 0x02, 0x0a, 0x10, - 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x17, 0x0a, 0x07, 0x76, 0x69, 0x65, 0x77, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x06, 0x76, 0x69, 0x65, 0x77, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x68, 0x61, 0x72, 0x64, 0x5f, - 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x73, 0x68, 0x61, 0x72, 0x64, 0x49, - 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, - 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, - 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x73, - 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x70, - 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, - 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f, - 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x18, 0x08, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x12, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, - 0x79, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x22, 0x97, 0x01, 0x0a, 0x0c, 0x44, 0x72, 0x61, 0x6e, - 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x08, 0x73, 0x68, 0x61, 0x72, - 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x42, 0x02, 0x18, 0x01, 0x52, 0x07, - 0x73, 0x68, 0x61, 0x72, 0x64, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0d, 0x73, 0x65, 0x6e, 0x64, 0x65, - 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x02, - 0x18, 0x01, 0x52, 0x0c, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, - 0x12, 0x21, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0c, 0x42, 0x02, 0x18, 0x01, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, - 0x61, 0x73, 0x68, 0x12, 0x1c, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0c, 0x42, 0x02, 0x18, 0x01, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, - 0x64, 0x22, 0xad, 0x03, 0x0a, 0x11, 0x56, 0x69, 0x65, 0x77, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x76, 0x69, 0x65, 0x77, 0x5f, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x76, 0x69, 0x65, 0x77, 0x49, 0x64, - 0x12, 0x1b, 0x0a, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x08, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x12, 0x19, 0x0a, - 0x08, 0x73, 0x68, 0x61, 0x72, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x07, 0x73, 0x68, 0x61, 0x72, 0x64, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x65, 0x6e, 0x64, + 0x74, 0x12, 0x50, 0x0a, 0x0f, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x5f, 0x70, + 0x6f, 0x77, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x68, 0x61, 0x72, + 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x61, 0x73, 0x74, + 0x53, 0x69, 0x67, 0x6e, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, + 0x73, 0x74, 0x48, 0x00, 0x52, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x53, 0x69, 0x67, 0x6e, 0x50, 0x6f, + 0x77, 0x65, 0x72, 0x42, 0x09, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xd9, + 0x01, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x1b, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0b, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2f, 0x0a, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x68, 0x61, 0x72, 0x6d, + 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x50, 0x0a, 0x10, + 0x6c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x02, 0x18, 0x01, 0x48, 0x00, 0x52, 0x0f, 0x6c, + 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0a, + 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x4f, 0x0a, 0x0f, 0x4c, 0x6f, + 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, + 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x42, 0x02, + 0x18, 0x01, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x1e, 0x0a, 0x08, 0x62, + 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x42, 0x02, 0x18, + 0x01, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x22, 0xca, 0x01, 0x0a, 0x0e, + 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x3b, + 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x68, + 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x6f, + 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x79, 0x70, + 0x65, 0x42, 0x02, 0x18, 0x01, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0b, 0x70, + 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x02, 0x18, 0x01, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, + 0x12, 0x1a, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x42, 0x02, 0x18, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x0a, 0x04, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x05, 0x45, 0x4e, 0x54, 0x45, 0x52, 0x10, 0x00, 0x1a, + 0x02, 0x08, 0x01, 0x12, 0x0e, 0x0a, 0x06, 0x52, 0x45, 0x53, 0x55, 0x4c, 0x54, 0x10, 0x01, 0x1a, + 0x02, 0x08, 0x01, 0x12, 0x13, 0x0a, 0x0b, 0x50, 0x49, 0x43, 0x4b, 0x5f, 0x57, 0x49, 0x4e, 0x4e, + 0x45, 0x52, 0x10, 0x02, 0x1a, 0x02, 0x08, 0x01, 0x22, 0x53, 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x6b, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0b, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, + 0x02, 0x18, 0x01, 0x52, 0x0b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x1b, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x22, 0x89, 0x02, + 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x76, 0x69, 0x65, 0x77, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x06, 0x76, 0x69, 0x65, 0x77, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x12, 0x19, 0x0a, 0x08, 0x73, 0x68, 0x61, 0x72, + 0x64, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x73, 0x68, 0x61, 0x72, + 0x64, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73, + 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, + 0x73, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x65, 0x6e, 0x64, + 0x65, 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x0c, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x12, 0x18, 0x0a, + 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, + 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x65, 0x6e, 0x64, 0x65, + 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x12, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, + 0x6b, 0x65, 0x79, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x22, 0x97, 0x01, 0x0a, 0x0c, 0x44, 0x72, + 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x08, 0x73, 0x68, + 0x61, 0x72, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x42, 0x02, 0x18, 0x01, + 0x52, 0x07, 0x73, 0x68, 0x61, 0x72, 0x64, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0d, 0x73, 0x65, 0x6e, + 0x64, 0x65, 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x42, 0x02, 0x18, 0x01, 0x52, 0x0c, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, + 0x65, 0x79, 0x12, 0x21, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x02, 0x18, 0x01, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1c, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x02, 0x18, 0x01, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, + 0x6f, 0x61, 0x64, 0x22, 0xad, 0x03, 0x0a, 0x11, 0x56, 0x69, 0x65, 0x77, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x76, 0x69, 0x65, + 0x77, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x76, 0x69, 0x65, 0x77, + 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x12, + 0x19, 0x0a, 0x08, 0x73, 0x68, 0x61, 0x72, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x07, 0x73, 0x68, 0x61, 0x72, 0x64, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x65, + 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x0c, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x12, + 0x23, 0x0a, 0x0d, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x50, 0x75, + 0x62, 0x6b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x25, + 0x0a, 0x0e, 0x76, 0x69, 0x65, 0x77, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x67, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x76, 0x69, 0x65, 0x77, 0x63, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x53, 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x76, 0x69, 0x65, 0x77, 0x69, 0x64, 0x5f, + 0x73, 0x69, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x76, 0x69, 0x65, 0x77, 0x69, + 0x64, 0x53, 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x32, 0x5f, 0x61, 0x67, 0x67, 0x73, 0x69, + 0x67, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6d, 0x32, 0x41, 0x67, 0x67, 0x73, + 0x69, 0x67, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x32, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, + 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6d, 0x32, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x70, + 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x33, 0x5f, 0x61, 0x67, 0x67, 0x73, 0x69, 0x67, 0x73, 0x18, 0x0b, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6d, 0x33, 0x41, 0x67, 0x67, 0x73, 0x69, 0x67, 0x73, 0x12, + 0x1b, 0x0a, 0x09, 0x6d, 0x33, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x08, 0x6d, 0x33, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x12, 0x25, 0x0a, 0x0e, + 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x0d, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x22, 0xa2, 0x01, 0x0a, 0x16, 0x4c, 0x61, 0x73, 0x74, 0x53, 0x69, 0x67, 0x6e, + 0x50, 0x6f, 0x77, 0x65, 0x72, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x07, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, + 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x12, 0x16, 0x0a, 0x06, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x06, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x0c, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x12, 0x23, 0x0a, - 0x0d, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x70, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, - 0x65, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x06, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x25, 0x0a, 0x0e, - 0x76, 0x69, 0x65, 0x77, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x67, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x76, 0x69, 0x65, 0x77, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x53, 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x76, 0x69, 0x65, 0x77, 0x69, 0x64, 0x5f, 0x73, 0x69, - 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x76, 0x69, 0x65, 0x77, 0x69, 0x64, 0x53, - 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x32, 0x5f, 0x61, 0x67, 0x67, 0x73, 0x69, 0x67, 0x73, - 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6d, 0x32, 0x41, 0x67, 0x67, 0x73, 0x69, 0x67, - 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x32, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x18, 0x0a, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6d, 0x32, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x12, 0x1d, - 0x0a, 0x0a, 0x6d, 0x33, 0x5f, 0x61, 0x67, 0x67, 0x73, 0x69, 0x67, 0x73, 0x18, 0x0b, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x09, 0x6d, 0x33, 0x41, 0x67, 0x67, 0x73, 0x69, 0x67, 0x73, 0x12, 0x1b, 0x0a, - 0x09, 0x6d, 0x33, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x08, 0x6d, 0x33, 0x42, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x72, - 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x18, 0x0d, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x0d, 0x70, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x42, 0x6c, 0x6f, 0x63, - 0x6b, 0x2a, 0x50, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, - 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x53, 0x45, 0x4e, 0x53, 0x55, 0x53, 0x10, 0x00, 0x12, - 0x0f, 0x0a, 0x07, 0x53, 0x54, 0x41, 0x4b, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x1a, 0x02, 0x08, 0x01, - 0x12, 0x0d, 0x0a, 0x05, 0x44, 0x52, 0x41, 0x4e, 0x44, 0x10, 0x02, 0x1a, 0x02, 0x08, 0x01, 0x12, - 0x12, 0x0a, 0x0e, 0x43, 0x4c, 0x49, 0x45, 0x4e, 0x54, 0x5f, 0x53, 0x55, 0x50, 0x50, 0x4f, 0x52, - 0x54, 0x10, 0x03, 0x2a, 0xd1, 0x01, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, - 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x16, 0x4e, 0x45, 0x57, 0x4e, 0x4f, 0x44, 0x45, 0x5f, 0x42, - 0x45, 0x41, 0x43, 0x4f, 0x4e, 0x5f, 0x53, 0x54, 0x41, 0x4b, 0x49, 0x4e, 0x47, 0x10, 0x00, 0x1a, - 0x02, 0x08, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x4e, 0x4e, 0x4f, 0x55, 0x4e, 0x43, 0x45, 0x10, - 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x45, 0x50, 0x41, 0x52, 0x45, 0x10, 0x02, 0x12, 0x0c, - 0x0a, 0x08, 0x50, 0x52, 0x45, 0x50, 0x41, 0x52, 0x45, 0x44, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, - 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x10, 0x04, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4d, 0x4d, - 0x49, 0x54, 0x54, 0x45, 0x44, 0x10, 0x05, 0x12, 0x0e, 0x0a, 0x0a, 0x56, 0x49, 0x45, 0x57, 0x43, - 0x48, 0x41, 0x4e, 0x47, 0x45, 0x10, 0x06, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x45, 0x57, 0x56, 0x49, - 0x45, 0x57, 0x10, 0x07, 0x12, 0x12, 0x0a, 0x0a, 0x44, 0x52, 0x41, 0x4e, 0x44, 0x5f, 0x49, 0x4e, - 0x49, 0x54, 0x10, 0x0a, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x14, 0x0a, 0x0c, 0x44, 0x52, 0x41, 0x4e, - 0x44, 0x5f, 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x10, 0x0b, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x17, - 0x0a, 0x0f, 0x4c, 0x4f, 0x54, 0x54, 0x45, 0x52, 0x59, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, - 0x54, 0x10, 0x0c, 0x1a, 0x02, 0x08, 0x01, 0x32, 0x4f, 0x0a, 0x0d, 0x43, 0x6c, 0x69, 0x65, 0x6e, - 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x63, - 0x65, 0x73, 0x73, 0x12, 0x17, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x68, - 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x3b, 0x68, - 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x0c, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x50, 0x75, 0x62, 0x6b, 0x65, 0x79, 0x12, 0x19, 0x0a, + 0x08, 0x73, 0x68, 0x61, 0x72, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x07, 0x73, 0x68, 0x61, 0x72, 0x64, 0x49, 0x64, 0x2a, 0x50, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x53, 0x45, + 0x4e, 0x53, 0x55, 0x53, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x07, 0x53, 0x54, 0x41, 0x4b, 0x49, 0x4e, + 0x47, 0x10, 0x01, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x0d, 0x0a, 0x05, 0x44, 0x52, 0x41, 0x4e, 0x44, + 0x10, 0x02, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x12, 0x0a, 0x0e, 0x43, 0x4c, 0x49, 0x45, 0x4e, 0x54, + 0x5f, 0x53, 0x55, 0x50, 0x50, 0x4f, 0x52, 0x54, 0x10, 0x03, 0x2a, 0xe6, 0x01, 0x0a, 0x0b, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x16, 0x4e, 0x45, + 0x57, 0x4e, 0x4f, 0x44, 0x45, 0x5f, 0x42, 0x45, 0x41, 0x43, 0x4f, 0x4e, 0x5f, 0x53, 0x54, 0x41, + 0x4b, 0x49, 0x4e, 0x47, 0x10, 0x00, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x4e, + 0x4e, 0x4f, 0x55, 0x4e, 0x43, 0x45, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x45, 0x50, + 0x41, 0x52, 0x45, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x52, 0x45, 0x50, 0x41, 0x52, 0x45, + 0x44, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x10, 0x04, 0x12, + 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x54, 0x45, 0x44, 0x10, 0x05, 0x12, 0x0e, + 0x0a, 0x0a, 0x56, 0x49, 0x45, 0x57, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x10, 0x06, 0x12, 0x0b, + 0x0a, 0x07, 0x4e, 0x45, 0x57, 0x56, 0x49, 0x45, 0x57, 0x10, 0x07, 0x12, 0x12, 0x0a, 0x0a, 0x44, + 0x52, 0x41, 0x4e, 0x44, 0x5f, 0x49, 0x4e, 0x49, 0x54, 0x10, 0x0a, 0x1a, 0x02, 0x08, 0x01, 0x12, + 0x14, 0x0a, 0x0c, 0x44, 0x52, 0x41, 0x4e, 0x44, 0x5f, 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x10, + 0x0b, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x17, 0x0a, 0x0f, 0x4c, 0x4f, 0x54, 0x54, 0x45, 0x52, 0x59, + 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, 0x10, 0x0c, 0x1a, 0x02, 0x08, 0x01, 0x12, 0x13, + 0x0a, 0x0f, 0x4c, 0x41, 0x53, 0x54, 0x5f, 0x53, 0x49, 0x47, 0x4e, 0x5f, 0x50, 0x4f, 0x57, 0x45, + 0x52, 0x10, 0x0d, 0x32, 0x4f, 0x0a, 0x0d, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x12, + 0x17, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x68, 0x61, 0x72, 0x6d, 0x6f, + 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x3b, 0x68, 0x61, 0x72, 0x6d, 0x6f, + 0x6e, 0x79, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -1133,19 +1246,20 @@ func file_harmonymessage_proto_rawDescGZIP() []byte { } var file_harmonymessage_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_harmonymessage_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_harmonymessage_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_harmonymessage_proto_goTypes = []interface{}{ - (ServiceType)(0), // 0: harmonymessage.ServiceType - (MessageType)(0), // 1: harmonymessage.MessageType - (LotteryRequest_Type)(0), // 2: harmonymessage.LotteryRequest.Type - (*Message)(nil), // 3: harmonymessage.Message - (*Response)(nil), // 4: harmonymessage.Response - (*LotteryResponse)(nil), // 5: harmonymessage.LotteryResponse - (*LotteryRequest)(nil), // 6: harmonymessage.LotteryRequest - (*StakingRequest)(nil), // 7: harmonymessage.StakingRequest - (*ConsensusRequest)(nil), // 8: harmonymessage.ConsensusRequest - (*DrandRequest)(nil), // 9: harmonymessage.DrandRequest - (*ViewChangeRequest)(nil), // 10: harmonymessage.ViewChangeRequest + (ServiceType)(0), // 0: harmonymessage.ServiceType + (MessageType)(0), // 1: harmonymessage.MessageType + (LotteryRequest_Type)(0), // 2: harmonymessage.LotteryRequest.Type + (*Message)(nil), // 3: harmonymessage.Message + (*Response)(nil), // 4: harmonymessage.Response + (*LotteryResponse)(nil), // 5: harmonymessage.LotteryResponse + (*LotteryRequest)(nil), // 6: harmonymessage.LotteryRequest + (*StakingRequest)(nil), // 7: harmonymessage.StakingRequest + (*ConsensusRequest)(nil), // 8: harmonymessage.ConsensusRequest + (*DrandRequest)(nil), // 9: harmonymessage.DrandRequest + (*ViewChangeRequest)(nil), // 10: harmonymessage.ViewChangeRequest + (*LastSignPowerBroadcast)(nil), // 11: harmonymessage.LastSignPowerBroadcast } var file_harmonymessage_proto_depIdxs = []int32{ 0, // 0: harmonymessage.Message.service_type:type_name -> harmonymessage.ServiceType @@ -1155,17 +1269,18 @@ var file_harmonymessage_proto_depIdxs = []int32{ 9, // 4: harmonymessage.Message.drand:type_name -> harmonymessage.DrandRequest 10, // 5: harmonymessage.Message.viewchange:type_name -> harmonymessage.ViewChangeRequest 6, // 6: harmonymessage.Message.lottery_request:type_name -> harmonymessage.LotteryRequest - 0, // 7: harmonymessage.Response.service_type:type_name -> harmonymessage.ServiceType - 1, // 8: harmonymessage.Response.type:type_name -> harmonymessage.MessageType - 5, // 9: harmonymessage.Response.lottery_response:type_name -> harmonymessage.LotteryResponse - 2, // 10: harmonymessage.LotteryRequest.type:type_name -> harmonymessage.LotteryRequest.Type - 3, // 11: harmonymessage.ClientService.Process:input_type -> harmonymessage.Message - 4, // 12: harmonymessage.ClientService.Process:output_type -> harmonymessage.Response - 12, // [12:13] is the sub-list for method output_type - 11, // [11:12] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 11, // 7: harmonymessage.Message.last_sign_power:type_name -> harmonymessage.LastSignPowerBroadcast + 0, // 8: harmonymessage.Response.service_type:type_name -> harmonymessage.ServiceType + 1, // 9: harmonymessage.Response.type:type_name -> harmonymessage.MessageType + 5, // 10: harmonymessage.Response.lottery_response:type_name -> harmonymessage.LotteryResponse + 2, // 11: harmonymessage.LotteryRequest.type:type_name -> harmonymessage.LotteryRequest.Type + 3, // 12: harmonymessage.ClientService.Process:input_type -> harmonymessage.Message + 4, // 13: harmonymessage.ClientService.Process:output_type -> harmonymessage.Response + 13, // [13:14] is the sub-list for method output_type + 12, // [12:13] is the sub-list for method input_type + 12, // [12:12] is the sub-list for extension type_name + 12, // [12:12] is the sub-list for extension extendee + 0, // [0:12] is the sub-list for field type_name } func init() { file_harmonymessage_proto_init() } @@ -1270,6 +1385,18 @@ func file_harmonymessage_proto_init() { return nil } } + file_harmonymessage_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LastSignPowerBroadcast); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } file_harmonymessage_proto_msgTypes[0].OneofWrappers = []interface{}{ (*Message_Staking)(nil), @@ -1277,6 +1404,7 @@ func file_harmonymessage_proto_init() { (*Message_Drand)(nil), (*Message_Viewchange)(nil), (*Message_LotteryRequest)(nil), + (*Message_LastSignPower)(nil), } file_harmonymessage_proto_msgTypes[1].OneofWrappers = []interface{}{ (*Response_LotteryResponse)(nil), @@ -1287,7 +1415,7 @@ func file_harmonymessage_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_harmonymessage_proto_rawDesc, NumEnums: 3, - NumMessages: 8, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/api/proto/message/harmonymessage.proto b/api/proto/message/harmonymessage.proto index f26cbf6085..8491300256 100644 --- a/api/proto/message/harmonymessage.proto +++ b/api/proto/message/harmonymessage.proto @@ -29,6 +29,7 @@ enum MessageType { DRAND_INIT = 10 [deprecated=true]; DRAND_COMMIT = 11 [deprecated=true]; LOTTERY_REQUEST = 12 [deprecated=true]; // it should be either ENTER or GETPLAYERS but it will be removed later. + LAST_SIGN_POWER = 13; } // This is universal message for all communication protocols. @@ -47,6 +48,7 @@ message Message { ViewChangeRequest viewchange = 7; // Refactor this later after demo. LotteryRequest lottery_request = 8 [deprecated=true]; + LastSignPowerBroadcast last_sign_power = 9; } } @@ -116,3 +118,11 @@ message ViewChangeRequest { bytes m3_bitmap= 12; bytes prepared_block = 13; } + +message LastSignPowerBroadcast { + int64 prepare = 1; + int64 commit = 2; + int64 change = 3; + bytes sender_pubkey = 4; + uint32 shard_id = 5; +} diff --git a/consensus/consensus.go b/consensus/consensus.go index 1a649e5ee9..ba82f5d255 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -138,6 +138,9 @@ type Consensus struct { // Both flags only for initialization state. start bool isInitialLeader bool + + // value receives from + lastKnownSignPower int64 } // Blockchain returns the blockchain. @@ -395,6 +398,18 @@ func (consensus *Consensus) InitConsensusWithValidators() (err error) { return nil } +func (consensus *Consensus) SetLastKnownSignPower(i int64) { + consensus.mutex.Lock() + defer consensus.mutex.Unlock() + consensus.lastKnownSignPower = i +} + +func (consensus *Consensus) GetLastKnownSignPower() int64 { + consensus.mutex.RLock() + defer consensus.mutex.RUnlock() + return consensus.lastKnownSignPower +} + type downloadAsync struct { } diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index e64f3007ab..cc5553adbf 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" bls_core "github.com/harmony-one/bls/ffi/go/bls" + "github.com/harmony-one/harmony/api/proto" msg_pb "github.com/harmony-one/harmony/api/proto/message" consensus_engine "github.com/harmony-one/harmony/consensus/engine" "github.com/harmony-one/harmony/consensus/quorum" @@ -17,8 +18,10 @@ import ( bls_cosi "github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/crypto/hash" "github.com/harmony-one/harmony/internal/chain" + nodeconfig "github.com/harmony-one/harmony/internal/configs/node" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/multibls" + "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/shard/committee" "github.com/harmony-one/harmony/webhooks" @@ -153,6 +156,50 @@ func (consensus *Consensus) updateBitmaps() { } +func (consensus *Consensus) sendLastSignPower() { + if consensus.isLeader() { + k, err := consensus.getLeaderPrivateKey(consensus.LeaderPubKey.Object) + if err != nil { + consensus.getLogger().Err(err).Msg("Leader not found in the committee") + return + } + comm := getOrZero(consensus.decider.CurrentTotalPower(quorum.Commit)) + prep := getOrZero(consensus.decider.CurrentTotalPower(quorum.Prepare)) + view := getOrZero(consensus.decider.CurrentTotalPower(quorum.ViewChange)) + msg := &msg_pb.Message{ + ServiceType: msg_pb.ServiceType_CONSENSUS, + Type: msg_pb.MessageType_LAST_SIGN_POWER, + Request: &msg_pb.Message_LastSignPower{ + LastSignPower: &msg_pb.LastSignPowerBroadcast{ + Prepare: prep, + Commit: comm, + Change: view, + SenderPubkey: k.Pub.Bytes[:], + ShardId: consensus.ShardID, + }, + }, + } + marshaledMessage, err := consensus.signAndMarshalConsensusMessage(msg, k.Pri) + if err != nil { + consensus.getLogger().Err(err). + Msg("[constructNewViewMessage] failed to sign and marshal the new view message") + return + } + if comm == 0 && prep == 0 && view == 0 { + return + } + msgToSend := proto.ConstructConsensusMessage(marshaledMessage) + if err := consensus.msgSender.SendWithoutRetry( + []nodeconfig.GroupID{ + nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(consensus.ShardID))}, + p2p.ConstructMessage(msgToSend), + ); err != nil { + consensus.getLogger().Err(err). + Msg("[LastSignPower] could not send out the ViewChange message") + } + } +} + // ResetState resets the state of the consensus func (consensus *Consensus) resetState() { consensus.switchPhase("ResetState", FBFTAnnounce) diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index dbc8e8bf3d..80f6d110ae 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -20,6 +20,7 @@ import ( vrf_bls "github.com/harmony-one/harmony/crypto/vrf/bls" nodeconfig "github.com/harmony-one/harmony/internal/configs/node" "github.com/harmony-one/harmony/internal/utils" + "github.com/harmony-one/harmony/numeric" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/shard" "github.com/harmony-one/vdf/src/vdf_go" @@ -89,6 +90,8 @@ func (consensus *Consensus) HandleMessageUpdate(ctx context.Context, peer libp2p case t == msg_pb.MessageType_NEWVIEW: members := consensus.decider.Participants() fbftMsg, err = ParseNewViewMessage(msg, members) + case t == msg_pb.MessageType_LAST_SIGN_POWER: + return nil default: fbftMsg, err = consensus.parseFBFTMessage(msg) } @@ -820,6 +823,7 @@ func (consensus *Consensus) setupForNewConsensus(blk *types.Block, committedMsg } consensus.fBFTLog.PruneCacheBeforeBlock(blk.NumberU64()) consensus.resetState() + consensus.sendLastSignPower() } func (consensus *Consensus) postCatchup(initBN uint64) { @@ -968,3 +972,10 @@ func (consensus *Consensus) DeleteMessagesLessThan(number uint64) { defer consensus.mutex.Unlock() consensus.fBFTLog.deleteMessagesLessThan(number) } + +func getOrZero(n *numeric.Dec, err error) int64 { + if n == nil { + return 0 + } + return (*n).Mul(numeric.NewDec(100)).TruncateInt64() +} diff --git a/consensus/fbft_log.go b/consensus/fbft_log.go index cec74e314b..60c4d248e1 100644 --- a/consensus/fbft_log.go +++ b/consensus/fbft_log.go @@ -36,6 +36,7 @@ type FBFTMessage struct { M3AggSig *bls_core.Sign M3Bitmap *bls_cosi.Mask Verified bool + LastVotePower int64 } func (m *FBFTMessage) Hash() []byte { diff --git a/hmy/hmy.go b/hmy/hmy.go index 12c3378844..c82ea7e78e 100644 --- a/hmy/hmy.go +++ b/hmy/hmy.go @@ -120,7 +120,6 @@ type NodeAPI interface { GetConfig() commonRPC.Config ShutDown() GetLastSigningPower() (float64, error) - GetLastSigningPower2() (float64, error) } // New creates a new Harmony object (including the diff --git a/node/harmony/api.go b/node/harmony/api.go index 56c4e0f4d2..7bb8138428 100644 --- a/node/harmony/api.go +++ b/node/harmony/api.go @@ -1,10 +1,7 @@ package node import ( - "github.com/harmony-one/harmony/consensus/quorum" - "github.com/harmony-one/harmony/consensus/votepower" "github.com/harmony-one/harmony/core/types" - "github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/eth/rpc" "github.com/harmony-one/harmony/hmy" "github.com/harmony-one/harmony/internal/tikv" @@ -171,37 +168,7 @@ func (node *Node) GetConfig() rpc_common.Config { // GetLastSigningPower get last signed power func (node *Node) GetLastSigningPower() (float64, error) { - power, err := node.Consensus.Decider().CurrentTotalPower(quorum.Commit) - if err != nil { - return 0, err - } - - round := float64(power.MulInt64(10000).RoundInt64()) / 10000 - return round, nil -} - -func (node *Node) GetLastSigningPower2() (float64, error) { - bc := node.Consensus.Blockchain() - cur := bc.CurrentBlock() - ss, err := bc.ReadShardState(cur.Epoch()) - if err != nil { - return 0, err - } - roster, err := votepower.Compute(&ss.Shards[bc.ShardID()], cur.Epoch()) - if err != nil { - return 0, err - } - blsPubKeys, err := ss.Shards[bc.ShardID()].BLSPublicKeys() - if err != nil { - return 0, err - } - - mask := bls.NewMask(blsPubKeys) - err = mask.SetMask(cur.Header().LastCommitBitmap()) - if err != nil { - return 0, err - } - power := roster.VotePowerByMask(mask) - round := float64(power.MulInt64(10000).RoundInt64()) / 10000 + p := node.Consensus.GetLastKnownSignPower() + round := float64(p) / 100 return round, nil } diff --git a/node/harmony/node.go b/node/harmony/node.go index 19778506a6..7c701c51b9 100644 --- a/node/harmony/node.go +++ b/node/harmony/node.go @@ -528,11 +528,16 @@ func validateShardBoundMessage(consensus *consensus.Consensus, peer libp2p_peer. } } - maybeCon, maybeVC := m.GetConsensus(), m.GetViewchange() - senderKey := []byte{} - senderBitmap := []byte{} + var ( + maybeCon = m.GetConsensus() + maybeVC = m.GetViewchange() + maybeSP = m.GetLastSignPower() + senderKey []byte + senderBitmap []byte + ) - if maybeCon != nil { + switch { + case maybeCon != nil: if maybeCon.ShardId != consensus.ShardID { nodeConsensusMessageCounterVec.With(prometheus.Labels{"type": "invalid_shard"}).Inc() return nil, nil, true, errors.WithStack(errWrongShardID) @@ -546,7 +551,7 @@ func validateShardBoundMessage(consensus *consensus.Consensus, peer libp2p_peer. if maybeCon.ViewId+5 < consensus.GetCurBlockViewID() { return nil, nil, true, errors.WithStack(errViewIDTooOld) } - } else if maybeVC != nil { + case maybeVC != nil: if maybeVC.ShardId != consensus.ShardID { nodeConsensusMessageCounterVec.With(prometheus.Labels{"type": "invalid_shard"}).Inc() return nil, nil, true, errors.WithStack(errWrongShardID) @@ -556,7 +561,14 @@ func validateShardBoundMessage(consensus *consensus.Consensus, peer libp2p_peer. if maybeVC.ViewId+5 < consensus.GetViewChangingID() { return nil, nil, true, errors.WithStack(errViewIDTooOld) } - } else { + case maybeSP != nil: + if maybeSP.ShardId != consensus.ShardID { + nodeConsensusMessageCounterVec.With(prometheus.Labels{"type": "invalid_shard"}).Inc() + return nil, nil, true, errors.WithStack(errWrongShardID) + } + senderKey = maybeSP.SenderPubkey + consensus.SetLastKnownSignPower(maybeSP.Commit) + default: nodeConsensusMessageCounterVec.With(prometheus.Labels{"type": "invalid"}).Inc() return nil, nil, true, errors.WithStack(errNoSenderPubKey) } diff --git a/rpc/harmony/private_debug.go b/rpc/harmony/private_debug.go index 97ade82dd2..921d6645d5 100644 --- a/rpc/harmony/private_debug.go +++ b/rpc/harmony/private_debug.go @@ -65,10 +65,3 @@ func (s *PrivateDebugService) GetLastSigningPower( ) (float64, error) { return s.hmy.NodeAPI.GetLastSigningPower() } - -// GetLastSigningPower2 get last signed power -func (s *PrivateDebugService) GetLastSigningPower2( - ctx context.Context, -) (float64, error) { - return s.hmy.NodeAPI.GetLastSigningPower2() -} From dbb4943696c18fd7c47d3f2f20015423f8e25288 Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:33:39 -0400 Subject: [PATCH 2/5] Moved `GetLastSigningPower` from private api to public. --- rpc/harmony/private_debug.go | 7 ------- rpc/harmony/public_debug.go | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rpc/harmony/private_debug.go b/rpc/harmony/private_debug.go index 921d6645d5..2da571b5f2 100644 --- a/rpc/harmony/private_debug.go +++ b/rpc/harmony/private_debug.go @@ -58,10 +58,3 @@ func (s *PrivateDebugService) GetConfig( ) (StructuredResponse, error) { return NewStructuredResponse(s.hmy.NodeAPI.GetConfig()) } - -// GetLastSigningPower get last signed power -func (s *PrivateDebugService) GetLastSigningPower( - ctx context.Context, -) (float64, error) { - return s.hmy.NodeAPI.GetLastSigningPower() -} diff --git a/rpc/harmony/public_debug.go b/rpc/harmony/public_debug.go index 08283b8342..e4f2c12d90 100644 --- a/rpc/harmony/public_debug.go +++ b/rpc/harmony/public_debug.go @@ -36,3 +36,10 @@ func (s *PublicDebugService) SetLogVerbosity(ctx context.Context, level int) (ma utils.SetLogVerbosity(verbosity) return map[string]interface{}{"verbosity": verbosity.String()}, nil } + +// GetLastSigningPower get last signed power +func (s *PublicDebugService) GetLastSigningPower( + ctx context.Context, +) (float64, error) { + return s.hmy.NodeAPI.GetLastSigningPower() +} From bf5e5fbed349df3850b5e574aa29968389087dff Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Wed, 4 Sep 2024 20:44:09 -0400 Subject: [PATCH 3/5] Fix for view change sign power. --- consensus/consensus.go | 9 +++++++-- consensus/consensus_service.go | 5 ++++- consensus/quorum/one-node-one-vote.go | 8 ++++++++ consensus/quorum/one-node-staked-vote.go | 8 ++++++++ consensus/quorum/quorum.go | 1 + consensus/quorum/thread_safe_decider.go | 6 ++++++ consensus/view_change.go | 1 + node/harmony/node.go | 2 +- 8 files changed, 36 insertions(+), 4 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index ba82f5d255..cd1a77ad93 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -141,6 +141,7 @@ type Consensus struct { // value receives from lastKnownSignPower int64 + lastKnowViewChange int64 } // Blockchain returns the blockchain. @@ -398,15 +399,19 @@ func (consensus *Consensus) InitConsensusWithValidators() (err error) { return nil } -func (consensus *Consensus) SetLastKnownSignPower(i int64) { +func (consensus *Consensus) SetLastKnownSignPower(signPower, viewChange int64) { consensus.mutex.Lock() defer consensus.mutex.Unlock() - consensus.lastKnownSignPower = i + consensus.lastKnownSignPower = signPower + consensus.lastKnowViewChange = viewChange } func (consensus *Consensus) GetLastKnownSignPower() int64 { consensus.mutex.RLock() defer consensus.mutex.RUnlock() + if consensus.isViewChangingMode() { + return consensus.lastKnowViewChange + } return consensus.lastKnownSignPower } diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index cc5553adbf..e5a60cd47a 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -165,7 +165,10 @@ func (consensus *Consensus) sendLastSignPower() { } comm := getOrZero(consensus.decider.CurrentTotalPower(quorum.Commit)) prep := getOrZero(consensus.decider.CurrentTotalPower(quorum.Prepare)) - view := getOrZero(consensus.decider.CurrentTotalPower(quorum.ViewChange)) + view := consensus.decider.ComputeTotalPowerByMask(consensus.vc.GetViewIDBitmap(consensus.current.viewChangingID)).Int64() + for view > 100 { + view /= 10 + } msg := &msg_pb.Message{ ServiceType: msg_pb.ServiceType_CONSENSUS, Type: msg_pb.MessageType_LAST_SIGN_POWER, diff --git a/consensus/quorum/one-node-one-vote.go b/consensus/quorum/one-node-one-vote.go index e9e229fdf3..4962dfc86e 100644 --- a/consensus/quorum/one-node-one-vote.go +++ b/consensus/quorum/one-node-one-vote.go @@ -71,6 +71,14 @@ func (v *uniformVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool { return true } +func (v *uniformVoteWeight) ComputeTotalPowerByMask(mask *bls_cosi.Mask) numeric.Dec { + if mask == nil { + return numeric.ZeroDec() + } + currentTotalPower := utils.CountOneBits(mask.Bitmap) + return numeric.NewDec(currentTotalPower) +} + // QuorumThreshold .. func (v *uniformVoteWeight) QuorumThreshold() numeric.Dec { return numeric.NewDec(v.TwoThirdsSignersCount()) diff --git a/consensus/quorum/one-node-staked-vote.go b/consensus/quorum/one-node-staked-vote.go index 2532f9691e..45f4289eab 100644 --- a/consensus/quorum/one-node-staked-vote.go +++ b/consensus/quorum/one-node-staked-vote.go @@ -163,6 +163,14 @@ func (v *stakedVoteWeight) IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool { return (*currentTotalPower).GT(threshold) } +func (v *stakedVoteWeight) ComputeTotalPowerByMask(mask *bls_cosi.Mask) numeric.Dec { + if mask == nil { + return numeric.ZeroDec() + } + currentTotalPower := v.computeTotalPowerByMask(mask) + return *currentTotalPower +} + // ComputeTotalPowerByMask computes the total power indicated by bitmap mask func (v *stakedVoteWeight) computeTotalPowerByMask(mask *bls_cosi.Mask) *numeric.Dec { currentTotal := numeric.ZeroDec() diff --git a/consensus/quorum/quorum.go b/consensus/quorum/quorum.go index 070a85e029..f2cfe82bee 100644 --- a/consensus/quorum/quorum.go +++ b/consensus/quorum/quorum.go @@ -118,6 +118,7 @@ type Decider interface { ) (*votepower.Ballot, error) IsQuorumAchieved(Phase) bool IsQuorumAchievedByMask(mask *bls_cosi.Mask) bool + ComputeTotalPowerByMask(mask *bls_cosi.Mask) numeric.Dec QuorumThreshold() numeric.Dec IsAllSigsCollected() bool ResetPrepareAndCommitVotes() diff --git a/consensus/quorum/thread_safe_decider.go b/consensus/quorum/thread_safe_decider.go index 6b6279e53e..ac5ae75dec 100644 --- a/consensus/quorum/thread_safe_decider.go +++ b/consensus/quorum/thread_safe_decider.go @@ -169,3 +169,9 @@ func (a threadSafeDeciderImpl) IsQuorumAchieved(p Phase) bool { defer a.mu.Unlock() return a.decider.IsQuorumAchieved(p) } + +func (a threadSafeDeciderImpl) ComputeTotalPowerByMask(mask *bls.Mask) numeric.Dec { + a.mu.Lock() + defer a.mu.Unlock() + return a.decider.ComputeTotalPowerByMask(mask) +} diff --git a/consensus/view_change.go b/consensus/view_change.go index 2752270cba..43e9921950 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -424,6 +424,7 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) { Msg("[onViewChange] process View Change message error") return } + consensus.sendLastSignPower() // received enough view change messages, change state to normal consensus if consensus.decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID)) && consensus.isViewChangingMode() { diff --git a/node/harmony/node.go b/node/harmony/node.go index 7c701c51b9..4cb34eccec 100644 --- a/node/harmony/node.go +++ b/node/harmony/node.go @@ -567,7 +567,7 @@ func validateShardBoundMessage(consensus *consensus.Consensus, peer libp2p_peer. return nil, nil, true, errors.WithStack(errWrongShardID) } senderKey = maybeSP.SenderPubkey - consensus.SetLastKnownSignPower(maybeSP.Commit) + consensus.SetLastKnownSignPower(maybeSP.Commit, maybeSP.Change) default: nodeConsensusMessageCounterVec.With(prometheus.Labels{"type": "invalid"}).Inc() return nil, nil, true, errors.WithStack(errNoSenderPubKey) From a8010284385bd924b7992d6dcff39c59143dd260 Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:53:29 -0400 Subject: [PATCH 4/5] Rebased and fixed conflicts. --- consensus/consensus_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index e5a60cd47a..83dd839698 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -158,7 +158,7 @@ func (consensus *Consensus) updateBitmaps() { func (consensus *Consensus) sendLastSignPower() { if consensus.isLeader() { - k, err := consensus.getLeaderPrivateKey(consensus.LeaderPubKey.Object) + k, err := consensus.getLeaderPrivateKey(consensus.getLeaderPubKey().Object) if err != nil { consensus.getLogger().Err(err).Msg("Leader not found in the committee") return From 7c0a8503b9db21b4f60f6975940d56d45ec758f6 Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:07:09 -0400 Subject: [PATCH 5/5] Fix for broadcasting consensus vote power. --- consensus/consensus.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index cd1a77ad93..e88cdff980 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -400,19 +400,15 @@ func (consensus *Consensus) InitConsensusWithValidators() (err error) { } func (consensus *Consensus) SetLastKnownSignPower(signPower, viewChange int64) { - consensus.mutex.Lock() - defer consensus.mutex.Unlock() - consensus.lastKnownSignPower = signPower - consensus.lastKnowViewChange = viewChange + atomic.StoreInt64(&consensus.lastKnownSignPower, signPower) + atomic.StoreInt64(&consensus.lastKnowViewChange, viewChange) } func (consensus *Consensus) GetLastKnownSignPower() int64 { - consensus.mutex.RLock() - defer consensus.mutex.RUnlock() - if consensus.isViewChangingMode() { - return consensus.lastKnowViewChange + if consensus.IsViewChangingMode() { + return atomic.LoadInt64(&consensus.lastKnowViewChange) } - return consensus.lastKnownSignPower + return atomic.LoadInt64(&consensus.lastKnownSignPower) } type downloadAsync struct {