From fe06318d04ea6ab22a48ee6e44193928dd07871a Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Thu, 24 Jan 2019 22:48:23 +0000 Subject: [PATCH] add PeerID in beacon chain RPC message wallet needs to use PeerID to talk to leaders Signed-off-by: Leo Chen --- api/beaconchain/beaconchain.pb.go | 37 +++++++++++++++++++----------- api/beaconchain/beaconchain.proto | 1 + cmd/client/wallet/main.go | 3 ++- internal/beaconchain/rpc/server.go | 2 +- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/api/beaconchain/beaconchain.pb.go b/api/beaconchain/beaconchain.pb.go index df3fd3c60..1f7e5003c 100644 --- a/api/beaconchain/beaconchain.pb.go +++ b/api/beaconchain/beaconchain.pb.go @@ -98,6 +98,7 @@ type FetchLeadersResponse_Leader struct { Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` Port string `protobuf:"bytes,2,opt,name=port,proto3" json:"port,omitempty"` ShardId uint32 `protobuf:"varint,3,opt,name=shardId,proto3" json:"shardId,omitempty"` + PeerID string `protobuf:"bytes,4,opt,name=peerID,proto3" json:"peerID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -149,6 +150,13 @@ func (m *FetchLeadersResponse_Leader) GetShardId() uint32 { return 0 } +func (m *FetchLeadersResponse_Leader) GetPeerID() string { + if m != nil { + return m.PeerID + } + return "" +} + func init() { proto.RegisterType((*FetchLeadersRequest)(nil), "beaconchain.FetchLeadersRequest") proto.RegisterType((*FetchLeadersResponse)(nil), "beaconchain.FetchLeadersResponse") @@ -158,20 +166,21 @@ func init() { func init() { proto.RegisterFile("beaconchain.proto", fileDescriptor_474fd8061d1037cf) } var fileDescriptor_474fd8061d1037cf = []byte{ - // 207 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0x4a, 0x4d, 0x4c, - 0xce, 0xcf, 0x4b, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x46, - 0x12, 0x52, 0x12, 0xe5, 0x12, 0x76, 0x4b, 0x2d, 0x49, 0xce, 0xf0, 0x49, 0x4d, 0x4c, 0x49, 0x2d, - 0x2a, 0x0e, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x51, 0x5a, 0xc4, 0xc8, 0x25, 0x82, 0x2a, 0x5e, - 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0xe4, 0xc4, 0xc5, 0x9e, 0x03, 0x11, 0x92, 0x60, 0x54, 0x60, - 0xd6, 0xe0, 0x36, 0xd2, 0xd0, 0x43, 0xb6, 0x01, 0x9b, 0x1e, 0x3d, 0x08, 0x3f, 0x08, 0xa6, 0x51, - 0xca, 0x8d, 0x8b, 0x0d, 0x22, 0x24, 0xc4, 0xc7, 0xc5, 0x94, 0x59, 0x20, 0xc1, 0xa8, 0xc0, 0xa8, - 0xc1, 0x19, 0xc4, 0x94, 0x59, 0x20, 0x24, 0xc4, 0xc5, 0x52, 0x90, 0x5f, 0x54, 0x22, 0xc1, 0x04, - 0x16, 0x01, 0xb3, 0x85, 0x24, 0xb8, 0xd8, 0x8b, 0x33, 0x12, 0x8b, 0x52, 0x3c, 0x53, 0x24, 0x98, - 0x15, 0x18, 0x35, 0x78, 0x83, 0x60, 0x5c, 0xa3, 0x6c, 0x2e, 0x21, 0x27, 0xb0, 0xdd, 0xce, 0x20, - 0xbb, 0x83, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0x85, 0x42, 0xb9, 0x78, 0x90, 0x5d, 0x21, 0xa4, - 0x80, 0xc7, 0x81, 0x60, 0xcf, 0x4a, 0x29, 0x12, 0xf4, 0x82, 0x12, 0x43, 0x12, 0x1b, 0x38, 0xf0, - 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x27, 0x0b, 0x9f, 0xda, 0x51, 0x01, 0x00, 0x00, + // 222 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0xcd, 0x4a, 0xc4, 0x30, + 0x14, 0x85, 0x4d, 0x67, 0xe8, 0xe0, 0x1d, 0x15, 0xbc, 0xfe, 0x10, 0x66, 0x15, 0xbb, 0xca, 0xaa, + 0x8b, 0xf1, 0x0d, 0xaa, 0x08, 0x05, 0x57, 0x11, 0xb7, 0x42, 0x9a, 0x5e, 0x68, 0x50, 0x9a, 0x98, + 0x44, 0x1f, 0xce, 0xa7, 0x13, 0x53, 0x0b, 0x15, 0x44, 0x77, 0x39, 0x1f, 0x39, 0xe4, 0xcb, 0x81, + 0xd3, 0x8e, 0xb4, 0x71, 0xa3, 0x19, 0xb4, 0x1d, 0x6b, 0x1f, 0x5c, 0x72, 0xb8, 0x5d, 0xa0, 0xea, + 0x02, 0xce, 0xee, 0x28, 0x99, 0xe1, 0x9e, 0x74, 0x4f, 0x21, 0x2a, 0x7a, 0x7d, 0xa3, 0x98, 0xaa, + 0x0f, 0x06, 0xe7, 0x3f, 0x79, 0xf4, 0x6e, 0x8c, 0x84, 0x0d, 0x6c, 0x5e, 0x26, 0xc4, 0x99, 0x58, + 0xc9, 0xed, 0x5e, 0xd6, 0xcb, 0x17, 0x7e, 0xeb, 0xd4, 0x53, 0x56, 0x73, 0x71, 0xf7, 0x04, 0xe5, + 0x84, 0xf0, 0x04, 0x0a, 0xeb, 0x39, 0x13, 0x4c, 0x1e, 0xaa, 0xc2, 0x7a, 0x44, 0x58, 0x7b, 0x17, + 0x12, 0x2f, 0x32, 0xc9, 0x67, 0xe4, 0xb0, 0x89, 0x83, 0x0e, 0x7d, 0xdb, 0xf3, 0x95, 0x60, 0xf2, + 0x58, 0xcd, 0x11, 0x2f, 0xa1, 0xf4, 0x44, 0xa1, 0xbd, 0xe5, 0xeb, 0x7c, 0xff, 0x3b, 0xed, 0x9f, + 0x01, 0x9b, 0xec, 0x74, 0xf3, 0xe5, 0xf4, 0x40, 0xe1, 0xdd, 0x1a, 0xc2, 0x47, 0x38, 0x5a, 0xda, + 0xa1, 0xf8, 0x43, 0x3c, 0x8f, 0xb0, 0xbb, 0xfa, 0xf7, 0x6b, 0xd5, 0x41, 0x57, 0xe6, 0x51, 0xaf, + 0x3f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x35, 0x50, 0x26, 0x86, 0x69, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/api/beaconchain/beaconchain.proto b/api/beaconchain/beaconchain.proto index 15d7406ab..f5f7bcf5e 100644 --- a/api/beaconchain/beaconchain.proto +++ b/api/beaconchain/beaconchain.proto @@ -17,6 +17,7 @@ message FetchLeadersResponse { string ip = 1; string port = 2; uint32 shardId = 3; + string peerID = 4; } repeated Leader leaders = 1; } diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index 7c697a208..f7c8f621a 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -28,6 +28,7 @@ import ( "github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/p2pimpl" + peer "github.com/libp2p/go-libp2p-peer" ) var ( @@ -295,7 +296,7 @@ func CreateWalletNode() *node.Node { response := bcClient.GetLeaders() for _, leader := range response.Leaders { - shardIDLeaderMap[leader.ShardId] = p2p.Peer{IP: leader.Ip, Port: leader.Port} + shardIDLeaderMap[leader.ShardId] = p2p.Peer{IP: leader.Ip, Port: leader.Port, PeerID: peer.ID(leader.PeerID)} } // dummy host for wallet diff --git a/internal/beaconchain/rpc/server.go b/internal/beaconchain/rpc/server.go index 1ae12c2f4..38cf13c4f 100644 --- a/internal/beaconchain/rpc/server.go +++ b/internal/beaconchain/rpc/server.go @@ -23,7 +23,7 @@ func (s *Server) FetchLeaders(ctx context.Context, request *proto.FetchLeadersRe leaders := []*proto.FetchLeadersResponse_Leader{} for shardID, leader := range s.shardLeaderMap() { - leaders = append(leaders, &proto.FetchLeadersResponse_Leader{Ip: leader.IP, Port: leader.Port, ShardId: uint32(shardID)}) + leaders = append(leaders, &proto.FetchLeadersResponse_Leader{Ip: leader.IP, Port: leader.Port, ShardId: uint32(shardID), PeerID: string(leader.PeerID)}) } log.Println(leaders) return &proto.FetchLeadersResponse{Leaders: leaders}, nil