diff --git a/api/transactionHandler/metamorph.go b/api/transactionHandler/metamorph.go index e143803d3..7a711aa20 100644 --- a/api/transactionHandler/metamorph.go +++ b/api/transactionHandler/metamorph.go @@ -2,43 +2,31 @@ package transactionHandler import ( "context" - "errors" "fmt" - "sync" "time" arc "github.com/bitcoin-sv/arc/api" - "github.com/bitcoin-sv/arc/blocktx" - "github.com/bitcoin-sv/arc/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/tracing" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/ordishs/go-utils" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) // Metamorph is the connector to a metamorph server. type Metamorph struct { - mu sync.RWMutex - Client metamorph_api.MetaMorphAPIClient - ClientCache map[string]metamorph_api.MetaMorphAPIClient - blockTxClient blocktx.ClientI - isCentralisedMetamorph bool + Client metamorph_api.MetaMorphAPIClient } // NewMetamorph creates a connection to a list of metamorph servers via gRPC. -func NewMetamorph(address string, blockTxClient blocktx.ClientI, grpcMessageSize int, isCentralisedMetamorph bool) (*Metamorph, error) { +func NewMetamorph(address string, grpcMessageSize int) (*Metamorph, error) { conn, err := DialGRPC(address, grpcMessageSize) if err != nil { return nil, fmt.Errorf("failed to get connection to address %s: %v", address, err) } return &Metamorph{ - Client: metamorph_api.NewMetaMorphAPIClient(conn), - ClientCache: make(map[string]metamorph_api.MetaMorphAPIClient), - blockTxClient: blockTxClient, - isCentralisedMetamorph: isCentralisedMetamorph, + Client: metamorph_api.NewMetaMorphAPIClient(conn), }, nil } @@ -61,13 +49,8 @@ func DialGRPC(address string, grpcMessageSize int) (*grpc.ClientConn, error) { // GetTransaction gets the transaction bytes from metamorph. func (m *Metamorph) GetTransaction(ctx context.Context, txID string) ([]byte, error) { - client, err := m.getMetamorphClientForTx(ctx, txID) - if err != nil { - return nil, err - } - var tx *metamorph_api.Transaction - tx, err = client.GetTransaction(ctx, &metamorph_api.TransactionStatusRequest{ + tx, err := m.Client.GetTransaction(ctx, &metamorph_api.TransactionStatusRequest{ Txid: txID, }) if err != nil { @@ -83,13 +66,8 @@ func (m *Metamorph) GetTransaction(ctx context.Context, txID string) ([]byte, er // GetTransactionStatus gets the status of a transaction. func (m *Metamorph) GetTransactionStatus(ctx context.Context, txID string) (status *TransactionStatus, err error) { - var client metamorph_api.MetaMorphAPIClient - if client, err = m.getMetamorphClientForTx(ctx, txID); err != nil { - return nil, err - } - var tx *metamorph_api.TransactionStatus - tx, err = client.GetTransactionStatus(ctx, &metamorph_api.TransactionStatusRequest{ + tx, err = m.Client.GetTransactionStatus(ctx, &metamorph_api.TransactionStatusRequest{ Txid: txID, }) if err != nil { @@ -171,52 +149,3 @@ func (m *Metamorph) SubmitTransactions(ctx context.Context, txs [][]byte, txOpti return ret, nil } - -func (m *Metamorph) getMetamorphClientForTx(ctx context.Context, txID string) (metamorph_api.MetaMorphAPIClient, error) { - if m.isCentralisedMetamorph { - return m.Client, nil - } - - hash, err := utils.DecodeAndReverseHexString(txID) - if err != nil { - return nil, err - } - - var target string - if target, err = m.blockTxClient.LocateTransaction(ctx, &blocktx_api.Transaction{ - Hash: hash, - }); err != nil { - if errors.Is(err, blocktx.ErrTransactionNotFound) { - return nil, ErrTransactionNotFound - } - return nil, err - } - - if target == "" { - // TODO what do we do in this case? Reach out to all metamorph servers or reach out to a node? - return nil, ErrTransactionNotFound - } - - m.mu.RLock() - client, found := m.ClientCache[target] - m.mu.RUnlock() - - if !found { - var conn *grpc.ClientConn - opts := []grpc.DialOption{ - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithChainUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor), - grpc.WithChainStreamInterceptor(grpc_prometheus.StreamClientInterceptor), - } - if conn, err = grpc.Dial(target, tracing.AddGRPCDialOptions(opts)...); err != nil { - return nil, err - } - client = metamorph_api.NewMetaMorphAPIClient(conn) - - m.mu.Lock() - m.ClientCache[target] = client - m.mu.Unlock() - } - - return client, nil -} diff --git a/blocktx/blocktx_api/blocktx_api.pb.go b/blocktx/blocktx_api/blocktx_api.pb.go index 388d78ec4..d53d1160b 100644 --- a/blocktx/blocktx_api/blocktx_api.pb.go +++ b/blocktx/blocktx_api/blocktx_api.pb.go @@ -539,55 +539,6 @@ func (x *Hash) GetHash() []byte { return nil } -// swagger:model Source -type Source struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Source string `protobuf:"bytes,1,opt,name=source,proto3" json:"source,omitempty"` -} - -func (x *Source) Reset() { - *x = Source{} - if protoimpl.UnsafeEnabled { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Source) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Source) ProtoMessage() {} - -func (x *Source) ProtoReflect() protoreflect.Message { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Source.ProtoReflect.Descriptor instead. -func (*Source) Descriptor() ([]byte, []int) { - return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{9} -} - -func (x *Source) GetSource() string { - if x != nil { - return x.Source - } - return "" -} - -// swagger:model Source type MerklePath struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -599,7 +550,7 @@ type MerklePath struct { func (x *MerklePath) Reset() { *x = MerklePath{} if protoimpl.UnsafeEnabled { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -612,7 +563,7 @@ func (x *MerklePath) String() string { func (*MerklePath) ProtoMessage() {} func (x *MerklePath) ProtoReflect() protoreflect.Message { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -625,7 +576,7 @@ func (x *MerklePath) ProtoReflect() protoreflect.Message { // Deprecated: Use MerklePath.ProtoReflect.Descriptor instead. func (*MerklePath) Descriptor() ([]byte, []int) { - return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{10} + return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{9} } func (x *MerklePath) GetMerklePath() string { @@ -647,7 +598,7 @@ type TransactionAndSource struct { func (x *TransactionAndSource) Reset() { *x = TransactionAndSource{} if protoimpl.UnsafeEnabled { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -660,7 +611,7 @@ func (x *TransactionAndSource) String() string { func (*TransactionAndSource) ProtoMessage() {} func (x *TransactionAndSource) ProtoReflect() protoreflect.Message { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -673,7 +624,7 @@ func (x *TransactionAndSource) ProtoReflect() protoreflect.Message { // Deprecated: Use TransactionAndSource.ProtoReflect.Descriptor instead. func (*TransactionAndSource) Descriptor() ([]byte, []int) { - return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{11} + return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{10} } func (x *TransactionAndSource) GetHash() []byte { @@ -704,7 +655,7 @@ type RegisterTransactionResponse struct { func (x *RegisterTransactionResponse) Reset() { *x = RegisterTransactionResponse{} if protoimpl.UnsafeEnabled { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -717,7 +668,7 @@ func (x *RegisterTransactionResponse) String() string { func (*RegisterTransactionResponse) ProtoMessage() {} func (x *RegisterTransactionResponse) ProtoReflect() protoreflect.Message { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -730,7 +681,7 @@ func (x *RegisterTransactionResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RegisterTransactionResponse.ProtoReflect.Descriptor instead. func (*RegisterTransactionResponse) Descriptor() ([]byte, []int) { - return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{12} + return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{11} } func (x *RegisterTransactionResponse) GetSource() string { @@ -774,7 +725,7 @@ type BlockAndSource struct { func (x *BlockAndSource) Reset() { *x = BlockAndSource{} if protoimpl.UnsafeEnabled { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[13] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -787,7 +738,7 @@ func (x *BlockAndSource) String() string { func (*BlockAndSource) ProtoMessage() {} func (x *BlockAndSource) ProtoReflect() protoreflect.Message { - mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[13] + mi := &file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -800,7 +751,7 @@ func (x *BlockAndSource) ProtoReflect() protoreflect.Message { // Deprecated: Use BlockAndSource.ProtoReflect.Descriptor instead. func (*BlockAndSource) Descriptor() ([]byte, []int) { - return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{13} + return file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{12} } func (x *BlockAndSource) GetHash() []byte { @@ -880,89 +831,82 @@ var file_blocktx_blocktx_api_blocktx_api_proto_rawDesc = []byte{ 0x68, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x1a, 0x0a, 0x04, 0x48, 0x61, 0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, 0x20, 0x0a, 0x06, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, - 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x2c, 0x0a, 0x0a, 0x4d, 0x65, 0x72, 0x6b, - 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, - 0x50, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x65, 0x72, 0x6b, - 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x22, 0x42, 0x0a, 0x14, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x6e, 0x64, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x12, - 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x68, 0x61, - 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x98, 0x01, 0x0a, 0x1b, 0x52, - 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, - 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, - 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, - 0x69, 0x67, 0x68, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x70, - 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, - 0x65, 0x50, 0x61, 0x74, 0x68, 0x22, 0x3c, 0x0a, 0x0e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x6e, - 0x64, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x73, - 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x32, 0x95, 0x07, 0x0a, 0x0a, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x78, 0x41, - 0x50, 0x49, 0x12, 0x3f, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x16, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, - 0x70, 0x69, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x64, 0x0a, 0x13, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x54, - 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x6e, 0x64, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x28, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, - 0x73, 0x74, 0x65, 0x72, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x11, 0x4c, 0x6f, 0x63, - 0x61, 0x74, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, - 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x13, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x00, 0x12, - 0x4f, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x18, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x17, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, - 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x22, 0x00, - 0x12, 0x47, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x6e, - 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x1a, 0x19, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, - 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x13, 0x47, 0x65, 0x74, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, - 0x12, 0x18, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, - 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x00, - 0x12, 0x53, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x12, 0x19, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x22, 0x2c, 0x0a, 0x0a, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, + 0x50, 0x61, 0x74, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x50, 0x61, + 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, + 0x50, 0x61, 0x74, 0x68, 0x22, 0x42, 0x0a, 0x14, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x41, 0x6e, 0x64, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, + 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x98, 0x01, 0x0a, 0x1b, 0x52, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x65, 0x72, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, + 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, + 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, + 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x50, + 0x61, 0x74, 0x68, 0x22, 0x3c, 0x0a, 0x0e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, + 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, + 0x65, 0x32, 0xcf, 0x06, 0x0a, 0x0a, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x78, 0x41, 0x50, 0x49, + 0x12, 0x3f, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, + 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x64, 0x0a, 0x13, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x41, 0x6e, 0x64, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x28, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x50, + 0x61, 0x74, 0x68, 0x12, 0x18, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, + 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x17, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, + 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x12, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x1a, 0x19, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, + 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, + 0x00, 0x12, 0x45, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x18, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x1a, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, - 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x6c, 0x6f, - 0x63, 0x6b, 0x73, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, - 0x6b, 0x12, 0x11, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, - 0x48, 0x61, 0x73, 0x68, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, - 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x11, 0x47, 0x65, - 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x46, 0x6f, 0x72, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, - 0x13, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, - 0x69, 0x67, 0x68, 0x74, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, - 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x15, 0x47, 0x65, - 0x74, 0x4c, 0x61, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x42, 0x6c, - 0x6f, 0x63, 0x6b, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x12, 0x2e, 0x62, 0x6c, + 0x6f, 0x6e, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, + 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x00, 0x12, 0x53, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x54, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, + 0x12, 0x19, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x1e, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x22, 0x00, 0x12, 0x33, 0x0a, + 0x08, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x11, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x61, 0x73, 0x68, 0x1a, 0x12, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x46, 0x6f, + 0x72, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x13, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, + 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x1a, 0x12, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x22, 0x00, 0x12, 0x45, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x4c, 0x61, 0x73, 0x74, 0x50, 0x72, 0x6f, + 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x16, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, + 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x00, 0x12, 0x5d, 0x0a, 0x1c, 0x47, 0x65, 0x74, + 0x4d, 0x69, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x46, 0x6f, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x1b, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x6e, 0x64, + 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, + 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x69, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x13, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, + 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, - 0x00, 0x12, 0x5d, 0x0a, 0x1c, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x6e, 0x65, 0x64, 0x54, 0x72, 0x61, - 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x46, 0x6f, 0x72, 0x42, 0x6c, 0x6f, 0x63, - 0x6b, 0x12, 0x1b, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, - 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x1e, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x69, 0x6e, - 0x65, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x00, - 0x12, 0x49, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x6f, 0x74, 0x69, - 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x13, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, 0x69, - 0x67, 0x68, 0x74, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, - 0x69, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x00, 0x30, 0x01, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, - 0x3b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x00, 0x30, 0x01, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x3b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, + 0x5f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -977,7 +921,7 @@ func file_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP() []byte { return file_blocktx_blocktx_api_blocktx_api_proto_rawDescData } -var file_blocktx_blocktx_api_blocktx_api_proto_msgTypes = make([]protoimpl.MessageInfo, 14) +var file_blocktx_blocktx_api_blocktx_api_proto_msgTypes = make([]protoimpl.MessageInfo, 13) var file_blocktx_blocktx_api_blocktx_api_proto_goTypes = []interface{}{ (*HealthResponse)(nil), // 0: blocktx_api.HealthResponse (*Block)(nil), // 1: blocktx_api.Block @@ -988,46 +932,43 @@ var file_blocktx_blocktx_api_blocktx_api_proto_goTypes = []interface{}{ (*Transaction)(nil), // 6: blocktx_api.Transaction (*Height)(nil), // 7: blocktx_api.Height (*Hash)(nil), // 8: blocktx_api.Hash - (*Source)(nil), // 9: blocktx_api.Source - (*MerklePath)(nil), // 10: blocktx_api.MerklePath - (*TransactionAndSource)(nil), // 11: blocktx_api.TransactionAndSource - (*RegisterTransactionResponse)(nil), // 12: blocktx_api.RegisterTransactionResponse - (*BlockAndSource)(nil), // 13: blocktx_api.BlockAndSource - (*timestamppb.Timestamp)(nil), // 14: google.protobuf.Timestamp - (*emptypb.Empty)(nil), // 15: google.protobuf.Empty + (*MerklePath)(nil), // 9: blocktx_api.MerklePath + (*TransactionAndSource)(nil), // 10: blocktx_api.TransactionAndSource + (*RegisterTransactionResponse)(nil), // 11: blocktx_api.RegisterTransactionResponse + (*BlockAndSource)(nil), // 12: blocktx_api.BlockAndSource + (*timestamppb.Timestamp)(nil), // 13: google.protobuf.Timestamp + (*emptypb.Empty)(nil), // 14: google.protobuf.Empty } var file_blocktx_blocktx_api_blocktx_api_proto_depIdxs = []int32{ - 14, // 0: blocktx_api.HealthResponse.timestamp:type_name -> google.protobuf.Timestamp + 13, // 0: blocktx_api.HealthResponse.timestamp:type_name -> google.protobuf.Timestamp 6, // 1: blocktx_api.Transactions.transactions:type_name -> blocktx_api.Transaction 3, // 2: blocktx_api.TransactionBlocks.transaction_blocks:type_name -> blocktx_api.TransactionBlock 1, // 3: blocktx_api.MinedTransactions.block:type_name -> blocktx_api.Block 6, // 4: blocktx_api.MinedTransactions.transactions:type_name -> blocktx_api.Transaction - 15, // 5: blocktx_api.BlockTxAPI.Health:input_type -> google.protobuf.Empty - 11, // 6: blocktx_api.BlockTxAPI.RegisterTransaction:input_type -> blocktx_api.TransactionAndSource - 6, // 7: blocktx_api.BlockTxAPI.LocateTransaction:input_type -> blocktx_api.Transaction - 6, // 8: blocktx_api.BlockTxAPI.GetTransactionMerklePath:input_type -> blocktx_api.Transaction - 1, // 9: blocktx_api.BlockTxAPI.GetBlockTransactions:input_type -> blocktx_api.Block - 6, // 10: blocktx_api.BlockTxAPI.GetTransactionBlock:input_type -> blocktx_api.Transaction - 2, // 11: blocktx_api.BlockTxAPI.GetTransactionBlocks:input_type -> blocktx_api.Transactions - 8, // 12: blocktx_api.BlockTxAPI.GetBlock:input_type -> blocktx_api.Hash - 7, // 13: blocktx_api.BlockTxAPI.GetBlockForHeight:input_type -> blocktx_api.Height - 15, // 14: blocktx_api.BlockTxAPI.GetLastProcessedBlock:input_type -> google.protobuf.Empty - 13, // 15: blocktx_api.BlockTxAPI.GetMinedTransactionsForBlock:input_type -> blocktx_api.BlockAndSource - 7, // 16: blocktx_api.BlockTxAPI.GetBlockNotificationStream:input_type -> blocktx_api.Height - 0, // 17: blocktx_api.BlockTxAPI.Health:output_type -> blocktx_api.HealthResponse - 12, // 18: blocktx_api.BlockTxAPI.RegisterTransaction:output_type -> blocktx_api.RegisterTransactionResponse - 9, // 19: blocktx_api.BlockTxAPI.LocateTransaction:output_type -> blocktx_api.Source - 10, // 20: blocktx_api.BlockTxAPI.GetTransactionMerklePath:output_type -> blocktx_api.MerklePath - 2, // 21: blocktx_api.BlockTxAPI.GetBlockTransactions:output_type -> blocktx_api.Transactions - 1, // 22: blocktx_api.BlockTxAPI.GetTransactionBlock:output_type -> blocktx_api.Block - 4, // 23: blocktx_api.BlockTxAPI.GetTransactionBlocks:output_type -> blocktx_api.TransactionBlocks - 1, // 24: blocktx_api.BlockTxAPI.GetBlock:output_type -> blocktx_api.Block - 1, // 25: blocktx_api.BlockTxAPI.GetBlockForHeight:output_type -> blocktx_api.Block - 1, // 26: blocktx_api.BlockTxAPI.GetLastProcessedBlock:output_type -> blocktx_api.Block - 5, // 27: blocktx_api.BlockTxAPI.GetMinedTransactionsForBlock:output_type -> blocktx_api.MinedTransactions - 1, // 28: blocktx_api.BlockTxAPI.GetBlockNotificationStream:output_type -> blocktx_api.Block - 17, // [17:29] is the sub-list for method output_type - 5, // [5:17] is the sub-list for method input_type + 14, // 5: blocktx_api.BlockTxAPI.Health:input_type -> google.protobuf.Empty + 10, // 6: blocktx_api.BlockTxAPI.RegisterTransaction:input_type -> blocktx_api.TransactionAndSource + 6, // 7: blocktx_api.BlockTxAPI.GetTransactionMerklePath:input_type -> blocktx_api.Transaction + 1, // 8: blocktx_api.BlockTxAPI.GetBlockTransactions:input_type -> blocktx_api.Block + 6, // 9: blocktx_api.BlockTxAPI.GetTransactionBlock:input_type -> blocktx_api.Transaction + 2, // 10: blocktx_api.BlockTxAPI.GetTransactionBlocks:input_type -> blocktx_api.Transactions + 8, // 11: blocktx_api.BlockTxAPI.GetBlock:input_type -> blocktx_api.Hash + 7, // 12: blocktx_api.BlockTxAPI.GetBlockForHeight:input_type -> blocktx_api.Height + 14, // 13: blocktx_api.BlockTxAPI.GetLastProcessedBlock:input_type -> google.protobuf.Empty + 12, // 14: blocktx_api.BlockTxAPI.GetMinedTransactionsForBlock:input_type -> blocktx_api.BlockAndSource + 7, // 15: blocktx_api.BlockTxAPI.GetBlockNotificationStream:input_type -> blocktx_api.Height + 0, // 16: blocktx_api.BlockTxAPI.Health:output_type -> blocktx_api.HealthResponse + 11, // 17: blocktx_api.BlockTxAPI.RegisterTransaction:output_type -> blocktx_api.RegisterTransactionResponse + 9, // 18: blocktx_api.BlockTxAPI.GetTransactionMerklePath:output_type -> blocktx_api.MerklePath + 2, // 19: blocktx_api.BlockTxAPI.GetBlockTransactions:output_type -> blocktx_api.Transactions + 1, // 20: blocktx_api.BlockTxAPI.GetTransactionBlock:output_type -> blocktx_api.Block + 4, // 21: blocktx_api.BlockTxAPI.GetTransactionBlocks:output_type -> blocktx_api.TransactionBlocks + 1, // 22: blocktx_api.BlockTxAPI.GetBlock:output_type -> blocktx_api.Block + 1, // 23: blocktx_api.BlockTxAPI.GetBlockForHeight:output_type -> blocktx_api.Block + 1, // 24: blocktx_api.BlockTxAPI.GetLastProcessedBlock:output_type -> blocktx_api.Block + 5, // 25: blocktx_api.BlockTxAPI.GetMinedTransactionsForBlock:output_type -> blocktx_api.MinedTransactions + 1, // 26: blocktx_api.BlockTxAPI.GetBlockNotificationStream:output_type -> blocktx_api.Block + 16, // [16:27] is the sub-list for method output_type + 5, // [5:16] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name 5, // [5:5] is the sub-list for extension extendee 0, // [0:5] is the sub-list for field type_name @@ -1148,18 +1089,6 @@ func file_blocktx_blocktx_api_blocktx_api_proto_init() { } } file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Source); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MerklePath); i { case 0: return &v.state @@ -1171,7 +1100,7 @@ func file_blocktx_blocktx_api_blocktx_api_proto_init() { return nil } } - file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*TransactionAndSource); i { case 0: return &v.state @@ -1183,7 +1112,7 @@ func file_blocktx_blocktx_api_blocktx_api_proto_init() { return nil } } - file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RegisterTransactionResponse); i { case 0: return &v.state @@ -1195,7 +1124,7 @@ func file_blocktx_blocktx_api_blocktx_api_proto_init() { return nil } } - file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BlockAndSource); i { case 0: return &v.state @@ -1214,7 +1143,7 @@ func file_blocktx_blocktx_api_blocktx_api_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_blocktx_blocktx_api_blocktx_api_proto_rawDesc, NumEnums: 0, - NumMessages: 14, + NumMessages: 13, NumExtensions: 0, NumServices: 1, }, diff --git a/blocktx/blocktx_api/blocktx_api.proto b/blocktx/blocktx_api/blocktx_api.proto index 060b50b06..42afbbdcb 100644 --- a/blocktx/blocktx_api/blocktx_api.proto +++ b/blocktx/blocktx_api/blocktx_api.proto @@ -14,9 +14,6 @@ service BlockTxAPI { // RegisterTransaction registers a transaction with the API. rpc RegisterTransaction (TransactionAndSource) returns (RegisterTransactionResponse) {} - // LocateTransaction returns the source of a transaction. - rpc LocateTransaction(Transaction) returns (Source) {} - // GetTransactionMerklePath returns the merkle path of a transaction. rpc GetTransactionMerklePath(Transaction) returns (MerklePath) {} @@ -98,12 +95,6 @@ message Hash { bytes hash = 1; } -// swagger:model Source -message Source { - string source = 1; -} - -// swagger:model Source message MerklePath { string merklePath = 1; } diff --git a/blocktx/blocktx_api/blocktx_api_grpc.pb.go b/blocktx/blocktx_api/blocktx_api_grpc.pb.go index 824c79255..07d6bd517 100644 --- a/blocktx/blocktx_api/blocktx_api_grpc.pb.go +++ b/blocktx/blocktx_api/blocktx_api_grpc.pb.go @@ -22,7 +22,6 @@ const _ = grpc.SupportPackageIsVersion7 const ( BlockTxAPI_Health_FullMethodName = "/blocktx_api.BlockTxAPI/Health" BlockTxAPI_RegisterTransaction_FullMethodName = "/blocktx_api.BlockTxAPI/RegisterTransaction" - BlockTxAPI_LocateTransaction_FullMethodName = "/blocktx_api.BlockTxAPI/LocateTransaction" BlockTxAPI_GetTransactionMerklePath_FullMethodName = "/blocktx_api.BlockTxAPI/GetTransactionMerklePath" BlockTxAPI_GetBlockTransactions_FullMethodName = "/blocktx_api.BlockTxAPI/GetBlockTransactions" BlockTxAPI_GetTransactionBlock_FullMethodName = "/blocktx_api.BlockTxAPI/GetTransactionBlock" @@ -42,8 +41,6 @@ type BlockTxAPIClient interface { Health(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*HealthResponse, error) // RegisterTransaction registers a transaction with the API. RegisterTransaction(ctx context.Context, in *TransactionAndSource, opts ...grpc.CallOption) (*RegisterTransactionResponse, error) - // LocateTransaction returns the source of a transaction. - LocateTransaction(ctx context.Context, in *Transaction, opts ...grpc.CallOption) (*Source, error) // GetTransactionMerklePath returns the merkle path of a transaction. GetTransactionMerklePath(ctx context.Context, in *Transaction, opts ...grpc.CallOption) (*MerklePath, error) // GetBlockTransactions returns a list of transaction hashes for a given block. @@ -90,15 +87,6 @@ func (c *blockTxAPIClient) RegisterTransaction(ctx context.Context, in *Transact return out, nil } -func (c *blockTxAPIClient) LocateTransaction(ctx context.Context, in *Transaction, opts ...grpc.CallOption) (*Source, error) { - out := new(Source) - err := c.cc.Invoke(ctx, BlockTxAPI_LocateTransaction_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *blockTxAPIClient) GetTransactionMerklePath(ctx context.Context, in *Transaction, opts ...grpc.CallOption) (*MerklePath, error) { out := new(MerklePath) err := c.cc.Invoke(ctx, BlockTxAPI_GetTransactionMerklePath_FullMethodName, in, out, opts...) @@ -211,8 +199,6 @@ type BlockTxAPIServer interface { Health(context.Context, *emptypb.Empty) (*HealthResponse, error) // RegisterTransaction registers a transaction with the API. RegisterTransaction(context.Context, *TransactionAndSource) (*RegisterTransactionResponse, error) - // LocateTransaction returns the source of a transaction. - LocateTransaction(context.Context, *Transaction) (*Source, error) // GetTransactionMerklePath returns the merkle path of a transaction. GetTransactionMerklePath(context.Context, *Transaction) (*MerklePath, error) // GetBlockTransactions returns a list of transaction hashes for a given block. @@ -244,9 +230,6 @@ func (UnimplementedBlockTxAPIServer) Health(context.Context, *emptypb.Empty) (*H func (UnimplementedBlockTxAPIServer) RegisterTransaction(context.Context, *TransactionAndSource) (*RegisterTransactionResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RegisterTransaction not implemented") } -func (UnimplementedBlockTxAPIServer) LocateTransaction(context.Context, *Transaction) (*Source, error) { - return nil, status.Errorf(codes.Unimplemented, "method LocateTransaction not implemented") -} func (UnimplementedBlockTxAPIServer) GetTransactionMerklePath(context.Context, *Transaction) (*MerklePath, error) { return nil, status.Errorf(codes.Unimplemented, "method GetTransactionMerklePath not implemented") } @@ -323,24 +306,6 @@ func _BlockTxAPI_RegisterTransaction_Handler(srv interface{}, ctx context.Contex return interceptor(ctx, in, info, handler) } -func _BlockTxAPI_LocateTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Transaction) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(BlockTxAPIServer).LocateTransaction(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: BlockTxAPI_LocateTransaction_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BlockTxAPIServer).LocateTransaction(ctx, req.(*Transaction)) - } - return interceptor(ctx, in, info, handler) -} - func _BlockTxAPI_GetTransactionMerklePath_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(Transaction) if err := dec(in); err != nil { @@ -521,10 +486,6 @@ var BlockTxAPI_ServiceDesc = grpc.ServiceDesc{ MethodName: "RegisterTransaction", Handler: _BlockTxAPI_RegisterTransaction_Handler, }, - { - MethodName: "LocateTransaction", - Handler: _BlockTxAPI_LocateTransaction_Handler, - }, { MethodName: "GetTransactionMerklePath", Handler: _BlockTxAPI_GetTransactionMerklePath_Handler, diff --git a/blocktx/blocktx_api/mock/blocktx_api_client_mock.go b/blocktx/blocktx_api/mock/blocktx_api_client_mock.go index add1b2643..d9c989ca7 100644 --- a/blocktx/blocktx_api/mock/blocktx_api_client_mock.go +++ b/blocktx/blocktx_api/mock/blocktx_api_client_mock.go @@ -51,9 +51,6 @@ var _ blocktx_api.BlockTxAPIClient = &BlockTxAPIClientMock{} // HealthFunc: func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*blocktx_api.HealthResponse, error) { // panic("mock out the Health method") // }, -// LocateTransactionFunc: func(ctx context.Context, in *blocktx_api.Transaction, opts ...grpc.CallOption) (*blocktx_api.Source, error) { -// panic("mock out the LocateTransaction method") -// }, // RegisterTransactionFunc: func(ctx context.Context, in *blocktx_api.TransactionAndSource, opts ...grpc.CallOption) (*blocktx_api.RegisterTransactionResponse, error) { // panic("mock out the RegisterTransaction method") // }, @@ -94,9 +91,6 @@ type BlockTxAPIClientMock struct { // HealthFunc mocks the Health method. HealthFunc func(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*blocktx_api.HealthResponse, error) - // LocateTransactionFunc mocks the LocateTransaction method. - LocateTransactionFunc func(ctx context.Context, in *blocktx_api.Transaction, opts ...grpc.CallOption) (*blocktx_api.Source, error) - // RegisterTransactionFunc mocks the RegisterTransaction method. RegisterTransactionFunc func(ctx context.Context, in *blocktx_api.TransactionAndSource, opts ...grpc.CallOption) (*blocktx_api.RegisterTransactionResponse, error) @@ -192,15 +186,6 @@ type BlockTxAPIClientMock struct { // Opts is the opts argument value. Opts []grpc.CallOption } - // LocateTransaction holds details about calls to the LocateTransaction method. - LocateTransaction []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // In is the in argument value. - In *blocktx_api.Transaction - // Opts is the opts argument value. - Opts []grpc.CallOption - } // RegisterTransaction holds details about calls to the RegisterTransaction method. RegisterTransaction []struct { // Ctx is the ctx argument value. @@ -221,7 +206,6 @@ type BlockTxAPIClientMock struct { lockGetTransactionBlocks sync.RWMutex lockGetTransactionMerklePath sync.RWMutex lockHealth sync.RWMutex - lockLocateTransaction sync.RWMutex lockRegisterTransaction sync.RWMutex } @@ -625,46 +609,6 @@ func (mock *BlockTxAPIClientMock) HealthCalls() []struct { return calls } -// LocateTransaction calls LocateTransactionFunc. -func (mock *BlockTxAPIClientMock) LocateTransaction(ctx context.Context, in *blocktx_api.Transaction, opts ...grpc.CallOption) (*blocktx_api.Source, error) { - if mock.LocateTransactionFunc == nil { - panic("BlockTxAPIClientMock.LocateTransactionFunc: method is nil but BlockTxAPIClient.LocateTransaction was just called") - } - callInfo := struct { - Ctx context.Context - In *blocktx_api.Transaction - Opts []grpc.CallOption - }{ - Ctx: ctx, - In: in, - Opts: opts, - } - mock.lockLocateTransaction.Lock() - mock.calls.LocateTransaction = append(mock.calls.LocateTransaction, callInfo) - mock.lockLocateTransaction.Unlock() - return mock.LocateTransactionFunc(ctx, in, opts...) -} - -// LocateTransactionCalls gets all the calls that were made to LocateTransaction. -// Check the length with: -// -// len(mockedBlockTxAPIClient.LocateTransactionCalls()) -func (mock *BlockTxAPIClientMock) LocateTransactionCalls() []struct { - Ctx context.Context - In *blocktx_api.Transaction - Opts []grpc.CallOption -} { - var calls []struct { - Ctx context.Context - In *blocktx_api.Transaction - Opts []grpc.CallOption - } - mock.lockLocateTransaction.RLock() - calls = mock.calls.LocateTransaction - mock.lockLocateTransaction.RUnlock() - return calls -} - // RegisterTransaction calls RegisterTransactionFunc. func (mock *BlockTxAPIClientMock) RegisterTransaction(ctx context.Context, in *blocktx_api.TransactionAndSource, opts ...grpc.CallOption) (*blocktx_api.RegisterTransactionResponse, error) { if mock.RegisterTransactionFunc == nil { diff --git a/blocktx/client.go b/blocktx/client.go index 97f03ac1e..ebe53a29f 100644 --- a/blocktx/client.go +++ b/blocktx/client.go @@ -19,7 +19,6 @@ import ( // ClientI is the interface for the block-tx transactionHandler. type ClientI interface { Start(minedBlockChan chan *blocktx_api.Block) - LocateTransaction(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) GetTransactionMerklePath(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) RegisterTransaction(ctx context.Context, transaction *blocktx_api.TransactionAndSource) (*blocktx_api.RegisterTransactionResponse, error) GetTransactionBlocks(ctx context.Context, transaction *blocktx_api.Transactions) (*blocktx_api.TransactionBlocks, error) @@ -124,15 +123,6 @@ func (btc *Client) Shutdown() { <-btc.shutdownComplete } -func (btc *Client) LocateTransaction(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) { - location, err := btc.client.LocateTransaction(ctx, transaction) - if err != nil { - return "", ErrTransactionNotFound - } - - return location.GetSource(), nil -} - func (btc *Client) GetTransactionMerklePath(ctx context.Context, hash *blocktx_api.Transaction) (string, error) { merklePath, err := btc.client.GetTransactionMerklePath(ctx, hash) if err != nil { diff --git a/blocktx/server.go b/blocktx/server.go index ceb78080c..9254d3d68 100644 --- a/blocktx/server.go +++ b/blocktx/server.go @@ -82,25 +82,6 @@ func (s *Server) Health(_ context.Context, _ *emptypb.Empty) (*blocktx_api.Healt }, nil } -func (s *Server) LocateTransaction(ctx context.Context, transaction *blocktx_api.Transaction) (*blocktx_api.Source, error) { - hash, err := chainhash.NewHash(transaction.GetHash()) - if err != nil { - return nil, err - } - - source, err := s.store.GetTransactionSource(ctx, hash) - if err != nil { - if errors.Is(err, store.ErrNotFound) { - return nil, ErrTransactionNotFound - } - return nil, err - } - - return &blocktx_api.Source{ - Source: source, - }, nil -} - func (s *Server) GetTransactionMerklePath(ctx context.Context, transaction *blocktx_api.Transaction) (*blocktx_api.MerklePath, error) { hash, err := chainhash.NewHash(transaction.GetHash()) if err != nil { diff --git a/blocktx/store/interface.go b/blocktx/store/interface.go index dae570597..1e50f313b 100644 --- a/blocktx/store/interface.go +++ b/blocktx/store/interface.go @@ -22,7 +22,6 @@ type Interface interface { RegisterTransaction(ctx context.Context, transaction *blocktx_api.TransactionAndSource) (string, string, []byte, uint64, error) TryToBecomePrimary(ctx context.Context, myHostName string) error PrimaryBlocktx(ctx context.Context) (string, error) - GetTransactionSource(ctx context.Context, hash *chainhash.Hash) (string, error) GetTransactionMerklePath(ctx context.Context, hash *chainhash.Hash) (string, error) GetBlock(ctx context.Context, hash *chainhash.Hash) (*blocktx_api.Block, error) GetBlockForHeight(ctx context.Context, height uint64) (*blocktx_api.Block, error) diff --git a/blocktx/store/mock.go b/blocktx/store/mock.go index bbf308f0a..a29e35a47 100644 --- a/blocktx/store/mock.go +++ b/blocktx/store/mock.go @@ -50,9 +50,6 @@ var _ Interface = &InterfaceMock{} // GetTransactionMerklePathFunc: func(ctx context.Context, hash *chainhash.Hash) (string, error) { // panic("mock out the GetTransactionMerklePath method") // }, -// GetTransactionSourceFunc: func(ctx context.Context, hash *chainhash.Hash) (string, error) { -// panic("mock out the GetTransactionSource method") -// }, // InsertBlockFunc: func(ctx context.Context, block *blocktx_api.Block) (uint64, error) { // panic("mock out the InsertBlock method") // }, @@ -114,9 +111,6 @@ type InterfaceMock struct { // GetTransactionMerklePathFunc mocks the GetTransactionMerklePath method. GetTransactionMerklePathFunc func(ctx context.Context, hash *chainhash.Hash) (string, error) - // GetTransactionSourceFunc mocks the GetTransactionSource method. - GetTransactionSourceFunc func(ctx context.Context, hash *chainhash.Hash) (string, error) - // InsertBlockFunc mocks the InsertBlock method. InsertBlockFunc func(ctx context.Context, block *blocktx_api.Block) (uint64, error) @@ -205,13 +199,6 @@ type InterfaceMock struct { // Hash is the hash argument value. Hash *chainhash.Hash } - // GetTransactionSource holds details about calls to the GetTransactionSource method. - GetTransactionSource []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Hash is the hash argument value. - Hash *chainhash.Hash - } // InsertBlock holds details about calls to the InsertBlock method. InsertBlock []struct { // Ctx is the ctx argument value. @@ -287,7 +274,6 @@ type InterfaceMock struct { lockGetTransactionBlock sync.RWMutex lockGetTransactionBlocks sync.RWMutex lockGetTransactionMerklePath sync.RWMutex - lockGetTransactionSource sync.RWMutex lockInsertBlock sync.RWMutex lockInsertBlockTransactions sync.RWMutex lockMarkBlockAsDone sync.RWMutex @@ -641,42 +627,6 @@ func (mock *InterfaceMock) GetTransactionMerklePathCalls() []struct { return calls } -// GetTransactionSource calls GetTransactionSourceFunc. -func (mock *InterfaceMock) GetTransactionSource(ctx context.Context, hash *chainhash.Hash) (string, error) { - if mock.GetTransactionSourceFunc == nil { - panic("InterfaceMock.GetTransactionSourceFunc: method is nil but Interface.GetTransactionSource was just called") - } - callInfo := struct { - Ctx context.Context - Hash *chainhash.Hash - }{ - Ctx: ctx, - Hash: hash, - } - mock.lockGetTransactionSource.Lock() - mock.calls.GetTransactionSource = append(mock.calls.GetTransactionSource, callInfo) - mock.lockGetTransactionSource.Unlock() - return mock.GetTransactionSourceFunc(ctx, hash) -} - -// GetTransactionSourceCalls gets all the calls that were made to GetTransactionSource. -// Check the length with: -// -// len(mockedInterface.GetTransactionSourceCalls()) -func (mock *InterfaceMock) GetTransactionSourceCalls() []struct { - Ctx context.Context - Hash *chainhash.Hash -} { - var calls []struct { - Ctx context.Context - Hash *chainhash.Hash - } - mock.lockGetTransactionSource.RLock() - calls = mock.calls.GetTransactionSource - mock.lockGetTransactionSource.RUnlock() - return calls -} - // InsertBlock calls InsertBlockFunc. func (mock *InterfaceMock) InsertBlock(ctx context.Context, block *blocktx_api.Block) (uint64, error) { if mock.InsertBlockFunc == nil { diff --git a/blocktx/store/sql/get_transaction_source.go b/blocktx/store/sql/get_transaction_source.go deleted file mode 100644 index 57a4ce552..000000000 --- a/blocktx/store/sql/get_transaction_source.go +++ /dev/null @@ -1,40 +0,0 @@ -package sql - -import ( - "context" - "database/sql" - - "github.com/bitcoin-sv/arc/blocktx/store" - "github.com/libsv/go-p2p/chaincfg/chainhash" - "github.com/ordishs/gocore" - "github.com/pkg/errors" -) - -// GetTransactionSource returns the source of a transaction. -func (s *SQL) GetTransactionSource(ctx context.Context, txhash *chainhash.Hash) (string, error) { - start := gocore.CurrentNanos() - defer func() { - gocore.NewStat("blocktx").NewStat("GetTransactionSource").AddTime(start) - }() - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - q := ` - SELECT - t.source - FROM transactions t - WHERE t.hash = $1 - ` - - var source sql.NullString - - if err := s.db.QueryRowContext(ctx, q, txhash[:]).Scan(&source); err != nil { - if errors.Is(err, sql.ErrNoRows) { - return "", store.ErrNotFound - } - return "", err - } - - return source.String, nil -} diff --git a/blocktx/store/sql/get_transaction_source_test.go b/blocktx/store/sql/get_transaction_source_test.go deleted file mode 100644 index 2416391b5..000000000 --- a/blocktx/store/sql/get_transaction_source_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package sql - -import ( - "context" - "testing" - - "github.com/bitcoin-sv/arc/blocktx/store" - . "github.com/bitcoin-sv/arc/database_testing" - "github.com/libsv/go-p2p/chaincfg/chainhash" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" -) - -type GetTransactionSourceSuite struct { - DatabaseTestSuite -} - -func (s *GetTransactionSourceSuite) Test() { - block := GetTestBlock() - tx := GetTestTransaction() - s.InsertBlock(block) - - s.InsertTransaction(tx) - - s.InsertBlockTransactionMap(&store.BlockTransactionMap{ - BlockID: block.ID, - TransactionID: tx.ID, - Pos: 2, - }) - - store, err := NewPostgresStore(DefaultParams) - require.NoError(s.T(), err) - - h, err := chainhash.NewHash([]byte(tx.Hash)) - require.NoError(s.T(), err) - - source, err := store.GetTransactionSource(context.Background(), h) - require.NoError(s.T(), err) - - assert.Equal(s.T(), tx.Source, source) -} - -func TestGetGetTransactionSourceSuite(t *testing.T) { - s := new(GetTransactionSourceSuite) - suite.Run(t, s) -} diff --git a/blocktx/store/sql/sql_test.go b/blocktx/store/sql/sql_test.go index e8b51f47a..f2f8979c3 100644 --- a/blocktx/store/sql/sql_test.go +++ b/blocktx/store/sql/sql_test.go @@ -50,10 +50,6 @@ func TestInOut(t *testing.T) { }) require.NoError(t, err) - source, err := s.GetTransactionSource(ctx, firstHash) - require.NoError(t, err) - assert.Equal(t, "TEST", source) - err = s.InsertBlockTransactions(ctx, blockId, transactions, make([]string, len(transactions))) require.NoError(t, err) diff --git a/cmd/api.go b/cmd/api.go index 01a71f303..c7c4045fd 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -11,9 +11,6 @@ import ( "github.com/bitcoin-sv/arc/api" "github.com/bitcoin-sv/arc/api/handler" "github.com/bitcoin-sv/arc/api/transactionHandler" - "github.com/bitcoin-sv/arc/blocktx" - "github.com/bitcoin-sv/arc/blocktx/blocktx_api" - "github.com/bitcoin-sv/arc/config" "github.com/labstack/echo/v4" echomiddleware "github.com/labstack/echo/v4/middleware" apmecho "github.com/opentracing-contrib/echo" @@ -91,34 +88,12 @@ func LoadArcHandler(e *echo.Echo, logger *slog.Logger) error { return fmt.Errorf("metamorph.dialAddr not found in config") } - blocktxAddress := viper.GetString("blocktx.dialAddr") - if blocktxAddress == "" { - return fmt.Errorf("blocktx.dialAddr not found in config") - } - - blockTxLogger, err := config.NewLogger() - if err != nil { - return fmt.Errorf("failed to create new logger: %v", err) - } - - conn, err := blocktx.DialGRPC(blocktxAddress) - if err != nil { - return fmt.Errorf("failed to connect to block-tx server: %v", err) - } - - bTx := blocktx.NewClient(blocktx_api.NewBlockTxAPIClient(conn), blocktx.WithLogger(blockTxLogger)) - grpcMessageSize := viper.GetInt("grpcMessageSize") if grpcMessageSize == 0 { return fmt.Errorf("grpcMessageSize not found in config") } - isCentralisedMetamorph := false - if viper.GetString("metamorph.db.mode") == "dynamodb" || viper.GetString("metamorph.db.mode") == "postgres" { - isCentralisedMetamorph = true - } - - txHandler, err := transactionHandler.NewMetamorph(addresses, bTx, grpcMessageSize, isCentralisedMetamorph) + txHandler, err := transactionHandler.NewMetamorph(addresses, grpcMessageSize) if err != nil { return err } diff --git a/cmd/txstatus/main.go b/cmd/txstatus/main.go index 42ea6eb6a..b863c745e 100644 --- a/cmd/txstatus/main.go +++ b/cmd/txstatus/main.go @@ -9,8 +9,6 @@ import ( "time" "github.com/bitcoin-sv/arc/api/transactionHandler" - "github.com/bitcoin-sv/arc/blocktx" - "github.com/bitcoin-sv/arc/blocktx/blocktx_api" "github.com/spf13/viper" ) @@ -38,23 +36,12 @@ func main() { panic("Missing metamorph.dialAddr") } - btxAddress := viper.GetString("blocktx.dialAddr") - if btxAddress == "" { - panic("Missing blocktx.dialAddr") - } - - conn, err := blocktx.DialGRPC(btxAddress) - if err != nil { - panic("failed to connect to block-tx server") - } - - bTx := blocktx.NewClient(blocktx_api.NewBlockTxAPIClient(conn)) grpcMessageSize := viper.GetInt("grpcMessageSize") if grpcMessageSize == 0 { panic("Missing grpcMessageSize") } - txHandler, err := transactionHandler.NewMetamorph(addresses, bTx, grpcMessageSize, false) + txHandler, err := transactionHandler.NewMetamorph(addresses, grpcMessageSize) if err != nil { panic(err) } diff --git a/examples/custom/main.go b/examples/custom/main.go index d13a9933b..7f443868a 100644 --- a/examples/custom/main.go +++ b/examples/custom/main.go @@ -11,8 +11,6 @@ import ( "github.com/bitcoin-sv/arc/api" apiHandler "github.com/bitcoin-sv/arc/api/handler" "github.com/bitcoin-sv/arc/api/transactionHandler" - "github.com/bitcoin-sv/arc/blocktx" - "github.com/bitcoin-sv/arc/blocktx/blocktx_api" "github.com/deepmap/oapi-codegen/pkg/middleware" "github.com/getkin/kin-openapi/openapi3filter" "github.com/labstack/echo/v4" @@ -69,16 +67,9 @@ func main() { }), ) - // init BlockTx client - conn, err := blocktx.DialGRPC("localhost:8021") - if err != nil { - panic("failed to connect to block-tx server") - } - - blockTxClient := blocktx.NewClient(blocktx_api.NewBlockTxAPIClient(conn)) grpcMessageSize := viper.GetInt("grpcMessageSize") // add a single metamorph, with the BlockTx client we want to use - txHandler, err := transactionHandler.NewMetamorph("localhost:8011", blockTxClient, grpcMessageSize, false) + txHandler, err := transactionHandler.NewMetamorph("localhost:8011", grpcMessageSize) if err != nil { panic(err) } diff --git a/metamorph/mocks/blocktx_mock.go b/metamorph/mocks/blocktx_mock.go index 346b719f6..9cf8ccbb5 100644 --- a/metamorph/mocks/blocktx_mock.go +++ b/metamorph/mocks/blocktx_mock.go @@ -39,9 +39,6 @@ var _ blocktx.ClientI = &ClientIMock{} // GetTransactionMerklePathFunc: func(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) { // panic("mock out the GetTransactionMerklePath method") // }, -// LocateTransactionFunc: func(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) { -// panic("mock out the LocateTransaction method") -// }, // RegisterTransactionFunc: func(ctx context.Context, transaction *blocktx_api.TransactionAndSource) (*blocktx_api.RegisterTransactionResponse, error) { // panic("mock out the RegisterTransaction method") // }, @@ -76,9 +73,6 @@ type ClientIMock struct { // GetTransactionMerklePathFunc mocks the GetTransactionMerklePath method. GetTransactionMerklePathFunc func(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) - // LocateTransactionFunc mocks the LocateTransaction method. - LocateTransactionFunc func(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) - // RegisterTransactionFunc mocks the RegisterTransaction method. RegisterTransactionFunc func(ctx context.Context, transaction *blocktx_api.TransactionAndSource) (*blocktx_api.RegisterTransactionResponse, error) @@ -130,13 +124,6 @@ type ClientIMock struct { // Transaction is the transaction argument value. Transaction *blocktx_api.Transaction } - // LocateTransaction holds details about calls to the LocateTransaction method. - LocateTransaction []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Transaction is the transaction argument value. - Transaction *blocktx_api.Transaction - } // RegisterTransaction holds details about calls to the RegisterTransaction method. RegisterTransaction []struct { // Ctx is the ctx argument value. @@ -159,7 +146,6 @@ type ClientIMock struct { lockGetTransactionBlock sync.RWMutex lockGetTransactionBlocks sync.RWMutex lockGetTransactionMerklePath sync.RWMutex - lockLocateTransaction sync.RWMutex lockRegisterTransaction sync.RWMutex lockShutdown sync.RWMutex lockStart sync.RWMutex @@ -377,42 +363,6 @@ func (mock *ClientIMock) GetTransactionMerklePathCalls() []struct { return calls } -// LocateTransaction calls LocateTransactionFunc. -func (mock *ClientIMock) LocateTransaction(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) { - if mock.LocateTransactionFunc == nil { - panic("ClientIMock.LocateTransactionFunc: method is nil but ClientI.LocateTransaction was just called") - } - callInfo := struct { - Ctx context.Context - Transaction *blocktx_api.Transaction - }{ - Ctx: ctx, - Transaction: transaction, - } - mock.lockLocateTransaction.Lock() - mock.calls.LocateTransaction = append(mock.calls.LocateTransaction, callInfo) - mock.lockLocateTransaction.Unlock() - return mock.LocateTransactionFunc(ctx, transaction) -} - -// LocateTransactionCalls gets all the calls that were made to LocateTransaction. -// Check the length with: -// -// len(mockedClientI.LocateTransactionCalls()) -func (mock *ClientIMock) LocateTransactionCalls() []struct { - Ctx context.Context - Transaction *blocktx_api.Transaction -} { - var calls []struct { - Ctx context.Context - Transaction *blocktx_api.Transaction - } - mock.lockLocateTransaction.RLock() - calls = mock.calls.LocateTransaction - mock.lockLocateTransaction.RUnlock() - return calls -} - // RegisterTransaction calls RegisterTransactionFunc. func (mock *ClientIMock) RegisterTransaction(ctx context.Context, transaction *blocktx_api.TransactionAndSource) (*blocktx_api.RegisterTransactionResponse, error) { if mock.RegisterTransactionFunc == nil { diff --git a/metamorph/mocks/store_mock.go b/metamorph/mocks/store_mock.go index 64b8bbd0b..82a36de70 100644 --- a/metamorph/mocks/store_mock.go +++ b/metamorph/mocks/store_mock.go @@ -37,9 +37,6 @@ var _ store.MetamorphStore = &MetamorphStoreMock{} // GetUnminedFunc: func(contextMoqParam context.Context, callback func(s *store.StoreData)) error { // panic("mock out the GetUnmined method") // }, -// IsCentralisedFunc: func() bool { -// panic("mock out the IsCentralised method") -// }, // RemoveCallbackerFunc: func(ctx context.Context, hash *chainhash.Hash) error { // panic("mock out the RemoveCallbacker method") // }, @@ -83,9 +80,6 @@ type MetamorphStoreMock struct { // GetUnminedFunc mocks the GetUnmined method. GetUnminedFunc func(contextMoqParam context.Context, callback func(s *store.StoreData)) error - // IsCentralisedFunc mocks the IsCentralised method. - IsCentralisedFunc func() bool - // RemoveCallbackerFunc mocks the RemoveCallbacker method. RemoveCallbackerFunc func(ctx context.Context, hash *chainhash.Hash) error @@ -142,9 +136,6 @@ type MetamorphStoreMock struct { // Callback is the callback argument value. Callback func(s *store.StoreData) } - // IsCentralised holds details about calls to the IsCentralised method. - IsCentralised []struct { - } // RemoveCallbacker holds details about calls to the RemoveCallbacker method. RemoveCallbacker []struct { // Ctx is the ctx argument value. @@ -210,7 +201,6 @@ type MetamorphStoreMock struct { lockGet sync.RWMutex lockGetBlockProcessed sync.RWMutex lockGetUnmined sync.RWMutex - lockIsCentralised sync.RWMutex lockRemoveCallbacker sync.RWMutex lockSet sync.RWMutex lockSetBlockProcessed sync.RWMutex @@ -396,33 +386,6 @@ func (mock *MetamorphStoreMock) GetUnminedCalls() []struct { return calls } -// IsCentralised calls IsCentralisedFunc. -func (mock *MetamorphStoreMock) IsCentralised() bool { - if mock.IsCentralisedFunc == nil { - panic("MetamorphStoreMock.IsCentralisedFunc: method is nil but MetamorphStore.IsCentralised was just called") - } - callInfo := struct { - }{} - mock.lockIsCentralised.Lock() - mock.calls.IsCentralised = append(mock.calls.IsCentralised, callInfo) - mock.lockIsCentralised.Unlock() - return mock.IsCentralisedFunc() -} - -// IsCentralisedCalls gets all the calls that were made to IsCentralised. -// Check the length with: -// -// len(mockedMetamorphStore.IsCentralisedCalls()) -func (mock *MetamorphStoreMock) IsCentralisedCalls() []struct { -} { - var calls []struct { - } - mock.lockIsCentralised.RLock() - calls = mock.calls.IsCentralised - mock.lockIsCentralised.RUnlock() - return calls -} - // RemoveCallbacker calls RemoveCallbackerFunc. func (mock *MetamorphStoreMock) RemoveCallbacker(ctx context.Context, hash *chainhash.Hash) error { if mock.RemoveCallbackerFunc == nil { diff --git a/metamorph/processor.go b/metamorph/processor.go index 9726cf854..1a3945886 100644 --- a/metamorph/processor.go +++ b/metamorph/processor.go @@ -281,32 +281,11 @@ func (p *Processor) GetPeers() ([]string, []string) { return peersConnected, peersDisconnected } -func (p *Processor) deleteExpired(record *store.StoreData) (recordDeleted bool) { - if p.now().Sub(record.StoredAt) <= p.dataRetentionPeriod { - return recordDeleted - } - - p.logger.Debug("deleting transaction from storage", slog.String("hash", record.Hash.String()), slog.String("status", metamorph_api.Status_name[int32(record.Status)]), slog.Time("storage date", record.StoredAt)) - - err := p.store.Del(context.Background(), record.Hash[:]) - if err != nil { - p.logger.Error("failed to delete transaction", slog.String("hash", record.Hash.String()), slog.String("err", err.Error())) - return recordDeleted - } - recordDeleted = true - - return recordDeleted -} - func (p *Processor) LoadUnmined() { span, spanCtx := opentracing.StartSpanFromContext(context.Background(), "Processor:LoadUnmined") defer span.Finish() err := p.store.GetUnmined(spanCtx, func(record *store.StoreData) { - if !p.store.IsCentralised() && p.deleteExpired(record) { - return - } - // add the records we have in the database, but that have not been processed, to the mempool watcher pr := processor_response.NewProcessorResponseWithStatus(record.Hash, record.Status) pr.NoStats = true diff --git a/metamorph/processor_test.go b/metamorph/processor_test.go index 81b28ccd4..9b44c1e6d 100644 --- a/metamorph/processor_test.go +++ b/metamorph/processor_test.go @@ -108,7 +108,6 @@ func TestLoadUnmined(t *testing.T) { getTransactionBlockErr error delErr error - expectedDeletions int expectedItemTxHashesFinal []*chainhash.Hash }{ { @@ -187,20 +186,6 @@ func TestLoadUnmined(t *testing.T) { expectedItemTxHashesFinal: []*chainhash.Hash{testdata.TX2Hash}, }, - { - name: "delete expired", - storedData: []*store.StoreData{ - { - StoredAt: storedAt.Add(-400 * time.Hour), - AnnouncedAt: storedAt.Add(1 * time.Second), - Hash: testdata.TX2Hash, - Status: metamorph_api.Status_SEEN_ON_NETWORK, - }, - }, - - expectedDeletions: 1, - expectedItemTxHashesFinal: []*chainhash.Hash{}, - }, { name: "delete expired - deletion fails", storedData: []*store.StoreData{ @@ -213,22 +198,6 @@ func TestLoadUnmined(t *testing.T) { }, delErr: errors.New("failed to delete hash"), - expectedDeletions: 1, - expectedItemTxHashesFinal: []*chainhash.Hash{testdata.TX2Hash}, - }, - { - name: "delete expired - centralised storage", - isCentralised: true, - storedData: []*store.StoreData{ - { - StoredAt: storedAt.Add(-400 * time.Hour), - AnnouncedAt: storedAt.Add(1 * time.Second), - Hash: testdata.TX2Hash, - Status: metamorph_api.Status_SEEN_ON_NETWORK, - }, - }, - - expectedDeletions: 0, expectedItemTxHashesFinal: []*chainhash.Hash{testdata.TX2Hash}, }, } @@ -287,9 +256,6 @@ func TestLoadUnmined(t *testing.T) { require.Equal(t, len(tc.expectedItemTxHashesFinal), len(hashes)) return nil }, - IsCentralisedFunc: func() bool { - return tc.isCentralised - }, RemoveCallbackerFunc: func(ctx context.Context, hash *chainhash.Hash) error { return nil }, @@ -317,7 +283,6 @@ func TestLoadUnmined(t *testing.T) { allItemHashes = append(allItemHashes, item.Hash) } - require.Equal(t, tc.expectedDeletions, len(mtmStore.DelCalls())) require.ElementsMatch(t, tc.expectedItemTxHashesFinal, allItemHashes) }) } diff --git a/metamorph/server.go b/metamorph/server.go index 18f87d930..8a7b7059e 100644 --- a/metamorph/server.go +++ b/metamorph/server.go @@ -27,8 +27,6 @@ import ( "github.com/pkg/errors" "github.com/spf13/viper" "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/reflection" "google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/timestamppb" @@ -40,6 +38,7 @@ func init() { const ( responseTimeout = 5 * time.Second + blocktxTimeout = 2 * time.Second ) type BitcoinNode interface { @@ -345,6 +344,35 @@ func (s *Server) processTransaction(ctx context.Context, waitForStatus metamorph } } +func (s *Server) registerTransaction(ctx context.Context, hash chainhash.Hash) (*blocktx_api.RegisterTransactionResponse, error) { + responseCh := make(chan *blocktx_api.RegisterTransactionResponse, 1) + errCh := make(chan error, 1) + blocktxCtx, cancel := context.WithTimeout(ctx, blocktxTimeout) + defer cancel() + + go func() { + rtr, err := s.btc.RegisterTransaction(blocktxCtx, &blocktx_api.TransactionAndSource{ + Hash: hash[:], + Source: s.source, + }) + if err != nil { + errCh <- err + return + } + + responseCh <- rtr + }() + + select { + case <-blocktxCtx.Done(): + return nil, errors.New("failed to register transaction due to timeout") + case err := <-errCh: + return nil, fmt.Errorf("failed to register transaction: %v", err) + case response := <-responseCh: + return response, nil + } +} + func (s *Server) putTransactionInit(ctx context.Context, req *metamorph_api.TransactionRequest, start int64) (int64, metamorph_api.Status, *chainhash.Hash, *metamorph_api.TransactionStatus, error) { initSpan, initCtx := opentracing.StartSpanFromContext(ctx, "Server:PutTransaction:init") defer initSpan.Finish() @@ -358,42 +386,11 @@ func (s *Server) putTransactionInit(ctx context.Context, req *metamorph_api.Tran initSpan.SetTag("txid", hash.String()) // Register the transaction in blocktx store - rtr, err := s.btc.RegisterTransaction(initCtx, &blocktx_api.TransactionAndSource{ - Hash: hash[:], - Source: s.source, - }) + rtr, err := s.registerTransaction(ctx, hash) if err != nil { return 0, 0, nil, nil, err } - if !s.store.IsCentralised() && rtr.GetSource() != s.source { - if isForwarded(ctx) { - // This is a forwarded request, so we should not forward it again - s.logger.Warn("Endless forwarding loop detected for", slog.String("hash", hash.String()), slog.String("address", s.source), slog.String("source", rtr.GetSource())) - return 0, 0, nil, nil, fmt.Errorf("endless forwarding loop detected") - } - - // This transaction was already registered by another metamorph, and we - // should forward the request to that metamorph - var ownerConn *grpc.ClientConn - if ownerConn, err = dialMetamorph(initCtx, rtr.GetSource()); err != nil { - return 0, 0, nil, nil, err - } - - defer ownerConn.Close() - - ownerMM := metamorph_api.NewMetaMorphAPIClient(ownerConn) - - var transactionStatus *metamorph_api.TransactionStatus - if transactionStatus, err = ownerMM.PutTransaction(createForwardedContext(initCtx), req); err != nil { - return 0, 0, nil, nil, err - } - - transactionStatus.MerklePath = rtr.GetMerklePath() - - return 0, 0, nil, transactionStatus, nil - } - if rtr.BlockHash != nil { // In case a transaction is submitted to network outside of ARC and mined and now // submitting the same transaction through arc endpoint we have problem. @@ -437,7 +434,6 @@ func (s *Server) putTransactionInit(ctx context.Context, req *metamorph_api.Tran return 0, 0, nil, &metamorph_api.TransactionStatus{ Status: metamorph_api.Status_REJECTED, Txid: hash.String(), - MerklePath: rtr.GetMerklePath(), RejectReason: err.Error(), }, nil } @@ -517,6 +513,39 @@ func (s *Server) GetTransaction(ctx context.Context, req *metamorph_api.Transact return txn, nil } +func (s *Server) getMerklePath(ctx context.Context, hash *chainhash.Hash, dataStatus metamorph_api.Status) (string, error) { + merklePathCh := make(chan string, 1) + errCh := make(chan error, 1) + blocktxCtx, cancel := context.WithTimeout(ctx, blocktxTimeout) + defer cancel() + + go func() { + mp, err := s.btc.GetTransactionMerklePath(blocktxCtx, &blocktx_api.Transaction{Hash: hash[:]}) + if err != nil { + if errors.Is(err, blocktx.ErrTransactionNotFoundForMerklePath) { + if dataStatus == metamorph_api.Status_MINED { + errCh <- fmt.Errorf("merkle path not found for mined transaction %s: %v", hash.String(), err) + return + } + } else { + errCh <- fmt.Errorf("failed to get Merkle path for transaction %s: %v", hash.String(), err) + return + } + } + + merklePathCh <- mp + }() + + select { + case <-blocktxCtx.Done(): + return "", errors.New("failed to get Merkle path due to timeout") + case err := <-errCh: + return "", fmt.Errorf("failed to get Merkle path: %v", err) + case merklePath := <-merklePathCh: + return merklePath, nil + } +} + func (s *Server) GetTransactionStatus(ctx context.Context, req *metamorph_api.TransactionStatusRequest) (*metamorph_api.TransactionStatus, error) { data, announcedAt, minedAt, storedAt, err := s.getTransactionData(ctx, req) if err != nil { @@ -532,16 +561,9 @@ func (s *Server) GetTransactionStatus(ctx context.Context, req *metamorph_api.Tr if err != nil { return nil, err } - - merklePath, err := s.btc.GetTransactionMerklePath(ctx, &blocktx_api.Transaction{Hash: hash[:]}) + merklePath, err := s.getMerklePath(ctx, hash, data.Status) if err != nil { - if errors.Is(err, blocktx.ErrTransactionNotFoundForMerklePath) { - if data.Status == metamorph_api.Status_MINED { - s.logger.Error("Merkle path not found for mined transaction", slog.String("hash", hash.String()), slog.String("err", err.Error())) - } - } else { - s.logger.Error("failed to get Merkle path for transaction", slog.String("hash", hash.String()), slog.String("err", err.Error())) - } + s.logger.Error("failed to get merkle path") } return &metamorph_api.TransactionStatus{ @@ -599,31 +621,3 @@ func (s *Server) SetUnlockedByName(ctx context.Context, req *metamorph_api.SetUn return result, err } - -func dialMetamorph(ctx context.Context, address string) (*grpc.ClientConn, error) { - opts := []grpc.DialOption{ - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithChainUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor), - grpc.WithChainStreamInterceptor(grpc_prometheus.StreamClientInterceptor), - } - - return grpc.DialContext(ctx, address, tracing.AddGRPCDialOptions(opts)...) -} - -func createForwardedContext(ctx context.Context) context.Context { - return metadata.NewOutgoingContext( - ctx, - metadata.Pairs("forwarded", "true"), - ) -} - -func isForwarded(ctx context.Context) bool { - if md, ok := metadata.FromIncomingContext(ctx); ok { - f := md.Get("forwarded") - if len(f) > 0 && f[0] == "true" { - return true - } - } - - return false -} diff --git a/metamorph/server_test.go b/metamorph/server_test.go index 8d44b5bfc..4d57d0729 100644 --- a/metamorph/server_test.go +++ b/metamorph/server_test.go @@ -268,6 +268,7 @@ func TestServer_GetTransactionStatus(t *testing.T) { getTxMerklePathErr error getErr error status metamorph_api.Status + merklePath string want *metamorph_api.TransactionStatus wantErr assert.ErrorAssertionFunc @@ -289,7 +290,8 @@ func TestServer_GetTransactionStatus(t *testing.T) { req: &metamorph_api.TransactionStatusRequest{ Txid: testdata.TX1, }, - status: metamorph_api.Status_SENT_TO_NETWORK, + status: metamorph_api.Status_SENT_TO_NETWORK, + merklePath: "00000", want: &metamorph_api.TransactionStatus{ StoredAt: timestamppb.New(testdata.Time), @@ -315,7 +317,7 @@ func TestServer_GetTransactionStatus(t *testing.T) { MinedAt: timestamppb.New(testdata.Time.Add(2 * time.Second)), Txid: testdata.TX1, Status: metamorph_api.Status_SENT_TO_NETWORK, - MerklePath: "00000", + MerklePath: "", }, wantErr: assert.NoError, }, @@ -333,7 +335,7 @@ func TestServer_GetTransactionStatus(t *testing.T) { MinedAt: timestamppb.New(testdata.Time.Add(2 * time.Second)), Txid: testdata.TX1, Status: metamorph_api.Status_MINED, - MerklePath: "00000", + MerklePath: "", }, wantErr: assert.NoError, }, @@ -342,7 +344,7 @@ func TestServer_GetTransactionStatus(t *testing.T) { t.Run(tt.name, func(t *testing.T) { client := &ClientIMock{ GetTransactionMerklePathFunc: func(ctx context.Context, transaction *blocktx_api.Transaction) (string, error) { - return "00000", tt.getTxMerklePathErr + return tt.merklePath, tt.getTxMerklePathErr }, } @@ -603,9 +605,6 @@ func TestPutTransactions(t *testing.T) { t.Run(tc.name, func(t *testing.T) { getCounter := 0 metamorphStore := &MetamorphStoreMock{ - IsCentralisedFunc: func() bool { - return false - }, GetFunc: func(ctx context.Context, key []byte) (*store.StoreData, error) { defer func() { getCounter++ }() diff --git a/metamorph/store/Interface.go b/metamorph/store/Interface.go index b8d63d554..902a6a344 100644 --- a/metamorph/store/Interface.go +++ b/metamorph/store/Interface.go @@ -208,7 +208,6 @@ type MetamorphStore interface { Set(ctx context.Context, key []byte, value *StoreData) error Del(ctx context.Context, key []byte) error - IsCentralised() bool SetUnlocked(ctx context.Context, hashes []*chainhash.Hash) error SetUnlockedByName(ctx context.Context, lockedBy string) (int, error) GetUnmined(_ context.Context, callback func(s *StoreData)) error diff --git a/metamorph/store/badger/badger.go b/metamorph/store/badger/badger.go index a06299823..e50e90534 100644 --- a/metamorph/store/badger/badger.go +++ b/metamorph/store/badger/badger.go @@ -78,10 +78,6 @@ func New(dir string) (*Badger, error) { return badgerStore, nil } -func (ddb *Badger) IsCentralised() bool { - return false -} - func (s *Badger) SetUnlocked(ctx context.Context, hashes []*chainhash.Hash) error { return nil } diff --git a/metamorph/store/dynamodb/dynamodb.go b/metamorph/store/dynamodb/dynamodb.go index c828d7903..14c99cc45 100644 --- a/metamorph/store/dynamodb/dynamodb.go +++ b/metamorph/store/dynamodb/dynamodb.go @@ -210,10 +210,6 @@ func (ddb *DynamoDB) CreateBlocksTable(ctx context.Context) error { return nil } -func (ddb *DynamoDB) IsCentralised() bool { - return true -} - func (ddb *DynamoDB) Get(ctx context.Context, key []byte) (*store.StoreData, error) { // config log and tracing startNanos := ddb.now().UnixNano() diff --git a/metamorph/store/postgresql/postgres.go b/metamorph/store/postgresql/postgres.go index e779a0b4d..6678d27fc 100644 --- a/metamorph/store/postgresql/postgres.go +++ b/metamorph/store/postgresql/postgres.go @@ -54,10 +54,6 @@ func New(dbInfo string, hostname string, idleConns int, maxOpenConns int, opts . return p, nil } -func (p *PostgreSQL) IsCentralised() bool { - return true -} - func (p *PostgreSQL) SetUnlocked(ctx context.Context, hashes []*chainhash.Hash) error { startNanos := p.now().UnixNano() defer func() { diff --git a/metamorph/store/postgresql/postgres_test.go b/metamorph/store/postgresql/postgres_test.go index 281332511..8d5097992 100644 --- a/metamorph/store/postgresql/postgres_test.go +++ b/metamorph/store/postgresql/postgres_test.go @@ -290,8 +290,4 @@ func TestPostgresDB(t *testing.T) { require.Equal(t, &now, processedAt) }) - - t.Run("is centralised", func(t *testing.T) { - require.True(t, postgresDB.IsCentralised()) - }) } diff --git a/metamorph/store/sqlite/sqlite.go b/metamorph/store/sqlite/sqlite.go index 67a555f2f..cee80c93b 100644 --- a/metamorph/store/sqlite/sqlite.go +++ b/metamorph/store/sqlite/sqlite.go @@ -121,10 +121,6 @@ type SqLite struct { now func() time.Time } -func (s *SqLite) IsCentralised() bool { - return false -} - func (s *SqLite) RemoveCallbacker(ctx context.Context, hash *chainhash.Hash) error { startNanos := s.now().UnixNano() defer func() {