Commit de67216c authored by Senthil Nathan N's avatar Senthil Nathan N Committed by Manish Sethi
Browse files

recon: rename CommitPvtData() ledger API



This CR renames CommitPvtData() to CommitPvtDataOfOldBlocks()
as it is more expressive.

FAB-12849 #done

Change-Id: I5feadfccb6a373314e23a92f08dc53a47ca923b7
Signed-off-by: default avatarsenthil <cendhu@gmail.com>
parent 4c7ffa33
......@@ -15,16 +15,16 @@ type PeerLedger struct {
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
CommitPvtDataStub func([]*ledgera.BlockPvtData) ([]*ledgera.PvtdataHashMismatch, error)
commitPvtDataMutex sync.RWMutex
commitPvtDataArgsForCall []struct {
CommitPvtDataOfOldBlocksStub func([]*ledgera.BlockPvtData) ([]*ledgera.PvtdataHashMismatch, error)
commitPvtDataOfOldBlocksMutex sync.RWMutex
commitPvtDataOfOldBlocksArgsForCall []struct {
arg1 []*ledgera.BlockPvtData
}
commitPvtDataReturns struct {
commitPvtDataOfOldBlocksReturns struct {
result1 []*ledgera.PvtdataHashMismatch
result2 error
}
commitPvtDataReturnsOnCall map[int]struct {
commitPvtDataOfOldBlocksReturnsOnCall map[int]struct {
result1 []*ledgera.PvtdataHashMismatch
result2 error
}
......@@ -279,69 +279,69 @@ func (fake *PeerLedger) CloseCalls(stub func()) {
fake.CloseStub = stub
}
func (fake *PeerLedger) CommitPvtData(arg1 []*ledgera.BlockPvtData) ([]*ledgera.PvtdataHashMismatch, error) {
func (fake *PeerLedger) CommitPvtDataOfOldBlocks(arg1 []*ledgera.BlockPvtData) ([]*ledgera.PvtdataHashMismatch, error) {
var arg1Copy []*ledgera.BlockPvtData
if arg1 != nil {
arg1Copy = make([]*ledgera.BlockPvtData, len(arg1))
copy(arg1Copy, arg1)
}
fake.commitPvtDataMutex.Lock()
ret, specificReturn := fake.commitPvtDataReturnsOnCall[len(fake.commitPvtDataArgsForCall)]
fake.commitPvtDataArgsForCall = append(fake.commitPvtDataArgsForCall, struct {
fake.commitPvtDataOfOldBlocksMutex.Lock()
ret, specificReturn := fake.commitPvtDataOfOldBlocksReturnsOnCall[len(fake.commitPvtDataOfOldBlocksArgsForCall)]
fake.commitPvtDataOfOldBlocksArgsForCall = append(fake.commitPvtDataOfOldBlocksArgsForCall, struct {
arg1 []*ledgera.BlockPvtData
}{arg1Copy})
fake.recordInvocation("CommitPvtData", []interface{}{arg1Copy})
fake.commitPvtDataMutex.Unlock()
if fake.CommitPvtDataStub != nil {
return fake.CommitPvtDataStub(arg1)
fake.recordInvocation("CommitPvtDataOfOldBlocks", []interface{}{arg1Copy})
fake.commitPvtDataOfOldBlocksMutex.Unlock()
if fake.CommitPvtDataOfOldBlocksStub != nil {
return fake.CommitPvtDataOfOldBlocksStub(arg1)
}
if specificReturn {
return ret.result1, ret.result2
}
fakeReturns := fake.commitPvtDataReturns
fakeReturns := fake.commitPvtDataOfOldBlocksReturns
return fakeReturns.result1, fakeReturns.result2
}
func (fake *PeerLedger) CommitPvtDataCallCount() int {
fake.commitPvtDataMutex.RLock()
defer fake.commitPvtDataMutex.RUnlock()
return len(fake.commitPvtDataArgsForCall)
func (fake *PeerLedger) CommitPvtDataOfOldBlocksCallCount() int {
fake.commitPvtDataOfOldBlocksMutex.RLock()
defer fake.commitPvtDataOfOldBlocksMutex.RUnlock()
return len(fake.commitPvtDataOfOldBlocksArgsForCall)
}
func (fake *PeerLedger) CommitPvtDataCalls(stub func([]*ledgera.BlockPvtData) ([]*ledgera.PvtdataHashMismatch, error)) {
fake.commitPvtDataMutex.Lock()
defer fake.commitPvtDataMutex.Unlock()
fake.CommitPvtDataStub = stub
func (fake *PeerLedger) CommitPvtDataOfOldBlocksCalls(stub func([]*ledgera.BlockPvtData) ([]*ledgera.PvtdataHashMismatch, error)) {
fake.commitPvtDataOfOldBlocksMutex.Lock()
defer fake.commitPvtDataOfOldBlocksMutex.Unlock()
fake.CommitPvtDataOfOldBlocksStub = stub
}
func (fake *PeerLedger) CommitPvtDataArgsForCall(i int) []*ledgera.BlockPvtData {
fake.commitPvtDataMutex.RLock()
defer fake.commitPvtDataMutex.RUnlock()
argsForCall := fake.commitPvtDataArgsForCall[i]
func (fake *PeerLedger) CommitPvtDataOfOldBlocksArgsForCall(i int) []*ledgera.BlockPvtData {
fake.commitPvtDataOfOldBlocksMutex.RLock()
defer fake.commitPvtDataOfOldBlocksMutex.RUnlock()
argsForCall := fake.commitPvtDataOfOldBlocksArgsForCall[i]
return argsForCall.arg1
}
func (fake *PeerLedger) CommitPvtDataReturns(result1 []*ledgera.PvtdataHashMismatch, result2 error) {
fake.commitPvtDataMutex.Lock()
defer fake.commitPvtDataMutex.Unlock()
fake.CommitPvtDataStub = nil
fake.commitPvtDataReturns = struct {
func (fake *PeerLedger) CommitPvtDataOfOldBlocksReturns(result1 []*ledgera.PvtdataHashMismatch, result2 error) {
fake.commitPvtDataOfOldBlocksMutex.Lock()
defer fake.commitPvtDataOfOldBlocksMutex.Unlock()
fake.CommitPvtDataOfOldBlocksStub = nil
fake.commitPvtDataOfOldBlocksReturns = struct {
result1 []*ledgera.PvtdataHashMismatch
result2 error
}{result1, result2}
}
func (fake *PeerLedger) CommitPvtDataReturnsOnCall(i int, result1 []*ledgera.PvtdataHashMismatch, result2 error) {
fake.commitPvtDataMutex.Lock()
defer fake.commitPvtDataMutex.Unlock()
fake.CommitPvtDataStub = nil
if fake.commitPvtDataReturnsOnCall == nil {
fake.commitPvtDataReturnsOnCall = make(map[int]struct {
func (fake *PeerLedger) CommitPvtDataOfOldBlocksReturnsOnCall(i int, result1 []*ledgera.PvtdataHashMismatch, result2 error) {
fake.commitPvtDataOfOldBlocksMutex.Lock()
defer fake.commitPvtDataOfOldBlocksMutex.Unlock()
fake.CommitPvtDataOfOldBlocksStub = nil
if fake.commitPvtDataOfOldBlocksReturnsOnCall == nil {
fake.commitPvtDataOfOldBlocksReturnsOnCall = make(map[int]struct {
result1 []*ledgera.PvtdataHashMismatch
result2 error
})
}
fake.commitPvtDataReturnsOnCall[i] = struct {
fake.commitPvtDataOfOldBlocksReturnsOnCall[i] = struct {
result1 []*ledgera.PvtdataHashMismatch
result2 error
}{result1, result2}
......@@ -1436,8 +1436,8 @@ func (fake *PeerLedger) Invocations() map[string][][]interface{} {
defer fake.invocationsMutex.RUnlock()
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
fake.commitPvtDataMutex.RLock()
defer fake.commitPvtDataMutex.RUnlock()
fake.commitPvtDataOfOldBlocksMutex.RLock()
defer fake.commitPvtDataOfOldBlocksMutex.RUnlock()
fake.commitWithPvtDataMutex.RLock()
defer fake.commitWithPvtDataMutex.RUnlock()
fake.getBlockByHashMutex.RLock()
......
......@@ -51,11 +51,11 @@ type Committer interface {
// GetConfigHistoryRetriever returns the ConfigHistoryRetriever
GetConfigHistoryRetriever() (ledger.ConfigHistoryRetriever, error)
// CommitPvtData commits the private data corresponding to already committed block
// CommitPvtDataOfOldBlocks commits the private data corresponding to already committed block
// If hashes for some of the private data supplied in this function does not match
// the corresponding hash present in the block, the unmatched private data is not
// committed and instead the mismatch inforation is returned back
CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error)
CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error)
// GetMissingPvtDataTracker return the MissingPvtDataTracker
GetMissingPvtDataTracker() (ledger.MissingPvtDataTracker, error)
......
......@@ -30,7 +30,7 @@ type PeerLedgerSupport interface {
CommitWithPvtData(blockAndPvtdata *ledger.BlockAndPvtData) error
CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error)
CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error)
GetBlockchainInfo() (*common.BlockchainInfo, error)
......
......@@ -113,7 +113,7 @@ func (m *mockLedger) CommitWithPvtData(blockAndPvtdata *ledger2.BlockAndPvtData)
return args.Error(0)
}
func (m *mockLedger) CommitPvtData(blockPvtData []*ledger2.BlockPvtData) ([]*ledger2.PvtdataHashMismatch, error) {
func (m *mockLedger) CommitPvtDataOfOldBlocks(blockPvtData []*ledger2.BlockPvtData) ([]*ledger2.PvtdataHashMismatch, error) {
panic("implement me")
}
......
......@@ -1627,7 +1627,7 @@ func (m *mockLedger) GetConfigHistoryRetriever() (ledger.ConfigHistoryRetriever,
return args.Get(0).(ledger.ConfigHistoryRetriever), nil
}
func (m *mockLedger) CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
func (m *mockLedger) CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
return nil, nil
}
......
......@@ -402,8 +402,7 @@ func (l *kvLedger) GetConfigHistoryRetriever() (ledger.ConfigHistoryRetriever, e
return l.configHistoryRetriever, nil
}
// TODO: FAB-12849 rename CommitPvtData() ledger API to CommitPvtDataOfOldBlocks()
func (l *kvLedger) CommitPvtData(pvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
func (l *kvLedger) CommitPvtDataOfOldBlocks(pvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
validPvtData, hashMismatches, err := ConstructValidAndInvalidPvtData(pvtData, l.blockStore)
if err != nil {
return nil, err
......
......@@ -87,11 +87,11 @@ type PeerLedger interface {
Prune(policy commonledger.PrunePolicy) error
// GetConfigHistoryRetriever returns the ConfigHistoryRetriever
GetConfigHistoryRetriever() (ConfigHistoryRetriever, error)
// CommitPvtData commits the private data corresponding to already committed block
// CommitPvtDataOfOldBlocks commits the private data corresponding to already committed block
// If hashes for some of the private data supplied in this function does not match
// the corresponding hash present in the block, the unmatched private data is not
// committed and instead the mismatch inforation is returned back
CommitPvtData(blockPvtData []*BlockPvtData) ([]*PvtdataHashMismatch, error)
CommitPvtDataOfOldBlocks(blockPvtData []*BlockPvtData) ([]*PvtdataHashMismatch, error)
// GetMissingPvtDataTracker return the MissingPvtDataTracker
GetMissingPvtDataTracker() (MissingPvtDataTracker, error)
}
......
......@@ -221,7 +221,7 @@ func (mock *committerMock) CommitWithPvtData(blockAndPvtData *ledger.BlockAndPvt
return args.Error(0)
}
func (mock *committerMock) CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
func (mock *committerMock) CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
args := mock.Called(blockPvtData)
return args.Get(0).([]*ledger.PvtdataHashMismatch), args.Error(1)
}
......
......@@ -176,7 +176,7 @@ func (r *Reconciler) reconcile() (int, uint64, uint64, error) {
pvtDataToCommit := r.preparePvtDataToCommit(fetchedData.AvailableElements)
// commit missing private data that was reconciled and log mismatched
pvtdataHashMismatch, err := r.CommitPvtData(pvtDataToCommit)
pvtdataHashMismatch, err := r.CommitPvtDataOfOldBlocks(pvtDataToCommit)
r.logMismatched(pvtdataHashMismatch)
if err != nil {
return 0, 0, 0, errors.Wrap(err, "failed to commit private data")
......
......@@ -133,25 +133,25 @@ func TestReconciliationHappyPathWithoutScheduler(t *testing.T) {
}
}).Return(result, nil)
var commitPvtDataHappened bool
var commitPvtDataOfOldBlocksHappened bool
var blockNum, seqInBlock uint64
blockNum = 3
seqInBlock = 1
committer.On("CommitPvtData", mock.Anything).Run(func(args mock.Arguments) {
committer.On("CommitPvtDataOfOldBlocks", mock.Anything).Run(func(args mock.Arguments) {
var blockPvtData = args.Get(0).([]*ledger.BlockPvtData)
assert.Equal(t, 1, len(blockPvtData))
assert.Equal(t, blockNum, blockPvtData[0].BlockNum)
assert.Equal(t, seqInBlock, blockPvtData[0].WriteSets[1].SeqInBlock)
assert.Equal(t, "ns1", blockPvtData[0].WriteSets[1].WriteSet.NsPvtRwset[0].Namespace)
assert.Equal(t, "col1", blockPvtData[0].WriteSets[1].WriteSet.NsPvtRwset[0].CollectionPvtRwset[0].CollectionName)
commitPvtDataHappened = true
commitPvtDataOfOldBlocksHappened = true
}).Return([]*ledger.PvtdataHashMismatch{}, nil)
r := &Reconciler{config: &ReconcilerConfig{sleepInterval: time.Minute, batchSize: 1, IsEnabled: true}, ReconciliationFetcher: fetcher, Committer: committer}
_, _, _, err := r.reconcile()
assert.NoError(t, err)
assert.True(t, commitPvtDataHappened)
assert.True(t, commitPvtDataOfOldBlocksHappened)
}
func TestReconciliationHappyPathWithScheduler(t *testing.T) {
......@@ -209,18 +209,18 @@ func TestReconciliationHappyPathWithScheduler(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
var commitPvtDataHappened bool
var commitPvtDataOfOldBlocksHappened bool
var blockNum, seqInBlock uint64
blockNum = 3
seqInBlock = 1
committer.On("CommitPvtData", mock.Anything).Run(func(args mock.Arguments) {
committer.On("CommitPvtDataOfOldBlocks", mock.Anything).Run(func(args mock.Arguments) {
var blockPvtData = args.Get(0).([]*ledger.BlockPvtData)
assert.Equal(t, 1, len(blockPvtData))
assert.Equal(t, blockNum, blockPvtData[0].BlockNum)
assert.Equal(t, seqInBlock, blockPvtData[0].WriteSets[1].SeqInBlock)
assert.Equal(t, "ns1", blockPvtData[0].WriteSets[1].WriteSet.NsPvtRwset[0].Namespace)
assert.Equal(t, "col1", blockPvtData[0].WriteSets[1].WriteSet.NsPvtRwset[0].CollectionPvtRwset[0].CollectionName)
commitPvtDataHappened = true
commitPvtDataOfOldBlocksHappened = true
wg.Done()
}).Return([]*ledger.PvtdataHashMismatch{}, nil)
......@@ -229,5 +229,5 @@ func TestReconciliationHappyPathWithScheduler(t *testing.T) {
wg.Wait()
r.Stop()
assert.True(t, commitPvtDataHappened)
assert.True(t, commitPvtDataOfOldBlocksHappened)
}
......@@ -352,7 +352,7 @@ func (li *mockLedgerInfo) CommitWithPvtData(blockAndPvtData *ledger.BlockAndPvtD
panic("implement me")
}
func (li *mockLedgerInfo) CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
func (li *mockLedgerInfo) CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
panic("implement me")
}
......
......@@ -241,7 +241,7 @@ func (*mockCommitter) GetMissingPvtDataTracker() (ledger.MissingPvtDataTracker,
panic("implement me")
}
func (*mockCommitter) CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
func (*mockCommitter) CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
panic("implement me")
}
......@@ -257,7 +257,7 @@ func (mock *ramLedger) GetMissingPvtDataTracker() (ledger.MissingPvtDataTracker,
panic("implement me")
}
func (mock *ramLedger) CommitPvtData(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
func (mock *ramLedger) CommitPvtDataOfOldBlocks(blockPvtData []*ledger.BlockPvtData) ([]*ledger.PvtdataHashMismatch, error) {
panic("implement me")
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment