Skip to content

Commit d3d8cc5

Browse files
committed
[FAB-6433] Pass ledger height at Persist()
This change set makes the coordinator pass the ledger height when it persists private data into the transient store. Change-Id: Id890b4ce6043b841e0d9c9db7959e01e393b2f78 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 9dadf0b commit d3d8cc5

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

gossip/privdata/coordinator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ func NewCoordinator(support Support, selfSignedData common.SignedData) Coordinat
113113

114114
// StorePvtData used to persist private date into transient store
115115
func (c *coordinator) StorePvtData(txID string, privData *rwset.TxPvtReadWriteSet) error {
116-
// TODO pass received at block height instead of 0
117-
return c.TransientStore.Persist(txID, 0, privData)
116+
height, err := c.Support.LedgerHeight()
117+
if err != nil {
118+
return errors.Wrap(err, "failed obtaining ledger height, thus cannot persist private data")
119+
}
120+
return c.TransientStore.Persist(txID, height, privData)
118121
}
119122

120123
// StoreBlock stores block with private data into the ledger
@@ -239,8 +242,9 @@ func (c *coordinator) fetchFromPeers(blockSeq uint64, ownedRWsets map[rwSetKey][
239242
}
240243
ownedRWsets[key] = rws
241244
delete(privateInfo.missingKeys, key)
242-
// TODO Pass received at block height instead of 0
243-
c.TransientStore.Persist(dig.TxId, 0, key.toTxPvtReadWriteSet(rws))
245+
// If we fetch private data that is associated to block i, then our last block persisted must be i-1
246+
// so our ledger height is i, since blocks start from 0.
247+
c.TransientStore.Persist(dig.TxId, blockSeq, key.toTxPvtReadWriteSet(rws))
244248
logger.Debug("Fetched", key)
245249
}
246250
}

gossip/privdata/coordinator_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (store *mockTransientStore) Persist(txid string, blockHeight uint64, res *r
8080
store.t.Fatal("Shouldn't have persisted", res)
8181
}
8282
delete(store.persists, key)
83-
store.Called(txid, res)
83+
store.Called(txid, blockHeight, res)
8484
return nil
8585
}
8686

@@ -163,6 +163,9 @@ func (mock *committerMock) Commit(block *common.Block) error {
163163

164164
func (mock *committerMock) LedgerHeight() (uint64, error) {
165165
args := mock.Called()
166+
if args.Get(0) == nil {
167+
return uint64(0), args.Error(1)
168+
}
166169
return args.Get(0).(uint64), args.Error(1)
167170
}
168171

@@ -787,7 +790,7 @@ func TestCoordinatorStoreBlock(t *testing.T) {
787790
Payload: [][]byte{[]byte("rws-pre-image")},
788791
},
789792
}, nil)
790-
store.On("Persist", mock.Anything, mock.Anything).
793+
store.On("Persist", mock.Anything, uint64(1), mock.Anything).
791794
expectRWSet("ns1", "c2", []byte("rws-pre-image")).
792795
expectRWSet("ns2", "c1", []byte("rws-pre-image")).Return(nil)
793796
pvtData = pdFactory.addRWSet().addNSRWSet("ns1", "c1").create()
@@ -831,7 +834,7 @@ func TestCoordinatorStoreBlock(t *testing.T) {
831834
}
832835
}).Return(nil)
833836
store.On("GetTxPvtRWSetByTxid", "tx3", mock.Anything).Return(&mockRWSetScanner{err: errors.New("uh oh")}, nil)
834-
store.On("Persist", mock.Anything, mock.Anything).expectRWSet("ns3", "c3", []byte("rws-pre-image"))
837+
store.On("Persist", mock.Anything, uint64(1), mock.Anything).expectRWSet("ns3", "c3", []byte("rws-pre-image"))
835838
committer = &committerMock{}
836839
committer.On("CommitWithPvtData", mock.Anything).Run(func(args mock.Arguments) {
837840
var privateDataPassed2Ledger privateData = args.Get(0).(*ledger.BlockAndPvtData).BlockPvtData
@@ -1032,3 +1035,30 @@ func TestCoordinatorGetBlocks(t *testing.T) {
10321035
assert.Empty(t, returnedPrivateData)
10331036
assert.Error(t, err)
10341037
}
1038+
1039+
func TestCoordinatorStorePvtData(t *testing.T) {
1040+
cs := createcollectionStore(common.SignedData{}).thatAcceptsAll()
1041+
committer := &committerMock{}
1042+
committer.On("LedgerHeight").Return(uint64(5), nil).Once()
1043+
store := &mockTransientStore{t: t}
1044+
store.On("Persist", mock.Anything, uint64(5), mock.Anything).
1045+
expectRWSet("ns1", "c1", []byte("rws-pre-image")).Return(nil)
1046+
fetcher := &fetcherMock{t: t}
1047+
coordinator := NewCoordinator(Support{
1048+
CollectionStore: cs,
1049+
Committer: committer,
1050+
Fetcher: fetcher,
1051+
TransientStore: store,
1052+
Validator: &validatorMock{},
1053+
}, common.SignedData{})
1054+
pvtData := (&pvtDataFactory{}).addRWSet().addNSRWSet("ns1", "c1").create()
1055+
// Green path: ledger height can be retrieved from ledger/committer
1056+
err := coordinator.StorePvtData("tx1", pvtData[0].WriteSet)
1057+
assert.NoError(t, err)
1058+
1059+
// Bad path: ledger height cannot be retrieved from ledger/committer
1060+
committer.On("LedgerHeight").Return(uint64(0), errors.New("I/O error: file system full"))
1061+
err = coordinator.StorePvtData("tx1", pvtData[0].WriteSet)
1062+
assert.Error(t, err)
1063+
assert.Contains(t, err.Error(), "I/O error: file system full")
1064+
}

0 commit comments

Comments
 (0)