diff --git a/Gopkg.lock b/Gopkg.lock index 8a70c7ed2..9c67e72b6 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -216,10 +216,9 @@ [[projects]] branch = "master" - digest = "1:b5936d38011189ba9b2e5890a38c7ffe0ac7f157eef2ddc0fe752117c50d394d" + digest = "1:d31a812696686f0059241fa6c3b56d89ada56dddde4db1d5036de5c1084000c5" name = "golang.org/x/net" packages = [ - "context", "http/httpguts", "http2", "http2/hpack", diff --git a/api/api.go b/api/api.go index e50ea84a5..1d07e32cf 100644 --- a/api/api.go +++ b/api/api.go @@ -6,6 +6,7 @@ import ( "github.com/zoobc/zoobc-core/common/chaintype" coreService "github.com/zoobc/zoobc-core/core/service" + p2p "github.com/zoobc/zoobc-core/p2p" "github.com/zoobc/zoobc-core/common/crypto" "github.com/zoobc/zoobc-core/common/transaction" @@ -13,7 +14,6 @@ import ( "github.com/sirupsen/logrus" "github.com/zoobc/zoobc-core/api/handler" "github.com/zoobc/zoobc-core/api/service" - "github.com/zoobc/zoobc-core/common/contract" "github.com/zoobc/zoobc-core/common/query" rpcService "github.com/zoobc/zoobc-core/common/service" "github.com/zoobc/zoobc-core/common/util" @@ -32,7 +32,8 @@ func init() { } } -func startGrpcServer(port int, queryExecutor query.ExecutorInterface, p2pHostService contract.P2PType) { +func startGrpcServer(port int, queryExecutor query.ExecutorInterface, p2pHostService p2p.ServiceInterface, + blockServices map[int32]coreService.BlockServiceInterface) { grpcServer := grpc.NewServer( grpc.UnaryInterceptor(util.NewServerInterceptor(apiLogger)), ) @@ -71,8 +72,7 @@ func startGrpcServer(port int, queryExecutor query.ExecutorInterface, p2pHostSer }) // Set GRPC handler for Transactions requests rpcService.RegisterHostServiceServer(grpcServer, &handler.HostHandler{ - Service: service.NewHostService(queryExecutor), - P2pHostService: p2pHostService, + Service: service.NewHostService(queryExecutor, p2pHostService, blockServices), }) // Set GRPC handler for account balance requests rpcService.RegisterAccountBalanceServiceServer(grpcServer, &handler.AccountBalanceHandler{ @@ -96,6 +96,7 @@ func startGrpcServer(port int, queryExecutor query.ExecutorInterface, p2pHostSer } // Start starts api servers in the given port and passing query executor -func Start(grpcPort, restPort int, queryExecutor query.ExecutorInterface, p2pHostService contract.P2PType) { - startGrpcServer(grpcPort, queryExecutor, p2pHostService) +func Start(grpcPort, restPort int, queryExecutor query.ExecutorInterface, p2pHostService p2p.ServiceInterface, + blockServices map[int32]coreService.BlockServiceInterface) { + startGrpcServer(grpcPort, queryExecutor, p2pHostService, blockServices) } diff --git a/api/client/GetBlockByID/client.go b/api/client/GetBlockByID/client.go index 679827644..4a10213bd 100644 --- a/api/client/GetBlockByID/client.go +++ b/api/client/GetBlockByID/client.go @@ -10,7 +10,7 @@ import ( ) func main() { - conn, err := grpc.Dial(":8000", grpc.WithInsecure()) + conn, err := grpc.Dial(":3001", grpc.WithInsecure()) if err != nil { log.Fatalf("did not connect: %s", err) } @@ -19,7 +19,7 @@ func main() { c := rpc_service.NewBlockServiceClient(conn) response, err := c.GetBlock(context.Background(), &rpc_model.GetBlockRequest{ - ID: -7639577553511789811, + ID: -8875736238633164302, }) if err != nil { diff --git a/api/client/GetBlocks/client.go b/api/client/GetBlocks/client.go index d5287cda2..ee22f90ce 100644 --- a/api/client/GetBlocks/client.go +++ b/api/client/GetBlocks/client.go @@ -10,7 +10,7 @@ import ( ) func main() { - conn, err := grpc.Dial(":8000", grpc.WithInsecure()) + conn, err := grpc.Dial(":3001", grpc.WithInsecure()) if err != nil { log.Fatalf("did not connect: %s", err) } @@ -19,8 +19,9 @@ func main() { c := rpc_service.NewBlockServiceClient(conn) response, err := c.GetBlocks(context.Background(), &rpc_model.GetBlocksRequest{ - Limit: 3, - Height: 12, + ChainType: 0, + Limit: 3, + Height: 1, }) if err != nil { diff --git a/api/handler/blockHandler.go b/api/handler/blockHandler.go index a306abcb8..24c396f34 100644 --- a/api/handler/blockHandler.go +++ b/api/handler/blockHandler.go @@ -15,8 +15,10 @@ type BlockHandler struct { // GetBlock handles request to get data of a single Block func (bs *BlockHandler) GetBlock(ctx context.Context, req *model.GetBlockRequest) (*model.Block, error) { - var blockResponse *model.Block - var err error + var ( + blockResponse *model.Block + err error + ) chainType := chaintype.GetChainType(req.ChainType) if req.ID != 0 { blockResponse, err = bs.Service.GetBlockByID(chainType, req.ID) diff --git a/api/handler/hostHandler.go b/api/handler/hostHandler.go index 6a3986442..d0714e73e 100644 --- a/api/handler/hostHandler.go +++ b/api/handler/hostHandler.go @@ -4,15 +4,13 @@ import ( "context" "github.com/zoobc/zoobc-core/api/service" - "github.com/zoobc/zoobc-core/common/contract" "github.com/zoobc/zoobc-core/common/model" ) type HostHandler struct { - Service service.HostServiceInterface - P2pHostService contract.P2PType + Service service.HostServiceInterface } -func (hh *HostHandler) GetHostInfo(ctx context.Context, req *model.Empty) (*model.Host, error) { - return hh.P2pHostService.GetHostInstance(), nil +func (hh *HostHandler) GetHostInfo(ctx context.Context, req *model.Empty) (*model.HostInfo, error) { + return hh.Service.GetHostInfo() } diff --git a/api/service/hostApiService.go b/api/service/hostApiService.go index de1345d2e..f722bbf83 100644 --- a/api/service/hostApiService.go +++ b/api/service/hostApiService.go @@ -3,27 +3,52 @@ package service import ( "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/query" + coreService "github.com/zoobc/zoobc-core/core/service" + "github.com/zoobc/zoobc-core/p2p" ) type ( HostServiceInterface interface { + GetHostInfo() (*model.HostInfo, error) } HostService struct { - Query query.ExecutorInterface + Query query.ExecutorInterface + BlockServices map[int32]coreService.BlockServiceInterface + P2pService p2p.ServiceInterface } ) var hostServiceInstance *HostService // NewHostService create a singleton instance of HostService -func NewHostService(queryExecutor query.ExecutorInterface) *HostService { +func NewHostService(queryExecutor query.ExecutorInterface, p2pService p2p.ServiceInterface, + blockServices map[int32]coreService.BlockServiceInterface) HostServiceInterface { if hostServiceInstance == nil { - hostServiceInstance = &HostService{Query: queryExecutor} + hostServiceInstance = &HostService{ + Query: queryExecutor, + P2pService: p2pService, + BlockServices: blockServices, + } } return hostServiceInstance } -func (*HostService) GetHostInfo() *model.Host { - return &model.Host{} +func (hs *HostService) GetHostInfo() (*model.HostInfo, error) { + chainStatuses := []*model.ChainStatus{} + for chainType, blockService := range hs.BlockServices { + lastBlock, err := blockService.GetLastBlock() + if lastBlock == nil || err != nil { + continue + } + chainStatuses = append(chainStatuses, &model.ChainStatus{ + ChainType: chainType, + Height: lastBlock.Height, + LastBlock: lastBlock, + }) + } + return &model.HostInfo{ + Host: hs.P2pService.GetHostInstance(), + ChainStatuses: chainStatuses, + }, nil } diff --git a/common/blocker/blocker.go b/common/blocker/blocker.go index 06bf610de..724464301 100644 --- a/common/blocker/blocker.go +++ b/common/blocker/blocker.go @@ -1,29 +1,33 @@ package blocker +import "fmt" + type ( - TypeBlocker int + TypeBlocker string - blocker struct { + Blocker struct { Type TypeBlocker Message string } ) var ( - DBErr TypeBlocker = 1 - BlockErr TypeBlocker = 2 - AppErr TypeBlocker = 3 - AuthErr TypeBlocker = 4 - ValidationErr TypeBlocker = 5 + DBErr TypeBlocker = "DBErr" + BlockErr TypeBlocker = "BlockErr" + BlockNotFoundErr TypeBlocker = "BlockNotFoundErr" + RequestParameterErr TypeBlocker = "RequestParameterErr" + AppErr TypeBlocker = "AppErr" + AuthErr TypeBlocker = "AuthErr" + ValidationErr TypeBlocker = "ValidationErr" ) func NewBlocker(typeBlocker TypeBlocker, message string) error { - return blocker{ + return Blocker{ Type: typeBlocker, Message: message, } } -func (e blocker) Error() string { - return e.Message +func (e Blocker) Error() string { + return fmt.Sprintf("%v: %v", e.Type, e.Message) } diff --git a/common/blocker/blocker_test.go b/common/blocker/blocker_test.go index d1c7d4a76..8c1b700d3 100644 --- a/common/blocker/blocker_test.go +++ b/common/blocker/blocker_test.go @@ -21,12 +21,12 @@ func TestBlocker_Error(t *testing.T) { Type: DBErr, Message: "sql error", }, - want: "sql error", + want: "DBErr: sql error", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - e := blocker{ + e := Blocker{ Type: tt.fields.Type, Message: tt.fields.Message, } @@ -68,5 +68,5 @@ func TestNewBlocker(t *testing.T) { func ExampleNewBlocker() { err := NewBlocker(BlockErr, "invalid block height") fmt.Println(err) - // Output: invalid block height + // Output: BlockErr: invalid block height } diff --git a/common/chaintype/mainchain.go b/common/chaintype/mainchain.go index fe5529807..d23606fa6 100644 --- a/common/chaintype/mainchain.go +++ b/common/chaintype/mainchain.go @@ -3,6 +3,11 @@ package chaintype // MainChain is struct should has methods in below type MainChain struct{} +// GetTypeInt return the value of the chain type in int +func (*MainChain) GetTypeInt() int32 { + return 0 +} + // GetTablePrefix return the value of current chain table prefix in the database func (*MainChain) GetTablePrefix() string { return "main" @@ -15,7 +20,7 @@ func (*MainChain) GetChainSmithingDelayTime() int64 { // GetName return the name of the chain : used in parsing chaintype across node func (*MainChain) GetName() string { - return "" + return "Mainchain" } // GetGenesisBlockID return the block ID of genesis block in the chain diff --git a/common/constant/blockchainSync.go b/common/constant/blockchainSync.go new file mode 100644 index 000000000..ad7841ddf --- /dev/null +++ b/common/constant/blockchainSync.go @@ -0,0 +1,14 @@ +package constant + +import "time" + +const ( + // GetMoreBlocksDelay returns delay between GetMoreBlocksThread in seconds + GetMoreBlocksDelay time.Duration = 10 + BlockDownloadSegSize uint32 = 36 + MaxResponseTime time.Duration = 1 * time.Minute + DefaultNumberOfForkConfirmations int32 = 1 + PeerGetBlocksLimit uint32 = 1440 + CommonMilestoneBlockIdsLimit int32 = 10 + SafeBlockGap uint32 = 1440 +) diff --git a/common/contract/chaintype.go b/common/contract/chaintype.go index eb04b8457..d19697597 100644 --- a/common/contract/chaintype.go +++ b/common/contract/chaintype.go @@ -2,6 +2,8 @@ package contract // ChainType interface define the different behavior of each chain type ChainType interface { + // GetTypeInt return the value of the chain type in int + GetTypeInt() int32 // GetTablePrefix return the value of current chain table prefix in the database GetTablePrefix() string // GetChainSmithingDelayTime return the value of chain smithing delay in second diff --git a/common/contract/p2pType.go b/common/contract/p2pType.go deleted file mode 100644 index 8216c68a4..000000000 --- a/common/contract/p2pType.go +++ /dev/null @@ -1,15 +0,0 @@ -package contract - -import ( - "github.com/zoobc/zoobc-core/common/model" - "github.com/zoobc/zoobc-core/observer" -) - -// P2PType is interface for P2p instance -type P2PType interface { - InitService(myAddress string, port uint32, wellknownPeers []string, obsr *observer.Observer) (P2PType, error) - StartP2P() - GetHostInstance() *model.Host - SendBlockListener() observer.Listener - SendTransactionListener() observer.Listener -} diff --git a/common/model/accountBalance.pb.go b/common/model/accountBalance.pb.go index bb6f434f8..7367534b3 100644 --- a/common/model/accountBalance.pb.go +++ b/common/model/accountBalance.pb.go @@ -333,30 +333,30 @@ func init() { func init() { proto.RegisterFile("model/accountBalance.proto", fileDescriptor_44b9b1c521a5bcaa) } var fileDescriptor_44b9b1c521a5bcaa = []byte{ - // 395 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xc1, 0x6e, 0x9b, 0x40, - 0x10, 0x15, 0xc6, 0xc6, 0xed, 0x58, 0xae, 0xdc, 0x95, 0x5a, 0x61, 0x57, 0xaa, 0x10, 0x87, 0x0a, - 0x59, 0x2d, 0x48, 0xcd, 0x35, 0x89, 0x62, 0x2e, 0xf1, 0xc1, 0x87, 0x08, 0xe7, 0xe4, 0x1b, 0x2c, - 0x23, 0x83, 0x02, 0x2c, 0x81, 0x25, 0x91, 0xfc, 0x0b, 0xf9, 0x80, 0xfc, 0x5a, 0x3e, 0x27, 0xca, - 0x1a, 0xc7, 0x18, 0xb0, 0xe5, 0x0b, 0xd2, 0xbe, 0xf7, 0xe6, 0xcd, 0xee, 0xbc, 0x01, 0x26, 0x31, - 0xf3, 0x31, 0xb2, 0x5c, 0x4a, 0x59, 0x91, 0x70, 0xdb, 0x8d, 0xdc, 0x84, 0xa2, 0x99, 0x66, 0x8c, - 0x33, 0xd2, 0x13, 0x9c, 0xfe, 0x26, 0xc1, 0xb7,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, 0x4e, - 0x56, 0x9a, 0x76, 0x45, 0xf9, 0x09, 0xc5, 0x47, 0xfd, 0x3e, 0xbb, 0x46, 0xfb, 0xde, 0xb6, 0xfe, - 0xb8, 0x82, 0xdc, 0xc0, 0xaf, 0x06, 0x5b, 0xb9, 0x80, 0x22, 0x0c, 0x4e, 0x49, 0xea, 0x7b, 0xdb, - 0x6f, 0xec, 0xad, 0xfe, 0x22, 0xc1, 0xa4, 0x2d, 0x99, 0x32, 0x77, 0x13, 0xc8, 0x21, 0xb5, 0x0c, - 0x37, 0x58, 0x86, 0xd3, 0xc2, 0xb4, 0xec, 0x49, 0x47, 0x93, 0xcf, 0xde, 0x13, 0x7b, 0xba, 0x32, - 0xd6, 0x21, 0x0f, 0x0a, 0xcf, 0xa4, 0x2c, 0xb6, 0x36, 0x8c, 0x79, 0x74, 0xfb, 0xfd, 0x47, 0x59, - 0x86, 0x16, 0x65, 0x71, 0xcc, 0x12, 0x4b, 0x58, 0x79, 0x8a, 0xf8, 0xb9, 0x2f, 0xde, 0x03, 0x00, - 0x00, 0xff, 0xff, 0x14, 0x15, 0x28, 0xbf, 0xfa, 0x03, 0x00, 0x00, + // 396 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcd, 0xae, 0x9a, 0x40, + 0x14, 0xce, 0x88, 0x62, 0x7b, 0x8c, 0x8d, 0x9d, 0xa4, 0x0d, 0xda, 0x2e, 0x08, 0x8b, 0x86, 0x98, + 0x16, 0x9a, 0x76, 0xdb, 0x36, 0x95, 0x4d, 0x5d, 0xb8, 0x68, 0xb0, 0x2b, 0x77, 0x30, 0x9c, 0x08, + 0x29, 0x30, 0x14, 0x86, 0xde, 0xc4, 0x57, 0xb8, 0x0f, 0x70, 0x5f, 0xf0, 0x3e, 0xc8, 0xcd, 0x1d, + 0x51, 0x11, 0xd0, 0xb8, 0x31, 0xf1, 0xfb, 0x3b, 0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x3f, 0xa1, 0x97, 0xca, + 0xf8, 0xb1, 0xdb, 0xc2, 0xe9, 0x47, 0x78, 0x5d, 0x61, 0xcb, 0x68, 0x1b, 0x56, 0xe2, 0x7d, 0x37, + 0x6d, 0x82, 0x7e, 0x83, 0x69, 0xb3, 0x85, 0xd3, 0x08, 0x45, 0xba, 0x2e, 0x0b, 0xe8, 0x0f, 0x98, + 0x35, 0xc9, 0xda, 0xd0, 0xbe, 0xb4, 0x5f, 0x51, 0x3c, 0xfb, 0x4f, 0xdd, 0xb5, 0xc6, 0x0f, 0xf6, + 0xfe, 0xcb, 0x0a, 0xfa, 0x13, 0xde, 0xb5, 0xd8, 0xda, 0x01, 0x54, 0x19, 0x70, 0x4d, 0xd2, 0xdc, + 0xe1, 0x61, 0x6b, 0x87, 0x8d, 0x7b, 0x02, 0xb3, 0xae, 0x66, 0xaa, 0xde, 0x2d, 0xa0, 0xe7, 0xd4, + 0x3a, 0xda, 0x61, 0x55, 0x4e, 0x07, 0xd3, 0xb1, 0x27, 0x3d, 0x5d, 0xb9, 0x79, 0x4f, 0x9c, 0xf9, + 0xc6, 0xdc, 0x46, 0x22, 0x2c, 0x7d, 0x8b, 0xf1, 0xc4, 0xde, 0x71, 0xee, 0xb3, 0xfd, 0xef, 0x27, + 0xc6, 0x73, 0xb4, 0x19, 0x4f, 0x12, 0x9e, 0xda, 0x32, 0xca, 0x57, 0xe5, 0x87, 0xfe, 0xf5, 0x29, + 0x00, 0x00, 0xff, 0xff, 0x29, 0xf8, 0xf6, 0xe9, 0x06, 0x04, 0x00, 0x00, } diff --git a/common/model/block.pb.go b/common/model/block.pb.go index 4da4cd271..b905f738b 100644 --- a/common/model/block.pb.go +++ b/common/model/block.pb.go @@ -306,7 +306,7 @@ type GetBlocksResponse struct { // Blocks height returned from Height uint32 `protobuf:"varint,3,opt,name=Height,proto3" json:"Height,omitempty"` // Blocks returned - Blocks []*Block `protobuf:"bytes,4,rep,name=blocks,proto3" json:"blocks,omitempty"` + Blocks []*Block `protobuf:"bytes,4,rep,name=Blocks,proto3" json:"Blocks,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -365,46 +365,246 @@ func (m *GetBlocksResponse) GetBlocks() []*Block { return nil } +type GetNextBlockIdsRequest struct { + // Number indicating chaintype + ChainType int32 `protobuf:"varint,1,opt,name=ChainType,proto3" json:"ChainType,omitempty"` + BlockId int64 `protobuf:"varint,2,opt,name=BlockId,proto3" json:"BlockId,omitempty"` + Limit uint32 `protobuf:"varint,3,opt,name=Limit,proto3" json:"Limit,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetNextBlockIdsRequest) Reset() { *m = GetNextBlockIdsRequest{} } +func (m *GetNextBlockIdsRequest) String() string { return proto.CompactTextString(m) } +func (*GetNextBlockIdsRequest) ProtoMessage() {} +func (*GetNextBlockIdsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_baa78346dbb08dbe, []int{4} +} + +func (m *GetNextBlockIdsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetNextBlockIdsRequest.Unmarshal(m, b) +} +func (m *GetNextBlockIdsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetNextBlockIdsRequest.Marshal(b, m, deterministic) +} +func (m *GetNextBlockIdsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetNextBlockIdsRequest.Merge(m, src) +} +func (m *GetNextBlockIdsRequest) XXX_Size() int { + return xxx_messageInfo_GetNextBlockIdsRequest.Size(m) +} +func (m *GetNextBlockIdsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetNextBlockIdsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetNextBlockIdsRequest proto.InternalMessageInfo + +func (m *GetNextBlockIdsRequest) GetChainType() int32 { + if m != nil { + return m.ChainType + } + return 0 +} + +func (m *GetNextBlockIdsRequest) GetBlockId() int64 { + if m != nil { + return m.BlockId + } + return 0 +} + +func (m *GetNextBlockIdsRequest) GetLimit() uint32 { + if m != nil { + return m.Limit + } + return 0 +} + +type BlockIdsResponse struct { + BlockIds []int64 `protobuf:"varint,1,rep,packed,name=BlockIds,proto3" json:"BlockIds,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlockIdsResponse) Reset() { *m = BlockIdsResponse{} } +func (m *BlockIdsResponse) String() string { return proto.CompactTextString(m) } +func (*BlockIdsResponse) ProtoMessage() {} +func (*BlockIdsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_baa78346dbb08dbe, []int{5} +} + +func (m *BlockIdsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlockIdsResponse.Unmarshal(m, b) +} +func (m *BlockIdsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlockIdsResponse.Marshal(b, m, deterministic) +} +func (m *BlockIdsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlockIdsResponse.Merge(m, src) +} +func (m *BlockIdsResponse) XXX_Size() int { + return xxx_messageInfo_BlockIdsResponse.Size(m) +} +func (m *BlockIdsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BlockIdsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BlockIdsResponse proto.InternalMessageInfo + +func (m *BlockIdsResponse) GetBlockIds() []int64 { + if m != nil { + return m.BlockIds + } + return nil +} + +type GetNextBlocksRequest struct { + // Number indicating chaintype + ChainType int32 `protobuf:"varint,1,opt,name=ChainType,proto3" json:"ChainType,omitempty"` + BlockId int64 `protobuf:"varint,2,opt,name=BlockId,proto3" json:"BlockId,omitempty"` + BlockIds []int64 `protobuf:"varint,3,rep,packed,name=BlockIds,proto3" json:"BlockIds,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetNextBlocksRequest) Reset() { *m = GetNextBlocksRequest{} } +func (m *GetNextBlocksRequest) String() string { return proto.CompactTextString(m) } +func (*GetNextBlocksRequest) ProtoMessage() {} +func (*GetNextBlocksRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_baa78346dbb08dbe, []int{6} +} + +func (m *GetNextBlocksRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetNextBlocksRequest.Unmarshal(m, b) +} +func (m *GetNextBlocksRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetNextBlocksRequest.Marshal(b, m, deterministic) +} +func (m *GetNextBlocksRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetNextBlocksRequest.Merge(m, src) +} +func (m *GetNextBlocksRequest) XXX_Size() int { + return xxx_messageInfo_GetNextBlocksRequest.Size(m) +} +func (m *GetNextBlocksRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetNextBlocksRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetNextBlocksRequest proto.InternalMessageInfo + +func (m *GetNextBlocksRequest) GetChainType() int32 { + if m != nil { + return m.ChainType + } + return 0 +} + +func (m *GetNextBlocksRequest) GetBlockId() int64 { + if m != nil { + return m.BlockId + } + return 0 +} + +func (m *GetNextBlocksRequest) GetBlockIds() []int64 { + if m != nil { + return m.BlockIds + } + return nil +} + +type BlocksData struct { + NextBlocks []*Block `protobuf:"bytes,1,rep,name=NextBlocks,proto3" json:"NextBlocks,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BlocksData) Reset() { *m = BlocksData{} } +func (m *BlocksData) String() string { return proto.CompactTextString(m) } +func (*BlocksData) ProtoMessage() {} +func (*BlocksData) Descriptor() ([]byte, []int) { + return fileDescriptor_baa78346dbb08dbe, []int{7} +} + +func (m *BlocksData) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BlocksData.Unmarshal(m, b) +} +func (m *BlocksData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BlocksData.Marshal(b, m, deterministic) +} +func (m *BlocksData) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlocksData.Merge(m, src) +} +func (m *BlocksData) XXX_Size() int { + return xxx_messageInfo_BlocksData.Size(m) +} +func (m *BlocksData) XXX_DiscardUnknown() { + xxx_messageInfo_BlocksData.DiscardUnknown(m) +} + +var xxx_messageInfo_BlocksData proto.InternalMessageInfo + +func (m *BlocksData) GetNextBlocks() []*Block { + if m != nil { + return m.NextBlocks + } + return nil +} + func init() { proto.RegisterType((*Block)(nil), "model.Block") proto.RegisterType((*GetBlockRequest)(nil), "model.GetBlockRequest") proto.RegisterType((*GetBlocksRequest)(nil), "model.GetBlocksRequest") proto.RegisterType((*GetBlocksResponse)(nil), "model.GetBlocksResponse") + proto.RegisterType((*GetNextBlockIdsRequest)(nil), "model.GetNextBlockIdsRequest") + proto.RegisterType((*BlockIdsResponse)(nil), "model.BlockIdsResponse") + proto.RegisterType((*GetNextBlocksRequest)(nil), "model.GetNextBlocksRequest") + proto.RegisterType((*BlocksData)(nil), "model.BlocksData") } func init() { proto.RegisterFile("model/block.proto", fileDescriptor_baa78346dbb08dbe) } var fileDescriptor_baa78346dbb08dbe = []byte{ - // 496 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x5d, 0x6b, 0x13, 0x41, - 0x14, 0x65, 0xd3, 0x24, 0x6d, 0x6e, 0x3e, 0xda, 0x0c, 0x45, 0x87, 0x22, 0xb2, 0x84, 0x22, 0x8b, - 0x68, 0x02, 0x15, 0x7c, 0x6f, 0x12, 0xb4, 0x85, 0x3e, 0x94, 0x4d, 0x50, 0xf0, 0x41, 0x98, 0x6c, - 0x6e, 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x9f, 0x1e, 0xf4, - 0x2b, 0x0d, 0xec, 0xda, 0x68, 0x8b, 0xff, 0xee, 0x30, 0xa1, 0x25, 0x97, 0x1d, 0x08, 0xec, 0x8d, - 0xff, 0x39, 0x34, 0xe9, 0x35, 0x5a, 0x5e, 0xa7, 0x61, 0x76, 0xca, 0x61, 0x16, 0xc3, 0x2a, 0xb5, - 0xf1, 0xeb, 0x2f, 0xc1, 0x4a, 0xba, 0x38, 0x5b, 0x0c, 0x23, 0xa3, 0x46, 0x3f, 0x8c, 0x59, 0x44, - 0xc5, 0xef, 0xdb, 0xc8, 0xa4, 0x38, 0x8a, 0x8c, 0x52, 0x46, 0x8f, 0xe8, 0xe4, 0xa2, 0x49, 0xef, - 0xf6, 0xdd, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9d, 0x78, 0x03, 0x78, 0xec, 0x03, 0x00, 0x00, + // 585 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x5f, 0x6b, 0x1a, 0x4f, + 0x14, 0x65, 0xdd, 0xf8, 0xef, 0xaa, 0x89, 0x0e, 0x92, 0xdf, 0xf0, 0x23, 0x84, 0x65, 0x91, 0xb2, + 0x94, 0x54, 0x8b, 0x85, 0x3e, 0xf4, 0x2d, 0x2a, 0x4d, 0x84, 0x50, 0xc2, 0x2a, 0x7d, 0x68, 0xa1, + 0x30, 0xee, 0x4e, 0xdc, 0x69, 0x77, 0x77, 0xec, 0xce, 0x6c, 0xa8, 0x7d, 0xef, 0x87, 0xec, 0xb7, + 0x29, 0xce, 0xfe, 0x35, 0x89, 0x34, 0x0f, 0x7d, 0x11, 0xef, 0x39, 0x77, 0xce, 0xb9, 0x73, 0xe6, + 0x2a, 0xf4, 0x02, 0xee, 0x52, 0x7f, 0xb4, 0xf2, 0xb9, 0xf3, 0x6d, 0xb8, 0x89, 0xb8, 0xe4, 0xa8, + 0xaa, 0xa0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0x7e, 0x85, + 0xd3, 0x2b, 0x2a, 0x3f, 0xd0, 0x1f, 0xc9, 0x28, 0x73, 0xf7, 0x99, 0xb7, 0x3d, 0x83, 0x7a, 0x7a, + 0xa0, 0x14, 0x68, 0x06, 0x15, 0x59, 0xe8, 0xa5, 0x2c, 0xcc, 0x31, 0x74, 0x0b, 0x93, 0xf4, 0xc6, + 0xe7, 0xd0, 0xc8, 0x30, 0xac, 0x19, 0x7a, 0xb6, 0xa8, 0x19, 0x66, 0x46, 0xd0, 0x2f, 0xcf, 0xf7, + 0x4f, 0xa6, 0x2b, 0x7b, 0xea, 0x4f, 0x78, 0xbe, 0x03, 0x48, 0xcc, 0x66, 0x44, 0x12, 0x74, 0x01, + 0x50, 0xd8, 0xab, 0x19, 0x1f, 0x66, 0x59, 0xe2, 0x27, 0x2f, 0x3f, 0x59, 0x6b, 0x26, 0xbd, 0x78, + 0x35, 0x74, 0x78, 0x30, 0xfa, 0xc9, 0xf9, 0xca, 0x49, 0x3e, 0x5f, 0x39, 0x3c, 0xa2, 0x23, 0x87, + 0x07, 0x01, 0x0f, 0x47, 0xea, 0xf4, 0xaa, 0xa6, 0xfe, 0x23, 0xdf, 0xfc, 0x09, 0x00, 0x00, 0xff, + 0xff, 0x5b, 0x15, 0xe2, 0xb3, 0x58, 0x05, 0x00, 0x00, } diff --git a/common/model/blockchain.pb.go b/common/model/blockchain.pb.go new file mode 100644 index 000000000..635ccd548 --- /dev/null +++ b/common/model/blockchain.pb.go @@ -0,0 +1,302 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: model/blockchain.proto + +package model + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ChainStatus struct { + // Integer indicating chaintype + ChainType int32 `protobuf:"varint,1,opt,name=ChainType,proto3" json:"ChainType,omitempty"` + Height uint32 `protobuf:"varint,2,opt,name=Height,proto3" json:"Height,omitempty"` + LastBlock *Block `protobuf:"bytes,3,opt,name=LastBlock,proto3" json:"LastBlock,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChainStatus) Reset() { *m = ChainStatus{} } +func (m *ChainStatus) String() string { return proto.CompactTextString(m) } +func (*ChainStatus) ProtoMessage() {} +func (*ChainStatus) Descriptor() ([]byte, []int) { + return fileDescriptor_c2ffcbd1121992b1, []int{0} +} + +func (m *ChainStatus) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChainStatus.Unmarshal(m, b) +} +func (m *ChainStatus) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChainStatus.Marshal(b, m, deterministic) +} +func (m *ChainStatus) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChainStatus.Merge(m, src) +} +func (m *ChainStatus) XXX_Size() int { + return xxx_messageInfo_ChainStatus.Size(m) +} +func (m *ChainStatus) XXX_DiscardUnknown() { + xxx_messageInfo_ChainStatus.DiscardUnknown(m) +} + +var xxx_messageInfo_ChainStatus proto.InternalMessageInfo + +func (m *ChainStatus) GetChainType() int32 { + if m != nil { + return m.ChainType + } + return 0 +} + +func (m *ChainStatus) GetHeight() uint32 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *ChainStatus) GetLastBlock() *Block { + if m != nil { + return m.LastBlock + } + return nil +} + +type GetCumulativeDifficultyResponse struct { + CumulativeDifficulty string `protobuf:"bytes,1,opt,name=CumulativeDifficulty,proto3" json:"CumulativeDifficulty,omitempty"` + Height uint32 `protobuf:"varint,2,opt,name=Height,proto3" json:"Height,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCumulativeDifficultyResponse) Reset() { *m = GetCumulativeDifficultyResponse{} } +func (m *GetCumulativeDifficultyResponse) String() string { return proto.CompactTextString(m) } +func (*GetCumulativeDifficultyResponse) ProtoMessage() {} +func (*GetCumulativeDifficultyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c2ffcbd1121992b1, []int{1} +} + +func (m *GetCumulativeDifficultyResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCumulativeDifficultyResponse.Unmarshal(m, b) +} +func (m *GetCumulativeDifficultyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCumulativeDifficultyResponse.Marshal(b, m, deterministic) +} +func (m *GetCumulativeDifficultyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCumulativeDifficultyResponse.Merge(m, src) +} +func (m *GetCumulativeDifficultyResponse) XXX_Size() int { + return xxx_messageInfo_GetCumulativeDifficultyResponse.Size(m) +} +func (m *GetCumulativeDifficultyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetCumulativeDifficultyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCumulativeDifficultyResponse proto.InternalMessageInfo + +func (m *GetCumulativeDifficultyResponse) GetCumulativeDifficulty() string { + if m != nil { + return m.CumulativeDifficulty + } + return "" +} + +func (m *GetCumulativeDifficultyResponse) GetHeight() uint32 { + if m != nil { + return m.Height + } + return 0 +} + +type GetCumulativeDifficultyRequest struct { + // Integer indicating chaintype + ChainType int32 `protobuf:"varint,1,opt,name=ChainType,proto3" json:"ChainType,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCumulativeDifficultyRequest) Reset() { *m = GetCumulativeDifficultyRequest{} } +func (m *GetCumulativeDifficultyRequest) String() string { return proto.CompactTextString(m) } +func (*GetCumulativeDifficultyRequest) ProtoMessage() {} +func (*GetCumulativeDifficultyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c2ffcbd1121992b1, []int{2} +} + +func (m *GetCumulativeDifficultyRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCumulativeDifficultyRequest.Unmarshal(m, b) +} +func (m *GetCumulativeDifficultyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCumulativeDifficultyRequest.Marshal(b, m, deterministic) +} +func (m *GetCumulativeDifficultyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCumulativeDifficultyRequest.Merge(m, src) +} +func (m *GetCumulativeDifficultyRequest) XXX_Size() int { + return xxx_messageInfo_GetCumulativeDifficultyRequest.Size(m) +} +func (m *GetCumulativeDifficultyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetCumulativeDifficultyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCumulativeDifficultyRequest proto.InternalMessageInfo + +func (m *GetCumulativeDifficultyRequest) GetChainType() int32 { + if m != nil { + return m.ChainType + } + return 0 +} + +type GetCommonMilestoneBlockIdsRequest struct { + // Integer indicating chaintype + ChainType int32 `protobuf:"varint,1,opt,name=ChainType,proto3" json:"ChainType,omitempty"` + LastBlockID int64 `protobuf:"varint,2,opt,name=LastBlockID,proto3" json:"LastBlockID,omitempty"` + LastMilestoneBlockID int64 `protobuf:"varint,3,opt,name=LastMilestoneBlockID,proto3" json:"LastMilestoneBlockID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCommonMilestoneBlockIdsRequest) Reset() { *m = GetCommonMilestoneBlockIdsRequest{} } +func (m *GetCommonMilestoneBlockIdsRequest) String() string { return proto.CompactTextString(m) } +func (*GetCommonMilestoneBlockIdsRequest) ProtoMessage() {} +func (*GetCommonMilestoneBlockIdsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c2ffcbd1121992b1, []int{3} +} + +func (m *GetCommonMilestoneBlockIdsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCommonMilestoneBlockIdsRequest.Unmarshal(m, b) +} +func (m *GetCommonMilestoneBlockIdsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCommonMilestoneBlockIdsRequest.Marshal(b, m, deterministic) +} +func (m *GetCommonMilestoneBlockIdsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCommonMilestoneBlockIdsRequest.Merge(m, src) +} +func (m *GetCommonMilestoneBlockIdsRequest) XXX_Size() int { + return xxx_messageInfo_GetCommonMilestoneBlockIdsRequest.Size(m) +} +func (m *GetCommonMilestoneBlockIdsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetCommonMilestoneBlockIdsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCommonMilestoneBlockIdsRequest proto.InternalMessageInfo + +func (m *GetCommonMilestoneBlockIdsRequest) GetChainType() int32 { + if m != nil { + return m.ChainType + } + return 0 +} + +func (m *GetCommonMilestoneBlockIdsRequest) GetLastBlockID() int64 { + if m != nil { + return m.LastBlockID + } + return 0 +} + +func (m *GetCommonMilestoneBlockIdsRequest) GetLastMilestoneBlockID() int64 { + if m != nil { + return m.LastMilestoneBlockID + } + return 0 +} + +type GetCommonMilestoneBlockIdsResponse struct { + BlockIds []int64 `protobuf:"varint,1,rep,packed,name=BlockIds,proto3" json:"BlockIds,omitempty"` + Last bool `protobuf:"varint,2,opt,name=Last,proto3" json:"Last,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetCommonMilestoneBlockIdsResponse) Reset() { *m = GetCommonMilestoneBlockIdsResponse{} } +func (m *GetCommonMilestoneBlockIdsResponse) String() string { return proto.CompactTextString(m) } +func (*GetCommonMilestoneBlockIdsResponse) ProtoMessage() {} +func (*GetCommonMilestoneBlockIdsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c2ffcbd1121992b1, []int{4} +} + +func (m *GetCommonMilestoneBlockIdsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetCommonMilestoneBlockIdsResponse.Unmarshal(m, b) +} +func (m *GetCommonMilestoneBlockIdsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetCommonMilestoneBlockIdsResponse.Marshal(b, m, deterministic) +} +func (m *GetCommonMilestoneBlockIdsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetCommonMilestoneBlockIdsResponse.Merge(m, src) +} +func (m *GetCommonMilestoneBlockIdsResponse) XXX_Size() int { + return xxx_messageInfo_GetCommonMilestoneBlockIdsResponse.Size(m) +} +func (m *GetCommonMilestoneBlockIdsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetCommonMilestoneBlockIdsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetCommonMilestoneBlockIdsResponse proto.InternalMessageInfo + +func (m *GetCommonMilestoneBlockIdsResponse) GetBlockIds() []int64 { + if m != nil { + return m.BlockIds + } + return nil +} + +func (m *GetCommonMilestoneBlockIdsResponse) GetLast() bool { + if m != nil { + return m.Last + } + return false +} + +func init() { + proto.RegisterType((*ChainStatus)(nil), "model.ChainStatus") + proto.RegisterType((*GetCumulativeDifficultyResponse)(nil), "model.GetCumulativeDifficultyResponse") + proto.RegisterType((*GetCumulativeDifficultyRequest)(nil), "model.GetCumulativeDifficultyRequest") + proto.RegisterType((*GetCommonMilestoneBlockIdsRequest)(nil), "model.GetCommonMilestoneBlockIdsRequest") + proto.RegisterType((*GetCommonMilestoneBlockIdsResponse)(nil), "model.GetCommonMilestoneBlockIdsResponse") +} + +func init() { proto.RegisterFile("model/blockchain.proto", fileDescriptor_c2ffcbd1121992b1) } + +var fileDescriptor_c2ffcbd1121992b1 = []byte{ + // 327 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x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0x3c, 0xe5, 0xa9, 0x8b, 0x9d, + 0xdc, 0xbe, 0x68, 0xde, 0x2d, 0xb4, 0xf7, 0xda, 0xbd, 0xe7, 0xca, 0xd8, 0xc3, 0x23, 0x7b, 0x5f, + 0x0c, 0xce, 0x0b, 0x01, 0x4c, 0x53, 0xcc, 0x1e, 0x75, 0xa2, 0x8c, 0xc5, 0x4c, 0xd1, 0x28, 0xc3, + 0x91, 0xf9, 0x93, 0x06, 0xbf, 0x80, 0xc6, 0x7a, 0xfe, 0xe1, 0x80, 0x02, 0x96, 0x7b, 0xa5, 0x2b, + 0x26, 0xb6, 0x61, 0x7e, 0x03, 0xcd, 0xa2, 0xfc, 0xe5, 0x31, 0xa0, 0x7d, 0x2e, 0xdb, 0x77, 0xf2, + 0xde, 0x0b, 0x78, 0x87, 0x02, 0xae, 0x76, 0xda, 0x86, 0xda, 0x0f, 0xe6, 0x30, 0xb7, 0xbc, 0x52, + 0x5c, 0x63, 0x9c, 0xc3, 0xbf, 0x42, 0x9d, 0xc2, 0xd5, 0x04, 0xdd, 0x7b, 0x9d, 0x57, 0x7f, 0xa2, + 0xed, 0x34, 0x8f, 0x03, 0x89, 0x69, 0xf8, 0x89, 0x18, 0xcb, 0xe5, 0x79, 0x29, 0x71, 0xae, 0x42, + 0x49, 0x96, 0x21, 0xbd, 0x73, 0x5c, 0xa5, 0xef, 0x74, 0xfd, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x34, + 0x29, 0x28, 0xfc, 0x82, 0x02, 0x00, 0x00, +} diff --git a/common/model/host.pb.go b/common/model/host.pb.go index 13a54397b..c9904ffc8 100644 --- a/common/model/host.pb.go +++ b/common/model/host.pb.go @@ -100,37 +100,88 @@ func (m *Host) GetStopped() bool { return false } +type HostInfo struct { + Host *Host `protobuf:"bytes,1,opt,name=Host,proto3" json:"Host,omitempty"` + ChainStatuses []*ChainStatus `protobuf:"bytes,2,rep,name=ChainStatuses,proto3" json:"ChainStatuses,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *HostInfo) Reset() { *m = HostInfo{} } +func (m *HostInfo) String() string { return proto.CompactTextString(m) } +func (*HostInfo) ProtoMessage() {} +func (*HostInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2105bc76e5d5e738, []int{1} +} + +func (m *HostInfo) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_HostInfo.Unmarshal(m, b) +} +func (m *HostInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_HostInfo.Marshal(b, m, deterministic) +} +func (m *HostInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_HostInfo.Merge(m, src) +} +func (m *HostInfo) XXX_Size() int { + return xxx_messageInfo_HostInfo.Size(m) +} +func (m *HostInfo) XXX_DiscardUnknown() { + xxx_messageInfo_HostInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_HostInfo proto.InternalMessageInfo + +func (m *HostInfo) GetHost() *Host { + if m != nil { + return m.Host + } + return nil +} + +func (m *HostInfo) GetChainStatuses() []*ChainStatus { + if m != nil { + return m.ChainStatuses + } + return nil +} + func init() { proto.RegisterType((*Host)(nil), "model.Host") proto.RegisterMapType((map[string]*Peer)(nil), "model.Host.BlacklistedPeersEntry") proto.RegisterMapType((map[string]*Peer)(nil), "model.Host.KnownPeersEntry") proto.RegisterMapType((map[string]*Peer)(nil), "model.Host.ResolvedPeersEntry") proto.RegisterMapType((map[string]*Peer)(nil), "model.Host.UnresolvedPeersEntry") + proto.RegisterType((*HostInfo)(nil), "model.HostInfo") } func init() { proto.RegisterFile("model/host.proto", fileDescriptor_2105bc76e5d5e738) } var fileDescriptor_2105bc76e5d5e738 = []byte{ - // 330 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x51, 0x4b, 0xfb, 0x30, - 0x14, 0xc5, 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 0xcd, 0xd4, 0xe6, 0x26, 0xb6, 0x46, 0x74, 0xf2, - 0x88, 0xb2, 0xc7, 0x80, 0xb6, 0xa2, 0xcc, 0x81, 0x7f, 0xaf, 0x8a, 0xd2, 0x14, 0x23, 0xa7, 0xee, - 0x5a, 0xde, 0x7f, 0xbe, 0x39, 0xb6, 0x07, 0xc0, 0xb6, 0x6b, 0x61, 0x2d, 0xa8, 0xce, 0x70, 0xa9, - 0xdb, 0x3e, 0xe0, 0xab, 0x2d, 0xeb, 0x80, 0xbd, 0x18, 0xc5, 0x73, 0x74, 0x2a, 0x85, 0x17, 0x58, - 0x65, 0xb8, 0x51, 0x6e, 0x2a, 0xd7, 0x56, 0xfb, 0x05, 0x8e, 0x76, 0xb5, 0xb3, 0x3f, 0xb0, 0x0f, - 0xcd, 0x52, 0x4f, 0xfb, 0xb3, 0x86, 0x70, 0xbc, 0xb3, 0xb0, 0xbd, 0x89, 0xbd, 0x8b, 0x77, 0xef, - 0x73, 0xaa, 0x26, 0xf3, 0xb1, 0x1f, 0x52, 0x12, 0x7c, 0x13, 0x8d, 0x43, 0xb3, 0x5e, 0x86, 0x24, - 0x31, 0x08, 0x29, 0x49, 0x48, 0x04, 0x3a, 0x3b, 0xae, 0xeb, 0x2f, 0x7d, 0xf5, 0x1b, 0x00, 0x00, - 0xff, 0xff, 0xa1, 0x93, 0x46, 0x51, 0x11, 0x03, 0x00, 0x00, + // 382 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x5f, 0x6b, 0xe2, 0x40, + 0x14, 0xc5, 0x89, 0x1a, 0xd7, 0xbd, 0x22, 0xca, 0xb0, 0xbb, 0x04, 0x17, 0xd6, 0xe8, 0x53, 0x58, + 0xd8, 0x04, 0xdc, 0x17, 0xd9, 0x7d, 0x73, 0xb7, 0xd0, 0x5a, 0x6c, 0x65, 0xa4, 0x2f, 0x7d, 0xcb, + 0x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, 0xb4, 0x16, 0x18, 0xc7, 0x2c, 0x30, 0xda, 0xa6, + 0x66, 0x75, 0x68, 0xf1, 0x39, 0x5c, 0x02, 0x39, 0x5d, 0x0b, 0x19, 0x40, 0x73, 0xc7, 0x8e, 0x72, + 0xdb, 0x9f, 0x69, 0xf6, 0x4a, 0xc6, 0xa0, 0x1f, 0xdc, 0x70, 0xcf, 0x8c, 0x46, 0xe5, 0x04, 0xb2, + 0x19, 0xaa, 0x9c, 0x3f, 0x8d, 0x99, 0x36, 0xbc, 0x87, 0x2f, 0xe7, 0xb6, 0x73, 0x39, 0x70, 0x01, + 0xfd, 0xda, 0x9e, 0x2e, 0x67, 0xad, 0xe0, 0xeb, 0xd9, 0x85, 0x5d, 0x4c, 0x9c, 0x30, 0xe8, 0x64, + 0xe7, 0x20, 0x1b, 0x38, 0x52, 0x55, 0xad, 0x55, 0x34, 0x93, 0xa8, 0xea, 0xf0, 0x0c, 0x7a, 0xff, + 0xb2, 0x6e, 0xaf, 0x85, 0x2b, 0xf6, 0x29, 0x2b, 0x2a, 0x4a, 0xf2, 0x64, 0xc9, 0xa3, 0xd5, 0xe0, + 0xfc, 0xe7, 0xa3, 0xf5, 0xbc, 0x15, 0x9b, 0xbd, 0x67, 0xfb, 0x18, 0x39, 0xaf, 0x88, 0x9e, 0xaf, + 0x9e, 0xbf, 0x7c, 0x4c, 0x98, 0xe3, 0x63, 0x14, 0x21, 0x77, 0x24, 0xc6, 0x6b, 0xcb, 0x9b, 0xf3, + 0xfb, 0x3d, 0x00, 0x00, 0xff, 0xff, 0x87, 0x32, 0xd4, 0x32, 0x90, 0x03, 0x00, 0x00, } diff --git a/common/model/mempool.pb.go b/common/model/mempool.pb.go index b030aaf64..cd37a0e2e 100644 --- a/common/model/mempool.pb.go +++ b/common/model/mempool.pb.go @@ -311,30 +311,31 @@ func init() { func init() { proto.RegisterFile("model/mempool.proto", fileDescriptor_22ea31ac6d427b7b) } var fileDescriptor_22ea31ac6d427b7b = []byte{ - // 396 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0x4d, 0xab, 0xd3, 0x40, - 0x14, 0x65, 0x92, 0xe6, 0x89, 0xf7, 0x7d, 0x20, 0xf3, 0x0a, 0x46, 0xd0, 0x47, 0xc8, 0x42, 0xc2, - 0x03, 0x13, 0x78, 0x6e, 0x04, 0x57, 0x7d, 0x3c, 0x95, 0xfa, 0x01, 0x65, 0xda, 0x95, 0xb8, 0x99, - 0x4e, 0x2e, 0x75, 0x20, 0x33, 0x13, 0x67, 0xa6, 0x82, 0x6e, 0xdd, 0xf9, 0x67, 0xfc, 0x8b, 0xd2, - 0x49, 0xab, 0xb5, 0x4d, 0xdc, 0x84, 0xdc, 0x73, 0xef, 0x39, 0x39, 0x9c, 0x43, 0xe0, 0x52, 0x99, - 0x1a, 0x9b, 0x4a, 0xa1, 0x6a, 0x8d, 0x69, 0xca, 0xd6, 0x1a, 0x6f, 0x68, 0x12, 0xc0, 0xfc, 0x67, - 0x04, 0xf4, 0x43, 0xb7, 0x58, 0x58, 0xae, 0x1d, 0x17, 0x5e, 0x1a, 0x4d, 0x2f, 0x20, 0x9a, 0xde, - 0xa5, 0x24, 0x23, 0x45, 0xcc, 0xa2, 0xe9, 0x1d, 0xbd, 0x02, 0x78, 0x8d, 0x38, 0x43, 0x7b, 0xfb, - 0xcd, 0x63, 0x1a, 0x65, 0xa4, 0x48, 0xd8, 0x1e, 0x42, 0xaf, 0xe1, 0xc1, 0xc4, 0x5a, 0xf9, 0x95, - 0x37, 0x0b, 0xa9, 0xd0, 0x79, 0xae, 0xda, 0x34, 0x0e, 0xec, 0x23, 0x7c, 0x73, 0xbb, 0xf7, 0xa9, - 0x0d, 0xdd, 0xa5, 0xa3, 0x8c, 0x14, 0x67, 0xec, 0x08, 0xa7, 0x37, 0x30, 0x9e, 0xa3, 0xae, 0xd1, - 0x4e, 0x84, 0x30, 0x6b, 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 0x96, 0xa2, 0x7b, 0x3e, 0x13, - 0xc6, 0x62, 0x25, 0x8c, 0x52, 0x46, 0x57, 0x41, 0x73, 0x79, 0x12, 0x7e, 0x94, 0xe7, 0xbf, 0x03, - 0x00, 0x00, 0xff, 0xff, 0x94, 0xb3, 0x24, 0x08, 0x3f, 0x03, 0x00, 0x00, + // 401 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0xdd, 0x6a, 0xd4, 0x40, + 0x18, 0x65, 0xb2, 0x9b, 0x8a, 0x5f, 0x5b, 0x29, 0x5f, 0x17, 0x8c, 0xa0, 0x25, 0xe4, 0x42, 0x42, + 0xc1, 0xac, 0xd4, 0x1b, 0xc1, 0xab, 0x5d, 0xaa, 0x52, 0x7f, 0xa0, 0x4c, 0xf7, 0x4a, 0xbc, 0x99, + 0x9d, 0x7c, 0xd4, 0x81, 0xcc, 0x4c, 0x9c, 0x99, 0x15, 0xf4, 0xd6, 0x37, 0xf0, 0x65, 0x7c, 0x3d, + 0x71, 0xd2, 0x9f, 0xd8, 0x4d, 0xbc, 0x09, 0x99, 0x73, 0xe6, 0x9c, 0x1c, 0xce, 0x21, 0x70, 0xa8, + 0x6d, 0x4d, 0xcd, 0x5c, 0x93, 0x6e, 0xad, 0x6d, 0xaa, 0xd6, 0xd9, 0x60, 0x31, 0x8d, 0x60, 0xf1, + 0x2b, 0x01, 0xfc, 0xd8, 0x11, 0x2b, 0x27, 0x8c, 0x17, 0x32, 0x28, 0x6b, 0x10, 0x21, 0x39, 0x3b, + 0xcd, 0x58, 0xce, 0xca, 0xc9, 0x32, 0x79, 0xce, 0x78, 0x72, 0x76, 0x8a, 0x47, 0x00, 0x6f, 0x88, + 0xce, 0xc9, 0x2d, 0xbf, 0x07, 0xca, 0x92, 0x9c, 0x95, 0x29, 0xef, 0x21, 0x58, 0xc1, 0xc1, 0xc2, + 0x39, 0xf5, 0x4d, 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0x58, 0xf2, 0xab, 0x66, 0x66, 0x90, 0xae, 0x6c, 0x10, 0x4d, + 0x4c, 0x3c, 0xe5, 0xdd, 0x01, 0xdf, 0xc3, 0xe1, 0x80, 0x28, 0x4b, 0xf2, 0xc9, 0xff, 0x7b, 0x1b, + 0x52, 0x2d, 0x8f, 0x3f, 0x95, 0x97, 0x2a, 0x7c, 0xd9, 0xac, 0x2b, 0x69, 0xf5, 0xfc, 0x87, 0xb5, + 0x6b, 0xd9, 0x3d, 0x9f, 0x49, 0xeb, 0x68, 0x2e, 0xad, 0xd6, 0xd6, 0xcc, 0xa3, 0xe7, 0x7a, 0x27, + 0xfe, 0x38, 0x2f, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x25, 0x2c, 0xc4, 0x4f, 0x03, 0x00, + 0x00, } diff --git a/common/model/nodeRegistration.pb.go b/common/model/nodeRegistration.pb.go index 400be9747..b5a68f6fe 100644 --- a/common/model/nodeRegistration.pb.go +++ b/common/model/nodeRegistration.pb.go @@ -429,29 +429,29 @@ func init() { func init() { proto.RegisterFile("model/nodeRegistration.proto", fileDescriptor_df1af0ec89e31788) } var fileDescriptor_df1af0ec89e31788 = []byte{ - // 369 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x94, 0xcf, 0x4a, 0xeb, 0x40, - 0x14, 0xc6, 0x99, 0xf4, 0xcf, 0x6d, 0xe7, 0xb6, 0xe5, 0x92, 0xc5, 0x65, 0xd0, 0x0a, 0x21, 0x88, - 0x04, 0xc1, 0x66, 0xe1, 0x13, 0xb4, 0x08, 0x2a, 0x16, 0xd1, 0x01, 0x37, 0xee, 0x92, 0x99, 0x43, - 0x1b, 0x6c, 0x72, 0x6a, 0x66, 0xb2, 0xd0, 0x57, 0xf1, 0x45, 0x5c, 0x74, 0xeb, 0x7b, 0xc9, 0xa4, - 0x11, 0xda, 0x34, 0x45, 0x05, 0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, 0xb7, 0xc8, 0xc7, 0xdc, - 0xb2, 0x3e, 0xe1, 0x56, 0x6d, 0x9b, 0x5b, 0xee, 0x82, 0xd0, 0x9d, 0x0a, 0x75, 0x3f, 0x42, 0x5c, - 0x79, 0x2b, 0xeb, 0x1b, 0x5b, 0xe9, 0xbe, 0x10, 0xba, 0x77, 0x33, 0x97, 0x81, 0x86, 0x6d, 0x1d, - 0xf4, 0xa8, 0x55, 0x04, 0xb4, 0xc3, 0xad, 0x2f, 0x0f, 0xe7, 0xbb, 0x0a, 0x37, 0xc3, 0xd6, 0xa8, - 0x08, 0x9b, 0xbb, 0xb0, 0x68, 0xbf, 0x3a, 0x24, 0x6a, 0x8e, 0x89, 0x82, 0x6f, 0x6e, 0xe3, 0x97, - 0x9f, 0xb1, 0xd1, 0xe1, 0xad, 0x37, 0x89, 0xf4, 0x34, 0x0b, 0x07, 0x02, 0x63, 0xff, 0x11, 0x31, - 0x14, 0xcb, 0xe7, 0x91, 0xc0, 0x14, 0x7c, 0x81, 0x71, 0x8c, 0x89, 0x9f, 0x5f, 0x65, 0x61, 0x33, - 0xbf, 0xd8, 0x8e, 0x5f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x3b, 0xa0, 0x49, 0x23, 0xf8, 0x04, 0x00, - 0x00, + // 371 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x54, 0xc1, 0x4a, 0xc3, 0x40, + 0x10, 0x65, 0xd3, 0x36, 0xb6, 0x6b, 0x5b, 0x64, 0x0f, 0x12, 0x6a, 0x85, 0x10, 0x44, 0x82, 0x60, + 0x23, 0xf8, 0x05, 0x2d, 0x82, 0x8a, 0x45, 0x74, 0xc1, 0x8b, 0xb7, 0x64, 0x33, 0xb4, 0xc1, 0x26, + 0x53, 0xb3, 0x9b, 0x83, 0xfe, 0x8a, 0xbf, 0xe2, 0xc1, 0xab, 0x7f, 0x25, 0x9b, 0x46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 0x14, 0x54, 0x59, 0x45, 0xc9, 0xe1, 0x3e, 0xd3, 0xff, 0x2d, 0x29, + 0x46, 0xbe, 0xa6, 0x98, 0xf1, 0x0d, 0xc5, 0x2a, 0xeb, 0x14, 0x73, 0x9e, 0x09, 0xed, 0xac, 0x60, + 0xf7, 0x27, 0xc8, 0x95, 0xdb, 0x59, 0x5d, 0x6a, 0xa7, 0xf3, 0x4a, 0xe8, 0xee, 0xcd, 0x34, 0xf4, + 0x15, 0xac, 0xab, 0xa0, 0x4d, 0x8d, 0xc2, 0xa8, 0x4d, 0x6e, 0xfc, 0xb8, 0x41, 0x3f, 0x65, 0xb8, + 0x6c, 0xb8, 0xda, 0x1a, 0xc3, 0xe9, 0x59, 0xeb, 0xae, 0x36, 0x8a, 0x9c, 0x62, 0x22, 0xe1, 0x97, + 0x4b, 0xf9, 0x07, 0xb3, 0x36, 0x38, 0xb8, 0x75, 0x47, 0x91, 0x1a, 0x67, 0x41, 0x4f, 0x60, 0xec, + 0x3d, 0x22, 0x06, 0x62, 0xf6, 0x3c, 0x14, 0x98, 0x82, 0x27, 0x30, 0x8e, 0x31, 0xf1, 0xf2, 0xd5, + 0x16, 0x98, 0xf9, 0xa2, 0x3b, 0x7e, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x67, 0xe1, 0x01, 0xd3, 0x08, + 0x05, 0x00, 0x00, } diff --git a/common/model/peer.pb.go b/common/model/peer.pb.go index dbc36b0bc..a640ed264 100644 --- a/common/model/peer.pb.go +++ b/common/model/peer.pb.go @@ -274,28 +274,28 @@ func init() { func init() { proto.RegisterFile("model/peer.proto", fileDescriptor_10c2876293c17304) } var fileDescriptor_10c2876293c17304 = []byte{ - // 357 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0xeb, 0xd3, 0x30, - 0x14, 0xc7, 0xc9, 0x6f, 0xed, 0xe6, 0xde, 0x10, 0x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x3d, 0x36, - 0x6d, 0xdf, 0x39, 0x96, 0x2c, 0x8d, 0xd5, 0x2d, 0x94, 0x6c, 0x60, 0xd1, 0xc7, 0xb0, 0x2e, 0x5c, - 0xad, 0x15, 0xba, 0x96, 0x8c, 0x43, 0x2e, 0x60, 0xb2, 0xef, 0xb4, 0x46, 0xe7, 0x42, 0x2c, 0x0f, - 0xd4, 0xb9, 0xe4, 0x4b, 0x88, 0xdf, 0x59, 0x4b, 0x36, 0xdc, 0x7f, 0xaa, 0x86, 0x22, 0xc9, 0x80, - 0x6f, 0xd1, 0xf7, 0x73, 0xfa, 0xc4, 0xce, 0x41, 0x08, 0x98, 0x7c, 0x45, 0xeb, 0x6a, 0x32, 0x61, - 0xca, 0x54, 0x9d, 0xcb, 0xe4, 0x0d, 0x2c, 0xb7, 0xe8, 0x3f, 0x90, 0xc5, 0xde, 0xe3, 0xfe, 0xed, - 0x7d, 0x0a, 0x71, 0x10, 0x04, 0x93, 0xa3, 0xff, 0x1f, 0x63, 0x20, 0xc9, 0x6b, 0x98, 0xef, 0xd1, - 0x54, 0x27, 0xdf, 0xb0, 0xe8, 0x7e, 0xdb, 0x7a, 0xf5, 0x2d, 0x3d, 0xd4, 0xfe, 0x47, 0x57, 0x66, - 0x9a, 0x9a, 0xfc, 0x37, 0x51, 0xa9, 0x87, 0xf3, 0xb9, 0x26, 0x8b, 0xb9, 0xa6, 0xa6, 0x21, 0x93, - 0x07, 0x5f, 0x39, 0x0e, 0x3f, 0xe4, 0xd5, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x2b, 0x21, - 0x42, 0x4e, 0x02, 0x00, 0x00, + // 362 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0xeb, 0xd3, 0x40, + 0x10, 0xc5, 0xd9, 0x36, 0x69, 0xed, 0x14, 0xa1, 0x5d, 0x7b, 0x58, 0xbc,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0x73, 0xd8, 0xb4, 0xfd, 0xf6, 0x24, 0x62, 0x49, 0x28, 0x6f, 0xa1, 0x78, 0x03, + 0xcb, 0xbe, 0x8e, 0xbc, 0xb0, 0xb5, 0x92, 0x68, 0x5b, 0xd2, 0x16, 0xb9, 0x80, 0xe9, 0xbe, 0x53, + 0x0a, 0xad, 0xf5, 0xf5, 0x3c, 0x90, 0xe7, 0x91, 0xaf, 0x20, 0x7c, 0x6f, 0x0c, 0x19, 0xdf, 0xc3, + 0x4c, 0x0e, 0x43, 0x9c, 0x02, 0xdf, 0xa2, 0xeb, 0xef, 0xf4, 0xcd, 0x9d, 0x0b, 0x11, 0x30, 0xfd, + 0x86, 0xc6, 0xd6, 0xa4, 0xfd, 0x95, 0x99, 0x3c, 0x8f, 0xf1, 0x5b, 0x58, 0x6d, 0xd1, 0x7d, 0x24, + 0x83, 0xbd, 0xc7, 0xfe, 0xcf, 0x7d, 0x0a, 0xa1, 0x17, 0x04, 0x8b, 0xc6, 0x77, 0x7f, 0xca, 0x40, + 0xe2, 0x37, 0xb0, 0xd8, 0xa3, 0xae, 0x4e, 0xbe, 0x21, 0xe8, 0x7e, 0x5b, 0xfe, 0xfc, 0x7b, 0x72, + 0xa8, 0xdd, 0xcf, 0xae, 0x4c, 0x15, 0x35, 0xd9, 0x1f, 0xa2, 0x52, 0x0d, 0xdf, 0x97, 0x8a, 0x0c, + 0x66, 0x8a, 0x9a, 0x86, 0x74, 0xe6, 0x7d, 0xe5, 0xc4, 0xbf, 0x94, 0xd7, 0xff, 0x02, 0x00, 0x00, + 0xff, 0xff, 0xa2, 0x5f, 0x65, 0xf2, 0x56, 0x02, 0x00, 0x00, } diff --git a/common/model/transaction.pb.go b/common/model/transaction.pb.go index 3a8ad3cdc..d47c3f698 100644 --- a/common/model/transaction.pb.go +++ b/common/model/transaction.pb.go @@ -724,51 +724,52 @@ func init() { func init() { proto.RegisterFile("model/transaction.proto", fileDescriptor_8333001f09b34082) } var fileDescriptor_8333001f09b34082 = []byte{ - // 734 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xdd, 0x6e, 0xda, 0x58, - 0x10, 0xc6, 0x18, 0x92, 0xcd, 0x00, 0xf9, 0x39, 0x22, 0x70, 0xb4, 0x1b, 0x29, 0xc8, 0xda, 0x64, - 0xad, 0x68, 0x03, 0x12, 0x1b, 0xad, 0xf6, 0x36, 0x88, 0x6d, 0x89, 0x9a, 0x36, 0xf4, 0x84, 0xf6, - 0xa2, 0x52, 0x2f, 0x8c, 0x3d, 0x01, 0x37, 0xf8, 0x1c, 0xd7, 0x3e, 0x28, 0xa2, 0xd7, 0x7d, 0x93, - 0xbe, 0x4a, 0x9f, 0xa5, 0xcf, 0x51, 0xf9, 0x60, 0x14, 0x63, 0x4c, 0x82, 0xd4, 0x1b, 0xc4, 0x7c, - 0xf3, 0xcd, 0x37, 0x33, 0x1e, 0xcf, 0x18, 0xea, 0x9e, 0x70, 0x70, 0xd2, 0x92, 0x81, 0xc5, 0x43, - 0xcb, 0x96, 0xae, 0xe0, 0x4d, 0x3f, 0x10, 0x52, 0x90, 0xa2, 0x72, 0xfc, 0x7e, 0x34, 0xf7, 0xfb, - 0x81, 0x10, 0x77, 0x37, 0x77, 0x37, 0x0f, 0x1c, 0x83, 0x70, 0xec, 0xfa, 0x73, 0x92, 0xf1, 0x6d, - 0x1b, 0x4a, 0x83, 0xc7, 0x50, 0x42, 0x61, 0xfb, 0x3d, 0x06, 0xa1, 0x2b, 0x38, 0xd5, 0x1a, 0x9a, - 0x59, 0x61, 0x0b, 0x93, 0xec, 0x42, 0xfe, 0xaa, 0x4b, 0xf3, 0x0d, 0xcd, 0xd4, 0x59, 0xfe, 0xaa, - 0x1b, 0x31, 0x3b, 0x13, 0x61, 0xdf, 0x5f, 0x75, 0xa9, 0xae, 0xc0, 0x85, 0x49, 0x6a, 0xb0, 0xd5, - 0x43, 0x77, 0x34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, 0x62, 0xb9, 0xf7, 0x01, 0xef, 0x07, 0x00, 0x00, + // 745 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xdd, 0x6e, 0xea, 0x46, + 0x10, 0xc6, 0xfc, 0x96, 0x01, 0xf2, 0xb3, 0x22, 0xb0, 0x4a, 0x23, 0xc5, 0xb2, 0x9a, 0xc8, 0x4a, + 0x1b, 0xa8, 0x68, 0x14, 0xf5, 0x36, 0x88, 0xb6, 0x44, 0x4d, 0x1b, 0xea, 0xd0, 0x5e, 0x54, 0xea, + 0x85, 0xb1, 0x27, 0xe0, 0x06, 0xef, 0xba, 0xf6, 0xa2, 0x88, 0x5e, 0xf7, 0x8d, 0xfa, 0x12, 0x7d, + 0x96, 0x3e, 0xc5, 0x91, 0xd7, 0x26, 0x31, 0xc6, 0x1c, 0x90, 0xce, 0x0d, 0x62, 0xbf, 0xf9, 0x66, + 0xe6, 0x9b, 0x9d, 0x9d, 0x31, 0xb4, 0x5d, 0x6e, 0xe3, 0xbc, 0x2b, 0x7c, 0x93, 0x05, 0xa6, 0x25, + 0x1c, 0xce, 0x3a, 0x9e, 0xcf, 0x05, 0x27, 0x25, 0x69, 0x38, 0x3d, 0x8b, 0xec, 0x9e, 0xcf, 0xf9, + 0xf3, 0xe3, 0xf3, 0xe3, 0x2b, 0x43, 0x3f, 0x98, 0x39, 0x5e, 0x44, 0xd2, 0xfe, 0xad, 0x40, 0x6d, + 0xfc, 0xee, 0x4a, 0x28, 0x54, 0x7e, 0x43, 0x3f, 0x70, 0x38, 0xa3, 0x8a, 0xaa, 0xe8, 0x0d, 0x63, + 0x75, 0x24, 0x04, 0xf2, 0xf7, 0x03, 0x9a, 0x57, 0x15, 0xbd, 0xd0, 0xcf, 0x7f, 0xad, 0x18, 0xf9, + 0xfb, 0x01, 0x39, 0x83, 0x4a, 0x7f, 0xce, 0xad, 0x97, 0xfb, 0x01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bb, 0x16, + 0x77, 0x5d, 0xce, 0xba, 0x52, 0xca, 0xa4, 0x2c, 0xbf, 0xe9, 0xdf, 0x7c, 0x08, 0x00, 0x00, 0xff, + 0xff, 0x67, 0xc6, 0xc5, 0x7c, 0x13, 0x08, 0x00, 0x00, } diff --git a/common/query/blockQuery.go b/common/query/blockQuery.go index 379a23279..29fed7a53 100644 --- a/common/query/blockQuery.go +++ b/common/query/blockQuery.go @@ -17,6 +17,7 @@ type ( GetGenesisBlock() string GetBlockByID(int64) string GetBlockByHeight(uint32) string + GetBlockFromHeight(uint32, uint32) string InsertBlock(block *model.Block) (str string, args []interface{}) ExtractModel(block *model.Block) []interface{} BuildModel(blocks []*model.Block, rows *sql.Rows) []*model.Block @@ -88,6 +89,12 @@ func (bq *BlockQuery) GetBlockByHeight(height uint32) string { return fmt.Sprintf("SELECT %s FROM %s WHERE height = %d", strings.Join(bq.Fields, ", "), bq.getTableName(), height) } +// GetBlockFromHeight returns query string to get blocks from a certain height +func (bq *BlockQuery) GetBlockFromHeight(startHeight, limit uint32) string { + return fmt.Sprintf("SELECT %s FROM %s WHERE HEIGHT >= %d ORDER BY HEIGHT LIMIT %d", + strings.Join(bq.Fields, ", "), bq.getTableName(), startHeight, limit) +} + // ExtractModel extract the model struct fields to the order of BlockQuery.Fields func (*BlockQuery) ExtractModel(block *model.Block) []interface{} { return []interface{}{ diff --git a/common/schema b/common/schema index 6111abb12..ef6b4cbdd 160000 --- a/common/schema +++ b/common/schema @@ -1 +1 @@ -Subproject commit 6111abb12863d1bb1bab8ad8cb199d5e49480693 +Subproject commit ef6b4cbdd8bf63846a4ead37326747d662b474ae diff --git a/common/service/host.pb.go b/common/service/host.pb.go index d02b8eda7..60e2512e3 100644 --- a/common/service/host.pb.go +++ b/common/service/host.pb.go @@ -35,13 +35,13 @@ var fileDescriptor_fc2df5144b0d0a79 = []byte{ 0x87, 0x8a, 0x49, 0x09, 0xe6, 0xe6, 0xa7, 0xa4, 0xe6, 0xe8, 0xa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x81, 0xdd, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xa2, 0xd3, 0xe6, 0xd9, 0xed, 0x00, + 0xba, 0xc9, 0xf9, 0x45, 0xa9, 0xfa, 0xc9, 0xf9, 0xb9, 0xb9, 0xf9, 0x79, 0xfa, 0x50, 0xbf, 0x24, + 0xb1, 0x81, 0xdd, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x2a, 0x13, 0x7f, 0x48, 0xf1, 0x00, 0x00, 0x00, } @@ -57,7 +57,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type HostServiceClient interface { - GetHostInfo(ctx context.Context, in *model.Empty, opts ...grpc.CallOption) (*model.Host, error) + GetHostInfo(ctx context.Context, in *model.Empty, opts ...grpc.CallOption) (*model.HostInfo, error) } type hostServiceClient struct { @@ -68,8 +68,8 @@ func NewHostServiceClient(cc *grpc.ClientConn) HostServiceClient { return &hostServiceClient{cc} } -func (c *hostServiceClient) GetHostInfo(ctx context.Context, in *model.Empty, opts ...grpc.CallOption) (*model.Host, error) { - out := new(model.Host) +func (c *hostServiceClient) GetHostInfo(ctx context.Context, in *model.Empty, opts ...grpc.CallOption) (*model.HostInfo, error) { + out := new(model.HostInfo) err := c.cc.Invoke(ctx, "/service.HostService/GetHostInfo", in, out, opts...) if err != nil { return nil, err @@ -79,14 +79,14 @@ func (c *hostServiceClient) GetHostInfo(ctx context.Context, in *model.Empty, op // HostServiceServer is the server API for HostService service. type HostServiceServer interface { - GetHostInfo(context.Context, *model.Empty) (*model.Host, error) + GetHostInfo(context.Context, *model.Empty) (*model.HostInfo, error) } // UnimplementedHostServiceServer can be embedded to have forward compatible implementations. type UnimplementedHostServiceServer struct { } -func (*UnimplementedHostServiceServer) GetHostInfo(ctx context.Context, req *model.Empty) (*model.Host, error) { +func (*UnimplementedHostServiceServer) GetHostInfo(ctx context.Context, req *model.Empty) (*model.HostInfo, error) { return nil, status.Errorf(codes.Unimplemented, "method GetHostInfo not implemented") } diff --git a/common/service/p2pCommunication.pb.go b/common/service/p2pCommunication.pb.go index b54b73503..44ba68e5b 100644 --- a/common/service/p2pCommunication.pb.go +++ b/common/service/p2pCommunication.pb.go @@ -28,25 +28,32 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package func init() { proto.RegisterFile("service/p2pCommunication.proto", fileDescriptor_5d547fbc25d9babc) } var fileDescriptor_5d547fbc25d9babc = []byte{ - // 280 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4f, 0x4b, 0xc4, 0x30, - 0x10, 0xc5, 0x17, 0x0f, 0x8a, 0xd9, 0x05, 0xd7, 0x5c, 0x16, 0x2b, 0x7a, 0xd8, 0x9b, 0xa2, 0x0d, - 0x54, 0xc1, 0x83, 0x17, 0x59, 0x91, 0xc5, 0x83, 0x52, 0x56, 0x4f, 0xde, 0xda, 0x74, 0xd4, 0xe2, - 0x26, 0x13, 0x93, 0x54, 0xd0, 0xaf, 0xe4, 0x97, 0x94, 0x34, 0xe9, 0x3f, 0x64, 0x2f, 0x85, 0xfe, - 0xde, 0x7b, 0xf3, 0xa6, 0x53, 0x72, 0x6c, 0x40, 0x7f, 0x95, 0x1c, 0x98, 0x4a, 0xd4, 0x2d, 0x0a, - 0x51, 0xc9, 0x92, 0x67, 0xb6, 0x44, 0x19, 0x2b, 0x8d, 0x16, 0xe9, 0x4e, 0xd0, 0xa3, 0xa9, 0xc0, - 0x02, 0xd6, 0x4c, 0x01, 0x68, 0x2f, 0x35, 0x44, 0x62, 0x01, 0x81, 0xec, 0x7b, 0x02, 0x42, 0xd9, - 0xef, 0x21, 0xca, 0xd7, 0xc8, 0x3f, 0x02, 0x9a, 0x79, 0x64, 0x75, 0x26, 0x4d, 0xc6, 0xbb, 0xae, - 0xe4, 0x77, 0x8b, 0x4c, 0xd3, 0x24, 0x1d, 0xac, 0x41, 0xaf, 0xc8, 0x78, 0x09, 0x36, 0x05, 0xd0, - 0xf7, 0xf2, 0x15, 0xe9, 0x41, 0x5c, 0xa7, 0xe3, 0x1e, 0x5b, 0xc1, 0x67, 0x05, 0xc6, 0x46, 0xe3, - 0x20, 0x3d, 0x62, 0x01, 0xf3, 0x11, 0xbd, 0x26, 0x93, 0x25, 0xd8, 0x07, 0xd4, 0xe0, 0x8c, 0x86, - 0x4e, 0x82, 0x7c, 0xe7, 0xb6, 0x8b, 0x0e, 0xbb, 0x39, 0xad, 0x65, 0x05, 0x46, 0xa1, 0x34, 0x2e, - 0x7c, 0x49, 0x76, 0x9f, 0x40, 0x16, 0x3e, 0x39, 0x0b, 0xde, 0x96, 0x34, 0x8d, 0x83, 0x91, 0xf3, - 0x11, 0x3d, 0xf1, 0xa9, 0x85, 0xfb, 0xd8, 0xb6, 0xaf, 0x7e, 0xfb, 0x67, 0xbd, 0x21, 0x7b, 0xce, - 0xfa, 0xdc, 0x1d, 0x81, 0x1e, 0xf5, 0x6a, 0x7a, 0x7c, 0x43, 0xd9, 0xe2, 0xec, 0xe5, 0xf4, 0xad, - 0xb4, 0xef, 0x55, 0x1e, 0x73, 0x14, 0xec, 0x07, 0x31, 0xe7, 0xfe, 0x79, 0xce, 0x51, 0x03, 0xe3, - 0x28, 0x04, 0x4a, 0x16, 0x7e, 0x5f, 0xbe, 0x5d, 0x9f, 0xf8, 0xe2, 0x2f, 0x00, 0x00, 0xff, 0xff, - 0xe0, 0x07, 0x23, 0x05, 0xf0, 0x01, 0x00, 0x00, + // 398 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x41, 0xeb, 0xd3, 0x40, + 0x10, 0xc5, 0x7b, 0x51, 0x71, 0xff, 0x95, 0xb6, 0x7b, 0x30, 0x98, 0x52, 0x0f, 0x05, 0xc5, 0x8a, + 0x26, 0x50, 0x05, 0x0f, 0x5e, 0xb4, 0xad, 0x84, 0x22, 0x2d, 0xa5, 0x7a, 0xf2, 0x96, 0x6c, 0xa6, + 0x76, 0x35, 0xbb, 0x13, 0xb3, 0x9b, 0x62, 0xfd, 0x2c, 0x7e, 0x58, 0x49, 0xb2, 0xdd, 0x6c, 0xb0, + 0xe2, 0xff, 0x12, 0xc8, 0x6f, 0xde, 0xbc, 0x37, 0x33, 0x24, 0xe4, 0xb1, 0x82, 0xe2, 0xc4, 0x19, + 0x84, 0xf9, 0x3c, 0x5f, 0xa2, 0x10, 0xa5, 0xe4, 0x2c, 0xd6, 0x1c, 0x65, 0x90, 0x17, 0xa8, 0x91, + 0xde, 0x33, 0x75, 0x7f, 0x28, 0x30, 0x85, 0x2c, 0xcc, 0x01, 0x8a, 0xa6, 0x74, 0x21, 0x12, 0x53, + 0x30, 0x64, 0xd4, 0x10, 0x10, 0xb9, 0x3e, 0x77, 0x51, 0x92, 0x21, 0xfb, 0x6e, 0xd0, 0x43, 0x07, + 0xb1, 0x63, 0xcc, 0x4d, 0x94, 0xef, 0x35, 0x5c, 0x17, 0xb1, 0x54, 0x31, 0x6b, 0x67, 0x98, 0xff, + 0xbe, 0x43, 0x86, 0xbb, 0xf9, 0xae, 0x33, 0x1e, 0x7d, 0x43, 0x6e, 0x22, 0xd0, 0x3b, 0x80, 0x62, + 0x2d, 0x0f, 0x48, 0x1f, 0x05, 0x75, 0x77, 0xe0, 0xb0, 0x3d, 0xfc, 0x28, 0x41, 0x69, 0xff, 0xc6, + 0x94, 0xb6, 0x98, 0xc2, 0xb4, 0x47, 0xdf, 0x92, 0x7e, 0x04, 0x7a, 0x83, 0x05, 0x54, 0x42, 0x45, + 0xfb, 0xa6, 0xfc, 0xa1, 0x9a, 0xda, 0x1f, 0xb7, 0x3e, 0x56, 0xb2, 0x07, 0x95, 0xa3, 0x54, 0x55, + 0xf3, 0x6b, 0x72, 0xff, 0x13, 0xc8, 0xb4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0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -66,6 +73,10 @@ type P2PCommunicationClient interface { SendPeers(ctx context.Context, in *model.SendPeersRequest, opts ...grpc.CallOption) (*model.Empty, error) SendBlock(ctx context.Context, in *model.Block, opts ...grpc.CallOption) (*model.Empty, error) SendTransaction(ctx context.Context, in *model.SendTransactionRequest, opts ...grpc.CallOption) (*model.Empty, error) + GetCumulativeDifficulty(ctx context.Context, in *model.GetCumulativeDifficultyRequest, opts ...grpc.CallOption) (*model.GetCumulativeDifficultyResponse, error) + GetCommonMilestoneBlockIDs(ctx context.Context, in *model.GetCommonMilestoneBlockIdsRequest, opts ...grpc.CallOption) (*model.GetCommonMilestoneBlockIdsResponse, error) + GetNextBlockIDs(ctx context.Context, in *model.GetNextBlockIdsRequest, opts ...grpc.CallOption) (*model.BlockIdsResponse, error) + GetNextBlocks(ctx context.Context, in *model.GetNextBlocksRequest, opts ...grpc.CallOption) (*model.BlocksData, error) } type p2PCommunicationClient struct { @@ -121,6 +132,42 @@ func (c *p2PCommunicationClient) SendTransaction(ctx context.Context, in *model. return out, nil } +func (c *p2PCommunicationClient) GetCumulativeDifficulty(ctx context.Context, in *model.GetCumulativeDifficultyRequest, opts ...grpc.CallOption) (*model.GetCumulativeDifficultyResponse, error) { + out := new(model.GetCumulativeDifficultyResponse) + err := c.cc.Invoke(ctx, "/service.P2PCommunication/GetCumulativeDifficulty", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p2PCommunicationClient) GetCommonMilestoneBlockIDs(ctx context.Context, in *model.GetCommonMilestoneBlockIdsRequest, opts ...grpc.CallOption) (*model.GetCommonMilestoneBlockIdsResponse, error) { + out := new(model.GetCommonMilestoneBlockIdsResponse) + err := c.cc.Invoke(ctx, "/service.P2PCommunication/GetCommonMilestoneBlockIDs", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p2PCommunicationClient) GetNextBlockIDs(ctx context.Context, in *model.GetNextBlockIdsRequest, opts ...grpc.CallOption) (*model.BlockIdsResponse, error) { + out := new(model.BlockIdsResponse) + err := c.cc.Invoke(ctx, "/service.P2PCommunication/GetNextBlockIDs", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *p2PCommunicationClient) GetNextBlocks(ctx context.Context, in *model.GetNextBlocksRequest, opts ...grpc.CallOption) (*model.BlocksData, error) { + out := new(model.BlocksData) + err := c.cc.Invoke(ctx, "/service.P2PCommunication/GetNextBlocks", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // P2PCommunicationServer is the server API for P2PCommunication service. type P2PCommunicationServer interface { GetPeerInfo(context.Context, *model.GetPeerInfoRequest) (*model.Node, error) @@ -128,6 +175,10 @@ type P2PCommunicationServer interface { SendPeers(context.Context, *model.SendPeersRequest) (*model.Empty, error) SendBlock(context.Context, *model.Block) (*model.Empty, error) SendTransaction(context.Context, *model.SendTransactionRequest) (*model.Empty, error) + GetCumulativeDifficulty(context.Context, *model.GetCumulativeDifficultyRequest) (*model.GetCumulativeDifficultyResponse, error) + GetCommonMilestoneBlockIDs(context.Context, *model.GetCommonMilestoneBlockIdsRequest) (*model.GetCommonMilestoneBlockIdsResponse, error) + GetNextBlockIDs(context.Context, *model.GetNextBlockIdsRequest) (*model.BlockIdsResponse, error) + GetNextBlocks(context.Context, *model.GetNextBlocksRequest) (*model.BlocksData, error) } // UnimplementedP2PCommunicationServer can be embedded to have forward compatible implementations. @@ -149,6 +200,18 @@ func (*UnimplementedP2PCommunicationServer) SendBlock(ctx context.Context, req * func (*UnimplementedP2PCommunicationServer) SendTransaction(ctx context.Context, req *model.SendTransactionRequest) (*model.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method SendTransaction not implemented") } +func (*UnimplementedP2PCommunicationServer) GetCumulativeDifficulty(ctx context.Context, req *model.GetCumulativeDifficultyRequest) (*model.GetCumulativeDifficultyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCumulativeDifficulty not implemented") +} +func (*UnimplementedP2PCommunicationServer) GetCommonMilestoneBlockIDs(ctx context.Context, req *model.GetCommonMilestoneBlockIdsRequest) (*model.GetCommonMilestoneBlockIdsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCommonMilestoneBlockIDs not implemented") +} +func (*UnimplementedP2PCommunicationServer) GetNextBlockIDs(ctx context.Context, req *model.GetNextBlockIdsRequest) (*model.BlockIdsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetNextBlockIDs not implemented") +} +func (*UnimplementedP2PCommunicationServer) GetNextBlocks(ctx context.Context, req *model.GetNextBlocksRequest) (*model.BlocksData, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetNextBlocks not implemented") +} func RegisterP2PCommunicationServer(s *grpc.Server, srv P2PCommunicationServer) { s.RegisterService(&_P2PCommunication_serviceDesc, srv) @@ -244,6 +307,78 @@ func _P2PCommunication_SendTransaction_Handler(srv interface{}, ctx context.Cont return interceptor(ctx, in, info, handler) } +func _P2PCommunication_GetCumulativeDifficulty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(model.GetCumulativeDifficultyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P2PCommunicationServer).GetCumulativeDifficulty(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/service.P2PCommunication/GetCumulativeDifficulty", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P2PCommunicationServer).GetCumulativeDifficulty(ctx, req.(*model.GetCumulativeDifficultyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _P2PCommunication_GetCommonMilestoneBlockIDs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(model.GetCommonMilestoneBlockIdsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P2PCommunicationServer).GetCommonMilestoneBlockIDs(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/service.P2PCommunication/GetCommonMilestoneBlockIDs", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P2PCommunicationServer).GetCommonMilestoneBlockIDs(ctx, req.(*model.GetCommonMilestoneBlockIdsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _P2PCommunication_GetNextBlockIDs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(model.GetNextBlockIdsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P2PCommunicationServer).GetNextBlockIDs(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/service.P2PCommunication/GetNextBlockIDs", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P2PCommunicationServer).GetNextBlockIDs(ctx, req.(*model.GetNextBlockIdsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _P2PCommunication_GetNextBlocks_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(model.GetNextBlocksRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(P2PCommunicationServer).GetNextBlocks(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/service.P2PCommunication/GetNextBlocks", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(P2PCommunicationServer).GetNextBlocks(ctx, req.(*model.GetNextBlocksRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _P2PCommunication_serviceDesc = grpc.ServiceDesc{ ServiceName: "service.P2PCommunication", HandlerType: (*P2PCommunicationServer)(nil), @@ -268,6 +403,22 @@ var _P2PCommunication_serviceDesc = grpc.ServiceDesc{ MethodName: "SendTransaction", Handler: _P2PCommunication_SendTransaction_Handler, }, + { + MethodName: "GetCumulativeDifficulty", + Handler: _P2PCommunication_GetCumulativeDifficulty_Handler, + }, + { + MethodName: "GetCommonMilestoneBlockIDs", + Handler: _P2PCommunication_GetCommonMilestoneBlockIDs_Handler, + }, + { + MethodName: "GetNextBlockIDs", + Handler: _P2PCommunication_GetNextBlockIDs_Handler, + }, + { + MethodName: "GetNextBlocks", + Handler: _P2PCommunication_GetNextBlocks_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "service/p2pCommunication.proto", diff --git a/common/util/number.go b/common/util/number.go new file mode 100644 index 000000000..b6c8f4350 --- /dev/null +++ b/common/util/number.go @@ -0,0 +1,17 @@ +package util + +// MinUint32 returns the smallest uint32 number supplied +func MinUint32(x, y uint32) uint32 { + if x < y { + return x + } + return y +} + +// MaxUint32 returns the largest uint32 number supplied +func MaxUint32(x, y uint32) uint32 { + if x > y { + return x + } + return y +} diff --git a/common/util/number_test.go b/common/util/number_test.go new file mode 100644 index 000000000..c007a591f --- /dev/null +++ b/common/util/number_test.go @@ -0,0 +1,75 @@ +package util + +import "testing" + +func TestMinUint32(t *testing.T) { + type args struct { + number1 uint32 + number2 uint32 + } + tests := []struct { + name string + args args + want uint32 + }{ + { + name: "TestMinUint32: first number is smaller", + args: args{ + number1: 1, + number2: 2, + }, + want: 1, + }, + { + name: "TestMinUint32: second number is smaller", + args: args{ + number1: 2, + number2: 1, + }, + want: 1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MinUint32(tt.args.number1, tt.args.number2); got != tt.want { + t.Errorf("TestMinUint32() = %v want %v", got, tt.want) + } + }) + } +} + +func TestMaxUint32(t *testing.T) { + type args struct { + number1 uint32 + number2 uint32 + } + tests := []struct { + name string + args args + want uint32 + }{ + { + name: "TestMaxUint32: first number is larger", + args: args{ + number1: 2, + number2: 1, + }, + want: 2, + }, + { + name: "TestMaxUint32: second number is larger", + args: args{ + number1: 1, + number2: 2, + }, + want: 2, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := MaxUint32(tt.args.number1, tt.args.number2); got != tt.want { + t.Errorf("TestMaxUint32() = %v want %v", got, tt.want) + } + }) + } +} diff --git a/core/blockchainsync/blockchainSync.go b/core/blockchainsync/blockchainSync.go new file mode 100644 index 000000000..7fee575a0 --- /dev/null +++ b/core/blockchainsync/blockchainSync.go @@ -0,0 +1,30 @@ +package blockchainsync + +import ( + "github.com/zoobc/zoobc-core/common/contract" + "github.com/zoobc/zoobc-core/common/model" + "github.com/zoobc/zoobc-core/core/service" + "github.com/zoobc/zoobc-core/p2p" +) + +type Service struct { + NeedGetMoreBlocks bool + IsDownloading bool // only for status + LastBlockchainFeeder *model.Peer + LastBlockchainFeederHeight uint32 + + PeerHasMore bool + + ChainType contract.ChainType + BlockService service.BlockServiceInterface + P2pService p2p.ServiceInterface +} + +func NewBlockchainSyncService(blockService service.BlockServiceInterface, p2pService p2p.ServiceInterface) *Service { + return &Service{ + NeedGetMoreBlocks: true, + ChainType: blockService.GetChainType(), + BlockService: blockService, + P2pService: p2pService, + } +} diff --git a/core/blockchainsync/downloadBlockchain.go b/core/blockchainsync/downloadBlockchain.go new file mode 100644 index 000000000..984ee7e6f --- /dev/null +++ b/core/blockchainsync/downloadBlockchain.go @@ -0,0 +1,379 @@ +package blockchainsync + +import ( + "errors" + "fmt" + "math/big" + "os" + "os/signal" + "syscall" + "time" + + log "github.com/sirupsen/logrus" + "github.com/zoobc/zoobc-core/common/blocker" + "github.com/zoobc/zoobc-core/common/model" + + "github.com/zoobc/zoobc-core/common/constant" + commonUtil "github.com/zoobc/zoobc-core/common/util" + coreUtil "github.com/zoobc/zoobc-core/core/util" +) + +func (bss *Service) Start(runNext chan bool) { + if bss.ChainType == nil { + log.Fatal("no chaintype") + } + if bss.P2pService == nil { + log.Fatal("no p2p service defined") + } + bss.GetMoreBlocksThread(runNext) +} + +func (bss *Service) GetMoreBlocksThread(runNext chan bool) { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + for { + select { + case download := <-runNext: + if download { + go bss.getMoreBlocks(runNext) + } + case <-sigs: + return + } + } +} + +func (bss Service) getMoreBlocks(runNext chan bool) { + log.Info("Get more blocks...") + // notify observer about start of blockchain download of this specific chain + + lastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + log.Fatal(fmt.Sprintf("failed to start getMoreBlocks go routine: %v", err)) + } + if lastBlock == nil { + log.Fatal("There is no genesis block found") + } + initialHeight := lastBlock.Height + for bss.NeedGetMoreBlocks { + currentLastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + log.Error(err) + continue + } + currentHeight := currentLastBlock.Height + err = bss.getPeerBlockchainInfo() + if err != nil { + log.Warnf("\nfailed to getPeerBlockchainInfo: %v\n\n", err) + } + afterDownloadLastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + log.Warnf("failed to get the last block state after block download") + continue + } + heightAfterDownload := afterDownloadLastBlock.Height + if currentHeight > 0 && currentHeight == heightAfterDownload { + bss.IsDownloading = false + log.Infof("Finished %s blockchain download: %d blocks pulled", bss.ChainType.GetName(), heightAfterDownload-initialHeight) + break + } + break + } + + // TODO: Handle interruption and other exceptions + time.Sleep(constant.GetMoreBlocksDelay * time.Second) + runNext <- true +} + +func (bss *Service) getPeerBlockchainInfo() error { + bss.PeerHasMore = true + peer := bss.P2pService.GetAnyResolvedPeer() + if peer == nil { + return errors.New("no connected peer can be found") + } + peerCumulativeDifficultyResponse, err := bss.P2pService.GetCumulativeDifficulty(peer, bss.ChainType) + if err != nil { + return fmt.Errorf("failed to get Cumulative Difficulty of peer %v: %v", peer.Info.Address, err) + } + + peerCumulativeDifficulty, _ := new(big.Int).SetString(peerCumulativeDifficultyResponse.CumulativeDifficulty, 10) + peerHeight := peerCumulativeDifficultyResponse.Height + + lastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + return err + } + lastBlockCumulativeDifficulty, _ := new(big.Int).SetString(lastBlock.CumulativeDifficulty, 10) + lastBlockHeight := lastBlock.Height + lastBlockID := lastBlock.ID + + if peerCumulativeDifficulty.Cmp(lastBlockCumulativeDifficulty) <= 0 { + return errors.New("peer's cumulative difficulty is lower/same with the current node's") + } + + // this is to set the status of download blockchain process + if peerHeight > 0 { + bss.LastBlockchainFeeder = peer + bss.LastBlockchainFeederHeight = peerHeight + } + + commonMilestoneBlockID := bss.ChainType.GetGenesisBlockID() + if lastBlockID != commonMilestoneBlockID { + var err error + commonMilestoneBlockID, err = bss.getPeerCommonBlockID(peer) + if err != nil { + return err + } + } + + chainBlockIds := bss.getBlockIdsAfterCommon(peer, commonMilestoneBlockID) + if len(chainBlockIds) < 2 || !bss.PeerHasMore { + return errors.New("the peer does not have more updated chain") + } + + commonBlockID := chainBlockIds[0] + commonBlock, err := bss.BlockService.GetBlockByID(commonBlockID) + if err != nil { + log.Warnf("common block %v not found, milestone block id: %v", commonBlockID, commonMilestoneBlockID) + return err + } + if commonBlock == nil || lastBlockHeight-commonBlock.GetHeight() >= 720 { + return errors.New("invalid common block") + } + + if !bss.IsDownloading && bss.LastBlockchainFeederHeight-commonBlock.GetHeight() > 10 { + log.Println("Blockchain download in progress") + bss.IsDownloading = true + } + + bss.BlockService.ChainWriteLock() + defer bss.BlockService.ChainWriteUnlock() + + errDownload := bss.downloadFromPeer(peer, chainBlockIds) + if errDownload != nil { + return errDownload + } + + // TODO: analyze the importance of this mechanism + confirmBlockchainError := bss.confirmBlockchainState(peer, commonMilestoneBlockID) + if confirmBlockchainError != nil { + return err + } + newLastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + return err + } + + if lastBlockID == newLastBlock.ID { + log.Println("Did not accept peers's blocks, back to our own fork") + } + return nil +} + +func (bss *Service) confirmBlockchainState(peer *model.Peer, commonMilestoneBlockID int64) error { + confirmations := int32(0) + // counting the confirmations of the common block received with other peers he knows + for _, peerToCheck := range bss.P2pService.GetResolvedPeers() { + if confirmations >= constant.DefaultNumberOfForkConfirmations { + break + } + + // if the host found other peer with better difficulty + otherPeerChainBlockIds := bss.getBlockIdsAfterCommon(peer, commonMilestoneBlockID) + currentLastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + return err + } + currentLastBlockCumulativeDifficulty, _ := new(big.Int).SetString(currentLastBlock.CumulativeDifficulty, 10) + if otherPeerChainBlockIds[0] == currentLastBlock.ID { + confirmations++ + continue + } + otherPeerCommonBlock, err := bss.BlockService.GetBlockByID(otherPeerChainBlockIds[0]) + if err != nil { + return err + } + if currentLastBlock.Height-otherPeerCommonBlock.Height >= 720 { + continue + } + + otherPeerCumulativeDifficultyResponse, err := bss.P2pService.GetCumulativeDifficulty(peerToCheck, bss.ChainType) + if err != nil || otherPeerCumulativeDifficultyResponse.CumulativeDifficulty == "" { + continue + } + + otherPeerCumulativeDifficulty, _ := new(big.Int).SetString(otherPeerCumulativeDifficultyResponse.CumulativeDifficulty, 10) + if otherPeerCumulativeDifficulty.Cmp(currentLastBlockCumulativeDifficulty) <= 0 { + continue + } + + log.Println("Found a peer with better difficulty") + errDownload := bss.downloadFromPeer(peerToCheck, otherPeerChainBlockIds) + if errDownload != nil { + return errDownload + } + } + log.Println("Got ", confirmations, " confirmations") + return nil +} + +func (bss *Service) downloadFromPeer(feederPeer *model.Peer, chainBlockIds []int64) error { + var peersTobeDeactivated []*model.Peer + segSize := constant.BlockDownloadSegSize + + stop := uint32(len(chainBlockIds) - 1) + + var peersSlice []*model.Peer + for _, peer := range bss.P2pService.GetResolvedPeers() { + peersSlice = append(peersSlice, peer) + } + + if len(peersSlice) < 1 { + return errors.New("the host does not have resolved peers") + } + + nextPeerIdx := int(commonUtil.GetSecureRandom()) % len(peersSlice) + peerUsed := feederPeer + blocksSegments := [][]*model.Block{} + + for start := uint32(0); start < stop; start += segSize { + if start != uint32(0) { + peerUsed = peersSlice[nextPeerIdx] + nextPeerIdx++ + if nextPeerIdx >= len(peersSlice) { + nextPeerIdx = 0 + } + } + + // TODO: apply retry mechanism + startTime := time.Now() + nextBlocks, err := bss.getNextBlocks(constant.BlockDownloadSegSize, peerUsed, chainBlockIds, + start, commonUtil.MinUint32(start+segSize, stop)) + if err != nil { + log.Warn(err) + return err + } + elapsedTime := time.Since(startTime) + if elapsedTime > constant.MaxResponseTime { + peersTobeDeactivated = append(peersTobeDeactivated, peerUsed) + } + + if len(nextBlocks) < 1 { + log.Warnf("disconnecting with peer %v for not responding correctly in getting the next blocks\n", peerUsed.Info.Address) + peersTobeDeactivated = append(peersTobeDeactivated, peerUsed) + continue + } + blocksSegments = append(blocksSegments, nextBlocks) + } + + blocksToBeProcessed := []*model.Block{} + for _, blockSegment := range blocksSegments { + for i := 0; i < len(blockSegment); i++ { + if coreUtil.IsBlockIDExist(chainBlockIds, blockSegment[i].ID) { + blocksToBeProcessed = append(blocksToBeProcessed, blockSegment[i]) + } + } + } + + for _, peer := range peersTobeDeactivated { + bss.P2pService.DisconnectPeer(peer) + } + + forkBlocks := []*model.Block{} + for _, block := range blocksToBeProcessed { + if block.Height == 0 { + continue + } + lastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + return err + } + previousBlockID := coreUtil.GetBlockIDFromHash(block.PreviousBlockHash) + if lastBlock.ID == previousBlockID { + err := bss.BlockService.PushBlock(lastBlock, block, false) + if err != nil { + // TODO: analyze the mechanism of blacklisting peer here + // bss.P2pService.Blacklist(peer) + log.Warnln("failed to push block from peer:", err) + } + } else { + forkBlocks = append(forkBlocks, block) + } + } + + if len(forkBlocks) > 0 { + log.Println("processing fork blocks...") + bss.processFork(forkBlocks) + } + return nil +} + +func (bss *Service) getPeerCommonBlockID(peer *model.Peer) (int64, error) { + lastMilestoneBlockID := int64(0) + lastBlock, err := bss.BlockService.GetLastBlock() + if err != nil { + log.Errorf("failed to get blockchain last block: %v\n", err) + return 0, err + } + lastBlockID := lastBlock.ID + for { + commonMilestoneBlockIDResponse, err := bss.P2pService.GetCommonMilestoneBlockIDs(peer, bss.ChainType, lastBlockID, lastMilestoneBlockID) + if err != nil { + log.Warnf("failed to get common milestone from the peer: %v\n", err) + bss.P2pService.DisconnectPeer(peer) + return 0, err + } + for _, blockID := range commonMilestoneBlockIDResponse.BlockIds { + _, err := bss.BlockService.GetBlockByID(blockID) + if err == nil { + return blockID, nil + } + errCasted := err.(blocker.Blocker) + if errCasted.Type != blocker.BlockNotFoundErr { + return 0, err + } + lastMilestoneBlockID = blockID + } + } +} + +func (bss *Service) getBlockIdsAfterCommon(peer *model.Peer, commonMilestoneBlockID int64) []int64 { + blockIds, err := bss.P2pService.GetNextBlockIDs(peer, bss.ChainType, commonMilestoneBlockID, constant.PeerGetBlocksLimit) + if err != nil { + return []int64{} + } + + newBlockIDIdx := 0 + for idx, blockID := range blockIds.BlockIds { + _, err := bss.BlockService.GetBlockByID(blockID) + // mark the new block ID starting where it is not found + if err != nil { + break + } + newBlockIDIdx = idx + } + if newBlockIDIdx >= len(blockIds.BlockIds) { + return []int64{} + } + return blockIds.BlockIds[newBlockIDIdx:] +} + +func (bss *Service) getNextBlocks(maxNextBlocks uint32, peerUsed *model.Peer, + blockIds []int64, start, stop uint32) ([]*model.Block, error) { + blocks := []*model.Block{} + nextBlocksResponse, err := bss.P2pService.GetNextBlocks(peerUsed, bss.ChainType, blockIds[start:stop], blockIds[start]) + nextBlocks := nextBlocksResponse.NextBlocks + nextBlocksLength := uint32(len(nextBlocks)) + if nextBlocksLength > maxNextBlocks { + return nil, fmt.Errorf("too many blocks returned (%d blocks), possibly a rogue peer %v", nextBlocksLength, peerUsed.Info.Address) + } + if nextBlocks == nil || err != nil || nextBlocksLength == 0 { + return nil, err + } + if len(nextBlocks) > 0 { + return nextBlocks, nil + } + return blocks, nil +} + +func (bss *Service) processFork(forkBlocks []*model.Block) {} diff --git a/core/blockchainsync/downloadBlockchain_test.go b/core/blockchainsync/downloadBlockchain_test.go new file mode 100644 index 000000000..f04e2d400 --- /dev/null +++ b/core/blockchainsync/downloadBlockchain_test.go @@ -0,0 +1,316 @@ +package blockchainsync + +import ( + "errors" + "fmt" + "reflect" + "testing" + + "github.com/zoobc/zoobc-core/common/blocker" + "github.com/zoobc/zoobc-core/common/chaintype" + + "github.com/zoobc/zoobc-core/common/contract" + "github.com/zoobc/zoobc-core/common/model" + coreService "github.com/zoobc/zoobc-core/core/service" + "github.com/zoobc/zoobc-core/p2p" +) + +type mockP2pServiceSuccess struct { + p2p.ServiceInterface +} + +func (*mockP2pServiceSuccess) GetNextBlocks(destPeer *model.Peer, _ contract.ChainType, + blockIDs []int64, blockID int64) (*model.BlocksData, error) { + return &model.BlocksData{ + NextBlocks: []*model.Block{ + { + ID: int64(123), + }, + { + ID: int64(234), + }, + }, + }, nil +} + +func (*mockP2pServiceSuccess) GetNextBlockIDs(destPeer *model.Peer, _ contract.ChainType, + blockID int64, limit uint32) (*model.BlockIdsResponse, error) { + return &model.BlockIdsResponse{ + BlockIds: []int64{1, 2, 3, 4}, + }, nil +} + +func (*mockP2pServiceSuccess) GetCommonMilestoneBlockIDs(destPeer *model.Peer, _ contract.ChainType, + lastBlockID, lastMilestoneBlockID int64) (*model.GetCommonMilestoneBlockIdsResponse, error) { + return &model.GetCommonMilestoneBlockIdsResponse{ + BlockIds: []int64{1, 2, 3, 4}, + }, nil +} + +type mockP2pServiceSuccessOneResult struct { + p2p.ServiceInterface +} + +func (*mockP2pServiceSuccessOneResult) GetNextBlockIDs(destPeer *model.Peer, _ contract.ChainType, + blockID int64, limit uint32) (*model.BlockIdsResponse, error) { + return &model.BlockIdsResponse{ + BlockIds: []int64{1}, + }, nil +} + +type mockP2pServiceSuccessNewResult struct { + p2p.ServiceInterface +} + +func (*mockP2pServiceSuccessNewResult) GetNextBlockIDs(destPeer *model.Peer, _ contract.ChainType, + blockID int64, limit uint32) (*model.BlockIdsResponse, error) { + return &model.BlockIdsResponse{ + BlockIds: []int64{3, 4}, + }, nil +} + +type mockP2pServiceFail struct { + p2p.ServiceInterface +} + +func (*mockP2pServiceFail) GetNextBlockIDs(destPeer *model.Peer, _ contract.ChainType, blockID int64, + limit uint32) (*model.BlockIdsResponse, error) { + return nil, errors.New("simulating error") +} + +func (*mockP2pServiceFail) GetCommonMilestoneBlockIDs(destPeer *model.Peer, _ contract.ChainType, + lastBlockID, lastMilestoneBlockID int64) (*model.GetCommonMilestoneBlockIdsResponse, error) { + return nil, errors.New("mock error") +} + +func (*mockP2pServiceFail) DisconnectPeer(peer *model.Peer) {} + +type mockBlockServiceSuccess struct { + coreService.BlockServiceInterface +} + +func (*mockBlockServiceSuccess) GetChainType() contract.ChainType { + return &chaintype.MainChain{} +} + +func (*mockBlockServiceSuccess) GetBlockByID(blockID int64) (*model.Block, error) { + if blockID == 1 || blockID == 2 { + return &model.Block{ + ID: 1, + }, nil + } + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, fmt.Sprintf("block is not found")) +} + +func (*mockBlockServiceSuccess) GetLastBlock() (*model.Block, error) { + return &model.Block{ID: 1}, nil +} + +type mockBlockServiceFail struct { + coreService.BlockServiceInterface +} + +func (*mockBlockServiceFail) GetChainType() contract.ChainType { + return &chaintype.MainChain{} +} + +func (*mockBlockServiceFail) GetLastBlock() (*model.Block, error) { + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, fmt.Sprintf("block is not found")) +} + +func TestGetPeerCommonBlockID(t *testing.T) { + type args struct { + p2pService p2p.ServiceInterface + blockService coreService.BlockServiceInterface + } + tests := []struct { + name string + args args + want int64 + wantErr bool + }{ + { + name: "want:getPeerCommonBlockID successfully return common block ID", + args: args{ + p2pService: &mockP2pServiceSuccess{}, + blockService: &mockBlockServiceSuccess{}, + }, + want: int64(1), + wantErr: false, + }, + { + name: "wantErr:getPeerCommonBlockID get last block failed", + args: args{ + p2pService: &mockP2pServiceSuccess{}, + blockService: &mockBlockServiceFail{}, + }, + want: int64(0), + wantErr: true, + }, + { + name: "wantErr:getPeerCommonBlockID grpc error", + args: args{ + p2pService: &mockP2pServiceFail{}, + blockService: &mockBlockServiceSuccess{}, + }, + want: int64(0), + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + blockchainSyncService := NewBlockchainSyncService(tt.args.blockService, tt.args.p2pService) + got, err := blockchainSyncService.getPeerCommonBlockID( + &model.Peer{}, + ) + if (err != nil) != tt.wantErr { + t.Errorf("getPeerCommonBlockID() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("getPeerCommonBlockID() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetBlockIdsAfterCommon(t *testing.T) { + type args struct { + p2pService p2p.ServiceInterface + blockService coreService.BlockServiceInterface + } + + tests := []struct { + name string + args args + want []int64 + }{ + { + name: "want:getBlockIdsAfterCommon (all getBlockIdsAfterCommon new)", + args: args{ + p2pService: &mockP2pServiceSuccessNewResult{}, + blockService: &mockBlockServiceSuccess{}, + }, + want: []int64{3, 4}, + }, + { + name: "want:getBlockIdsAfterCommon (some getBlockIdsAfterCommon already exists)", + args: args{ + p2pService: &mockP2pServiceSuccess{}, + blockService: &mockBlockServiceSuccess{}, + }, + want: []int64{2, 3, 4}, + }, + { + name: "want:getBlockIdsAfterCommon (all getBlockIdsAfterCommon already exists)", + args: args{ + p2pService: &mockP2pServiceSuccessOneResult{}, + blockService: &mockBlockServiceSuccess{}, + }, + want: []int64{1}, + }, + { + name: "want:getBlockIdsAfterCommon (GetNextBlockIDs produce error)", + args: args{ + p2pService: &mockP2pServiceFail{}, + blockService: &mockBlockServiceSuccess{}, + }, + want: []int64{}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + blockchainSyncService := NewBlockchainSyncService(tt.args.blockService, tt.args.p2pService) + got := blockchainSyncService.getBlockIdsAfterCommon( + &model.Peer{}, + 0, + ) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("getNextBlocks() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetNextBlocks(t *testing.T) { + blockService := coreService.NewBlockService(&chaintype.MainChain{}, nil, nil, nil, nil, nil, nil, nil, nil, nil) + blockchainSyncService := NewBlockchainSyncService(blockService, &mockP2pServiceSuccess{}) + type args struct { + maxNextBlocks uint32 + peerUsed *model.Peer + blockIDs []int64 + blockID int64 + start uint32 + stop uint32 + } + + tests := []struct { + name string + args args + want []*model.Block + wantErr bool + }{ + { + name: "wantSuccess:GetNextBlocks", + args: args{ + maxNextBlocks: uint32(2), + peerUsed: &model.Peer{ + Info: &model.Node{ + Address: "127.0.0.1", + }, + }, + blockIDs: []int64{1, 2, 3}, + blockID: int64(1), + start: uint32(1), + stop: uint32(2), + }, + want: []*model.Block{ + { + ID: int64(123), + }, + { + ID: int64(234), + }, + }, + wantErr: false, + }, + { + name: "wantError:GetNextBlocks Too many blocks returned", + args: args{ + maxNextBlocks: uint32(0), + peerUsed: &model.Peer{ + Info: &model.Node{ + Address: "127.0.0.1", + }, + }, + blockIDs: []int64{1, 2, 3}, + blockID: int64(1), + start: uint32(1), + stop: uint32(2), + }, + want: nil, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := blockchainSyncService.getNextBlocks( + tt.args.maxNextBlocks, + tt.args.peerUsed, + tt.args.blockIDs, + tt.args.start, + tt.args.stop, + ) + if (err != nil) != tt.wantErr { + t.Errorf("getNextBlocks() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("getNextBlocks() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/core/service/blockCoreService.go b/core/service/blockCoreService.go index 7a94dfd22..4067559a7 100644 --- a/core/service/blockCoreService.go +++ b/core/service/blockCoreService.go @@ -3,11 +3,14 @@ package service import ( "bytes" "errors" + "fmt" "math/big" "strconv" "strings" + "sync" log "github.com/sirupsen/logrus" + "github.com/zoobc/zoobc-core/common/blocker" "github.com/zoobc/zoobc-core/common/chaintype" "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/contract" @@ -39,18 +42,24 @@ type ( timestamp int64, blockSmithAccountAddress string, ) (*model.Block, error) - PushBlock(previousBlock, block *model.Block) error + PushBlock(previousBlock, block *model.Block, needLock bool) error + GetBlockByID(int64) (*model.Block, error) + GetBlockByHeight(uint32) (*model.Block, error) + GetBlocksFromHeight(uint32, uint32) ([]*model.Block, error) GetLastBlock() (*model.Block, error) - GetBlockByHeight(height uint32) (*model.Block, error) GetBlocks() ([]*model.Block, error) GetGenesisBlock() (*model.Block, error) RemoveMempoolTransactions(transactions []*model.Transaction) error AddGenesis() error CheckGenesis() bool + GetChainType() contract.ChainType + ChainWriteLock() + ChainWriteUnlock() ReceivedBlockListener() observer.Listener } BlockService struct { + chainWriteLock sync.WaitGroup Chaintype contract.ChainType QueryExecutor query.ExecutorInterface BlockQuery query.BlockQueryInterface @@ -125,6 +134,21 @@ func (bs *BlockService) NewBlock( return block } +// GetChainType returns the chaintype +func (bs *BlockService) GetChainType() contract.ChainType { + return bs.Chaintype +} + +// ChainWriteLock locks the chain +func (bs *BlockService) ChainWriteLock() { + bs.chainWriteLock.Add(1) +} + +// ChainWriteUnlock unlocks the chain +func (bs *BlockService) ChainWriteUnlock() { + bs.chainWriteLock.Done() +} + // NewGenesisBlock create new block that is fixed in the value of cumulative difficulty, smith scale, and the block signature func (bs *BlockService) NewGenesisBlock( version uint32, @@ -175,7 +199,11 @@ func (*BlockService) VerifySeed( } // PushBlock push block into blockchain -func (bs *BlockService) PushBlock(previousBlock, block *model.Block) error { +func (bs *BlockService) PushBlock(previousBlock, block *model.Block, needLock bool) error { + // needLock indicates the push block needs to be protected + if needLock { + bs.chainWriteLock.Wait() + } if previousBlock.GetID() != -1 { block.Height = previousBlock.GetHeight() + 1 block = coreUtil.CalculateSmithScale(previousBlock, block, bs.Chaintype.GetChainSmithingDelayTime()) @@ -229,6 +257,40 @@ func (bs *BlockService) PushBlock(previousBlock, block *model.Block) error { } +// GetBlockByID return the last pushed block +func (bs *BlockService) GetBlockByID(id int64) (*model.Block, error) { + rows, err := bs.QueryExecutor.ExecuteSelect(bs.BlockQuery.GetBlockByID(id)) + defer func() { + if rows != nil { + _ = rows.Close() + } + }() + if err != nil { + return nil, blocker.NewBlocker(blocker.DBErr, err.Error()) + } + var blocks []*model.Block + blocks = bs.BlockQuery.BuildModel(blocks, rows) + if len(blocks) > 0 { + return blocks[0], nil + } + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, fmt.Sprintf("block %v is not found", id)) +} + +func (bs *BlockService) GetBlocksFromHeight(startHeight, limit uint32) ([]*model.Block, error) { + var blocks []*model.Block + rows, err := bs.QueryExecutor.ExecuteSelect(bs.BlockQuery.GetBlockFromHeight(startHeight, limit)) + defer func() { + if rows != nil { + _ = rows.Close() + } + }() + if err != nil { + return []*model.Block{}, err + } + blocks = bs.BlockQuery.BuildModel(blocks, rows) + return blocks, nil +} + // GetLastBlock return the last pushed block func (bs *BlockService) GetLastBlock() (*model.Block, error) { rows, err := bs.QueryExecutor.ExecuteSelect(bs.BlockQuery.GetLastBlock()) @@ -238,9 +300,7 @@ func (bs *BlockService) GetLastBlock() (*model.Block, error) { } }() if err != nil { - return &model.Block{ - ID: -1, - }, err + return nil, blocker.NewBlocker(blocker.DBErr, err.Error()) } var ( blocks []*model.Block @@ -252,17 +312,12 @@ func (bs *BlockService) GetLastBlock() (*model.Block, error) { transactionQ, transactionArg := bs.TransactionQuery.GetTransactionsByBlockID(blocks[0].ID) rows, err = bs.QueryExecutor.ExecuteSelect(transactionQ, transactionArg...) if err != nil { - return &model.Block{ - ID: -1, - }, err + return nil, blocker.NewBlocker(blocker.DBErr, err.Error()) } blocks[0].Transactions = bs.TransactionQuery.BuildModel(transactions, rows) return blocks[0], nil } - return &model.Block{ - ID: -1, - }, errors.New("BlockNotFound") - + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, "last block is not found") } // GetLastBlock return the last pushed block @@ -274,18 +329,14 @@ func (bs *BlockService) GetBlockByHeight(height uint32) (*model.Block, error) { } }() if err != nil { - return &model.Block{ - ID: -1, - }, err + return nil, blocker.NewBlocker(blocker.DBErr, err.Error()) } var blocks []*model.Block blocks = bs.BlockQuery.BuildModel(blocks, rows) if len(blocks) > 0 { return blocks[0], nil } - return &model.Block{ - ID: -1, - }, errors.New("BlockNotFound") + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, fmt.Sprintf("block with height %v is not found", height)) } @@ -298,9 +349,7 @@ func (bs *BlockService) GetGenesisBlock() (*model.Block, error) { } }() if err != nil { - return &model.Block{ - ID: -1, - }, err + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, "genesis block is not found") } var lastBlock model.Block if rows.Next() { @@ -322,15 +371,11 @@ func (bs *BlockService) GetGenesisBlock() (*model.Block, error) { &lastBlock.Version, ) if err != nil { - return &model.Block{ - ID: -1, - }, err + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, "genesis block is not found") } return &lastBlock, nil } - return &model.Block{ - ID: -1, - }, errors.New("BlockNotFound") + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, "genesis block is not found") } @@ -485,9 +530,10 @@ func (bs *BlockService) AddGenesis() error { ) // assign genesis block id block.ID = coreUtil.GetBlockID(block) - err := bs.PushBlock(&model.Block{ID: -1, Height: 0}, block) + fmt.Printf("\n\ngenesis block: %v\n\n ", block) + err := bs.PushBlock(&model.Block{ID: -1, Height: 0}, block, true) if err != nil { - panic("PushGenesisBlock:fail") + log.Fatal("PushGenesisBlock:fail") } return nil } @@ -534,7 +580,7 @@ func (bs *BlockService) ReceivedBlockListener() observer.Listener { // check equality last block hash with previous block hash from received block if bytes.Equal(lastBlockHash[:], receivedBlock.GetPreviousBlockHash()) { - err := bs.PushBlock(lastBlock, receivedBlock) + err := bs.PushBlock(lastBlock, receivedBlock, true) if err != nil { return } diff --git a/core/service/blockCoreService_test.go b/core/service/blockCoreService_test.go index 94f1d3434..9a88db244 100644 --- a/core/service/blockCoreService_test.go +++ b/core/service/blockCoreService_test.go @@ -138,6 +138,22 @@ func (*mockQueryExecutorSuccess) ExecuteSelect(qe string, args ...interface{}) ( "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", "Version"}, ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) + case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block WHERE id = 1": + mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ + "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", + "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", + "Version"}, + ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) + case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block " + + "WHERE HEIGHT >= 0 ORDER BY HEIGHT LIMIT 2": + mock.ExpectQuery(regexp.QuoteMeta(qe)).WillReturnRows(sqlmock.NewRows([]string{ + "ID", "PreviousBlockHash", "Height", "Timestamp", "BlockSeed", "BlockSignature", "CumulativeDifficulty", + "SmithScale", "PayloadLength", "PayloadHash", "BlocksmithAddress", "TotalAmount", "TotalFee", "TotalCoinBase", + "Version"}, + ).AddRow(1, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1).AddRow( + 2, []byte{}, 1, 10000, []byte{}, []byte{}, "", 1, 2, []byte{}, "BCZ", 0, 0, 0, 1)) case "SELECT id, previous_block_hash, height, timestamp, block_seed, block_signature, cumulative_difficulty, smith_scale, " + "payload_length, payload_hash, blocksmith_address, total_amount, total_fee, total_coinbase, version FROM main_block ORDER BY " + "height DESC LIMIT 1": @@ -698,7 +714,7 @@ func TestBlockService_PushBlock(t *testing.T) { ActionTypeSwitcher: tt.fields.ActionTypeSwitcher, Observer: tt.fields.Observer, } - if err := bs.PushBlock(tt.args.previousBlock, tt.args.block); (err != nil) != tt.wantErr { + if err := bs.PushBlock(tt.args.previousBlock, tt.args.block, false); (err != nil) != tt.wantErr { t.Errorf("BlockService.PushBlock() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -758,9 +774,7 @@ func TestBlockService_GetLastBlock(t *testing.T) { QueryExecutor: &mockQueryExecutorFail{}, BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, - want: &model.Block{ - ID: -1, - }, + want: nil, wantErr: true, }, { @@ -770,9 +784,7 @@ func TestBlockService_GetLastBlock(t *testing.T) { QueryExecutor: &mockQueryExecuteNotNil{}, BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, - want: &model.Block{ - ID: -1, - }, + want: nil, wantErr: true, }, } @@ -848,9 +860,7 @@ func TestBlockService_GetGenesisBlock(t *testing.T) { QueryExecutor: &mockQueryExecutorFail{}, BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, - want: &model.Block{ - ID: -1, - }, + want: nil, wantErr: true, }, { @@ -860,9 +870,7 @@ func TestBlockService_GetGenesisBlock(t *testing.T) { QueryExecutor: &mockQueryExecutorScanFail{}, BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, - want: &model.Block{ - ID: -1, - }, + want: nil, wantErr: true, }, } @@ -1656,9 +1664,7 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { QueryExecutor: &mockQueryExecutorFail{}, BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), }, - want: &model.Block{ - ID: -1, - }, + want: nil, wantErr: true, }, } @@ -1687,3 +1693,204 @@ func TestBlockService_GetBlockByHeight(t *testing.T) { }) } } + +func TestBlockService_GetBlockByID(t *testing.T) { + type fields struct { + Chaintype contract.ChainType + QueryExecutor query.ExecutorInterface + BlockQuery query.BlockQueryInterface + MempoolQuery query.MempoolQueryInterface + TransactionQuery query.TransactionQueryInterface + Signature crypto.SignatureInterface + MempoolService MempoolServiceInterface + ActionTypeSwitcher transaction.TypeActionSwitcher + AccountBalanceQuery query.AccountBalanceQueryInterface + Observer *observer.Observer + } + type args struct { + ID int64 + } + tests := []struct { + name string + fields fields + args args + want *model.Block + wantErr bool + }{ + { + name: "GetBlockByID:Success", // All is good + fields: fields{ + Chaintype: &chaintype.MainChain{}, + QueryExecutor: &mockQueryExecutorSuccess{}, + BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), + }, + args: args{ + ID: int64(1), + }, + want: &model.Block{ + ID: 1, + PreviousBlockHash: []byte{}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, + }, + wantErr: false, + }, + { + name: "GetBlockByID:FailNoEntryFound", // All is good + fields: fields{ + Chaintype: &chaintype.MainChain{}, + QueryExecutor: &mockQueryExecutorFail{}, + BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), + }, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + bs := &BlockService{ + Chaintype: tt.fields.Chaintype, + QueryExecutor: tt.fields.QueryExecutor, + BlockQuery: tt.fields.BlockQuery, + MempoolQuery: tt.fields.MempoolQuery, + TransactionQuery: tt.fields.TransactionQuery, + Signature: tt.fields.Signature, + MempoolService: tt.fields.MempoolService, + ActionTypeSwitcher: tt.fields.ActionTypeSwitcher, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + Observer: tt.fields.Observer, + } + got, err := bs.GetBlockByID(tt.args.ID) + if (err != nil) != tt.wantErr { + t.Errorf("BlockService.GetBlockByID() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("BlockService.GetBlockByID() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBlockService_GetBlocksFromHeight(t *testing.T) { + type fields struct { + Chaintype contract.ChainType + QueryExecutor query.ExecutorInterface + BlockQuery query.BlockQueryInterface + MempoolQuery query.MempoolQueryInterface + TransactionQuery query.TransactionQueryInterface + Signature crypto.SignatureInterface + MempoolService MempoolServiceInterface + ActionTypeSwitcher transaction.TypeActionSwitcher + AccountBalanceQuery query.AccountBalanceQueryInterface + Observer *observer.Observer + } + type args struct { + startHeight, limit uint32 + } + tests := []struct { + name string + fields fields + args args + want []*model.Block + wantErr bool + }{ + { + name: "GetBlocksFromHeight:Success", // All is good + fields: fields{ + Chaintype: &chaintype.MainChain{}, + QueryExecutor: &mockQueryExecutorSuccess{}, + BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), + }, + args: args{ + startHeight: 0, + limit: 2, + }, + want: []*model.Block{ + { + ID: 1, + PreviousBlockHash: []byte{}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, + }, + { + ID: 2, + PreviousBlockHash: []byte{}, + Height: 1, + Timestamp: 10000, + BlockSeed: []byte{}, + BlockSignature: []byte{}, + CumulativeDifficulty: "", + SmithScale: 1, + PayloadLength: 2, + PayloadHash: []byte{}, + BlocksmithAddress: "BCZ", + TotalAmount: 0, + TotalFee: 0, + TotalCoinBase: 0, + Version: 1, + }, + }, + wantErr: false, + }, + { + name: "GetBlocksFromHeight:FailNoEntryFound", // All is good + fields: fields{ + Chaintype: &chaintype.MainChain{}, + QueryExecutor: &mockQueryExecutorFail{}, + BlockQuery: query.NewBlockQuery(&chaintype.MainChain{}), + }, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + bs := &BlockService{ + Chaintype: tt.fields.Chaintype, + QueryExecutor: tt.fields.QueryExecutor, + BlockQuery: tt.fields.BlockQuery, + MempoolQuery: tt.fields.MempoolQuery, + TransactionQuery: tt.fields.TransactionQuery, + Signature: tt.fields.Signature, + MempoolService: tt.fields.MempoolService, + ActionTypeSwitcher: tt.fields.ActionTypeSwitcher, + AccountBalanceQuery: tt.fields.AccountBalanceQuery, + Observer: tt.fields.Observer, + } + got, err := bs.GetBlocksFromHeight(tt.args.startHeight, tt.args.limit) + if (err != nil) != tt.wantErr { + t.Errorf("BlockService.GetBlocksFromHeight() error = %v, wantErr %v", err, tt.wantErr) + return + } + if len(got) == 0 && len(tt.want) == 0 { + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("BlockService.GetBlocksFromHeight() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/core/smith/blockchainProcessor.go b/core/smith/blockchainProcessor.go index 5d8839aa2..b8517b83e 100644 --- a/core/smith/blockchainProcessor.go +++ b/core/smith/blockchainProcessor.go @@ -129,7 +129,7 @@ func (bp *BlockchainProcessor) StartSmithing() error { return err } // if validated push - err = bp.BlockService.PushBlock(previousBlock, block) + err = bp.BlockService.PushBlock(previousBlock, block, true) if err != nil { return err } diff --git a/core/util/blockUtil.go b/core/util/blockUtil.go index 6fb604bc5..0e5765b79 100644 --- a/core/util/blockUtil.go +++ b/core/util/blockUtil.go @@ -3,9 +3,10 @@ package util import ( "bytes" + "math/big" + "github.com/zoobc/zoobc-core/common/blocker" "github.com/zoobc/zoobc-core/common/crypto" - "math/big" "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/model" @@ -85,22 +86,30 @@ func CalculateSmithScale(previousBlock, block *model.Block, smithingDelayTime in // return the assigned ID if assigned func GetBlockID(block *model.Block) int64 { if block.ID == 0 { + digest := sha3.New512() + blockByte, _ := GetBlockByte(block, true) + _, _ = digest.Write(blockByte) hash, _ := GetBlockHash(block) - res := new(big.Int) - block.ID = res.SetBytes([]byte{ - hash[7], - hash[6], - hash[5], - hash[4], - hash[3], - hash[2], - hash[1], - hash[0], - }).Int64() + block.ID = GetBlockIDFromHash(hash) } return block.ID } +// GetBlockIdFromHash returns blockID from given hash +func GetBlockIDFromHash(blockHash []byte) int64 { + res := new(big.Int) + return res.SetBytes([]byte{ + blockHash[7], + blockHash[6], + blockHash[5], + blockHash[4], + blockHash[3], + blockHash[2], + blockHash[1], + blockHash[0], + }).Int64() +} + // GetBlockHash return the block's bytes hash. // note: the block must be signed, otherwise this function returns an error func GetBlockHash(block *model.Block) ([]byte, error) { @@ -177,3 +186,12 @@ func ValidateBlock(block, previousLastBlock *model.Block, curTime int64) error { } return nil } + +func IsBlockIDExist(blockIds []int64, expectedBlockID int64) bool { + for _, blockID := range blockIds { + if blockID == expectedBlockID { + return true + } + } + return false +} diff --git a/core/util/blockUtil_test.go b/core/util/blockUtil_test.go index 2e737b874..f29ca9c40 100644 --- a/core/util/blockUtil_test.go +++ b/core/util/blockUtil_test.go @@ -516,3 +516,39 @@ func TestValidateBlock(t *testing.T) { }) } } + +func TestIsBlockIDExist(t *testing.T) { //todo:update test after applying signature related functionalities + type args struct { + blockIds []int64 + expectedBlockID int64 + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "wantSuccess:BlockIDFound", + args: args{ + blockIds: []int64{1, 2, 3, 4}, + expectedBlockID: int64(1), + }, + want: true, + }, + { + name: "wantSuccess:InvalidTimestamp", + args: args{ + blockIds: []int64{1, 2, 3, 4}, + expectedBlockID: int64(5), + }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsBlockIDExist(tt.args.blockIds, tt.args.expectedBlockID); got != tt.want { + t.Errorf("TestIsBlockIDExist() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/main.go b/main.go index d3669681d..cd413069b 100644 --- a/main.go +++ b/main.go @@ -8,13 +8,15 @@ import ( "syscall" "time" - "github.com/zoobc/zoobc-core/common/contract" + "github.com/sirupsen/logrus" "github.com/zoobc/zoobc-core/common/crypto" "github.com/zoobc/zoobc-core/common/chaintype" "github.com/zoobc/zoobc-core/common/transaction" + "github.com/zoobc/zoobc-core/core/blockchainsync" "github.com/zoobc/zoobc-core/core/service" + coreService "github.com/zoobc/zoobc-core/core/service" "github.com/zoobc/zoobc-core/core/smith" "github.com/spf13/viper" @@ -32,11 +34,17 @@ var ( dbInstance *database.SqliteDB db *sql.DB apiRPCPort, apiHTTPPort int - p2pServiceInstance contract.P2PType + p2pServiceInstance p2p.ServiceInterface queryExecutor *query.Executor observerInstance *observer.Observer ) +var ( + blockServices = make(map[int32]coreService.BlockServiceInterface) + mempoolServices = make(map[int32]service.MempoolServiceInterface) + p2pService p2p.ServiceInterface +) + func init() { var ( configPostfix string @@ -47,7 +55,7 @@ func init() { flag.Parse() if err := util.LoadConfig("./resource", "config"+configPostfix, "toml"); err != nil { - panic(err) + logrus.Fatal(err) } else { dbPath = viper.GetString("dbPath") dbName = viper.GetString("dbName") @@ -64,11 +72,11 @@ func init() { dbInstance = database.NewSqliteDB() if err := dbInstance.InitializeDB(dbPath, dbName); err != nil { - panic(err) + logrus.Fatal(err) } db, err = dbInstance.OpenDB(dbPath, dbName, 10, 20) if err != nil { - panic(err) + logrus.Fatal(err) } queryExecutor = query.NewQueryExecutor(db) @@ -77,18 +85,20 @@ func init() { } func startServices(queryExecutor query.ExecutorInterface) { - p2pService() - api.Start(apiRPCPort, apiHTTPPort, queryExecutor, p2pServiceInstance) + startP2pService() + api.Start(apiRPCPort, apiHTTPPort, queryExecutor, p2pServiceInstance, blockServices) } -func p2pService() { +func startP2pService() { myAddress := viper.GetString("myAddress") peerPort := viper.GetUint32("peerPort") wellknownPeers := viper.GetStringSlice("wellknownPeers") p2pServiceInstance = p2p.InitP2P(myAddress, peerPort, wellknownPeers, &p2pNative.Service{}, observerInstance) + p2pServiceInstance.SetBlockServices(blockServices) // run P2P service with any chaintype go p2pServiceInstance.StartP2P() + p2pService = p2pServiceInstance } func startSmith(sleepPeriod int, processor *smith.BlockchainProcessor) { for { @@ -98,16 +108,7 @@ func startSmith(sleepPeriod int, processor *smith.BlockchainProcessor) { } -func main() { - - migration := database.Migration{Query: queryExecutor} - if err := migration.Init(); err != nil { - panic(err) - } - - if err := migration.Apply(); err != nil { - panic(err) - } +func startMainchain(mainchainSyncChannel chan bool) { mainchain := &chaintype.MainChain{} sleepPeriod := int(mainchain.GetChainSmithingDelayTime()) mempoolService := service.NewMempoolService( @@ -120,7 +121,9 @@ func main() { query.NewAccountBalanceQuery(), observerInstance, ) - blockService := service.NewBlockService( + mempoolServices[mainchain.GetTypeInt()] = mempoolService + + mainchainBlockService := service.NewBlockService( mainchain, queryExecutor, query.NewBlockQuery(mainchain), @@ -134,35 +137,58 @@ func main() { query.NewAccountBalanceQuery(), observerInstance, ) - blockchainProcessor := smith.NewBlockchainProcessor( + blockServices[mainchain.GetTypeInt()] = mainchainBlockService + + mainchainProcessor := smith.NewBlockchainProcessor( mainchain, smith.NewBlocksmith(nodeSecretPhrase), - blockService, + mainchainBlockService, ) - if !blockchainProcessor.BlockService.CheckGenesis() { // Add genesis if not exist + if !mainchainProcessor.BlockService.CheckGenesis() { // Add genesis if not exist // genesis account will be inserted in the very beginning if err := service.AddGenesisAccount(queryExecutor); err != nil { - panic("Fail to add genesis account") + logrus.Fatal("Fail to add genesis account") } - if err := blockchainProcessor.BlockService.AddGenesis(); err != nil { - panic(err) + if err := mainchainProcessor.BlockService.AddGenesis(); err != nil { + logrus.Fatal(err) } } if len(nodeSecretPhrase) > 0 { - go startSmith(sleepPeriod, blockchainProcessor) + go startSmith(sleepPeriod, mainchainProcessor) + } + mainchainSynchronizer := blockchainsync.NewBlockchainSyncService(mainchainBlockService, p2pServiceInstance) + mainchainSynchronizer.Start(mainchainSyncChannel) +} + +func main() { + migration := database.Migration{Query: queryExecutor} + if err := migration.Init(); err != nil { + logrus.Fatal(err) + } + + if err := migration.Apply(); err != nil { + logrus.Fatal(err) } startServices(queryExecutor) + mainchainSyncChannel := make(chan bool, 1) + mainchainSyncChannel <- true + startMainchain(mainchainSyncChannel) + // observer observerInstance.AddListener(observer.BlockPushed, p2pServiceInstance.SendBlockListener()) - observerInstance.AddListener(observer.BlockReceived, blockService.ReceivedBlockListener()) observerInstance.AddListener(observer.TransactionAdded, p2pServiceInstance.SendTransactionListener()) - observerInstance.AddListener(observer.TransactionReceived, mempoolService.ReceivedTransactionListener()) + for _, blockService := range blockServices { + observerInstance.AddListener(observer.BlockReceived, blockService.ReceivedBlockListener()) + } + for _, mempoolService := range mempoolServices { + observerInstance.AddListener(observer.TransactionReceived, mempoolService.ReceivedTransactionListener()) + } sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) diff --git a/p2p/native/native.go b/p2p/native/native.go index 735060249..31e14e421 100644 --- a/p2p/native/native.go +++ b/p2p/native/native.go @@ -1,23 +1,27 @@ package native import ( - "github.com/zoobc/zoobc-core/common/contract" "github.com/zoobc/zoobc-core/common/model" + coreService "github.com/zoobc/zoobc-core/core/service" "github.com/zoobc/zoobc-core/observer" + "github.com/zoobc/zoobc-core/p2p" "github.com/zoobc/zoobc-core/p2p/native/service" nativeUtil "github.com/zoobc/zoobc-core/p2p/native/util" ) type Service struct { - HostService *service.HostService - Observer *observer.Observer + HostService *service.HostService + BlockServices map[int32]coreService.BlockServiceInterface + service.PeerServiceClient + Observer *observer.Observer } var hostServiceInstance *service.HostService // InitService to initialize services of the native strategy -func (s *Service) InitService(myAddress string, port uint32, wellknownPeers []string, obsr *observer.Observer) (contract.P2PType, error) { +func (s *Service) InitService(myAddress string, port uint32, wellknownPeers []string, + obsr *observer.Observer) (p2p.ServiceInterface, error) { if s.HostService == nil { knownPeersResult, err := nativeUtil.ParseKnownPeers(wellknownPeers) if err != nil { @@ -31,14 +35,33 @@ func (s *Service) InitService(myAddress string, port uint32, wellknownPeers []st return s, nil } +func (s *Service) SetBlockServices(blockServices map[int32]coreService.BlockServiceInterface) { + s.BlockServices = blockServices +} + // GetHostInstance returns the host model func (s *Service) GetHostInstance() *model.Host { return s.HostService.Host } +// DisconnectPeer returns the host model +func (s *Service) DisconnectPeer(peer *model.Peer) { + s.HostService.DisconnectPeer(peer) +} + +// GetAnyResolvedPeer Get any random resolved peer +func (s *Service) GetAnyResolvedPeer() *model.Peer { + return s.HostService.GetAnyResolvedPeer() +} + +// GetResolvedPeer Get resolved peers +func (s *Service) GetResolvedPeers() map[string]*model.Peer { + return s.HostService.GetResolvedPeers() +} + // StartP2P to run all p2p Thread service func (s *Service) StartP2P() { - startServer(s.Observer) + startServer(s.BlockServices, s.Observer) // p2p thread go resolvePeersThread() diff --git a/p2p/native/nativeProcess.go b/p2p/native/nativeProcess.go index 94a6cb257..95a1c46de 100644 --- a/p2p/native/nativeProcess.go +++ b/p2p/native/nativeProcess.go @@ -9,17 +9,18 @@ import ( log "github.com/sirupsen/logrus" "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/model" + coreService "github.com/zoobc/zoobc-core/core/service" "github.com/zoobc/zoobc-core/observer" "github.com/zoobc/zoobc-core/p2p/native/service" nativeUtil "github.com/zoobc/zoobc-core/p2p/native/util" ) // startServer to run p2p service as server -func startServer(obsr *observer.Observer) { +func startServer(blockServices map[int32]coreService.BlockServiceInterface, obsr *observer.Observer) { port := hostServiceInstance.Host.GetInfo().GetPort() listener := nativeUtil.ServerListener(int(port)) go func() { - _ = service.NewServerService(obsr).StartListening(listener) + _ = service.NewServerService(blockServices, obsr).StartListening(listener) }() } diff --git a/p2p/native/native_test.go b/p2p/native/native_test.go index 2db1406c6..f5a9d0d99 100644 --- a/p2p/native/native_test.go +++ b/p2p/native/native_test.go @@ -4,9 +4,9 @@ import ( "reflect" "testing" - "github.com/zoobc/zoobc-core/common/contract" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/observer" + "github.com/zoobc/zoobc-core/p2p" "github.com/zoobc/zoobc-core/p2p/native/service" ) @@ -28,7 +28,7 @@ func TestService_InitService(t *testing.T) { name string fields fields args args - want contract.P2PType + want p2p.ServiceInterface wantErr bool }{ // Add test cases. diff --git a/p2p/native/service/client.go b/p2p/native/service/client.go index 1b8f9e4df..77bd87c3a 100644 --- a/p2p/native/service/client.go +++ b/p2p/native/service/client.go @@ -4,26 +4,45 @@ import ( "context" "sync" + log "github.com/sirupsen/logrus" "google.golang.org/grpc" + "github.com/zoobc/zoobc-core/common/contract" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/service" "github.com/zoobc/zoobc-core/common/util" nativeUtil "github.com/zoobc/zoobc-core/p2p/native/util" ) +type ( + // PeerServiceClientInterface acts as interface for PeerServiceClient + PeerServiceClientInterface interface { + GetPeerInfo(destPeer *model.Peer) (*model.Node, error) + GetMorePeers(destPeer *model.Peer) (*model.GetMorePeersResponse, error) + SendPeers(destPeer *model.Peer, peersInfo []*model.Node) (*model.Empty, error) + SendBlock(destPeer *model.Peer, block *model.Block) (*model.Empty, error) + SendTransaction(destPeer *model.Peer, transactionBytes []byte) (*model.Empty, error) + + GetCumulativeDifficulty(*model.Peer, contract.ChainType) (*model.GetCumulativeDifficultyResponse, error) + GetCommonMilestoneBlockIDs(destPeer *model.Peer, chaintype contract.ChainType, lastBlockID, + astMilestoneBlockID int64) (*model.GetCommonMilestoneBlockIdsResponse, error) + GetNextBlockIDs(destPeer *model.Peer, chaintype contract.ChainType, blockID int64, limit uint32) (*model.BlockIdsResponse, error) + GetNextBlocks(destPeer *model.Peer, chaintype contract.ChainType, blockIds []int64, blockID int64) (*model.BlocksData, error) + } + // PeerService represent peer service + PeerServiceClient struct { + Dialer Dialer + } +) + // PeerService represent peer service type Dialer func(destinationPeer *model.Peer) (*grpc.ClientConn, error) -type PeerServiceClient struct { - Dialer Dialer -} - var PeerServiceClientInstance *PeerServiceClient var once sync.Once // ClientPeerService to get instance of singleton peer service -func NewPeerServiceClient() *PeerServiceClient { +func NewPeerServiceClient() PeerServiceClientInterface { once.Do(func() { if PeerServiceClientInstance == nil { apiLogger, _ = util.InitLogger(".log/", "debugP2PClient.log") @@ -115,3 +134,89 @@ func (psc *PeerServiceClient) SendTransaction(destPeer *model.Peer, transactionB } return res, err } + +// GetCumulativeDifficulty request the cumulative difficulty status of a node +func (psc PeerServiceClient) GetCumulativeDifficulty(destPeer *model.Peer, + chaintype contract.ChainType) (*model.GetCumulativeDifficultyResponse, error) { + connection, _ := grpc.Dial( + nativeUtil.GetFullAddressPeer(destPeer), + grpc.WithInsecure(), + // grpc.WithUnaryInterceptor(), + ) + defer connection.Close() + p2pClient := service.NewP2PCommunicationClient(connection) + res, err := p2pClient.GetCumulativeDifficulty(context.Background(), &model.GetCumulativeDifficultyRequest{ + ChainType: chaintype.GetTypeInt(), + }) + if err != nil { + log.Printf("could not greet %v: %v\n", nativeUtil.GetFullAddressPeer(destPeer), err) + return nil, err + } + return res, err +} + +// GetCommonMilestoneBlockIDs request the blockIds that may act as milestone block +func (psc PeerServiceClient) GetCommonMilestoneBlockIDs(destPeer *model.Peer, chaintype contract.ChainType, lastBlockID, + lastMilestoneBlockID int64) (*model.GetCommonMilestoneBlockIdsResponse, error) { + connection, _ := grpc.Dial( + nativeUtil.GetFullAddressPeer(destPeer), + grpc.WithInsecure(), + // grpc.WithUnaryInterceptor(), + ) + defer connection.Close() + p2pClient := service.NewP2PCommunicationClient(connection) + res, err := p2pClient.GetCommonMilestoneBlockIDs(context.Background(), &model.GetCommonMilestoneBlockIdsRequest{ + ChainType: chaintype.GetTypeInt(), + LastBlockID: lastBlockID, + LastMilestoneBlockID: lastMilestoneBlockID, + }) + if err != nil { + log.Printf("could not greet %v: %v\n", nativeUtil.GetFullAddressPeer(destPeer), err) + return nil, err + } + return res, err +} + +// GetNextBlockIDs request the blockIds of the next blocks requested +func (psc PeerServiceClient) GetNextBlockIDs(destPeer *model.Peer, chaintype contract.ChainType, + blockID int64, limit uint32) (*model.BlockIdsResponse, error) { + connection, _ := grpc.Dial( + nativeUtil.GetFullAddressPeer(destPeer), + grpc.WithInsecure(), + // grpc.WithUnaryInterceptor(), + ) + defer connection.Close() + p2pClient := service.NewP2PCommunicationClient(connection) + res, err := p2pClient.GetNextBlockIDs(context.Background(), &model.GetNextBlockIdsRequest{ + ChainType: chaintype.GetTypeInt(), + BlockId: blockID, + Limit: limit, + }) + if err != nil { + log.Printf("could not greet %v: %v\n", nativeUtil.GetFullAddressPeer(destPeer), err) + return nil, err + } + return res, err +} + +// GetNextBlocks request the next blocks matching the array of blockIds +func (psc PeerServiceClient) GetNextBlocks(destPeer *model.Peer, chaintype contract.ChainType, blockIds []int64, + blockID int64) (*model.BlocksData, error) { + connection, _ := grpc.Dial( + nativeUtil.GetFullAddressPeer(destPeer), + grpc.WithInsecure(), + // grpc.WithUnaryInterceptor(), + ) + defer connection.Close() + p2pClient := service.NewP2PCommunicationClient(connection) + res, err := p2pClient.GetNextBlocks(context.Background(), &model.GetNextBlocksRequest{ + ChainType: chaintype.GetTypeInt(), + BlockId: blockID, + BlockIds: blockIds, + }) + if err != nil { + log.Printf("could not greet %v: %v\n", nativeUtil.GetFullAddressPeer(destPeer), err) + return nil, err + } + return res, err +} diff --git a/p2p/native/service/host.go b/p2p/native/service/host.go index 515276ff8..4b910f3ed 100644 --- a/p2p/native/service/host.go +++ b/p2p/native/service/host.go @@ -59,7 +59,7 @@ func (hs *HostService) GetResolvedPeers() map[string]*model.Peer { return newResolvedPeers } -// GetAnyResolvedPeer Get any random connected peer +// GetAnyResolvedPeer Get any random resolved peer func (hs *HostService) GetAnyResolvedPeer() *model.Peer { resolvedPeers := hs.GetResolvedPeers() if len(resolvedPeers) < 1 { @@ -257,7 +257,7 @@ func (hs *HostService) GetExceedMaxUnresolvedPeers() int32 { return int32(len(hs.GetUnresolvedPeers())) - hs.MaxUnresolvedPeers + 1 } -// GetExceedMaxResolvedPeers returns number of peers exceeding max number of the connected peers +// GetExceedMaxResolvedPeers returns number of peers exceeding max number of the resolved peers func (hs *HostService) GetExceedMaxResolvedPeers() int32 { return int32(len(hs.GetResolvedPeers())) - hs.MaxResolvedPeers + 1 } diff --git a/p2p/native/service/hostProcess.go b/p2p/native/service/hostProcess.go index 4764aeb1e..ef48d03a7 100644 --- a/p2p/native/service/hostProcess.go +++ b/p2p/native/service/hostProcess.go @@ -57,6 +57,7 @@ func (hs *HostService) UpdateResolvedPeers() { func (hs *HostService) resolvePeer(destPeer *model.Peer) { _, err := NewPeerServiceClient().GetPeerInfo(destPeer) if err != nil { + // TODO: add mechanism to blacklist failing peers hs.DisconnectPeer(destPeer) return } diff --git a/p2p/native/service/server.go b/p2p/native/service/server.go index 093d9c8d6..9a1ec1332 100644 --- a/p2p/native/service/server.go +++ b/p2p/native/service/server.go @@ -2,13 +2,19 @@ package service import ( "context" + "errors" + "fmt" "net" log "github.com/sirupsen/logrus" + "github.com/zoobc/zoobc-core/common/blocker" + "github.com/zoobc/zoobc-core/common/chaintype" + "github.com/zoobc/zoobc-core/common/constant" "github.com/zoobc/zoobc-core/common/model" "github.com/zoobc/zoobc-core/common/service" "github.com/zoobc/zoobc-core/common/util" + coreService "github.com/zoobc/zoobc-core/core/service" "github.com/zoobc/zoobc-core/observer" "google.golang.org/grpc" @@ -20,7 +26,8 @@ var ( // ServerService represent data service node as server type ServerService struct { - Observer *observer.Observer + BlockServices map[int32]coreService.BlockServiceInterface + Observer *observer.Observer } var serverServiceInstance *ServerService @@ -32,10 +39,11 @@ func init() { } } -func NewServerService(obsr *observer.Observer) *ServerService { +func NewServerService(blockServices map[int32]coreService.BlockServiceInterface, obsr *observer.Observer) *ServerService { if serverServiceInstance == nil { serverServiceInstance = &ServerService{ - Observer: obsr, + BlockServices: blockServices, + Observer: obsr, } } return serverServiceInstance @@ -102,6 +110,154 @@ func (ss *ServerService) SendPeers(ctx context.Context, req *model.SendPeersRequ return &model.Empty{}, nil } +// GetCumulativeDifficulty responds to the request of the cummulative difficulty status of a node +func (ss *ServerService) GetCumulativeDifficulty(ctx context.Context, + req *model.GetCumulativeDifficultyRequest) (*model.GetCumulativeDifficultyResponse, error) { + blockService := ss.BlockServices[req.ChainType] + lastBlock, err := blockService.GetLastBlock() + if err != nil { + return nil, err + } + return &model.GetCumulativeDifficultyResponse{ + CumulativeDifficulty: lastBlock.CumulativeDifficulty, + Height: lastBlock.Height, + }, nil +} + +func (ss *ServerService) GetCommonMilestoneBlockIDs(ctx context.Context, + req *model.GetCommonMilestoneBlockIdsRequest) (*model.GetCommonMilestoneBlockIdsResponse, error) { + // if `lastBlockID` is supplied + // check it the last `lastBlockID` got matches with the host's lastBlock then return the response as is + chainType := chaintype.GetChainType(req.ChainType) + blockService := ss.BlockServices[chainType.GetTypeInt()] + if blockService == nil { + return nil, errors.New("the block service is not set for this chaintype in this host") + } + + lastBlockID := req.LastBlockID + lastMilestoneBlockID := req.LastMilestoneBlockID + if lastBlockID == 0 && lastMilestoneBlockID == 0 { + return nil, blocker.NewBlocker(blocker.RequestParameterErr, "either LastBlockID or LastMilestoneBlockID has to be supplied") + } + myLastBlock, err := blockService.GetLastBlock() + if err != nil || myLastBlock == nil { + return nil, errors.New("failed to get last block") + } + myLastBlockID := myLastBlock.ID + myBlockchainHeight := myLastBlock.Height + + if _, err := blockService.GetBlockByID(lastBlockID); err == nil { + preparedResponse := &model.GetCommonMilestoneBlockIdsResponse{ + BlockIds: []int64{lastBlockID}, + } + if lastBlockID == myLastBlockID { + preparedResponse.Last = true + } + return preparedResponse, nil + } + + // if not, send (assumed) milestoneBlock of the host + var height, jump uint32 + limit := constant.CommonMilestoneBlockIdsLimit + if lastMilestoneBlockID != 0 { + lastMilestoneBlock, err := blockService.GetBlockByID(lastMilestoneBlockID) + if err != nil { + return nil, err + } + height = lastMilestoneBlock.GetHeight() + jump = util.MinUint32(constant.SafeBlockGap, util.MaxUint32(myBlockchainHeight, 1)) + } else if lastBlockID != 0 { + // TODO: analyze difference of height jump + height = myBlockchainHeight + jump = 10 + } + + block, err := blockService.GetBlockByHeight(height) + if err != nil { + return nil, err + } + blockIDAtHeight := block.ID + blockIds := []int64{} + for { + limit-- + if height > 0 && limit > 0 { + blockIds = append(blockIds, blockIDAtHeight) + height -= jump + block, err := blockService.GetBlockByHeight(height) + if err != nil { + return nil, err + } + blockIDAtHeight = block.ID + } else { + break + } + if limit < 1 { + break + } + } + + return &model.GetCommonMilestoneBlockIdsResponse{BlockIds: blockIds}, nil +} + +func (ss *ServerService) GetNextBlockIDs(ctx context.Context, req *model.GetNextBlockIdsRequest) (*model.BlockIdsResponse, error) { + chainType := chaintype.GetChainType(req.ChainType) + blockService := ss.BlockServices[chainType.GetTypeInt()] + if blockService == nil { + return nil, errors.New("the block service is not set for this chaintype in this host") + } + reqLimit := req.Limit + reqBlockID := req.BlockId + limit := constant.PeerGetBlocksLimit + if reqLimit != 0 && reqLimit < limit { + limit = reqLimit + } + + foundBlock, err := blockService.GetBlockByID(reqBlockID) + if err != nil { + return nil, blocker.NewBlocker(blocker.BlockNotFoundErr, err.Error()) + } + blocks, err := blockService.GetBlocksFromHeight(foundBlock.Height, limit) + if err != nil { + return nil, fmt.Errorf("failed to get the block IDs: %v", err) + } + if len(blocks) == 0 { + return &model.BlockIdsResponse{}, nil + } + + blockIds := []int64{} + for _, block := range blocks { + blockIds = append(blockIds, block.ID) + } + + return &model.BlockIdsResponse{BlockIds: blockIds}, nil +} + +func (ss *ServerService) GetNextBlocks(ctx context.Context, req *model.GetNextBlocksRequest) (*model.BlocksData, error) { + // TODO: getting data from cache + chainType := chaintype.GetChainType(req.ChainType) + blockService := ss.BlockServices[chainType.GetTypeInt()] + + reqBlockID := req.BlockId + reqBlockIDList := req.BlockIds + blocksMessage := []*model.Block{} + block, err := blockService.GetBlockByID(reqBlockID) + if err != nil { + return nil, err + } + blocks, err := blockService.GetBlocksFromHeight(block.Height, uint32(len(reqBlockIDList))) + if err != nil { + return nil, fmt.Errorf("failed to get the blocks: %v", err) + } + for idx, block := range blocks { + if block.ID != reqBlockIDList[idx] { + break + } + + blocksMessage = append(blocksMessage, block) + } + return &model.BlocksData{NextBlocks: blocksMessage}, nil +} + // SendBlock receive block from other node and calling BlockReceived Event func (ss *ServerService) SendBlock(ctx context.Context, req *model.Block) (*model.Empty, error) { ss.Observer.Notify(observer.BlockReceived, req, nil) diff --git a/p2p/native/service/server_test.go b/p2p/native/service/server_test.go index 6efb810af..fed574b82 100644 --- a/p2p/native/service/server_test.go +++ b/p2p/native/service/server_test.go @@ -59,7 +59,7 @@ func TestServerService_GetPeerInfo(t *testing.T) { t.Run(tt.name, func(t *testing.T) { hostServiceInstance = CreateHostService(tt.fields.Host) obsr := &observer.Observer{} - ss := NewServerService(obsr) + ss := NewServerService(nil, obsr) got, err := ss.GetPeerInfo(tt.args.ctx, tt.args.req) if (err != nil) != tt.wantErr { t.Errorf("HostService.GetPeerInfo() error = %v, wantErr %v", err, tt.wantErr) @@ -130,7 +130,7 @@ func TestServerService_GetMorePeers(t *testing.T) { t.Run(tt.name, func(t *testing.T) { hostServiceInstance = CreateHostService(tt.fields.Host) obsr := &observer.Observer{} - ss := NewServerService(obsr) + ss := NewServerService(nil, obsr) got, err := ss.GetMorePeers(tt.args.ctx, tt.args.req) if (err != nil) != tt.wantErr { t.Errorf("HostService.GetMorePeers() error = %v, wantErr %v", err, tt.wantErr) diff --git a/p2p/p2p.go b/p2p/p2p.go index 05e3d099b..cd57bd536 100644 --- a/p2p/p2p.go +++ b/p2p/p2p.go @@ -2,13 +2,34 @@ package p2p import ( log "github.com/sirupsen/logrus" - "github.com/zoobc/zoobc-core/common/contract" + "github.com/zoobc/zoobc-core/common/model" + coreService "github.com/zoobc/zoobc-core/core/service" "github.com/zoobc/zoobc-core/observer" + nativeService "github.com/zoobc/zoobc-core/p2p/native/service" ) +type ServiceInterface interface { + InitService(myAddress string, port uint32, wellknownPeers []string, obsr *observer.Observer) (ServiceInterface, error) + SetBlockServices(blockServices map[int32]coreService.BlockServiceInterface) + StartP2P() + + GetHostInstance() *model.Host + DisconnectPeer(*model.Peer) + + // GetAnyResolvedPeer Get any random connected peer + GetAnyResolvedPeer() *model.Peer + // GetResolvedPeers returns resolved peers in thread-safe manner + GetResolvedPeers() map[string]*model.Peer + + SendBlockListener() observer.Listener + SendTransactionListener() observer.Listener + nativeService.PeerServiceClientInterface +} + // InitP2P to initialize p2p strategy will used // TODO: Add Switcer Interface -func InitP2P(myAddress string, port uint32, wellknownPeers []string, p2pType contract.P2PType, obsr *observer.Observer) contract.P2PType { +func InitP2P(myAddress string, port uint32, wellknownPeers []string, p2pType ServiceInterface, + obsr *observer.Observer) ServiceInterface { p2pService, err := p2pType.InitService(myAddress, port, wellknownPeers, obsr) if err != nil { log.Fatalf("Faild to initialize P2P service\nError : %v\n", err) diff --git a/resource/config.toml b/resource/config.toml index a06ce1802..f13f3f6c1 100644 --- a/resource/config.toml +++ b/resource/config.toml @@ -6,7 +6,7 @@ peerPort=8001 myAddress="127.0.0.1" wellknownPeers=["127.0.0.1:8002"] -apiRPCPort=3001 +apiRPCPort=7000 apiHTTPPort=3031 nodeSecretPhrase = "sprinkled sneak species pork outpost thrift unwind cheesy vexingly dizzy neurology neatness" ownerAccountType = 0 diff --git a/resource/config2.toml b/resource/config2.toml index 9ab1358e5..edf51bca5 100644 --- a/resource/config2.toml +++ b/resource/config2.toml @@ -4,10 +4,10 @@ dbName = "zoobc_2.db" # Peer peerPort=8002 myAddress="127.0.0.1" -wellknownPeers=["127.0.0.1:8003"] +wellknownPeers=["127.0.0.1:8001"] apiRPCPort=3002 apiHTTPPort=3032 -nodeSecretPhrase = "demanding unlined hazard neuter condone anime asleep ascent capitol sitter marathon armband" +# nodeSecretPhrase = "demanding unlined hazard neuter condone anime asleep ascent capitol sitter marathon armband" ownerAccountType = 0 ownerAccountAddress = "BCZnSfqpP5tqFQlMTYkDeBVFWnbyVK7vLr5ORFpTjgtN" diff --git a/resource/config3.toml b/resource/config3.toml index f432daa94..b50c6cd2c 100644 --- a/resource/config3.toml +++ b/resource/config3.toml @@ -8,6 +8,6 @@ wellknownPeers=["127.0.0.1:8002"] apiRPCPort=3003 apiHTTPPort=3033 -nodeSecretPhrase = "street roast immovable escalator stinger nervy provider debug flavoring hubcap creature remix" +# nodeSecretPhrase = "street roast immovable escalator stinger nervy provider debug flavoring hubcap creature remix" ownerAccountType = 0 ownerAccountAddress = "BCZKLvgUYZ1KKx-jtF9KoJskjVPvB9jpIjfzzI6zDW0J" diff --git a/resource/config4.toml b/resource/config4.toml index dd8f36ca1..4d00caed6 100644 --- a/resource/config4.toml +++ b/resource/config4.toml @@ -8,6 +8,6 @@ wellknownPeers=["127.0.0.1:8002"] apiRPCPort=3004 apiHTTPPort=3034 -nodeSecretPhrase = "spree uplifted stapling quotable disfigure lair deduct untying timothy maggot cryptic unrigged" +# nodeSecretPhrase = "spree uplifted stapling quotable disfigure lair deduct untying timothy maggot cryptic unrigged" ownerAccountType = 0 ownerAccountAddress = "BCZD_VxfO2S9aziIL3cn_cXW7uPDVPOrnXuP98GEAUC7" \ No newline at end of file