diff --git a/internal/blocktx/blocktx_api/blocktx_api.pb.go b/internal/blocktx/blocktx_api/blocktx_api.pb.go index 4bfee0bcd..788d74816 100644 --- a/internal/blocktx/blocktx_api/blocktx_api.pb.go +++ b/internal/blocktx/blocktx_api/blocktx_api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.3 +// protoc v5.28.0 // source: internal/blocktx/blocktx_api/blocktx_api.proto package blocktx_api @@ -562,61 +562,6 @@ func (x *RowsAffectedResponse) GetRows() int64 { return 0 } -type TransactionAndSource struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` - Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` -} - -func (x *TransactionAndSource) Reset() { - *x = TransactionAndSource{} - if protoimpl.UnsafeEnabled { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *TransactionAndSource) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*TransactionAndSource) ProtoMessage() {} - -func (x *TransactionAndSource) ProtoReflect() protoreflect.Message { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use TransactionAndSource.ProtoReflect.Descriptor instead. -func (*TransactionAndSource) Descriptor() ([]byte, []int) { - return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{8} -} - -func (x *TransactionAndSource) GetHash() []byte { - if x != nil { - return x.Hash - } - return nil -} - -func (x *TransactionAndSource) GetSource() string { - if x != nil { - return x.Source - } - return "" -} - type DelUnfinishedBlockProcessingRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -628,7 +573,7 @@ type DelUnfinishedBlockProcessingRequest struct { func (x *DelUnfinishedBlockProcessingRequest) Reset() { *x = DelUnfinishedBlockProcessingRequest{} if protoimpl.UnsafeEnabled { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -641,7 +586,7 @@ func (x *DelUnfinishedBlockProcessingRequest) String() string { func (*DelUnfinishedBlockProcessingRequest) ProtoMessage() {} func (x *DelUnfinishedBlockProcessingRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -654,7 +599,7 @@ func (x *DelUnfinishedBlockProcessingRequest) ProtoReflect() protoreflect.Messag // Deprecated: Use DelUnfinishedBlockProcessingRequest.ProtoReflect.Descriptor instead. func (*DelUnfinishedBlockProcessingRequest) Descriptor() ([]byte, []int) { - return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{9} + return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{8} } func (x *DelUnfinishedBlockProcessingRequest) GetProcessedBy() string { @@ -676,7 +621,7 @@ type MerkleRootVerificationRequest struct { func (x *MerkleRootVerificationRequest) Reset() { *x = MerkleRootVerificationRequest{} if protoimpl.UnsafeEnabled { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -689,7 +634,7 @@ func (x *MerkleRootVerificationRequest) String() string { func (*MerkleRootVerificationRequest) ProtoMessage() {} func (x *MerkleRootVerificationRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -702,7 +647,7 @@ func (x *MerkleRootVerificationRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use MerkleRootVerificationRequest.ProtoReflect.Descriptor instead. func (*MerkleRootVerificationRequest) Descriptor() ([]byte, []int) { - return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{10} + return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{9} } func (x *MerkleRootVerificationRequest) GetMerkleRoot() string { @@ -730,7 +675,7 @@ type MerkleRootsVerificationRequest struct { func (x *MerkleRootsVerificationRequest) Reset() { *x = MerkleRootsVerificationRequest{} if protoimpl.UnsafeEnabled { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -743,7 +688,7 @@ func (x *MerkleRootsVerificationRequest) String() string { func (*MerkleRootsVerificationRequest) ProtoMessage() {} func (x *MerkleRootsVerificationRequest) ProtoReflect() protoreflect.Message { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -756,7 +701,7 @@ func (x *MerkleRootsVerificationRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use MerkleRootsVerificationRequest.ProtoReflect.Descriptor instead. func (*MerkleRootsVerificationRequest) Descriptor() ([]byte, []int) { - return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{11} + return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{10} } func (x *MerkleRootsVerificationRequest) GetMerkleRoots() []*MerkleRootVerificationRequest { @@ -777,7 +722,7 @@ type MerkleRootVerificationResponse struct { func (x *MerkleRootVerificationResponse) Reset() { *x = MerkleRootVerificationResponse{} if protoimpl.UnsafeEnabled { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -790,7 +735,7 @@ func (x *MerkleRootVerificationResponse) String() string { func (*MerkleRootVerificationResponse) ProtoMessage() {} func (x *MerkleRootVerificationResponse) ProtoReflect() protoreflect.Message { - mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12] + mi := &file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -803,7 +748,7 @@ func (x *MerkleRootVerificationResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use MerkleRootVerificationResponse.ProtoReflect.Descriptor instead. func (*MerkleRootVerificationResponse) Descriptor() ([]byte, []int) { - return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{12} + return file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP(), []int{11} } func (x *MerkleRootVerificationResponse) GetUnverifiedBlockHeights() []uint64 { @@ -878,75 +823,71 @@ var file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDesc = []byte{ 0x61, 0x79, 0x73, 0x22, 0x2a, 0x0a, 0x14, 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x72, 0x6f, 0x77, 0x73, 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, 0x48, 0x0a, 0x23, 0x44, 0x65, 0x6c, 0x55, 0x6e, 0x66, 0x69, 0x6e, 0x69, - 0x73, 0x68, 0x65, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, - 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, - 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x5f, 0x62, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0b, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x42, 0x79, 0x22, 0x63, 0x0a, - 0x1d, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, - 0x0a, 0x0b, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, - 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, - 0x68, 0x74, 0x22, 0x6f, 0x0a, 0x1e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, - 0x73, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x4d, 0x0a, 0x0c, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x72, - 0x6f, 0x6f, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, - 0x6f, 0x6f, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0b, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, - 0x6f, 0x74, 0x73, 0x22, 0x5a, 0x0a, 0x1e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, - 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x18, 0x75, 0x6e, 0x76, 0x65, 0x72, 0x69, 0x66, - 0x69, 0x65, 0x64, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x04, 0x52, 0x16, 0x75, 0x6e, 0x76, 0x65, 0x72, 0x69, 0x66, - 0x69, 0x65, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x2a, - 0x3b, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, - 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4c, 0x4f, 0x4e, 0x47, 0x45, 0x53, - 0x54, 0x10, 0x0a, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x54, 0x41, 0x4c, 0x45, 0x10, 0x14, 0x12, 0x0c, - 0x0a, 0x08, 0x4f, 0x52, 0x50, 0x48, 0x41, 0x4e, 0x45, 0x44, 0x10, 0x1e, 0x32, 0xad, 0x04, 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, 0x50, 0x0a, 0x11, - 0x43, 0x6c, 0x65, 0x61, 0x72, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, - 0x43, 0x6c, 0x65, 0x61, 0x72, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, - 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, - 0x0a, 0x0b, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x12, 0x16, 0x2e, + 0x48, 0x0a, 0x23, 0x44, 0x65, 0x6c, 0x55, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, + 0x73, 0x65, 0x64, 0x5f, 0x62, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, + 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x64, 0x42, 0x79, 0x22, 0x63, 0x0a, 0x1d, 0x4d, 0x65, 0x72, + 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x65, + 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x6f, + 0x0a, 0x1e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x73, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x4d, 0x0a, 0x0c, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, + 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x56, + 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x52, 0x0b, 0x6d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x73, 0x22, + 0x5a, 0x0a, 0x1e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x38, 0x0a, 0x18, 0x75, 0x6e, 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5f, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x04, 0x52, 0x16, 0x75, 0x6e, 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x65, 0x64, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x2a, 0x3b, 0x0a, 0x06, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, + 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4c, 0x4f, 0x4e, 0x47, 0x45, 0x53, 0x54, 0x10, 0x0a, 0x12, + 0x09, 0x0a, 0x05, 0x53, 0x54, 0x41, 0x4c, 0x45, 0x10, 0x14, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x52, + 0x50, 0x48, 0x41, 0x4e, 0x45, 0x44, 0x10, 0x1e, 0x32, 0xad, 0x04, 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, 0x50, 0x0a, 0x11, 0x43, 0x6c, 0x65, 0x61, + 0x72, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x58, 0x0a, 0x19, 0x43, 0x6c, - 0x65, 0x61, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x4d, 0x61, 0x70, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, - 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x44, 0x61, 0x74, 0x61, 0x1a, - 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x6f, - 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x00, 0x12, 0x75, 0x0a, 0x1c, 0x44, 0x65, 0x6c, 0x55, 0x6e, 0x66, 0x69, 0x6e, - 0x69, 0x73, 0x68, 0x65, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, - 0x73, 0x69, 0x6e, 0x67, 0x12, 0x30, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, - 0x70, 0x69, 0x2e, 0x44, 0x65, 0x6c, 0x55, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, - 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, - 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, - 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6f, 0x0a, 0x11, 0x56, - 0x65, 0x72, 0x69, 0x66, 0x79, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x73, - 0x12, 0x2b, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, - 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x73, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, - 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 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, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0b, 0x43, 0x6c, + 0x65, 0x61, 0x72, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x44, 0x61, 0x74, + 0x61, 0x1a, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, + 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x58, 0x0a, 0x19, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x4d, 0x61, 0x70, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, + 0x69, 0x2e, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x21, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, + 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x75, 0x0a, 0x1c, 0x44, 0x65, 0x6c, 0x55, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, + 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, + 0x12, 0x30, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x44, + 0x65, 0x6c, 0x55, 0x6e, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, + 0x2e, 0x52, 0x6f, 0x77, 0x73, 0x41, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6f, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, + 0x79, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x73, 0x12, 0x2b, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, + 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x73, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x74, 0x78, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, + 0x6f, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 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 ( @@ -962,7 +903,7 @@ func file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDescGZIP() []byte { } var file_internal_blocktx_blocktx_api_blocktx_api_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_internal_blocktx_blocktx_api_blocktx_api_proto_goTypes = []any{ (Status)(0), // 0: blocktx_api.Status (*HealthResponse)(nil), // 1: blocktx_api.HealthResponse @@ -973,32 +914,31 @@ var file_internal_blocktx_blocktx_api_blocktx_api_proto_goTypes = []any{ (*Transaction)(nil), // 6: blocktx_api.Transaction (*ClearData)(nil), // 7: blocktx_api.ClearData (*RowsAffectedResponse)(nil), // 8: blocktx_api.RowsAffectedResponse - (*TransactionAndSource)(nil), // 9: blocktx_api.TransactionAndSource - (*DelUnfinishedBlockProcessingRequest)(nil), // 10: blocktx_api.DelUnfinishedBlockProcessingRequest - (*MerkleRootVerificationRequest)(nil), // 11: blocktx_api.MerkleRootVerificationRequest - (*MerkleRootsVerificationRequest)(nil), // 12: blocktx_api.MerkleRootsVerificationRequest - (*MerkleRootVerificationResponse)(nil), // 13: blocktx_api.MerkleRootVerificationResponse - (*timestamppb.Timestamp)(nil), // 14: google.protobuf.Timestamp - (*emptypb.Empty)(nil), // 15: google.protobuf.Empty + (*DelUnfinishedBlockProcessingRequest)(nil), // 9: blocktx_api.DelUnfinishedBlockProcessingRequest + (*MerkleRootVerificationRequest)(nil), // 10: blocktx_api.MerkleRootVerificationRequest + (*MerkleRootsVerificationRequest)(nil), // 11: blocktx_api.MerkleRootsVerificationRequest + (*MerkleRootVerificationResponse)(nil), // 12: blocktx_api.MerkleRootVerificationResponse + (*timestamppb.Timestamp)(nil), // 13: google.protobuf.Timestamp + (*emptypb.Empty)(nil), // 14: google.protobuf.Empty } var file_internal_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 0, // 1: blocktx_api.Block.status:type_name -> blocktx_api.Status 6, // 2: blocktx_api.Transactions.transactions:type_name -> blocktx_api.Transaction 4, // 3: blocktx_api.TransactionBlocks.transaction_blocks:type_name -> blocktx_api.TransactionBlock - 11, // 4: blocktx_api.MerkleRootsVerificationRequest.merkle_roots:type_name -> blocktx_api.MerkleRootVerificationRequest - 15, // 5: blocktx_api.BlockTxAPI.Health:input_type -> google.protobuf.Empty + 10, // 4: blocktx_api.MerkleRootsVerificationRequest.merkle_roots:type_name -> blocktx_api.MerkleRootVerificationRequest + 14, // 5: blocktx_api.BlockTxAPI.Health:input_type -> google.protobuf.Empty 7, // 6: blocktx_api.BlockTxAPI.ClearTransactions:input_type -> blocktx_api.ClearData 7, // 7: blocktx_api.BlockTxAPI.ClearBlocks:input_type -> blocktx_api.ClearData 7, // 8: blocktx_api.BlockTxAPI.ClearBlockTransactionsMap:input_type -> blocktx_api.ClearData - 10, // 9: blocktx_api.BlockTxAPI.DelUnfinishedBlockProcessing:input_type -> blocktx_api.DelUnfinishedBlockProcessingRequest - 12, // 10: blocktx_api.BlockTxAPI.VerifyMerkleRoots:input_type -> blocktx_api.MerkleRootsVerificationRequest + 9, // 9: blocktx_api.BlockTxAPI.DelUnfinishedBlockProcessing:input_type -> blocktx_api.DelUnfinishedBlockProcessingRequest + 11, // 10: blocktx_api.BlockTxAPI.VerifyMerkleRoots:input_type -> blocktx_api.MerkleRootsVerificationRequest 1, // 11: blocktx_api.BlockTxAPI.Health:output_type -> blocktx_api.HealthResponse 8, // 12: blocktx_api.BlockTxAPI.ClearTransactions:output_type -> blocktx_api.RowsAffectedResponse 8, // 13: blocktx_api.BlockTxAPI.ClearBlocks:output_type -> blocktx_api.RowsAffectedResponse 8, // 14: blocktx_api.BlockTxAPI.ClearBlockTransactionsMap:output_type -> blocktx_api.RowsAffectedResponse 8, // 15: blocktx_api.BlockTxAPI.DelUnfinishedBlockProcessing:output_type -> blocktx_api.RowsAffectedResponse - 13, // 16: blocktx_api.BlockTxAPI.VerifyMerkleRoots:output_type -> blocktx_api.MerkleRootVerificationResponse + 12, // 16: blocktx_api.BlockTxAPI.VerifyMerkleRoots:output_type -> blocktx_api.MerkleRootVerificationResponse 11, // [11:17] is the sub-list for method output_type 5, // [5:11] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name @@ -1109,18 +1049,6 @@ func file_internal_blocktx_blocktx_api_blocktx_api_proto_init() { } } file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[8].Exporter = func(v any, i int) any { - switch v := v.(*TransactionAndSource); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*DelUnfinishedBlockProcessingRequest); i { case 0: return &v.state @@ -1132,7 +1060,7 @@ func file_internal_blocktx_blocktx_api_blocktx_api_proto_init() { return nil } } - file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10].Exporter = func(v any, i int) any { + file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*MerkleRootVerificationRequest); i { case 0: return &v.state @@ -1144,7 +1072,7 @@ func file_internal_blocktx_blocktx_api_blocktx_api_proto_init() { return nil } } - file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11].Exporter = func(v any, i int) any { + file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[10].Exporter = func(v any, i int) any { switch v := v.(*MerkleRootsVerificationRequest); i { case 0: return &v.state @@ -1156,7 +1084,7 @@ func file_internal_blocktx_blocktx_api_blocktx_api_proto_init() { return nil } } - file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[12].Exporter = func(v any, i int) any { + file_internal_blocktx_blocktx_api_blocktx_api_proto_msgTypes[11].Exporter = func(v any, i int) any { switch v := v.(*MerkleRootVerificationResponse); i { case 0: return &v.state @@ -1175,7 +1103,7 @@ func file_internal_blocktx_blocktx_api_blocktx_api_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_blocktx_blocktx_api_blocktx_api_proto_rawDesc, NumEnums: 1, - NumMessages: 13, + NumMessages: 12, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/blocktx/blocktx_api/blocktx_api.proto b/internal/blocktx/blocktx_api/blocktx_api.proto index 4e640a294..a8ccdce96 100644 --- a/internal/blocktx/blocktx_api/blocktx_api.proto +++ b/internal/blocktx/blocktx_api/blocktx_api.proto @@ -87,18 +87,10 @@ message RowsAffectedResponse { int64 rows = 1; } - -message TransactionAndSource { - bytes hash = 1; - string source = 2; -} - - message DelUnfinishedBlockProcessingRequest { string processed_by = 1; } - message MerkleRootVerificationRequest { string merkle_root = 1; uint64 block_height = 2; diff --git a/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go b/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go index dbc8396c7..bb0571f0c 100644 --- a/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go +++ b/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.27.3 +// - protoc v5.28.0 // source: internal/blocktx/blocktx_api/blocktx_api.proto package blocktx_api diff --git a/internal/blocktx/processor.go b/internal/blocktx/processor.go index 1de2bf2b7..fa2101d96 100644 --- a/internal/blocktx/processor.go +++ b/internal/blocktx/processor.go @@ -224,7 +224,7 @@ func (p *Processor) StartFillGaps(peers []p2p.PeerI) { func (p *Processor) StartProcessRegisterTxs() { p.waitGroup.Add(1) - txHashes := make([]*blocktx_api.TransactionAndSource, 0, p.registerTxsBatchSize) + txHashes := make([][]byte, 0, p.registerTxsBatchSize) ticker := time.NewTicker(p.registerTxsInterval) go func() { @@ -234,16 +234,14 @@ func (p *Processor) StartProcessRegisterTxs() { case <-p.ctx.Done(): return case txHash := <-p.registerTxsChan: - txHashes = append(txHashes, &blocktx_api.TransactionAndSource{ - Hash: txHash, - }) + txHashes = append(txHashes, txHash) if len(txHashes) < p.registerTxsBatchSize { continue } p.registerTransactions(txHashes[:]) - txHashes = make([]*blocktx_api.TransactionAndSource, 0, p.registerTxsBatchSize) + txHashes = txHashes[:0] ticker.Reset(p.registerTxsInterval) case <-ticker.C: @@ -252,7 +250,7 @@ func (p *Processor) StartProcessRegisterTxs() { } p.registerTransactions(txHashes[:]) - txHashes = make([]*blocktx_api.TransactionAndSource, 0, p.registerTxsBatchSize) + txHashes = txHashes[:0] ticker.Reset(p.registerTxsInterval) } } @@ -337,7 +335,7 @@ func (p *Processor) publishMinedTxs(txHashes []*chainhash.Hash) error { return nil } -func (p *Processor) registerTransactions(txHashes []*blocktx_api.TransactionAndSource) { +func (p *Processor) registerTransactions(txHashes [][]byte) { updatedTxs, err := p.store.RegisterTransactions(p.ctx, txHashes) if err != nil { p.logger.Error("failed to register transactions", slog.String("err", err.Error())) @@ -410,6 +408,12 @@ func (p *Processor) processBlock(msg *p2p.BlockMessage) error { previousBlockHash := msg.Header.PrevBlock merkleRoot := msg.Header.MerkleRoot + // don't process block that was already processed + existingBlock, _ := p.store.GetBlock(ctx, &blockHash) + if existingBlock != nil { + return nil + } + prevBlock, err := p.getPrevBlock(ctx, &previousBlockHash) if err != nil { p.logger.Error("unable to get previous block from db", slog.String("hash", blockHash.String()), slog.Uint64("height", msg.Height), slog.String("prevHash", previousBlockHash.String()), slog.String("err", err.Error())) @@ -444,6 +448,9 @@ func (p *Processor) processBlock(msg *p2p.BlockMessage) error { return err } + // find competing chains back to the common ancestor + // get all registered transactions + // prepare msg with competing blocks incomingBlock.Status = blocktx_api.Status_STALE if hasGreatestChainwork { @@ -479,16 +486,7 @@ func (p *Processor) processBlock(msg *p2p.BlockMessage) error { return err } - block := &p2p.Block{ - Hash: &blockHash, - MerkleRoot: &merkleRoot, - PreviousHash: &previousBlockHash, - Height: msg.Height, - Size: msg.Size, - TxCount: uint64(len(msg.TransactionHashes)), - } - - if err = p.markBlockAsProcessed(ctx, block); err != nil { + if err = p.store.MarkBlockAsDone(ctx, &blockHash, msg.Size, uint64(len(msg.TransactionHashes))); err != nil { p.logger.Error("unable to mark block as processed", slog.String("hash", blockHash.String()), slog.String("err", err.Error())) return err } @@ -601,8 +599,7 @@ func (p *Processor) markTransactionsAsMined(ctx context.Context, blockId uint64, ctx, span = tracer.Start(ctx, "markTransactionsAsMined") defer span.End() } - txs := make([]*blocktx_api.TransactionAndSource, 0, p.transactionStorageBatchSize) - merklePaths := make([]string, 0, p.transactionStorageBatchSize) + txs := make([]store.TxWithMerklePath, 0, p.transactionStorageBatchSize) leaves := merkleTree[:(len(merkleTree)+1)/2] var totalSize int @@ -627,11 +624,6 @@ func (p *Processor) markTransactionsAsMined(ctx context.Context, blockId uint64, break } - // Otherwise they're txids, which should have merkle paths calculated. - txs = append(txs, &blocktx_api.TransactionAndSource{ - Hash: hash[:], - }) - bump, err := bc.NewBUMPFromMerkleTreeAndIndex(blockHeight, merkleTree, uint64(txIndex)) if err != nil { return fmt.Errorf("failed to create new bump for tx hash %s from merkle tree and index at block height %d: %v", hash.String(), blockHeight, err) @@ -642,19 +634,22 @@ func (p *Processor) markTransactionsAsMined(ctx context.Context, blockId uint64, return fmt.Errorf("failed to get string from bump for tx hash %s at block height %d: %v", hash.String(), blockHeight, err) } - merklePaths = append(merklePaths, bumpHex) + txs = append(txs, store.TxWithMerklePath{ + Hash: hash[:], + MerklePath: bumpHex, + }) + if (txIndex+1)%p.transactionStorageBatchSize == 0 { - updateResp, err := p.store.UpsertBlockTransactions(ctx, blockId, txs, merklePaths) + updateResp, err := p.store.UpsertBlockTransactions(ctx, blockId, txs) if err != nil { return fmt.Errorf("failed to insert block transactions at block height %d: %v", blockHeight, err) } // free up memory - txs = make([]*blocktx_api.TransactionAndSource, 0, p.transactionStorageBatchSize) - merklePaths = make([]string, 0, p.transactionStorageBatchSize) + txs = txs[:0] for _, updResp := range updateResp { txBlock := &blocktx_api.TransactionBlock{ - TransactionHash: updResp.TxHash[:], + TransactionHash: updResp.Hash[:], BlockHash: blockhash[:], BlockHeight: blockHeight, MerklePath: updResp.MerklePath, @@ -678,14 +673,14 @@ func (p *Processor) markTransactionsAsMined(ctx context.Context, blockId uint64, } // update all remaining transactions - updateResp, err := p.store.UpsertBlockTransactions(ctx, blockId, txs, merklePaths) + updateResp, err := p.store.UpsertBlockTransactions(ctx, blockId, txs) if err != nil { return fmt.Errorf("failed to insert block transactions at block height %d: %v", blockHeight, err) } for _, updResp := range updateResp { txBlock := &blocktx_api.TransactionBlock{ - TransactionHash: updResp.TxHash[:], + TransactionHash: updResp.Hash[:], BlockHash: blockhash[:], BlockHeight: blockHeight, MerklePath: updResp.MerklePath, @@ -699,15 +694,6 @@ func (p *Processor) markTransactionsAsMined(ctx context.Context, blockId uint64, return nil } -func (p *Processor) markBlockAsProcessed(ctx context.Context, block *p2p.Block) error { - err := p.store.MarkBlockAsDone(ctx, block.Hash, block.Size, block.TxCount) - if err != nil { - return err - } - - return nil -} - func (p *Processor) Shutdown() { p.cancelAll() p.waitGroup.Wait() diff --git a/internal/blocktx/processor_test.go b/internal/blocktx/processor_test.go index 5d2fa2e31..1dcecef41 100644 --- a/internal/blocktx/processor_test.go +++ b/internal/blocktx/processor_test.go @@ -36,16 +36,25 @@ func TestHandleBlock(t *testing.T) { merkleRootHash1585018, _ := chainhash.NewHashFromStr("9c1fe95a7ac4502e281f4f2eaa2902e12b0f486cf610977c73afb3cd060bebde") tt := []struct { - name string - prevBlockHash chainhash.Hash - merkleRoot chainhash.Hash - height uint64 - txHashes []string - size uint64 - nonce uint32 - setBlockProcessingErr error - bhsProcInProg []*chainhash.Hash + name string + prevBlockHash chainhash.Hash + merkleRoot chainhash.Hash + height uint64 + txHashes []string + size uint64 + nonce uint32 + blockAlreadyExists bool }{ + { + name: "block height 1573650", + txHashes: []string{}, // expect this block to not be processed + prevBlockHash: *prevBlockHash1573650, + merkleRoot: *merkleRootHash1573650, + height: 1573650, + nonce: 3694498168, + size: 216, + blockAlreadyExists: true, + }, { name: "block height 1573650", txHashes: []string{"3d64b2bb6bd4e85aacb6d1965a2407fa21846c08dd9a8616866ad2f5c80fda7f"}, @@ -136,6 +145,9 @@ func TestHandleBlock(t *testing.T) { batchSize := 4 storeMock := &storeMocks.BlocktxStoreMock{ GetBlockFunc: func(ctx context.Context, hash *chainhash.Hash) (*blocktx_api.Block, error) { + if tc.blockAlreadyExists { + return &blocktx_api.Block{}, nil + } return nil, store.ErrBlockNotFound }, GetBlockByHeightFunc: func(ctx context.Context, height uint64, status blocktx_api.Status) (*blocktx_api.Block, error) { @@ -170,41 +182,35 @@ func TestHandleBlock(t *testing.T) { processor.StartBlockProcessing() - var expectedInsertedTransactions []*blocktx_api.TransactionAndSource + var expectedInsertedTransactions [][]byte transactionHashes := make([]*chainhash.Hash, len(tc.txHashes)) for i, hash := range tc.txHashes { txHash, err := chainhash.NewHashFromStr(hash) require.NoError(t, err) transactionHashes[i] = txHash - expectedInsertedTransactions = append(expectedInsertedTransactions, &blocktx_api.TransactionAndSource{Hash: txHash[:]}) + expectedInsertedTransactions = append(expectedInsertedTransactions, txHash[:]) } - var insertedBlockTransactions []*blocktx_api.TransactionAndSource + var insertedBlockTransactions [][]byte - storeMock.UpsertBlockTransactionsFunc = func(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) ([]store.UpsertBlockTransactionsResult, error) { - require.True(t, len(merklePaths) <= batchSize) - require.True(t, len(transactions) <= batchSize) + storeMock.UpsertBlockTransactionsFunc = func(ctx context.Context, blockId uint64, txsWithMerklePaths []store.TxWithMerklePath) ([]store.TxWithMerklePath, error) { + require.True(t, len(txsWithMerklePaths) <= batchSize) - for i, path := range merklePaths { - bump, err := bc.NewBUMPFromStr(path) + for _, tx := range txsWithMerklePaths { + bump, err := bc.NewBUMPFromStr(tx.MerklePath) require.NoError(t, err) - tx, err := chainhash.NewHash(transactions[i].GetHash()) + tx, err := chainhash.NewHash(tx.Hash) require.NoError(t, err) root, err := bump.CalculateRootGivenTxid(tx.String()) require.NoError(t, err) require.Equal(t, root, tc.merkleRoot.String()) - } - - insertedBlockTransactions = append(insertedBlockTransactions, transactions...) - result := make([]store.UpsertBlockTransactionsResult, len(transactions)) - for i, tx := range transactions { - result[i] = store.UpsertBlockTransactionsResult{TxHash: tx.Hash} + insertedBlockTransactions = append(insertedBlockTransactions, tx[:]) } - return result, nil + return txsWithMerklePaths, nil } peer := &mocks.PeerMock{ @@ -301,8 +307,15 @@ func TestHandleBlockReorg(t *testing.T) { var mtx sync.Mutex var insertedBlock *blocktx_api.Block + shouldReturnNoBlock := true + storeMock := &storeMocks.BlocktxStoreMock{ GetBlockFunc: func(ctx context.Context, hash *chainhash.Hash) (*blocktx_api.Block, error) { + if shouldReturnNoBlock { + shouldReturnNoBlock = false + return nil, nil + } + return &blocktx_api.Block{ Status: tc.prevBlockStatus, }, nil @@ -348,8 +361,8 @@ func TestHandleBlockReorg(t *testing.T) { MarkBlockAsDoneFunc: func(ctx context.Context, hash *chainhash.Hash, size uint64, txCount uint64) error { return nil }, - UpsertBlockTransactionsFunc: func(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) ([]store.UpsertBlockTransactionsResult, error) { - return []store.UpsertBlockTransactionsResult{}, nil + UpsertBlockTransactionsFunc: func(ctx context.Context, blockId uint64, txsWithMerklePaths []store.TxWithMerklePath) ([]store.TxWithMerklePath, error) { + return []store.TxWithMerklePath{}, nil }, } @@ -510,7 +523,7 @@ func TestStartProcessRegisterTxs(t *testing.T) { t.Run(tc.name, func(t *testing.T) { registerErrTest := tc.registerErr storeMock := &storeMocks.BlocktxStoreMock{ - RegisterTransactionsFunc: func(ctx context.Context, transaction []*blocktx_api.TransactionAndSource) ([]*chainhash.Hash, error) { + RegisterTransactionsFunc: func(ctx context.Context, transaction [][]byte) ([]*chainhash.Hash, error) { return nil, registerErrTest }, } diff --git a/internal/blocktx/store/mocks/blocktx_store_mock.go b/internal/blocktx/store/mocks/blocktx_store_mock.go index e4ac26b9c..1af179145 100644 --- a/internal/blocktx/store/mocks/blocktx_store_mock.go +++ b/internal/blocktx/store/mocks/blocktx_store_mock.go @@ -63,7 +63,7 @@ var _ store.BlocktxStore = &BlocktxStoreMock{} // PingFunc: func(ctx context.Context) error { // panic("mock out the Ping method") // }, -// RegisterTransactionsFunc: func(ctx context.Context, transaction []*blocktx_api.TransactionAndSource) ([]*chainhash.Hash, error) { +// RegisterTransactionsFunc: func(ctx context.Context, txHashes [][]byte) ([]*chainhash.Hash, error) { // panic("mock out the RegisterTransactions method") // }, // SetBlockProcessingFunc: func(ctx context.Context, hash *chainhash.Hash, processedBy string) (string, error) { @@ -72,7 +72,7 @@ var _ store.BlocktxStore = &BlocktxStoreMock{} // UpdateBlocksStatusesFunc: func(ctx context.Context, blockStatusUpdates []store.BlockStatusUpdate) error { // panic("mock out the UpdateBlocksStatuses method") // }, -// UpsertBlockTransactionsFunc: func(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) ([]store.UpsertBlockTransactionsResult, error) { +// UpsertBlockTransactionsFunc: func(ctx context.Context, blockId uint64, txsWithMerklePaths []store.TxWithMerklePath) ([]store.TxWithMerklePath, error) { // panic("mock out the UpsertBlockTransactions method") // }, // VerifyMerkleRootsFunc: func(ctx context.Context, merkleRoots []*blocktx_api.MerkleRootVerificationRequest, maxAllowedBlockHeightMismatch int) (*blocktx_api.MerkleRootVerificationResponse, error) { @@ -128,7 +128,7 @@ type BlocktxStoreMock struct { PingFunc func(ctx context.Context) error // RegisterTransactionsFunc mocks the RegisterTransactions method. - RegisterTransactionsFunc func(ctx context.Context, transaction []*blocktx_api.TransactionAndSource) ([]*chainhash.Hash, error) + RegisterTransactionsFunc func(ctx context.Context, txHashes [][]byte) ([]*chainhash.Hash, error) // SetBlockProcessingFunc mocks the SetBlockProcessing method. SetBlockProcessingFunc func(ctx context.Context, hash *chainhash.Hash, processedBy string) (string, error) @@ -137,7 +137,7 @@ type BlocktxStoreMock struct { UpdateBlocksStatusesFunc func(ctx context.Context, blockStatusUpdates []store.BlockStatusUpdate) error // UpsertBlockTransactionsFunc mocks the UpsertBlockTransactions method. - UpsertBlockTransactionsFunc func(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) ([]store.UpsertBlockTransactionsResult, error) + UpsertBlockTransactionsFunc func(ctx context.Context, blockId uint64, txsWithMerklePaths []store.TxWithMerklePath) ([]store.TxWithMerklePath, error) // VerifyMerkleRootsFunc mocks the VerifyMerkleRoots method. VerifyMerkleRootsFunc func(ctx context.Context, merkleRoots []*blocktx_api.MerkleRootVerificationRequest, maxAllowedBlockHeightMismatch int) (*blocktx_api.MerkleRootVerificationResponse, error) @@ -248,8 +248,8 @@ type BlocktxStoreMock struct { RegisterTransactions []struct { // Ctx is the ctx argument value. Ctx context.Context - // Transaction is the transaction argument value. - Transaction []*blocktx_api.TransactionAndSource + // TxHashes is the txHashes argument value. + TxHashes [][]byte } // SetBlockProcessing holds details about calls to the SetBlockProcessing method. SetBlockProcessing []struct { @@ -273,10 +273,8 @@ type BlocktxStoreMock struct { Ctx context.Context // BlockId is the blockId argument value. BlockId uint64 - // Transactions is the transactions argument value. - Transactions []*blocktx_api.TransactionAndSource - // MerklePaths is the merklePaths argument value. - MerklePaths []string + // TxsWithMerklePaths is the txsWithMerklePaths argument value. + TxsWithMerklePaths []store.TxWithMerklePath } // VerifyMerkleRoots holds details about calls to the VerifyMerkleRoots method. VerifyMerkleRoots []struct { @@ -817,21 +815,21 @@ func (mock *BlocktxStoreMock) PingCalls() []struct { } // RegisterTransactions calls RegisterTransactionsFunc. -func (mock *BlocktxStoreMock) RegisterTransactions(ctx context.Context, transaction []*blocktx_api.TransactionAndSource) ([]*chainhash.Hash, error) { +func (mock *BlocktxStoreMock) RegisterTransactions(ctx context.Context, txHashes [][]byte) ([]*chainhash.Hash, error) { if mock.RegisterTransactionsFunc == nil { panic("BlocktxStoreMock.RegisterTransactionsFunc: method is nil but BlocktxStore.RegisterTransactions was just called") } callInfo := struct { - Ctx context.Context - Transaction []*blocktx_api.TransactionAndSource + Ctx context.Context + TxHashes [][]byte }{ - Ctx: ctx, - Transaction: transaction, + Ctx: ctx, + TxHashes: txHashes, } mock.lockRegisterTransactions.Lock() mock.calls.RegisterTransactions = append(mock.calls.RegisterTransactions, callInfo) mock.lockRegisterTransactions.Unlock() - return mock.RegisterTransactionsFunc(ctx, transaction) + return mock.RegisterTransactionsFunc(ctx, txHashes) } // RegisterTransactionsCalls gets all the calls that were made to RegisterTransactions. @@ -839,12 +837,12 @@ func (mock *BlocktxStoreMock) RegisterTransactions(ctx context.Context, transact // // len(mockedBlocktxStore.RegisterTransactionsCalls()) func (mock *BlocktxStoreMock) RegisterTransactionsCalls() []struct { - Ctx context.Context - Transaction []*blocktx_api.TransactionAndSource + Ctx context.Context + TxHashes [][]byte } { var calls []struct { - Ctx context.Context - Transaction []*blocktx_api.TransactionAndSource + Ctx context.Context + TxHashes [][]byte } mock.lockRegisterTransactions.RLock() calls = mock.calls.RegisterTransactions @@ -929,25 +927,23 @@ func (mock *BlocktxStoreMock) UpdateBlocksStatusesCalls() []struct { } // UpsertBlockTransactions calls UpsertBlockTransactionsFunc. -func (mock *BlocktxStoreMock) UpsertBlockTransactions(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) ([]store.UpsertBlockTransactionsResult, error) { +func (mock *BlocktxStoreMock) UpsertBlockTransactions(ctx context.Context, blockId uint64, txsWithMerklePaths []store.TxWithMerklePath) ([]store.TxWithMerklePath, error) { if mock.UpsertBlockTransactionsFunc == nil { panic("BlocktxStoreMock.UpsertBlockTransactionsFunc: method is nil but BlocktxStore.UpsertBlockTransactions was just called") } callInfo := struct { - Ctx context.Context - BlockId uint64 - Transactions []*blocktx_api.TransactionAndSource - MerklePaths []string + Ctx context.Context + BlockId uint64 + TxsWithMerklePaths []store.TxWithMerklePath }{ - Ctx: ctx, - BlockId: blockId, - Transactions: transactions, - MerklePaths: merklePaths, + Ctx: ctx, + BlockId: blockId, + TxsWithMerklePaths: txsWithMerklePaths, } mock.lockUpsertBlockTransactions.Lock() mock.calls.UpsertBlockTransactions = append(mock.calls.UpsertBlockTransactions, callInfo) mock.lockUpsertBlockTransactions.Unlock() - return mock.UpsertBlockTransactionsFunc(ctx, blockId, transactions, merklePaths) + return mock.UpsertBlockTransactionsFunc(ctx, blockId, txsWithMerklePaths) } // UpsertBlockTransactionsCalls gets all the calls that were made to UpsertBlockTransactions. @@ -955,16 +951,14 @@ func (mock *BlocktxStoreMock) UpsertBlockTransactions(ctx context.Context, block // // len(mockedBlocktxStore.UpsertBlockTransactionsCalls()) func (mock *BlocktxStoreMock) UpsertBlockTransactionsCalls() []struct { - Ctx context.Context - BlockId uint64 - Transactions []*blocktx_api.TransactionAndSource - MerklePaths []string + Ctx context.Context + BlockId uint64 + TxsWithMerklePaths []store.TxWithMerklePath } { var calls []struct { - Ctx context.Context - BlockId uint64 - Transactions []*blocktx_api.TransactionAndSource - MerklePaths []string + Ctx context.Context + BlockId uint64 + TxsWithMerklePaths []store.TxWithMerklePath } mock.lockUpsertBlockTransactions.RLock() calls = mock.calls.UpsertBlockTransactions diff --git a/internal/blocktx/store/model.go b/internal/blocktx/store/model.go index 8fff83d5f..260df433c 100644 --- a/internal/blocktx/store/model.go +++ b/internal/blocktx/store/model.go @@ -10,8 +10,8 @@ type BlockGap struct { Hash *chainhash.Hash } -type UpsertBlockTransactionsResult struct { - TxHash []byte +type TxWithMerklePath struct { + Hash []byte MerklePath string } diff --git a/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.block_transactions_map.yaml b/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.block_transactions_map.yaml index 93c4c50e8..a405ab034 100644 --- a/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.block_transactions_map.yaml +++ b/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.block_transactions_map.yaml @@ -1,40 +1,40 @@ - blockid: 1 txid: 1 - pos: 1 + merkle_path: merkle-path-1 inserted_at: 2023-12-10 14:00:00 - blockid: 1 txid: 2 - pos: 2 + merkle_path: merkle-path-2 inserted_at: 2023-12-10 14:00:00 - blockid: 1 txid: 3 - pos: 3 + merkle_path: merkle-path-3 inserted_at: 2023-12-10 14:00:00 - blockid: 1 txid: 4 - pos: 4 + merkle_path: merkle-path-4 inserted_at: 2023-12-10 14:00:00 - blockid: 1 txid: 5 - pos: 5 + merkle_path: merkle-path-5 inserted_at: 2023-12-10 14:00:00 - blockid: 2 txid: 6 - pos: 1 + merkle_path: merkle-path-6 inserted_at: 2023-12-15 14:00:00 - blockid: 2 txid: 7 - pos: 2 + merkle_path: merkle-path-7 inserted_at: 2023-12-15 14:00:00 - blockid: 2 txid: 8 - pos: 3 + merkle_path: merkle-path-8 inserted_at: 2023-12-15 14:00:00 - blockid: 2 txid: 9 - pos: 4 + merkle_path: merkle-path-9 inserted_at: 2023-12-15 14:00:00 - blockid: 2 txid: 10 - pos: 5 + merkle_path: merkle-path-10 inserted_at: 2023-12-15 14:00:00 diff --git a/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.transactions.yaml b/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.transactions.yaml index ddf165a9f..8b36a806e 100644 --- a/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.transactions.yaml +++ b/internal/blocktx/store/postgresql/fixtures/clear_data/blocktx.transactions.yaml @@ -1,40 +1,30 @@ - id: 1 hash: 0xcd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853 inserted_at: 2023-12-10 14:00:00 - source: local - id: 2 hash: 0x21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e inserted_at: 2023-12-10 14:00:00 - source: local - id: 3 hash: 0xb16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430 inserted_at: 2023-12-10 14:00:00 - source: local - id: 4 hash: 0xee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa inserted_at: 2023-12-10 14:00:00 - source: local - id: 5 hash: 0x3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd inserted_at: 2023-12-10 14:00:00 - source: local - id: 6 hash: 0x213a8c87c5460e82b5ae529212956b853c7ce6bf06e56b2e040eb063cf9a49f0 inserted_at: 2023-12-15 14:00:00 - source: local - id: 7 hash: 0x12c04cfc5643f1cd25639ad42d6f8f0489557699d92071d7e0a5b940438c4357 inserted_at: 2023-12-15 14:00:00 - source: local - id: 8 hash: 0xece2b7e40d98749c03c551b783420d6e3fdc3c958244bbf275437839585829a6 inserted_at: 2023-12-15 14:00:00 - source: local - id: 9 hash: 0x5c5b621b81fb63d9df4595ee2e6b3c50cce1f5f0e1b83510aac504931ed22799 inserted_at: 2023-12-15 14:00:00 - source: local - id: 10 hash: 0xa3d4e78a8e11e97c8faf34880da861412273948edf467f23590601a1057079d8 inserted_at: 2023-12-15 14:00:00 - source: local diff --git a/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.block_transactions_map.yaml b/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.block_transactions_map.yaml index b0c6701d4..f87903b98 100644 --- a/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.block_transactions_map.yaml +++ b/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.block_transactions_map.yaml @@ -1,12 +1,12 @@ - blockid: 9736 txid: 115361489 - pos: 36 + merkle_path: merkle-path-1 inserted_at: 2024-01-10 12:00:00 - blockid: 9736 txid: 115361490 - pos: 37 + merkle_path: merkle-path-2 inserted_at: 2024-01-10 12:00:00 - blockid: 9736 txid: 115361491 - pos: 38 + merkle_path: merkle-path-3 inserted_at: 2024-01-10 12:00:00 diff --git a/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.transactions.yaml b/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.transactions.yaml index 6eb06d968..a8bffc9e8 100644 --- a/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.transactions.yaml +++ b/internal/blocktx/store/postgresql/fixtures/get_mined_transactions/blocktx.transactions.yaml @@ -1,20 +1,12 @@ - id: 115361488 hash: 0x76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b - source: "" - merkle_path: "" inserted_at: 2024-01-09 13:00:00 - id: 115361489 hash: 0x164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 - id: 115361490 hash: 0xdbbd24251b9bb824566412395bb76a579bca3477c2d0b4cbc210a769d3bb4177 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 - id: 115361491 hash: 0x0d60dd6dc1f2649efb2847f801dfaa61361a438deb526da2de5b6875e0016514 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 diff --git a/internal/blocktx/store/postgresql/fixtures/register_transactions/blocktx.transactions.yaml b/internal/blocktx/store/postgresql/fixtures/register_transactions/blocktx.transactions.yaml index 2889dab14..de3289b32 100644 --- a/internal/blocktx/store/postgresql/fixtures/register_transactions/blocktx.transactions.yaml +++ b/internal/blocktx/store/postgresql/fixtures/register_transactions/blocktx.transactions.yaml @@ -1,48 +1,32 @@ - id: 110383995 hash: 0x76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b - source: "" - merkle_path: "" inserted_at: 2024-01-09 13:00:00 is_registered: FALSE - id: 115361489 hash: 0x164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: FALSE - id: 115361490 hash: 0xb4201cc6fc5768abff14adf75042ace6061da9176ee5bb943291b9ba7d7f5743 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361491 hash: 0x37bd6c87927e75faeb3b3c939f64721cda48e1bb98742676eebe83aceee1a669 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361492 hash: 0x952f80e20a0330f3b9c2dfd1586960064e797218b5c5df665cada221452c17eb - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361493 hash: 0x861a281b27de016e50887288de87eab5ca56a1bb172cdff6dba965474ce0f608 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361494 hash: 0x9421cc760c5405af950a76dc3e4345eaefd4e7322f172a3aee5e0ddc7b4f8313 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: FALSE - id: 115361495 hash: 0x8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: FALSE diff --git a/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.blocks.yaml b/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.blocks.yaml index 2cf6008e8..3e007ea6c 100644 --- a/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.blocks.yaml +++ b/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.blocks.yaml @@ -8,4 +8,13 @@ size: 108689370 tx_count: 799 orphanedyn: FALSE - merkle_path: "" +- inserted_at: 2024-01-10 13:06:03.375 + id: 9737 + hash: 0x7258b02da70a3e367e4c993b049fa9b76ef8f090ef9fd2010000000000000000 + prevhash: 0x000000000000000001a7aa3999410ca53fb645851531ec0a7a5cb9ce2d4ae313 + merkleroot: 0x0d72bf92e7862df18d1935c171ca4dbb70d268b0f025e46716e913bc7e4f2bdb + height: 826481 + processed_at: 2024-01-10 13:06:06.122 + size: 108689370 + tx_count: 799 + orphanedyn: FALSE diff --git a/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.transactions.yaml b/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.transactions.yaml index 7f8604020..944dd462a 100644 --- a/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.transactions.yaml +++ b/internal/blocktx/store/postgresql/fixtures/upsert_block_transactions/blocktx.transactions.yaml @@ -1,48 +1,32 @@ - id: 110383995 hash: 0x76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b - source: "" - merkle_path: "" inserted_at: 2024-01-09 13:00:00 is_registered: TRUE - id: 115361489 hash: 0x164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361490 hash: 0xb4201cc6fc5768abff14adf75042ace6061da9176ee5bb943291b9ba7d7f5743 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361491 hash: 0x37bd6c87927e75faeb3b3c939f64721cda48e1bb98742676eebe83aceee1a669 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361492 hash: 0x952f80e20a0330f3b9c2dfd1586960064e797218b5c5df665cada221452c17eb - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361493 hash: 0x861a281b27de016e50887288de87eab5ca56a1bb172cdff6dba965474ce0f608 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361494 hash: 0x9421cc760c5405af950a76dc3e4345eaefd4e7322f172a3aee5e0ddc7b4f8313 - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE - id: 115361495 hash: 0x8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b - source: "" - merkle_path: "" inserted_at: 2024-01-10 12:00:00 is_registered: TRUE diff --git a/internal/blocktx/store/postgresql/get_mined_transactions.go b/internal/blocktx/store/postgresql/get_mined_transactions.go index 371f48d64..2178c32fe 100644 --- a/internal/blocktx/store/postgresql/get_mined_transactions.go +++ b/internal/blocktx/store/postgresql/get_mined_transactions.go @@ -28,10 +28,10 @@ func (p *PostgreSQL) GetMinedTransactions(ctx context.Context, hashes []*chainha t.hash, b.hash, b.height, - t.merkle_path - FROM blocktx.transactions as t - JOIN blocktx.block_transactions_map ON t.id = blocktx.block_transactions_map.txid - JOIN blocktx.blocks as b ON blocktx.block_transactions_map.blockid = b.id + m.merkle_path + FROM blocktx.transactions AS t + JOIN blocktx.block_transactions_map AS m ON t.id = m.txid + JOIN blocktx.blocks AS b ON m.blockid = b.id WHERE t.hash = ANY($1) ` diff --git a/internal/blocktx/store/postgresql/migrations/000016_remove_unused_values.down.sql b/internal/blocktx/store/postgresql/migrations/000016_remove_unused_values.down.sql new file mode 100644 index 000000000..9c66127da --- /dev/null +++ b/internal/blocktx/store/postgresql/migrations/000016_remove_unused_values.down.sql @@ -0,0 +1,7 @@ +ALTER TABLE blocktx.block_transactions_map ADD COLUMN pos BIGINT NOT NULL; +ALTER TABLE blocktx.transactions ADD COLUMN source TEXT; + +CREATE TABLE primary_blocktx ( + host_name TEXT PRIMARY KEY, + primary_until TIMESTAMP +); diff --git a/internal/blocktx/store/postgresql/migrations/000016_remove_unused_values.up.sql b/internal/blocktx/store/postgresql/migrations/000016_remove_unused_values.up.sql new file mode 100644 index 000000000..8374a50c2 --- /dev/null +++ b/internal/blocktx/store/postgresql/migrations/000016_remove_unused_values.up.sql @@ -0,0 +1,6 @@ +-- Remove unused fields +ALTER TABLE blocktx.block_transactions_map DROP COLUMN pos; +ALTER TABLE blocktx.transactions DROP COLUMN source; + +-- Remove unused table +DROP TABLE blocktx.primary_blocktx; diff --git a/internal/blocktx/store/postgresql/migrations/000017_move_merklepath_to_block_txs_map.down.sql b/internal/blocktx/store/postgresql/migrations/000017_move_merklepath_to_block_txs_map.down.sql new file mode 100644 index 000000000..372f1a436 --- /dev/null +++ b/internal/blocktx/store/postgresql/migrations/000017_move_merklepath_to_block_txs_map.down.sql @@ -0,0 +1,9 @@ +ALTER TABLE blocktx.transactions +ADD COLUMN merkle_path TEXT DEFAULT (''); + +UPDATE blocktx.transactions AS t +SET merkle_path = btm.merkle_path +FROM blocktx.block_transactions_map btm +WHERE t.id = btm.txid; + +ALTER TABLE blocktx.block_transactions_map DROP COLUMN merkle_path; diff --git a/internal/blocktx/store/postgresql/migrations/000017_move_merklepath_to_block_txs_map.up.sql b/internal/blocktx/store/postgresql/migrations/000017_move_merklepath_to_block_txs_map.up.sql new file mode 100644 index 000000000..1b3a883d0 --- /dev/null +++ b/internal/blocktx/store/postgresql/migrations/000017_move_merklepath_to_block_txs_map.up.sql @@ -0,0 +1,11 @@ +-- move merkle_path to block_transactions_map, because in case there are +-- competing blocks - there may be multiple merkle paths for one transaction +ALTER TABLE blocktx.block_transactions_map +ADD COLUMN merkle_path TEXT DEFAULT (''); + +UPDATE blocktx.block_transactions_map AS btm +SET merkle_path = t.merkle_path +FROM blocktx.transactions t +WHERE btm.txid = t.id; + +ALTER TABLE blocktx.transactions DROP COLUMN merkle_path; diff --git a/internal/blocktx/store/postgresql/postgres_test.go b/internal/blocktx/store/postgresql/postgres_test.go index d71c20c5d..d5beab153 100644 --- a/internal/blocktx/store/postgresql/postgres_test.go +++ b/internal/blocktx/store/postgresql/postgres_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "database/sql" - "errors" "log" "os" "testing" @@ -45,15 +44,15 @@ type Block struct { type Transaction struct { ID int64 `db:"id"` Hash []byte `db:"hash"` - MerklePath string `db:"merkle_path"` IsRegistered bool `db:"is_registered"` InsertedAt time.Time `db:"inserted_at"` } type BlockTransactionMap struct { - BlockID int64 `db:"blockid"` - TransactionID int64 `db:"txid"` - Pos int64 `db:"pos"` + BlockID int64 `db:"blockid"` + TransactionID int64 `db:"txid"` + MerklePath string `db:"merkle_path"` + InsertedAt time.Time `db:"inserted_at"` } const ( @@ -348,7 +347,7 @@ func TestPostgresDB(t *testing.T) { require.Equal(t, int64(5), resp.Rows) var txs []Transaction - require.NoError(t, d.Select(&txs, "SELECT id FROM blocktx.transactions")) + require.NoError(t, d.Select(&txs, "SELECT hash FROM blocktx.transactions")) require.Len(t, txs, 5) }) @@ -458,72 +457,64 @@ func TestPostgresStore_UpsertBlockTransactions(t *testing.T) { } tcs := []struct { - name string - txs []*blocktx_api.TransactionAndSource - merklePaths []string + name string + txsWithMerklePaths []store.TxWithMerklePath expectedErr error expectedUpdatedResLen int }{ - { - name: "mismatched lengths of merkle paths and transactions", - txs: []*blocktx_api.TransactionAndSource{ - { - Hash: testutils.RevChainhash(t, "76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b")[:], - }, - { - Hash: testutils.RevChainhash(t, "164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0")[:], - }, - }, - merklePaths: []string{"test1"}, - expectedErr: errors.New("transactions (len=2) and Merkle paths (len=1) have not the same lengths"), - }, { name: "upsert all registered transactions (updates only)", - txs: []*blocktx_api.TransactionAndSource{ + txsWithMerklePaths: []store.TxWithMerklePath{ { - Hash: testutils.RevChainhash(t, "76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b")[:], + Hash: testutils.RevChainhash(t, "76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b")[:], + MerklePath: "test1", }, { - Hash: testutils.RevChainhash(t, "164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0")[:], + Hash: testutils.RevChainhash(t, "164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0")[:], + MerklePath: "test2", }, }, - merklePaths: []string{"test1", "test2"}, expectedUpdatedResLen: 2, }, { name: "upsert all non-registered transactions (inserts only)", - txs: []*blocktx_api.TransactionAndSource{ + txsWithMerklePaths: []store.TxWithMerklePath{ { - Hash: testutils.RevChainhash(t, "edd33fdcdfa68444d227780e2b62a4437c00120c5320d2026aeb24a781f4c3f1")[:], + Hash: testutils.RevChainhash(t, "edd33fdcdfa68444d227780e2b62a4437c00120c5320d2026aeb24a781f4c3f1")[:], + MerklePath: "test1", }, }, - merklePaths: []string{"test1"}, expectedUpdatedResLen: 0, }, { name: "update exceeds max batch size (more txs than 5)", - txs: []*blocktx_api.TransactionAndSource{ + txsWithMerklePaths: []store.TxWithMerklePath{ { - Hash: testutils.RevChainhash(t, "b4201cc6fc5768abff14adf75042ace6061da9176ee5bb943291b9ba7d7f5743")[:], + Hash: testutils.RevChainhash(t, "b4201cc6fc5768abff14adf75042ace6061da9176ee5bb943291b9ba7d7f5743")[:], + MerklePath: "test1", }, { - Hash: testutils.RevChainhash(t, "37bd6c87927e75faeb3b3c939f64721cda48e1bb98742676eebe83aceee1a669")[:], + Hash: testutils.RevChainhash(t, "37bd6c87927e75faeb3b3c939f64721cda48e1bb98742676eebe83aceee1a669")[:], + MerklePath: "test2", }, { - Hash: testutils.RevChainhash(t, "952f80e20a0330f3b9c2dfd1586960064e797218b5c5df665cada221452c17eb")[:], + Hash: testutils.RevChainhash(t, "952f80e20a0330f3b9c2dfd1586960064e797218b5c5df665cada221452c17eb")[:], + MerklePath: "test3", }, { - Hash: testutils.RevChainhash(t, "861a281b27de016e50887288de87eab5ca56a1bb172cdff6dba965474ce0f608")[:], + Hash: testutils.RevChainhash(t, "861a281b27de016e50887288de87eab5ca56a1bb172cdff6dba965474ce0f608")[:], + MerklePath: "test4", }, { - Hash: testutils.RevChainhash(t, "9421cc760c5405af950a76dc3e4345eaefd4e7322f172a3aee5e0ddc7b4f8313")[:], + Hash: testutils.RevChainhash(t, "9421cc760c5405af950a76dc3e4345eaefd4e7322f172a3aee5e0ddc7b4f8313")[:], + MerklePath: "test5", }, { - Hash: testutils.RevChainhash(t, "8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b")[:], + Hash: testutils.RevChainhash(t, "8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b")[:], + MerklePath: "test6", }, }, - merklePaths: []string{"test1", "test2", "test3", "test4", "test5", "test6"}, expectedUpdatedResLen: 6, }, } @@ -539,7 +530,7 @@ func TestPostgresStore_UpsertBlockTransactions(t *testing.T) { testBlockID := uint64(9736) - res, err := sut.UpsertBlockTransactions(ctx, testBlockID, tc.txs, tc.merklePaths) + res, err := sut.UpsertBlockTransactions(ctx, testBlockID, tc.txsWithMerklePaths) if tc.expectedErr != nil { require.ErrorContains(t, err, tc.expectedErr.Error()) @@ -553,34 +544,93 @@ func TestPostgresStore_UpsertBlockTransactions(t *testing.T) { // assert correctness of returned values // assume registered transactions are at the beginning of tc.txs for i := 0; i < tc.expectedUpdatedResLen; i++ { - require.True(t, bytes.Equal(tc.txs[i].Hash, res[i].TxHash)) - require.Equal(t, tc.merklePaths[i], res[i].MerklePath) + require.True(t, bytes.Equal(tc.txsWithMerklePaths[i].Hash, res[i].Hash)) + require.Equal(t, tc.txsWithMerklePaths[i].MerklePath, res[i].MerklePath) } // assert data are correctly saved in the store d, err := sqlx.Open("postgres", dbInfo) require.NoError(t, err) - for i, tx := range tc.txs { + for i, tx := range tc.txsWithMerklePaths { var storedtx Transaction - err = d.Get(&storedtx, "SELECT id, hash, merkle_path, is_registered from blocktx.transactions WHERE hash=$1", tx.Hash[:]) + err = d.Get(&storedtx, "SELECT id, hash, is_registered from blocktx.transactions WHERE hash=$1", tx.Hash[:]) require.NoError(t, err, "error during getting transaction") - require.Equal(t, tc.merklePaths[i], storedtx.MerklePath) require.Equal(t, i < tc.expectedUpdatedResLen, storedtx.IsRegistered) var mp BlockTransactionMap - err = d.Get(&mp, "SELECT blockid, txid, pos from blocktx.block_transactions_map WHERE txid=$1", storedtx.ID) + err = d.Get(&mp, "SELECT blockid, txid, merkle_path from blocktx.block_transactions_map WHERE txid=$1", storedtx.ID) require.NoError(t, err, "error during getting block transactions map") - require.Equal(t, storedtx.ID, mp.TransactionID) + require.Equal(t, tx.MerklePath, mp.MerklePath) require.Equal(t, testBlockID, uint64(mp.BlockID)) } }) } } +func TestPostgresStore_UpsertBlockTransactions_CompetingBlocks(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + // given + ctx, _, sut := setupPostgresTest(t) + defer sut.Close() + sut.maxPostgresBulkInsertRows = 5 + + prepareDb(t, sut.db, "fixtures/upsert_block_transactions") + + testBlockID := uint64(9736) + competingBlockID := uint64(9737) + + txHash := testutils.RevChainhash(t, "76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b") + + txsWithMerklePaths := []store.TxWithMerklePath{ + { + Hash: txHash[:], + MerklePath: "merkle-path-1", + }, + } + + competingTxsWithMerklePaths := []store.TxWithMerklePath{ + { + Hash: txHash[:], + MerklePath: "merkle-path-2", + }, + } + + expected := []store.GetMinedTransactionResult{ + { + TxHash: txHash[:], + BlockHash: testutils.RevChainhash(t, "6258b02da70a3e367e4c993b049fa9b76ef8f090ef9fd2010000000000000000")[:], + BlockHeight: uint64(826481), + MerklePath: "merkle-path-1", + }, + { + TxHash: txHash[:], + BlockHash: testutils.RevChainhash(t, "7258b02da70a3e367e4c993b049fa9b76ef8f090ef9fd2010000000000000000")[:], + BlockHeight: uint64(826481), + MerklePath: "merkle-path-2", + }, + } + + // when + _, err := sut.UpsertBlockTransactions(ctx, testBlockID, txsWithMerklePaths) + require.NoError(t, err) + + _, err = sut.UpsertBlockTransactions(ctx, competingBlockID, competingTxsWithMerklePaths) + require.NoError(t, err) + + // then + actual, err := sut.GetMinedTransactions(ctx, []*chainhash.Hash{txHash}) + require.NoError(t, err) + + require.ElementsMatch(t, expected, actual) +} + func TestPostgresStore_RegisterTransactions(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") @@ -588,57 +638,33 @@ func TestPostgresStore_RegisterTransactions(t *testing.T) { tcs := []struct { name string - txs []*blocktx_api.TransactionAndSource + txs [][]byte }{ { name: "register new transactions", - txs: []*blocktx_api.TransactionAndSource{ - { - Hash: testdata.TX1Hash[:], - }, - { - Hash: testdata.TX2Hash[:], - }, - { - Hash: testdata.TX3Hash[:], - }, - { - Hash: testdata.TX4Hash[:], - }, + txs: [][]byte{ + testdata.TX1Hash[:], + testdata.TX2Hash[:], + testdata.TX3Hash[:], + testdata.TX4Hash[:], }, }, { name: "register already known, not registered transactions", - txs: []*blocktx_api.TransactionAndSource{ - { - Hash: testutils.RevChainhash(t, "76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b")[:], - }, - { - Hash: testutils.RevChainhash(t, "164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0")[:], - }, - { - Hash: testutils.RevChainhash(t, "8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b")[:], - }, - { - Hash: testutils.RevChainhash(t, "9421cc760c5405af950a76dc3e4345eaefd4e7322f172a3aee5e0ddc7b4f8313")[:], - }, + txs: [][]byte{ + testutils.RevChainhash(t, "76732b80598326a18d3bf0a86518adbdf95d0ddc6ff6693004440f4776168c3b")[:], + testutils.RevChainhash(t, "164e85a5d5bc2b2372e8feaa266e5e4b7d0808f8d2b784fb1f7349c4726392b0")[:], + testutils.RevChainhash(t, "8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b")[:], + testutils.RevChainhash(t, "9421cc760c5405af950a76dc3e4345eaefd4e7322f172a3aee5e0ddc7b4f8313")[:], }, }, { name: "register already registered transactions", - txs: []*blocktx_api.TransactionAndSource{ - { - Hash: testutils.RevChainhash(t, "b4201cc6fc5768abff14adf75042ace6061da9176ee5bb943291b9ba7d7f5743")[:], - }, - { - Hash: testutils.RevChainhash(t, "37bd6c87927e75faeb3b3c939f64721cda48e1bb98742676eebe83aceee1a669")[:], - }, - { - Hash: testutils.RevChainhash(t, "952f80e20a0330f3b9c2dfd1586960064e797218b5c5df665cada221452c17eb")[:], - }, - { - Hash: testutils.RevChainhash(t, "861a281b27de016e50887288de87eab5ca56a1bb172cdff6dba965474ce0f608")[:], - }, + txs: [][]byte{ + testutils.RevChainhash(t, "b4201cc6fc5768abff14adf75042ace6061da9176ee5bb943291b9ba7d7f5743")[:], + testutils.RevChainhash(t, "37bd6c87927e75faeb3b3c939f64721cda48e1bb98742676eebe83aceee1a669")[:], + testutils.RevChainhash(t, "952f80e20a0330f3b9c2dfd1586960064e797218b5c5df665cada221452c17eb")[:], + testutils.RevChainhash(t, "861a281b27de016e50887288de87eab5ca56a1bb172cdff6dba965474ce0f608")[:], }, }, } @@ -665,9 +691,9 @@ func TestPostgresStore_RegisterTransactions(t *testing.T) { require.NoError(t, err) updatedCounter := 0 - for _, tx := range tc.txs { + for _, hash := range tc.txs { var storedtx Transaction - err = d.Get(&storedtx, "SELECT id, hash, is_registered from blocktx.transactions WHERE hash=$1", string(tx.GetHash())) + err = d.Get(&storedtx, "SELECT hash, is_registered from blocktx.transactions WHERE hash=$1", hash) require.NoError(t, err) require.NotNil(t, storedtx) diff --git a/internal/blocktx/store/postgresql/register_transactions.go b/internal/blocktx/store/postgresql/register_transactions.go index a74531c72..088546bd3 100644 --- a/internal/blocktx/store/postgresql/register_transactions.go +++ b/internal/blocktx/store/postgresql/register_transactions.go @@ -5,17 +5,11 @@ import ( "fmt" "time" - "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/lib/pq" "github.com/libsv/go-p2p/chaincfg/chainhash" ) -func (p *PostgreSQL) RegisterTransactions(ctx context.Context, transactions []*blocktx_api.TransactionAndSource) ([]*chainhash.Hash, error) { - hashes := make([][]byte, len(transactions)) - for i, transaction := range transactions { - hashes[i] = transaction.Hash - } - +func (p *PostgreSQL) RegisterTransactions(ctx context.Context, txHashes [][]byte) ([]*chainhash.Hash, error) { const q = ` INSERT INTO blocktx.transactions (hash, is_registered) SELECT hash, TRUE @@ -26,7 +20,7 @@ func (p *PostgreSQL) RegisterTransactions(ctx context.Context, transactions []*b ` now := p.now() - rows, err := p.db.QueryContext(ctx, q, pq.Array(hashes)) + rows, err := p.db.QueryContext(ctx, q, pq.Array(txHashes)) if err != nil { return nil, fmt.Errorf("failed to bulk insert transactions: %v", err) } diff --git a/internal/blocktx/store/postgresql/upsert_block_transactions.go b/internal/blocktx/store/postgresql/upsert_block_transactions.go index 818820548..f93cacb5a 100644 --- a/internal/blocktx/store/postgresql/upsert_block_transactions.go +++ b/internal/blocktx/store/postgresql/upsert_block_transactions.go @@ -2,109 +2,85 @@ package postgresql import ( "context" - "encoding/hex" "fmt" - "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/blocktx/store" "github.com/lib/pq" "go.opentelemetry.io/otel/trace" ) // UpsertBlockTransactions upserts the transaction hashes for a given block hash and returns updated registered transactions hashes. -func (p *PostgreSQL) UpsertBlockTransactions(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) ([]store.UpsertBlockTransactionsResult, error) { +func (p *PostgreSQL) UpsertBlockTransactions(ctx context.Context, blockId uint64, txsWithMerklePaths []store.TxWithMerklePath) ([]store.TxWithMerklePath, error) { if tracer != nil { var span trace.Span ctx, span = tracer.Start(ctx, "UpdateBlockTransactions") defer span.End() } - if len(transactions) != len(merklePaths) { - return nil, fmt.Errorf("transactions (len=%d) and Merkle paths (len=%d) have not the same lengths", len(transactions), len(merklePaths)) + txHashesBytes := make([][]byte, len(txsWithMerklePaths)) + merklePaths := make([]string, len(txsWithMerklePaths)) + for i, tx := range txsWithMerklePaths { + txHashesBytes[i] = tx.Hash + merklePaths[i] = tx.MerklePath } - txHashes := make([][]byte, len(transactions)) - txHashesMap := map[string]int{} - for pos, tx := range transactions { - txHashes[pos] = tx.Hash - txHashesMap[hex.EncodeToString(tx.Hash)] = pos + qUpsertTransactions := ` + WITH inserted_transactions AS ( + INSERT INTO blocktx.transactions (hash) + SELECT UNNEST($2::BYTEA[]) + ON CONFLICT (hash) + DO UPDATE SET hash = EXCLUDED.hash + RETURNING id, hash + ) + + INSERT INTO blocktx.block_transactions_map (blockid, txid, merkle_path) + SELECT + $1::BIGINT, + it.id, + t.merkle_path + FROM inserted_transactions it + JOIN LATERAL UNNEST($2::BYTEA[], $3::TEXT[]) AS t(hash, merkle_path) ON it.hash = t.hash; + ` + + qRegisteredTransactions := ` + SELECT + t.hash, + m.merkle_path + FROM blocktx.transactions t + JOIN blocktx.block_transactions_map AS m ON t.id = m.txid + WHERE m.blockid = $1 AND t.is_registered = TRUE AND t.hash = ANY($2) + ` + + _, err := p.db.ExecContext(ctx, qUpsertTransactions, blockId, pq.Array(txHashesBytes), pq.Array(merklePaths)) + if err != nil { + return nil, fmt.Errorf("failed to execute transactions upsert query: %v", err) } - qBulkUpsert := ` - INSERT INTO blocktx.transactions (hash, merkle_path) - SELECT hash, merkle_path - FROM UNNEST($1::BYTEA[], $2::TEXT[]) AS t(hash, merkle_path) - ON CONFLICT (hash) DO UPDATE SET - merkle_path = EXCLUDED.merkle_path - RETURNING id, hash, merkle_path, is_registered` - - rows, err := p.db.QueryContext(ctx, qBulkUpsert, pq.Array(txHashes), pq.Array(merklePaths)) + rows, err := p.db.QueryContext(ctx, qRegisteredTransactions, blockId, pq.Array(txHashesBytes)) if err != nil { - return nil, fmt.Errorf("failed to execute transaction update query: %v", err) + return nil, fmt.Errorf("failed to get registered transactions for block with id %d: %v", blockId, err) } + defer rows.Close() - txIDs := make([]uint64, 0) - blockIDs := make([]uint64, 0) - positions := make([]int, 0) - registeredRows := make([]store.UpsertBlockTransactionsResult, 0) + registeredRows := make([]store.TxWithMerklePath, 0) for rows.Next() { - var txID uint64 var txHash []byte var merklePath string - var isRegistered bool - err = rows.Scan(&txID, &txHash, &merklePath, &isRegistered) + err = rows.Scan(&txHash, &merklePath) if err != nil { return nil, fmt.Errorf("failed to get rows: %v", err) } - if isRegistered { - registeredRows = append(registeredRows, store.UpsertBlockTransactionsResult{ - TxHash: txHash, - MerklePath: merklePath, - }) - } - - txIDs = append(txIDs, txID) - blockIDs = append(blockIDs, blockId) - - positions = append(positions, txHashesMap[hex.EncodeToString(txHash)]) - - if len(txIDs) >= p.maxPostgresBulkInsertRows { - err = p.insertTxsIntoBlockMap(ctx, blockId, blockIDs, txIDs, positions) - if err != nil { - return nil, err - } - txIDs = make([]uint64, 0) - blockIDs = make([]uint64, 0) - positions = make([]int, 0) - } + registeredRows = append(registeredRows, store.TxWithMerklePath{ + Hash: txHash, + MerklePath: merklePath, + }) } - if len(txIDs) > 0 { - err = p.insertTxsIntoBlockMap(ctx, blockId, blockIDs, txIDs, positions) - if err != nil { - return nil, err - } + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("error getting registered transactions for block with id %d: %v", blockId, err) } return registeredRows, nil } - -func (p *PostgreSQL) insertTxsIntoBlockMap(ctx context.Context, blockId uint64, blockIDs, txIDs []uint64, positions []int) error { - const qMap = ` - INSERT INTO blocktx.block_transactions_map ( - blockid - ,txid - ,pos - ) - SELECT * FROM UNNEST($1::INT[], $2::INT[], $3::INT[]) - ON CONFLICT DO NOTHING - ` - _, err := p.db.ExecContext(ctx, qMap, pq.Array(blockIDs), pq.Array(txIDs), pq.Array(positions)) - if err != nil { - return fmt.Errorf("failed to bulk insert transactions into block transactions map for block with id %d: %v", blockId, err) - } - - return nil -} diff --git a/internal/blocktx/store/store.go b/internal/blocktx/store/store.go index 709f890b5..9dc23c618 100644 --- a/internal/blocktx/store/store.go +++ b/internal/blocktx/store/store.go @@ -15,12 +15,12 @@ var ( ) type BlocktxStore interface { - RegisterTransactions(ctx context.Context, transaction []*blocktx_api.TransactionAndSource) (updatedTxs []*chainhash.Hash, err error) + RegisterTransactions(ctx context.Context, txHashes [][]byte) (updatedTxs []*chainhash.Hash, err error) GetBlock(ctx context.Context, hash *chainhash.Hash) (*blocktx_api.Block, error) GetBlockByHeight(ctx context.Context, height uint64, status blocktx_api.Status) (*blocktx_api.Block, error) GetChainTip(ctx context.Context) (*blocktx_api.Block, error) InsertBlock(ctx context.Context, block *blocktx_api.Block) (uint64, error) - UpsertBlockTransactions(ctx context.Context, blockId uint64, transactions []*blocktx_api.TransactionAndSource, merklePaths []string) (registeredTxs []UpsertBlockTransactionsResult, err error) + UpsertBlockTransactions(ctx context.Context, blockId uint64, txsWithMerklePaths []TxWithMerklePath) (registeredTxs []TxWithMerklePath, err error) MarkBlockAsDone(ctx context.Context, hash *chainhash.Hash, size uint64, txCount uint64) error GetBlockGaps(ctx context.Context, heightRange int) ([]*BlockGap, error) ClearBlocktxTable(ctx context.Context, retentionDays int32, table string) (*blocktx_api.RowsAffectedResponse, error) diff --git a/internal/callbacker/callbacker_api/callbacker_api.pb.go b/internal/callbacker/callbacker_api/callbacker_api.pb.go index 1a5d3d604..457136d16 100644 --- a/internal/callbacker/callbacker_api/callbacker_api.pb.go +++ b/internal/callbacker/callbacker_api/callbacker_api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.3 +// protoc v5.28.0 // source: internal/callbacker/callbacker_api/callbacker_api.proto package callbacker_api diff --git a/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go b/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go index e2578fba3..f8841e724 100644 --- a/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go +++ b/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.27.3 +// - protoc v5.28.0 // source: internal/callbacker/callbacker_api/callbacker_api.proto package callbacker_api diff --git a/internal/metamorph/metamorph_api/metamorph_api.pb.go b/internal/metamorph/metamorph_api/metamorph_api.pb.go index db1d8e3da..23a32872e 100644 --- a/internal/metamorph/metamorph_api/metamorph_api.pb.go +++ b/internal/metamorph/metamorph_api/metamorph_api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.3 +// protoc v5.28.0 // source: internal/metamorph/metamorph_api/metamorph_api.proto package metamorph_api diff --git a/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go b/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go index ab025428f..88ba08c75 100644 --- a/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go +++ b/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.27.3 +// - protoc v5.28.0 // source: internal/metamorph/metamorph_api/metamorph_api.proto package metamorph_api