@@ -28,6 +28,7 @@ import (
2828	"github.com/hyperledger/fabric-x-orderer/node/consensus/badb" 
2929	"github.com/hyperledger/fabric-x-orderer/node/consensus/state" 
3030	"github.com/hyperledger/fabric-x-orderer/node/delivery" 
31+ 	"github.com/hyperledger/fabric-x-orderer/node/ledger" 
3132	protos "github.com/hyperledger/fabric-x-orderer/node/protos/comm" 
3233	"github.com/hyperledger/fabric/protoutil" 
3334	"github.com/pkg/errors" 
@@ -244,6 +245,19 @@ func (c *Consensus) VerifyProposal(proposal smartbft_types.Proposal) ([]smartbft
244245			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 )
245246		}
246247
248+ 		blockMetadata , err  :=  ledger .AssemblerBlockMetadataToBytes (ba [0 ], & state.OrderingInformation {DecisionNum : arma_types .DecisionNum (md .LatestSequence ), BatchCount : len (attestations ), BatchIndex : i }, 0 )
249+ 		if  err  !=  nil  {
250+ 			c .Logger .Panicf ("Failed to invoke AssemblerBlockMetadataToBytes: %s" , err )
251+ 		}
252+ 
253+ 		if  hdr .AvailableCommonBlocks [i ].Metadata  ==  nil  ||  hdr .AvailableCommonBlocks [i ].Metadata .Metadata  ==  nil  {
254+ 			return  nil , fmt .Errorf ("proposed common block metadata in index %d is nil" , i )
255+ 		}
256+ 
257+ 		if  ! bytes .Equal (blockMetadata , hdr .AvailableCommonBlocks [i ].Metadata .Metadata [common .BlockMetadataIndex_ORDERER ]) {
258+ 			return  nil , fmt .Errorf ("proposed common block metadata in index %d isn't equal to computed metadata" , i )
259+ 		}
260+ 
247261	}
248262
249263	for  i , availableBlock  :=  range  hdr .AvailableBlocks  {
@@ -325,7 +339,7 @@ func (c *Consensus) VerifySignature(signature smartbft_types.Signature) error {
325339// VerificationSequence returns the current verification sequence 
326340// (from SmartBFT API) 
327341func  (c  * Consensus ) VerificationSequence () uint64  {
328- 	return  0 
342+ 	return  0   // TODO save current verification sequence and return it here 
329343}
330344
331345// RequestsFromProposal returns from the given proposal the included requests' info 
@@ -448,6 +462,11 @@ func (c *Consensus) AssembleProposal(metadata []byte, requests [][]byte) smartbf
448462	lastBlockNumber  :=  lastCommonBlockHeader .Number 
449463	prevHash  :=  protoutil .BlockHeaderHash (lastCommonBlockHeader )
450464
465+ 	md  :=  & smartbftprotos.ViewMetadata {}
466+ 	if  err  :=  proto .Unmarshal (metadata , md ); err  !=  nil  {
467+ 		panic (err )
468+ 	}
469+ 
451470	c .Logger .Infof ("Creating proposal with %d attestations" , len (attestations ))
452471
453472	availableBlocks  :=  make ([]state.AvailableBlock , len (attestations ))
@@ -463,6 +482,12 @@ func (c *Consensus) AssembleProposal(metadata []byte, requests [][]byte) smartbf
463482		lastBlockNumber ++ 
464483		availableCommonBlocks [i ] =  protoutil .NewBlock (lastBlockNumber , prevHash )
465484		availableCommonBlocks [i ].Header .DataHash  =  ba [0 ].Digest ()
485+ 		blockMetadata , err  :=  ledger .AssemblerBlockMetadataToBytes (ba [0 ], & state.OrderingInformation {DecisionNum : arma_types .DecisionNum (md .LatestSequence ), BatchCount : len (attestations ), BatchIndex : i }, 0 )
486+ 		if  err  !=  nil  {
487+ 			c .Logger .Panicf ("Failed to invoke AssemblerBlockMetadataToBytes: %s" , err )
488+ 		}
489+ 		protoutil .InitBlockMetadata (availableCommonBlocks [i ])
490+ 		availableCommonBlocks [i ].Metadata .Metadata [common .BlockMetadataIndex_ORDERER ] =  blockMetadata 
466491		hdr .Number  =  lastBlockNumber 
467492		hdr .PrevHash  =  prevHash 
468493		prevHash  =  protoutil .BlockHeaderHash (availableCommonBlocks [i ].Header )
@@ -473,11 +498,6 @@ func (c *Consensus) AssembleProposal(metadata []byte, requests [][]byte) smartbf
473498		newState .AppContext  =  protoutil .MarshalOrPanic (availableCommonBlocks [len (attestations )- 1 ].Header )
474499	}
475500
476- 	md  :=  & smartbftprotos.ViewMetadata {}
477- 	if  err  :=  proto .Unmarshal (metadata , md ); err  !=  nil  {
478- 		panic (err )
479- 	}
480- 
481501	reqs  :=  arma_types .BatchedRequests (requests )
482502
483503	return  smartbft_types.Proposal {
0 commit comments