Skip to content

Commit

Permalink
[FAB-10248] add ledger height while sending pvt tx
Browse files Browse the repository at this point in the history
While answering pull message for missing private data we need to
distiguish and choose most recent collection configuration. This commits
adds ledger height while distributing pvt with collection config, hence
while answering pull request we can pick most updated one.

Change-Id: Id50e0e9e8910f33f154cd95f7adc84dc91deb28b
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed May 21, 2018
1 parent b959477 commit 534a029
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 27 deletions.
9 changes: 9 additions & 0 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type Support interface {

// EndorseWithPlugin endorses the response with a plugin
EndorseWithPlugin(ctx Context) (*pb.ProposalResponse, error)

// GetLedgerHeight returns ledger height for given channelID
GetLedgerHeight(channelID string) (uint64, error)
}

// Endorser provides the Endorser service ProcessProposal
Expand Down Expand Up @@ -285,6 +288,12 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
if err != nil {
return nil, nil, nil, nil, errors.WithMessage(err, "failed to obtain collections config")
}
endosedAt, err := e.s.GetLedgerHeight(chainID)
if err != nil {
return nil, nil, nil, nil, errors.WithMessage(err, fmt.Sprint("failed to obtain ledger height for channel", chainID))
}
// Add ledger height at which transaction was endorsed
pvtDataWithConfig.EndorsedAt = endosedAt
if err := e.distributePrivateData(chainID, txid, pvtDataWithConfig, simResult.SimulationBlkHt); err != nil {
return nil, nil, nil, nil, err
}
Expand Down
17 changes: 17 additions & 0 deletions core/endorser/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package endorser

import (
"fmt"

"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/core/aclmgmt"
Expand Down Expand Up @@ -89,6 +91,21 @@ func (s *SupportImpl) GetTransactionByID(chid, txID string) (*pb.ProcessedTransa
return tx, nil
}

// GetLedgerHeight returns ledger height for given channelID
func (s *SupportImpl) GetLedgerHeight(channelID string) (uint64, error) {
lgr := s.Peer.GetLedger(channelID)
if lgr == nil {
return 0, errors.Errorf("failed to look up the ledger for Channel %s", channelID)
}

info, err := lgr.GetBlockchainInfo()
if err != nil {
return 0, errors.Wrap(err, fmt.Sprintf("failed to obtain information for Channel %s", channelID))
}

return info.Height, nil
}

// IsSysCC returns true if the name matches a system chaincode's
// system chaincode names are system, chain wide
func (s *SupportImpl) IsSysCC(name string) bool {
Expand Down
5 changes: 5 additions & 0 deletions core/mocks/endorser/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (s *MockSupport) GetTransactionByID(chid, txID string) (*pb.ProcessedTransa
return nil, s.GetTransactionByIDErr
}

func (s *MockSupport) GetLedgerHeight(channelID string) (uint64, error) {
args := s.Called(channelID)
return args.Get(0).(uint64), args.Error(1)
}

func (s *MockSupport) IsSysCC(name string) bool {
if s.SysCCMap != nil {
_, in := s.SysCCMap[name]
Expand Down
8 changes: 5 additions & 3 deletions gossip/privdata/dataretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (dr *dataRetriever) fromTransientStore(dig *gossip2.PvtDataDigest, filter m
}
defer it.Close()

maxEndorsedAt := uint64(0)
for {
res, err := it.NextWithConfig()
if err != nil {
Expand Down Expand Up @@ -171,9 +172,10 @@ func (dr *dataRetriever) fromTransientStore(dig *gossip2.PvtDataDigest, filter m
}

pvtRWSet := dr.extractPvtRWsets(txPvtRWSet.NsPvtRwset, dig.Namespace, dig.Collection)
// TODO: Next CR will extend TxPvtReadWriteSetWithConfigInfo to have ledger height of
// endorsement time to be used here in order to select most updated collection config.
results.CollectionConfig = configs
if rws.EndorsedAt >= maxEndorsedAt {
maxEndorsedAt = rws.EndorsedAt
results.CollectionConfig = configs
}
results.RWSet = append(results.RWSet, pvtRWSet...)
}
}
Expand Down
53 changes: 31 additions & 22 deletions protos/transientstore/transientstore.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions protos/transientstore/transientstore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import "common/collection.proto";
// read-write set and additional information about the configurations such as
// the latest collection config when the transaction is simulated
message TxPvtReadWriteSetWithConfigInfo {
rwset.TxPvtReadWriteSet pvt_rwset = 1;
map<string, common.CollectionConfigPackage> collection_configs = 2;
uint64 endorsed_at = 1;
rwset.TxPvtReadWriteSet pvt_rwset = 2;
map<string, common.CollectionConfigPackage> collection_configs = 3;
}

0 comments on commit 534a029

Please sign in to comment.