-
Couldn't load subscription status.
- Fork 9
add metadata to common block #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e1a5fb4
97625d2
82df2e1
2667ce3
5a247f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import ( | |
| "github.com/hyperledger/fabric-x-orderer/node/consensus/badb" | ||
| "github.com/hyperledger/fabric-x-orderer/node/consensus/state" | ||
| "github.com/hyperledger/fabric-x-orderer/node/delivery" | ||
| "github.com/hyperledger/fabric-x-orderer/node/ledger" | ||
| protos "github.com/hyperledger/fabric-x-orderer/node/protos/comm" | ||
| "github.com/hyperledger/fabric/protoutil" | ||
| "github.com/pkg/errors" | ||
|
|
@@ -244,6 +245,19 @@ func (c *Consensus) VerifyProposal(proposal smartbft_types.Proposal) ([]smartbft | |
| return nil, fmt.Errorf("proposed common block header number %d in index %d isn't equal to computed number %d", hdr.AvailableCommonBlocks[i].Header.Number, i, lastBlockNumber) | ||
| } | ||
|
|
||
| blockMetadata, err := ledger.AssemblerBlockMetadataToBytes(ba[0], &state.OrderingInformation{DecisionNum: arma_types.DecisionNum(md.LatestSequence), BatchCount: len(attestations), BatchIndex: i}, 0) | ||
| if err != nil { | ||
| c.Logger.Panicf("Failed to invoke AssemblerBlockMetadataToBytes: %s", err) | ||
| } | ||
|
|
||
| if hdr.AvailableCommonBlocks[i].Metadata == nil || hdr.AvailableCommonBlocks[i].Metadata.Metadata == nil { | ||
| return nil, fmt.Errorf("proposed common block metadata in index %d is nil", i) | ||
| } | ||
|
|
||
| if !bytes.Equal(blockMetadata, hdr.AvailableCommonBlocks[i].Metadata.Metadata[common.BlockMetadataIndex_ORDERER]) { | ||
| return nil, fmt.Errorf("proposed common block metadata in index %d isn't equal to computed metadata", i) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| for i, availableBlock := range hdr.AvailableBlocks { | ||
|
|
@@ -325,7 +339,7 @@ func (c *Consensus) VerifySignature(signature smartbft_types.Signature) error { | |
| // VerificationSequence returns the current verification sequence | ||
| // (from SmartBFT API) | ||
| func (c *Consensus) VerificationSequence() uint64 { | ||
| return 0 | ||
| return 0 // TODO save current verification sequence and return it here | ||
| } | ||
|
|
||
| // RequestsFromProposal returns from the given proposal the included requests' info | ||
|
|
@@ -448,6 +462,11 @@ func (c *Consensus) AssembleProposal(metadata []byte, requests [][]byte) smartbf | |
| lastBlockNumber := lastCommonBlockHeader.Number | ||
| prevHash := protoutil.BlockHeaderHash(lastCommonBlockHeader) | ||
|
|
||
| md := &smartbftprotos.ViewMetadata{} | ||
| if err := proto.Unmarshal(metadata, md); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| c.Logger.Infof("Creating proposal with %d attestations", len(attestations)) | ||
|
|
||
| availableBlocks := make([]state.AvailableBlock, len(attestations)) | ||
|
|
@@ -463,6 +482,12 @@ func (c *Consensus) AssembleProposal(metadata []byte, requests [][]byte) smartbf | |
| lastBlockNumber++ | ||
| availableCommonBlocks[i] = protoutil.NewBlock(lastBlockNumber, prevHash) | ||
| availableCommonBlocks[i].Header.DataHash = ba[0].Digest() | ||
| blockMetadata, err := ledger.AssemblerBlockMetadataToBytes(ba[0], &state.OrderingInformation{DecisionNum: arma_types.DecisionNum(md.LatestSequence), BatchCount: len(attestations), BatchIndex: i}, 0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here - TX count There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. next PR |
||
| if err != nil { | ||
| c.Logger.Panicf("Failed to invoke AssemblerBlockMetadataToBytes: %s", err) | ||
| } | ||
| protoutil.InitBlockMetadata(availableCommonBlocks[i]) | ||
| availableCommonBlocks[i].Metadata.Metadata[common.BlockMetadataIndex_ORDERER] = blockMetadata | ||
| hdr.Number = lastBlockNumber | ||
| hdr.PrevHash = prevHash | ||
| prevHash = protoutil.BlockHeaderHash(availableCommonBlocks[i].Header) | ||
|
|
@@ -473,11 +498,6 @@ func (c *Consensus) AssembleProposal(metadata []byte, requests [][]byte) smartbf | |
| newState.AppContext = protoutil.MarshalOrPanic(availableCommonBlocks[len(attestations)-1].Header) | ||
| } | ||
|
|
||
| md := &smartbftprotos.ViewMetadata{} | ||
| if err := proto.Unmarshal(metadata, md); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| reqs := arma_types.BatchedRequests(requests) | ||
|
|
||
| return smartbft_types.Proposal{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,19 +111,26 @@ func (cr *ConsensusBAReplicator) Replicate() <-chan types.OrderedBatchAttestatio | |
| cr.logger.Panicf("Failed extracting ordered batch attestation from decision: %s", err2) | ||
| } | ||
|
|
||
| cr.logger.Infof("Decision %d, with %d AvailableBlocks", block.GetHeader().GetNumber(), len(header.AvailableBlocks)) | ||
| for index, ab := range header.AvailableBlocks { | ||
| cr.logger.Infof("BA index: %d; BatchID: %s; BA block header: %s; BA block signers: %+v", index, types.BatchIDToString(ab.Batch), ab.Header.String(), signersFromSigs(sigs[index])) | ||
| cr.logger.Infof("Decision %d, with %d AvailableCommonBlocks", block.GetHeader().GetNumber(), len(header.AvailableCommonBlocks)) | ||
| for index, acb := range header.AvailableCommonBlocks { | ||
|
|
||
| primary, shard, seq, _, _, _, _, err := ledger.AssemblerBlockMetadataFromBytes(acb.Metadata.Metadata[common.BlockMetadataIndex_ORDERER]) | ||
| if err != nil { | ||
| cr.logger.Panicf("Failed extracting info from metadata: %s", err) | ||
| } | ||
|
|
||
| acbBatch := state.NewAvailableBatch(primary, shard, seq, acb.Header.DataHash) | ||
|
Comment on lines
+117
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably bundle this into a method "AssemblerBatchIDFromBlock" and put it in utils... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next PR |
||
|
|
||
| cr.logger.Infof("BA index: %d; BatchID: %s; Common Block: %s; BA block signers: %+v", index, types.BatchIDToString(acbBatch), types.CommonBlockToString(acb), signersFromSigs(sigs[index])) | ||
|
|
||
| abo := &state.AvailableBatchOrdered{ | ||
| AvailableBatch: ab.Batch, | ||
| AvailableBatch: acbBatch, | ||
| OrderingInformation: &state.OrderingInformation{ | ||
| CommonBlock: header.AvailableCommonBlocks[index], | ||
| BlockHeader: ab.Header, | ||
| Signatures: sigs[index], | ||
| DecisionNum: header.Num, | ||
| BatchIndex: index, | ||
| BatchCount: len(header.AvailableBlocks), | ||
| BatchCount: len(header.AvailableCommonBlocks), | ||
| }, | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculate the TX count, or tests will break when you switch to use this metadata instead of creating it in the assembler.
In addition, right now we are not signing the metadata when we sign the block, but in fabric they do. One more reason to have the orderer metadata computed correctly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add this in the next PR