Skip to content

Commit 534a029

Browse files
committed
[FAB-10248] add ledger height while sending pvt tx
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>
1 parent b959477 commit 534a029

File tree

6 files changed

+70
-27
lines changed

6 files changed

+70
-27
lines changed

core/endorser/endorser.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ type Support interface {
8383

8484
// EndorseWithPlugin endorses the response with a plugin
8585
EndorseWithPlugin(ctx Context) (*pb.ProposalResponse, error)
86+
87+
// GetLedgerHeight returns ledger height for given channelID
88+
GetLedgerHeight(channelID string) (uint64, error)
8689
}
8790

8891
// Endorser provides the Endorser service ProcessProposal
@@ -285,6 +288,12 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
285288
if err != nil {
286289
return nil, nil, nil, nil, errors.WithMessage(err, "failed to obtain collections config")
287290
}
291+
endosedAt, err := e.s.GetLedgerHeight(chainID)
292+
if err != nil {
293+
return nil, nil, nil, nil, errors.WithMessage(err, fmt.Sprint("failed to obtain ledger height for channel", chainID))
294+
}
295+
// Add ledger height at which transaction was endorsed
296+
pvtDataWithConfig.EndorsedAt = endosedAt
288297
if err := e.distributePrivateData(chainID, txid, pvtDataWithConfig, simResult.SimulationBlkHt); err != nil {
289298
return nil, nil, nil, nil, err
290299
}

core/endorser/support.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package endorser
88

99
import (
10+
"fmt"
11+
1012
"github.com/hyperledger/fabric/common/channelconfig"
1113
"github.com/hyperledger/fabric/common/crypto"
1214
"github.com/hyperledger/fabric/core/aclmgmt"
@@ -89,6 +91,21 @@ func (s *SupportImpl) GetTransactionByID(chid, txID string) (*pb.ProcessedTransa
8991
return tx, nil
9092
}
9193

94+
// GetLedgerHeight returns ledger height for given channelID
95+
func (s *SupportImpl) GetLedgerHeight(channelID string) (uint64, error) {
96+
lgr := s.Peer.GetLedger(channelID)
97+
if lgr == nil {
98+
return 0, errors.Errorf("failed to look up the ledger for Channel %s", channelID)
99+
}
100+
101+
info, err := lgr.GetBlockchainInfo()
102+
if err != nil {
103+
return 0, errors.Wrap(err, fmt.Sprintf("failed to obtain information for Channel %s", channelID))
104+
}
105+
106+
return info.Height, nil
107+
}
108+
92109
// IsSysCC returns true if the name matches a system chaincode's
93110
// system chaincode names are system, chain wide
94111
func (s *SupportImpl) IsSysCC(name string) bool {

core/mocks/endorser/support.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ func (s *MockSupport) GetTransactionByID(chid, txID string) (*pb.ProcessedTransa
7777
return nil, s.GetTransactionByIDErr
7878
}
7979

80+
func (s *MockSupport) GetLedgerHeight(channelID string) (uint64, error) {
81+
args := s.Called(channelID)
82+
return args.Get(0).(uint64), args.Error(1)
83+
}
84+
8085
func (s *MockSupport) IsSysCC(name string) bool {
8186
if s.SysCCMap != nil {
8287
_, in := s.SysCCMap[name]

gossip/privdata/dataretriever.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func (dr *dataRetriever) fromTransientStore(dig *gossip2.PvtDataDigest, filter m
136136
}
137137
defer it.Close()
138138

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

173174
pvtRWSet := dr.extractPvtRWsets(txPvtRWSet.NsPvtRwset, dig.Namespace, dig.Collection)
174-
// TODO: Next CR will extend TxPvtReadWriteSetWithConfigInfo to have ledger height of
175-
// endorsement time to be used here in order to select most updated collection config.
176-
results.CollectionConfig = configs
175+
if rws.EndorsedAt >= maxEndorsedAt {
176+
maxEndorsedAt = rws.EndorsedAt
177+
results.CollectionConfig = configs
178+
}
177179
results.RWSet = append(results.RWSet, pvtRWSet...)
178180
}
179181
}

protos/transientstore/transientstore.pb.go

Lines changed: 31 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/transientstore/transientstore.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import "common/collection.proto";
2929
// read-write set and additional information about the configurations such as
3030
// the latest collection config when the transaction is simulated
3131
message TxPvtReadWriteSetWithConfigInfo {
32-
rwset.TxPvtReadWriteSet pvt_rwset = 1;
33-
map<string, common.CollectionConfigPackage> collection_configs = 2;
32+
uint64 endorsed_at = 1;
33+
rwset.TxPvtReadWriteSet pvt_rwset = 2;
34+
map<string, common.CollectionConfigPackage> collection_configs = 3;
3435
}

0 commit comments

Comments
 (0)