From d5a70d164b47037d9da318041b6525ebe08177ec Mon Sep 17 00:00:00 2001 From: Kostas Christidis Date: Thu, 19 Jan 2017 18:10:33 -0500 Subject: [PATCH] [FAB-1773] Add metadata field for orderer use https://jira.hyperledger.org/browse/FAB-1773 A consensus implementation may need to read the ledger and extract metadata from it during operation (most likely when booting up). As an example, the Kafka-based orderer, should read the offset of the last envelope it placed into a block *and* wrote to the local ledger, and use that value to resume consumption of chain's partition. This changeset: 1. Introduces a metadata field for the described use above 2. Sizes and populates the `Metadata` field of a newly-constructed block appropriately. These changes will be put into use in a follow-up changeset [FAB-1774]. Change-Id: Ib3d7d8f77c1a888ebec5790a144457913b201202 Signed-off-by: Kostas Christidis --- protos/common/block.go | 8 ++++++-- protos/common/common.pb.go | 19 +++++++++++-------- protos/common/common.proto | 4 +++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/protos/common/block.go b/protos/common/block.go index 96635f611f1..449c74a80b6 100644 --- a/protos/common/block.go +++ b/protos/common/block.go @@ -28,9 +28,13 @@ func NewBlock(seqNum uint64, previousHash []byte) *Block { block.Header.Number = seqNum block.Header.PreviousHash = previousHash block.Data = &BlockData{} - block.Metadata = &BlockMetadata{ - Metadata: [][]byte{[]byte{}, []byte{}, []byte{}}, + + var metadataContents [][]byte + for i := 0; i < len(BlockMetadataIndex_name); i++ { + metadataContents = append(metadataContents, []byte{}) } + block.Metadata = &BlockMetadata{Metadata: metadataContents} + return block } diff --git a/protos/common/common.pb.go b/protos/common/common.pb.go index 487b3a9012d..842f40998ce 100644 --- a/protos/common/common.pb.go +++ b/protos/common/common.pb.go @@ -129,24 +129,27 @@ func (x HeaderType) String() string { } func (HeaderType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } -// This enum enlist indexes of the block metadata array +// This enum enlists indexes of the block metadata array type BlockMetadataIndex int32 const ( BlockMetadataIndex_SIGNATURES BlockMetadataIndex = 0 BlockMetadataIndex_LAST_CONFIGURATION BlockMetadataIndex = 1 BlockMetadataIndex_TRANSACTIONS_FILTER BlockMetadataIndex = 2 + BlockMetadataIndex_ORDERER BlockMetadataIndex = 3 ) var BlockMetadataIndex_name = map[int32]string{ 0: "SIGNATURES", 1: "LAST_CONFIGURATION", 2: "TRANSACTIONS_FILTER", + 3: "ORDERER", } var BlockMetadataIndex_value = map[string]int32{ "SIGNATURES": 0, "LAST_CONFIGURATION": 1, "TRANSACTIONS_FILTER": 2, + "ORDERER": 3, } func (x BlockMetadataIndex) String() string { @@ -388,7 +391,7 @@ func init() { func init() { proto.RegisterFile("common/common.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 866 bytes of a gzipped FileDescriptorProto + // 871 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x55, 0xdd, 0x6e, 0xe3, 0x44, 0x14, 0xae, 0xe3, 0xfc, 0x34, 0x27, 0xa5, 0xeb, 0x4e, 0xb7, 0xbb, 0xde, 0x8a, 0xd5, 0x56, 0x96, 0x40, 0xa5, 0x15, 0x89, 0x28, 0x42, 0x82, 0x4b, 0x27, 0x9e, 0x74, 0xad, 0x4d, 0xed, 0x65, 0xc6, @@ -437,11 +440,11 @@ var fileDescriptor0 = []byte{ 0x11, 0xd3, 0xa1, 0xe6, 0x80, 0x9f, 0x35, 0x05, 0xbd, 0x00, 0x54, 0xa5, 0x6d, 0x0f, 0x5f, 0x69, 0x35, 0xa4, 0xc3, 0x73, 0xec, 0x58, 0x2e, 0xa1, 0x98, 0x54, 0x6e, 0xa8, 0xe8, 0x25, 0x1c, 0xba, 0xc4, 0xc2, 0xe4, 0x11, 0x51, 0x47, 0x47, 0x70, 0x60, 0xe1, 0x91, 0xcd, 0x3d, 0x53, 0x8c, 0xdf, - 0xf9, 0xb6, 0x33, 0x74, 0xb5, 0xc6, 0xd9, 0x18, 0x50, 0x65, 0xec, 0x36, 0xff, 0x67, 0x8c, 0xf6, + 0xf9, 0xb6, 0x33, 0x74, 0xb5, 0xc6, 0xd9, 0x04, 0x50, 0x65, 0xec, 0x36, 0xff, 0x67, 0x8c, 0xf6, 0x01, 0xa8, 0x7d, 0xe9, 0x98, 0xde, 0x98, 0x60, 0xaa, 0xed, 0x70, 0x1f, 0x23, 0x93, 0x7a, 0x7e, - 0xc5, 0x8c, 0xa6, 0xf0, 0x6a, 0x5b, 0x55, 0xa8, 0x3f, 0xb4, 0x47, 0x1e, 0x26, 0x5a, 0xad, 0xff, - 0xf9, 0x0f, 0xe7, 0xf3, 0x30, 0x5b, 0x6c, 0x26, 0xfc, 0xf9, 0xf5, 0x16, 0xf7, 0x6b, 0x96, 0x2c, - 0xd9, 0x6c, 0xce, 0x92, 0xde, 0x4d, 0x30, 0x49, 0xc2, 0x69, 0xfe, 0xc9, 0x48, 0x8b, 0xcf, 0xca, - 0xa4, 0x29, 0xe0, 0x97, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x24, 0x97, 0x92, 0x02, 0x6e, 0x06, - 0x00, 0x00, + 0xc5, 0x8c, 0xa6, 0xf0, 0x6a, 0x5b, 0x55, 0xa8, 0x3f, 0xb4, 0x47, 0x1e, 0x26, 0x5a, 0x8d, 0x37, + 0x59, 0xd8, 0xd0, 0xd4, 0xfe, 0xe7, 0x3f, 0x9c, 0xcf, 0xc3, 0x6c, 0xb1, 0x99, 0xf0, 0xb7, 0xd8, + 0x5b, 0xdc, 0xaf, 0x59, 0xb2, 0x64, 0xb3, 0x39, 0x4b, 0x7a, 0x37, 0xc1, 0x24, 0x09, 0xa7, 0xf9, + 0xf7, 0x23, 0x2d, 0xbe, 0x31, 0x93, 0xa6, 0x80, 0x5f, 0xfe, 0x17, 0x00, 0x00, 0xff, 0xff, 0x21, + 0xa9, 0x8a, 0xec, 0x7b, 0x06, 0x00, 0x00, } diff --git a/protos/common/common.proto b/protos/common/common.proto index 2f836882cab..2a34050bfa3 100644 --- a/protos/common/common.proto +++ b/protos/common/common.proto @@ -43,11 +43,13 @@ enum HeaderType { DELIVER_SEEK_INFO = 5; // Used as the type for Envelope messages submitted to instruct the Deliver API to seek } -// This enum enlist indexes of the block metadata array +// This enum enlists indexes of the block metadata array enum BlockMetadataIndex { SIGNATURES = 0; // Block metadata array position for block signatures LAST_CONFIGURATION = 1; // Block metadata array poistion to store last configuration block sequence number TRANSACTIONS_FILTER = 2; // Block metadata array poistion to store serialized bit array filter of invalid transactions + ORDERER = 3; // Block metadata array position to store operational metadata for orderers + // e.g. For Kafka, this is where we store the last offset written to the local ledger. } // LastConfiguration is the encoded value for the Metadata message which is encoded in the LAST_CONFIGURATION block metadata index