Merge remote-tracking branch 'origin/release1901'

Signed-off-by: Leo Chen <leo@harmony.one>
pull/351/head
Leo Chen 6 years ago
commit 4b15b3a0ad
  1. 37
      api/beaconchain/beaconchain.pb.go
  2. 1
      api/beaconchain/beaconchain.proto
  3. 21
      cmd/client/wallet/main.go
  4. 6
      cmd/client/wallet/wallet_test.go
  5. 2
      internal/beaconchain/rpc/server.go
  6. 2
      node/node.go

@ -98,6 +98,7 @@ type FetchLeadersResponse_Leader struct {
Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"` Ip string `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
Port string `protobuf:"bytes,2,opt,name=port,proto3" json:"port,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"` 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_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -149,6 +150,13 @@ func (m *FetchLeadersResponse_Leader) GetShardId() uint32 {
return 0 return 0
} }
func (m *FetchLeadersResponse_Leader) GetPeerID() string {
if m != nil {
return m.PeerID
}
return ""
}
func init() { func init() {
proto.RegisterType((*FetchLeadersRequest)(nil), "beaconchain.FetchLeadersRequest") proto.RegisterType((*FetchLeadersRequest)(nil), "beaconchain.FetchLeadersRequest")
proto.RegisterType((*FetchLeadersResponse)(nil), "beaconchain.FetchLeadersResponse") proto.RegisterType((*FetchLeadersResponse)(nil), "beaconchain.FetchLeadersResponse")
@ -158,20 +166,21 @@ func init() {
func init() { proto.RegisterFile("beaconchain.proto", fileDescriptor_474fd8061d1037cf) } func init() { proto.RegisterFile("beaconchain.proto", fileDescriptor_474fd8061d1037cf) }
var fileDescriptor_474fd8061d1037cf = []byte{ var fileDescriptor_474fd8061d1037cf = []byte{
// 207 bytes of a gzipped FileDescriptorProto // 222 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0x4a, 0x4d, 0x4c, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0xcd, 0x4a, 0xc4, 0x30,
0xce, 0xcf, 0x4b, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x46, 0x14, 0x85, 0x4d, 0x67, 0xe8, 0xe0, 0x1d, 0x15, 0xbc, 0xfe, 0x10, 0x66, 0x15, 0xbb, 0xca, 0xaa,
0x12, 0x52, 0x12, 0xe5, 0x12, 0x76, 0x4b, 0x2d, 0x49, 0xce, 0xf0, 0x49, 0x4d, 0x4c, 0x49, 0x2d, 0x8b, 0xf1, 0x0d, 0xaa, 0x08, 0x05, 0x57, 0x11, 0xb7, 0x42, 0x9a, 0x5e, 0x68, 0x50, 0x9a, 0x98,
0x2a, 0x0e, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x51, 0x5a, 0xc4, 0xc8, 0x25, 0x82, 0x2a, 0x5e, 0x44, 0x1f, 0xce, 0xa7, 0x13, 0x53, 0x0b, 0x15, 0x44, 0x77, 0x39, 0x1f, 0x39, 0xe4, 0xcb, 0x81,
0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0xe4, 0xc4, 0xc5, 0x9e, 0x03, 0x11, 0x92, 0x60, 0x54, 0x60, 0xd3, 0x8e, 0xb4, 0x71, 0xa3, 0x19, 0xb4, 0x1d, 0x6b, 0x1f, 0x5c, 0x72, 0xb8, 0x5d, 0xa0, 0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xe5, 0xeb, 0x7c, 0xff, 0x3b, 0xed, 0x9f,
0x80, 0xc7, 0x81, 0x60, 0xcf, 0x4a, 0x29, 0x12, 0xf4, 0x82, 0x12, 0x43, 0x12, 0x1b, 0x38, 0xf0, 0x01, 0x9b, 0xec, 0x74, 0xf3, 0xe5, 0xf4, 0x40, 0xe1, 0xdd, 0x1a, 0xc2, 0x47, 0x38, 0x5a, 0xda,
0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x27, 0x0b, 0x9f, 0xda, 0x51, 0x01, 0x00, 0x00, 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. // Reference imports to suppress errors if they are not otherwise used.

@ -17,6 +17,7 @@ message FetchLeadersResponse {
string ip = 1; string ip = 1;
string port = 2; string port = 2;
uint32 shardId = 3; uint32 shardId = 3;
string peerID = 4;
} }
repeated Leader leaders = 1; repeated Leader leaders = 1;
} }

@ -28,6 +28,7 @@ import (
"github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl" "github.com/harmony-one/harmony/p2p/p2pimpl"
peer "github.com/libp2p/go-libp2p-peer"
) )
var ( var (
@ -294,14 +295,24 @@ func CreateWalletNode() *node.Node {
bcClient := beaconchain.NewClient("54.183.5.66", strconv.Itoa(port+libs.BeaconchainServicePortDiff)) bcClient := beaconchain.NewClient("54.183.5.66", strconv.Itoa(port+libs.BeaconchainServicePortDiff))
response := bcClient.GetLeaders() response := bcClient.GetLeaders()
for _, leader := range response.Leaders {
shardIDLeaderMap[leader.ShardId] = p2p.Peer{IP: leader.Ip, Port: leader.Port}
}
// dummy host for wallet // dummy host for wallet
self := p2p.Peer{IP: "127.0.0.1", Port: "6789"} self := p2p.Peer{IP: "127.0.0.1", Port: "6789"}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "6789") priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "6789")
host, _ := p2pimpl.NewHost(&self, priKey) host, err := p2pimpl.NewHost(&self, priKey)
if err != nil {
panic(err)
}
for _, leader := range response.Leaders {
peerID, err := peer.IDB58Decode(leader.PeerID)
if err != nil {
panic(err)
}
leaderPeer := p2p.Peer{IP: leader.Ip, Port: leader.Port, PeerID: peerID}
shardIDLeaderMap[leader.ShardId] = leaderPeer
host.AddPeer(&leaderPeer)
}
walletNode := node.New(host, nil, nil) walletNode := node.New(host, nil, nil)
walletNode.Client = client.NewClient(walletNode.GetHost(), &shardIDLeaderMap) walletNode.Client = client.NewClient(walletNode.GetHost(), &shardIDLeaderMap)
return walletNode return walletNode

@ -7,9 +7,11 @@ import (
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/harmony-one/harmony/api/client" "github.com/harmony-one/harmony/api/client"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
mock_host "github.com/harmony-one/harmony/p2p/host/mock" mock_host "github.com/harmony-one/harmony/p2p/host/mock"
peer "github.com/libp2p/go-libp2p-peer"
) )
func TestCreateWalletNode(test *testing.T) { func TestCreateWalletNode(test *testing.T) {
@ -30,7 +32,9 @@ func TestSubmitTransaction(test *testing.T) {
m.EXPECT().SendMessage(gomock.Any(), gomock.Any()).Times(1) m.EXPECT().SendMessage(gomock.Any(), gomock.Any()).Times(1)
walletNode := node.New(m, nil, nil) walletNode := node.New(m, nil, nil)
walletNode.Client = client.NewClient(walletNode.GetHost(), &map[uint32]p2p.Peer{0: p2p.Peer{IP: "1", Port: "2"}}) priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9990")
peerID, _ := peer.IDFromPrivateKey(priKey)
walletNode.Client = client.NewClient(walletNode.GetHost(), &map[uint32]p2p.Peer{0: p2p.Peer{IP: "127.0.0.1", Port: "9990", PeerID: peerID}})
SubmitTransaction(&types.Transaction{}, walletNode, 0) SubmitTransaction(&types.Transaction{}, walletNode, 0)

@ -23,7 +23,7 @@ func (s *Server) FetchLeaders(ctx context.Context, request *proto.FetchLeadersRe
leaders := []*proto.FetchLeadersResponse_Leader{} leaders := []*proto.FetchLeadersResponse_Leader{}
for shardID, leader := range s.shardLeaderMap() { 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: leader.PeerID.Pretty()})
} }
log.Println(leaders) log.Println(leaders)
return &proto.FetchLeadersResponse{Leaders: leaders}, nil return &proto.FetchLeadersResponse{Leaders: leaders}, nil

@ -604,7 +604,7 @@ func (node *Node) SendNewBlockToUnsync() {
continue continue
} }
response := config.client.PushNewBlock(selfPeerID, blockHash, false) response := config.client.PushNewBlock(selfPeerID, blockHash, false)
if response.Type == downloader_pb.DownloaderResponse_INSYNC { if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC {
node.stateMutex.Lock() node.stateMutex.Lock()
node.peerRegistrationRecord[peerID].client.Close() node.peerRegistrationRecord[peerID].client.Close()
delete(node.peerRegistrationRecord, peerID) delete(node.peerRegistrationRecord, peerID)

Loading…
Cancel
Save