diff --git a/common/ledger/blkstorage/blockfile_mgr.go b/common/ledger/blkstorage/blockfile_mgr.go index 22cb29bee7f..12815742f6b 100644 --- a/common/ledger/blkstorage/blockfile_mgr.go +++ b/common/ledger/blkstorage/blockfile_mgr.go @@ -544,15 +544,15 @@ func (mgr *blockfileMgr) retrieveBlockByTxID(txID string) (*common.Block, error) return mgr.fetchBlock(loc) } -func (mgr *blockfileMgr) retrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) { +func (mgr *blockfileMgr) retrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, uint64, error) { logger.Debugf("retrieveTxValidationCodeByTxID() - txID = [%s]", txID) - validationCode, err := mgr.index.getTxValidationCodeByTxID(txID) + validationCode, blkNum, err := mgr.index.getTxValidationCodeByTxID(txID) if err == errNilValue { - return peer.TxValidationCode(-1), errors.Errorf( + return peer.TxValidationCode(-1), 0, errors.Errorf( "details for the TXID [%s] not available. Ledger bootstrapped from a snapshot. First available block = [%d]", txID, mgr.firstPossibleBlockNumberInBlockFiles()) } - return validationCode, err + return validationCode, blkNum, err } func (mgr *blockfileMgr) retrieveBlockHeaderByNumber(blockNum uint64) (*common.BlockHeader, error) { diff --git a/common/ledger/blkstorage/blockfile_mgr_test.go b/common/ledger/blkstorage/blockfile_mgr_test.go index de74018fafe..a091ca8dfdc 100644 --- a/common/ledger/blkstorage/blockfile_mgr_test.go +++ b/common/ledger/blkstorage/blockfile_mgr_test.go @@ -294,12 +294,15 @@ func TestBlockfileMgrGetTxByIdDuplicateTxid(t *testing.T) { blk, _ = blkFileMgr.retrieveBlockByTxID("txid-3") require.Equal(t, block2, blk) - validationCode, _ := blkFileMgr.retrieveTxValidationCodeByTxID("txid-1") + validationCode, blkNum, _ := blkFileMgr.retrieveTxValidationCodeByTxID("txid-1") require.Equal(t, peer.TxValidationCode_VALID, validationCode) - validationCode, _ = blkFileMgr.retrieveTxValidationCodeByTxID("txid-2") + require.Equal(t, uint64(1), blkNum) + validationCode, blkNum, _ = blkFileMgr.retrieveTxValidationCodeByTxID("txid-2") require.Equal(t, peer.TxValidationCode_INVALID_OTHER_REASON, validationCode) - validationCode, _ = blkFileMgr.retrieveTxValidationCodeByTxID("txid-3") + require.Equal(t, uint64(1), blkNum) + validationCode, blkNum, _ = blkFileMgr.retrieveTxValidationCodeByTxID("txid-3") require.Equal(t, peer.TxValidationCode_VALID, validationCode) + require.Equal(t, uint64(2), blkNum) // though we do not expose an API for retrieving all the txs by same id but we may in future // and the data is persisted to support this. below code tests this behavior internally diff --git a/common/ledger/blkstorage/blockindex.go b/common/ledger/blkstorage/blockindex.go index cf57e89862c..a9ef014c7b7 100644 --- a/common/ledger/blkstorage/blockindex.go +++ b/common/ledger/blkstorage/blockindex.go @@ -196,7 +196,7 @@ func (index *blockIndex) getBlockLocByBlockNum(blockNum uint64) (*fileLocPointer } func (index *blockIndex) getTxLoc(txID string) (*fileLocPointer, error) { - v, err := index.getTxIDVal(txID) + v, _, err := index.getTxIDVal(txID) if err != nil { return nil, err } @@ -208,7 +208,7 @@ func (index *blockIndex) getTxLoc(txID string) (*fileLocPointer, error) { } func (index *blockIndex) getBlockLocByTxID(txID string) (*fileLocPointer, error) { - v, err := index.getTxIDVal(txID) + v, _, err := index.getTxIDVal(txID) if err != nil { return nil, err } @@ -219,12 +219,12 @@ func (index *blockIndex) getBlockLocByTxID(txID string) (*fileLocPointer, error) return blkFLP, nil } -func (index *blockIndex) getTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) { - v, err := index.getTxIDVal(txID) +func (index *blockIndex) getTxValidationCodeByTxID(txID string) (peer.TxValidationCode, uint64, error) { + v, blkNum, err := index.getTxIDVal(txID) if err != nil { - return peer.TxValidationCode(-1), err + return peer.TxValidationCode(-1), 0, err } - return peer.TxValidationCode(v.TxValidationCode), nil + return peer.TxValidationCode(v.TxValidationCode), blkNum, nil } func (index *blockIndex) txIDExists(txID string) (bool, error) { @@ -245,33 +245,37 @@ func (index *blockIndex) txIDExists(txID string) (bool, error) { return present, nil } -func (index *blockIndex) getTxIDVal(txID string) (*TxIDIndexValue, error) { +func (index *blockIndex) getTxIDVal(txID string) (*TxIDIndexValue, uint64, error) { if !index.isAttributeIndexed(IndexableAttrTxID) { - return nil, errors.New("transaction IDs not maintained in index") + return nil, 0, errors.New("transaction IDs not maintained in index") } rangeScan := constructTxIDRangeScan(txID) itr, err := index.db.GetIterator(rangeScan.startKey, rangeScan.stopKey) if err != nil { - return nil, errors.WithMessagef(err, "error while trying to retrieve transaction info by TXID [%s]", txID) + return nil, 0, errors.WithMessagef(err, "error while trying to retrieve transaction info by TXID [%s]", txID) } defer itr.Release() present := itr.Next() if err := itr.Error(); err != nil { - return nil, errors.Wrapf(err, "error while trying to retrieve transaction info by TXID [%s]", txID) + return nil, 0, errors.Wrapf(err, "error while trying to retrieve transaction info by TXID [%s]", txID) } if !present { - return nil, errors.Errorf("no such transaction ID [%s] in index", txID) + return nil, 0, errors.Errorf("no such transaction ID [%s] in index", txID) } valBytes := itr.Value() if len(valBytes) == 0 { - return nil, errNilValue + return nil, 0, errNilValue } val := &TxIDIndexValue{} if err := proto.Unmarshal(valBytes, val); err != nil { - return nil, errors.Wrapf(err, "unexpected error while unmarshalling bytes [%#v] into TxIDIndexValProto", valBytes) + return nil, 0, errors.Wrapf(err, "unexpected error while unmarshalling bytes [%#v] into TxIDIndexValProto", valBytes) + } + blockNum, err := retrieveBlockNum(itr.Key(), len(rangeScan.startKey)) + if err != nil { + return nil, 0, errors.WithMessage(err, "error while decoding block number from txID index key") } - return val, nil + return val, blockNum, nil } func (index *blockIndex) getTXLocByBlockNumTranNum(blockNum uint64, tranNum uint64) (*fileLocPointer, error) { @@ -444,6 +448,11 @@ func retrieveTxID(encodedTxIDKey []byte) (string, error) { return string(remainingBytes[:int(txIDLen)]), nil } +func retrieveBlockNum(encodedTxIDKey []byte, BlkNumStartingIndex int) (uint64, error) { + n, _, err := util.DecodeOrderPreservingVarUint64(encodedTxIDKey[BlkNumStartingIndex:]) + return n, err +} + type rangeScan struct { startKey []byte stopKey []byte diff --git a/common/ledger/blkstorage/blockindex_test.go b/common/ledger/blkstorage/blockindex_test.go index da9f0cf2910..5ddfe63346c 100644 --- a/common/ledger/blkstorage/blockindex_test.go +++ b/common/ledger/blkstorage/blockindex_test.go @@ -189,12 +189,13 @@ func testBlockIndexSelectiveIndexing(t *testing.T, indexItems []IndexableAttr) { txid, err = protoutil.GetOrComputeTxIDFromEnvelope(d) require.NoError(t, err) - reason, err := blockfileMgr.retrieveTxValidationCodeByTxID(txid) + reason, blkNum, err := blockfileMgr.retrieveTxValidationCodeByTxID(txid) if containsAttr(indexItems, IndexableAttrTxID) { require.NoError(t, err) reasonFromFlags := flags.Flag(idx) require.Equal(t, reasonFromFlags, reason) + require.Equal(t, block.Header.Number, blkNum) } else { require.EqualError(t, err, "transaction IDs not maintained in index") } diff --git a/common/ledger/blkstorage/blockstore.go b/common/ledger/blkstorage/blockstore.go index 553cd30f8ff..d7b32c6540f 100644 --- a/common/ledger/blkstorage/blockstore.go +++ b/common/ledger/blkstorage/blockstore.go @@ -93,7 +93,7 @@ func (store *BlockStore) RetrieveBlockByTxID(txID string) (*common.Block, error) } // RetrieveTxValidationCodeByTxID returns the validation code for the specified txID -func (store *BlockStore) RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) { +func (store *BlockStore) RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, uint64, error) { return store.fileMgr.retrieveTxValidationCodeByTxID(txID) } diff --git a/common/ledger/blkstorage/blockstore_provider_test.go b/common/ledger/blkstorage/blockstore_provider_test.go index a2ebb87e136..e4cb1b52768 100644 --- a/common/ledger/blkstorage/blockstore_provider_test.go +++ b/common/ledger/blkstorage/blockstore_provider_test.go @@ -130,9 +130,10 @@ func checkBlocks(t *testing.T, expectedBlocks []*common.Block, store *BlockStore retrievedTxEnv, _ = store.RetrieveTxByBlockNumTranNum(uint64(blockNum), uint64(txNum)) require.Equal(t, txEnv, retrievedTxEnv) - retrievedTxValCode, err := store.RetrieveTxValidationCodeByTxID(txid) + retrievedTxValCode, blkNum, err := store.RetrieveTxValidationCodeByTxID(txid) require.NoError(t, err) require.Equal(t, flags.Flag(txNum), retrievedTxValCode) + require.Equal(t, uint64(blockNum), blkNum) } } } @@ -154,8 +155,9 @@ func checkWithWrongInputs(t *testing.T, store *BlockStore, numBlocks int) { require.Nil(t, tx) require.EqualError(t, err, fmt.Sprintf("no such blockNumber, transactionNumber <%d, 0> in index", numBlocks+1)) - txCode, err := store.RetrieveTxValidationCodeByTxID("non-existent-txid") + txCode, blkNum, err := store.RetrieveTxValidationCodeByTxID("non-existent-txid") require.Equal(t, peer.TxValidationCode(-1), txCode) + require.Equal(t, uint64(0), blkNum) require.EqualError(t, err, "no such transaction ID [non-existent-txid] in index") } diff --git a/common/ledger/blkstorage/blockstore_test.go b/common/ledger/blkstorage/blockstore_test.go index d84a9d63d7c..fbdabbdb35a 100644 --- a/common/ledger/blkstorage/blockstore_test.go +++ b/common/ledger/blkstorage/blockstore_test.go @@ -56,7 +56,7 @@ func TestTxIDIndexErrorPropagations(t *testing.T) { return err }, func() error { - _, err := store.RetrieveTxValidationCodeByTxID("junkTxID") + _, _, err := store.RetrieveTxValidationCodeByTxID("junkTxID") return err }, } diff --git a/common/ledger/blkstorage/snapshot_test.go b/common/ledger/blkstorage/snapshot_test.go index bb3d2848637..fa36b1707b7 100644 --- a/common/ledger/blkstorage/snapshot_test.go +++ b/common/ledger/blkstorage/snapshot_test.go @@ -488,7 +488,7 @@ func verifyQueriesOnBlocksPriorToSnapshot( _, err = bootstrappedBlockStore.RetrieveTxByID(txID) require.EqualError(t, err, expectedErrorStr) - _, err = bootstrappedBlockStore.RetrieveTxValidationCodeByTxID(txID) + _, _, err = bootstrappedBlockStore.RetrieveTxValidationCodeByTxID(txID) require.EqualError(t, err, expectedErrorStr) exists, err := bootstrappedBlockStore.TxIDExists(txID) @@ -550,9 +550,10 @@ func verifyQueriesOnBlocksAddedAfterBootstrapping(t *testing.T, } for j, validationCode := range d.validationCodes { - retrievedValidationCode, err := bootstrappedBlockStore.RetrieveTxValidationCodeByTxID(d.txIDs[j]) + retrievedValidationCode, blkNum, err := bootstrappedBlockStore.RetrieveTxValidationCodeByTxID(d.txIDs[j]) require.NoError(t, err) require.Equal(t, validationCode, retrievedValidationCode) + require.Equal(t, block.Header.Number, blkNum) } } } diff --git a/core/chaincode/mock/peer_ledger.go b/core/chaincode/mock/peer_ledger.go index 70fae50b49a..31c8838efbc 100644 --- a/core/chaincode/mock/peer_ledger.go +++ b/core/chaincode/mock/peer_ledger.go @@ -207,18 +207,20 @@ type PeerLedger struct { result1 *peer.ProcessedTransaction result2 error } - GetTxValidationCodeByTxIDStub func(string) (peer.TxValidationCode, error) + GetTxValidationCodeByTxIDStub func(string) (peer.TxValidationCode, uint64, error) getTxValidationCodeByTxIDMutex sync.RWMutex getTxValidationCodeByTxIDArgsForCall []struct { arg1 string } getTxValidationCodeByTxIDReturns struct { result1 peer.TxValidationCode - result2 error + result2 uint64 + result3 error } getTxValidationCodeByTxIDReturnsOnCall map[int]struct { result1 peer.TxValidationCode - result2 error + result2 uint64 + result3 error } NewHistoryQueryExecutorStub func() (ledger.HistoryQueryExecutor, error) newHistoryQueryExecutorMutex sync.RWMutex @@ -1249,7 +1251,7 @@ func (fake *PeerLedger) GetTransactionByIDReturnsOnCall(i int, result1 *peer.Pro }{result1, result2} } -func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peer.TxValidationCode, error) { +func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peer.TxValidationCode, uint64, error) { fake.getTxValidationCodeByTxIDMutex.Lock() ret, specificReturn := fake.getTxValidationCodeByTxIDReturnsOnCall[len(fake.getTxValidationCodeByTxIDArgsForCall)] fake.getTxValidationCodeByTxIDArgsForCall = append(fake.getTxValidationCodeByTxIDArgsForCall, struct { @@ -1261,10 +1263,10 @@ func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peer.TxValidatio return fake.GetTxValidationCodeByTxIDStub(arg1) } if specificReturn { - return ret.result1, ret.result2 + return ret.result1, ret.result2, ret.result3 } fakeReturns := fake.getTxValidationCodeByTxIDReturns - return fakeReturns.result1, fakeReturns.result2 + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 } func (fake *PeerLedger) GetTxValidationCodeByTxIDCallCount() int { @@ -1273,7 +1275,7 @@ func (fake *PeerLedger) GetTxValidationCodeByTxIDCallCount() int { return len(fake.getTxValidationCodeByTxIDArgsForCall) } -func (fake *PeerLedger) GetTxValidationCodeByTxIDCalls(stub func(string) (peer.TxValidationCode, error)) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDCalls(stub func(string) (peer.TxValidationCode, uint64, error)) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = stub @@ -1286,30 +1288,33 @@ func (fake *PeerLedger) GetTxValidationCodeByTxIDArgsForCall(i int) string { return argsForCall.arg1 } -func (fake *PeerLedger) GetTxValidationCodeByTxIDReturns(result1 peer.TxValidationCode, result2 error) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDReturns(result1 peer.TxValidationCode, result2 uint64, result3 error) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = nil fake.getTxValidationCodeByTxIDReturns = struct { result1 peer.TxValidationCode - result2 error - }{result1, result2} + result2 uint64 + result3 error + }{result1, result2, result3} } -func (fake *PeerLedger) GetTxValidationCodeByTxIDReturnsOnCall(i int, result1 peer.TxValidationCode, result2 error) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDReturnsOnCall(i int, result1 peer.TxValidationCode, result2 uint64, result3 error) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = nil if fake.getTxValidationCodeByTxIDReturnsOnCall == nil { fake.getTxValidationCodeByTxIDReturnsOnCall = make(map[int]struct { result1 peer.TxValidationCode - result2 error + result2 uint64 + result3 error }) } fake.getTxValidationCodeByTxIDReturnsOnCall[i] = struct { result1 peer.TxValidationCode - result2 error - }{result1, result2} + result2 uint64 + result3 error + }{result1, result2, result3} } func (fake *PeerLedger) NewHistoryQueryExecutor() (ledger.HistoryQueryExecutor, error) { diff --git a/core/committer/txvalidator/v14/validator_test.go b/core/committer/txvalidator/v14/validator_test.go index 787891aed22..a9179c9ff6c 100644 --- a/core/committer/txvalidator/v14/validator_test.go +++ b/core/committer/txvalidator/v14/validator_test.go @@ -1450,9 +1450,9 @@ func (m *mockLedger) GetBlockByTxID(txID string) (*common.Block, error) { } // GetTxValidationCodeByTxID returns validation code of give tx -func (m *mockLedger) GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) { +func (m *mockLedger) GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, uint64, error) { args := m.Called(txID) - return args.Get(0).(peer.TxValidationCode), nil + return args.Get(0).(peer.TxValidationCode), args.Get(1).(uint64), nil } // NewTxSimulator creates new transaction simulator diff --git a/core/ledger/kvledger/kv_ledger.go b/core/ledger/kvledger/kv_ledger.go index d79303da30e..8221cd11719 100644 --- a/core/ledger/kvledger/kv_ledger.go +++ b/core/ledger/kvledger/kv_ledger.go @@ -502,7 +502,7 @@ func (l *kvLedger) GetTransactionByID(txID string) (*peer.ProcessedTransaction, if err != nil { return nil, err } - txVResult, err := l.blockStore.RetrieveTxValidationCodeByTxID(txID) + txVResult, _, err := l.blockStore.RetrieveTxValidationCodeByTxID(txID) if err != nil { return nil, err } @@ -554,11 +554,11 @@ func (l *kvLedger) GetBlockByTxID(txID string) (*common.Block, error) { return block, err } -func (l *kvLedger) GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) { +func (l *kvLedger) GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, uint64, error) { l.blockAPIsRWLock.RLock() defer l.blockAPIsRWLock.RUnlock() - txValidationCode, err := l.blockStore.RetrieveTxValidationCodeByTxID(txID) - return txValidationCode, err + txValidationCode, blkNum, err := l.blockStore.RetrieveTxValidationCodeByTxID(txID) + return txValidationCode, blkNum, err } // NewTxSimulator returns new `ledger.TxSimulator` diff --git a/core/ledger/kvledger/kv_ledger_test.go b/core/ledger/kvledger/kv_ledger_test.go index 810adf15145..c6594cddd47 100644 --- a/core/ledger/kvledger/kv_ledger_test.go +++ b/core/ledger/kvledger/kv_ledger_test.go @@ -148,8 +148,10 @@ func TestKVLedgerBlockStorage(t *testing.T) { require.True(t, proto.Equal(b1, block1), "proto messages are not equal") // get the transaction validation code for this transaction id - validCode, _ := lgr.GetTxValidationCodeByTxID(txID2) + validCode, blkNum, err := lgr.GetTxValidationCodeByTxID(txID2) + require.NoError(t, err) require.Equal(t, peer.TxValidationCode_VALID, validCode) + require.Equal(t, uint64(1), blkNum) exists, err = lgr.TxIDExists("random-txid") require.NoError(t, err) diff --git a/core/ledger/kvledger/tests/snapshot_test.go b/core/ledger/kvledger/tests/snapshot_test.go index e80c18df763..56c10b70892 100644 --- a/core/ledger/kvledger/tests/snapshot_test.go +++ b/core/ledger/kvledger/tests/snapshot_test.go @@ -89,7 +89,7 @@ func TestSnapshotGenerationAndBootstrap(t *testing.T) { _, err = lgr.GetBlockByNumber(3) require.EqualError(t, err, "cannot serve block [3]. The ledger is bootstrapped from a snapshot. First available block = [4]") - _, err = lgr.GetTxValidationCodeByTxID("txid-1") + _, _, err = lgr.GetTxValidationCodeByTxID("txid-1") require.EqualError(t, err, "details for the TXID [txid-1] not available. Ledger bootstrapped from a snapshot. First available block = [4]") testLedger.verifyTXIDExists("txid-1", "txid-2") diff --git a/core/ledger/ledger_interface.go b/core/ledger/ledger_interface.go index a5d6af9cfaf..3b4f24606fa 100644 --- a/core/ledger/ledger_interface.go +++ b/core/ledger/ledger_interface.go @@ -164,7 +164,7 @@ type PeerLedger interface { // GetBlockByTxID returns a block which contains a transaction GetBlockByTxID(txID string) (*common.Block, error) // GetTxValidationCodeByTxID returns reason code of transaction validation - GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error) + GetTxValidationCodeByTxID(txID string) (peer.TxValidationCode, uint64, error) // NewTxSimulator gives handle to a transaction simulator. // A client can obtain more than one 'TxSimulator's for parallel execution. // Any snapshoting/synchronization should be performed at the implementation level if required diff --git a/core/peer/mock/peer_ledger.go b/core/peer/mock/peer_ledger.go index e0017fc426e..64fa28a1d84 100644 --- a/core/peer/mock/peer_ledger.go +++ b/core/peer/mock/peer_ledger.go @@ -207,18 +207,20 @@ type PeerLedger struct { result1 *peera.ProcessedTransaction result2 error } - GetTxValidationCodeByTxIDStub func(string) (peera.TxValidationCode, error) + GetTxValidationCodeByTxIDStub func(string) (peera.TxValidationCode, uint64, error) getTxValidationCodeByTxIDMutex sync.RWMutex getTxValidationCodeByTxIDArgsForCall []struct { arg1 string } getTxValidationCodeByTxIDReturns struct { result1 peera.TxValidationCode - result2 error + result2 uint64 + result3 error } getTxValidationCodeByTxIDReturnsOnCall map[int]struct { result1 peera.TxValidationCode - result2 error + result2 uint64 + result3 error } NewHistoryQueryExecutorStub func() (ledger.HistoryQueryExecutor, error) newHistoryQueryExecutorMutex sync.RWMutex @@ -1249,7 +1251,7 @@ func (fake *PeerLedger) GetTransactionByIDReturnsOnCall(i int, result1 *peera.Pr }{result1, result2} } -func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peera.TxValidationCode, error) { +func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peera.TxValidationCode, uint64, error) { fake.getTxValidationCodeByTxIDMutex.Lock() ret, specificReturn := fake.getTxValidationCodeByTxIDReturnsOnCall[len(fake.getTxValidationCodeByTxIDArgsForCall)] fake.getTxValidationCodeByTxIDArgsForCall = append(fake.getTxValidationCodeByTxIDArgsForCall, struct { @@ -1261,10 +1263,10 @@ func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peera.TxValidati return fake.GetTxValidationCodeByTxIDStub(arg1) } if specificReturn { - return ret.result1, ret.result2 + return ret.result1, ret.result2, ret.result3 } fakeReturns := fake.getTxValidationCodeByTxIDReturns - return fakeReturns.result1, fakeReturns.result2 + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 } func (fake *PeerLedger) GetTxValidationCodeByTxIDCallCount() int { @@ -1273,7 +1275,7 @@ func (fake *PeerLedger) GetTxValidationCodeByTxIDCallCount() int { return len(fake.getTxValidationCodeByTxIDArgsForCall) } -func (fake *PeerLedger) GetTxValidationCodeByTxIDCalls(stub func(string) (peera.TxValidationCode, error)) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDCalls(stub func(string) (peera.TxValidationCode, uint64, error)) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = stub @@ -1286,30 +1288,33 @@ func (fake *PeerLedger) GetTxValidationCodeByTxIDArgsForCall(i int) string { return argsForCall.arg1 } -func (fake *PeerLedger) GetTxValidationCodeByTxIDReturns(result1 peera.TxValidationCode, result2 error) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDReturns(result1 peera.TxValidationCode, result2 uint64, result3 error) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = nil fake.getTxValidationCodeByTxIDReturns = struct { result1 peera.TxValidationCode - result2 error - }{result1, result2} + result2 uint64 + result3 error + }{result1, result2, result3} } -func (fake *PeerLedger) GetTxValidationCodeByTxIDReturnsOnCall(i int, result1 peera.TxValidationCode, result2 error) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDReturnsOnCall(i int, result1 peera.TxValidationCode, result2 uint64, result3 error) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = nil if fake.getTxValidationCodeByTxIDReturnsOnCall == nil { fake.getTxValidationCodeByTxIDReturnsOnCall = make(map[int]struct { result1 peera.TxValidationCode - result2 error + result2 uint64 + result3 error }) } fake.getTxValidationCodeByTxIDReturnsOnCall[i] = struct { result1 peera.TxValidationCode - result2 error - }{result1, result2} + result2 uint64 + result3 error + }{result1, result2, result3} } func (fake *PeerLedger) NewHistoryQueryExecutor() (ledger.HistoryQueryExecutor, error) { diff --git a/internal/peer/node/mock/peer_ledger.go b/internal/peer/node/mock/peer_ledger.go index 70fae50b49a..31c8838efbc 100644 --- a/internal/peer/node/mock/peer_ledger.go +++ b/internal/peer/node/mock/peer_ledger.go @@ -207,18 +207,20 @@ type PeerLedger struct { result1 *peer.ProcessedTransaction result2 error } - GetTxValidationCodeByTxIDStub func(string) (peer.TxValidationCode, error) + GetTxValidationCodeByTxIDStub func(string) (peer.TxValidationCode, uint64, error) getTxValidationCodeByTxIDMutex sync.RWMutex getTxValidationCodeByTxIDArgsForCall []struct { arg1 string } getTxValidationCodeByTxIDReturns struct { result1 peer.TxValidationCode - result2 error + result2 uint64 + result3 error } getTxValidationCodeByTxIDReturnsOnCall map[int]struct { result1 peer.TxValidationCode - result2 error + result2 uint64 + result3 error } NewHistoryQueryExecutorStub func() (ledger.HistoryQueryExecutor, error) newHistoryQueryExecutorMutex sync.RWMutex @@ -1249,7 +1251,7 @@ func (fake *PeerLedger) GetTransactionByIDReturnsOnCall(i int, result1 *peer.Pro }{result1, result2} } -func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peer.TxValidationCode, error) { +func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peer.TxValidationCode, uint64, error) { fake.getTxValidationCodeByTxIDMutex.Lock() ret, specificReturn := fake.getTxValidationCodeByTxIDReturnsOnCall[len(fake.getTxValidationCodeByTxIDArgsForCall)] fake.getTxValidationCodeByTxIDArgsForCall = append(fake.getTxValidationCodeByTxIDArgsForCall, struct { @@ -1261,10 +1263,10 @@ func (fake *PeerLedger) GetTxValidationCodeByTxID(arg1 string) (peer.TxValidatio return fake.GetTxValidationCodeByTxIDStub(arg1) } if specificReturn { - return ret.result1, ret.result2 + return ret.result1, ret.result2, ret.result3 } fakeReturns := fake.getTxValidationCodeByTxIDReturns - return fakeReturns.result1, fakeReturns.result2 + return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 } func (fake *PeerLedger) GetTxValidationCodeByTxIDCallCount() int { @@ -1273,7 +1275,7 @@ func (fake *PeerLedger) GetTxValidationCodeByTxIDCallCount() int { return len(fake.getTxValidationCodeByTxIDArgsForCall) } -func (fake *PeerLedger) GetTxValidationCodeByTxIDCalls(stub func(string) (peer.TxValidationCode, error)) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDCalls(stub func(string) (peer.TxValidationCode, uint64, error)) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = stub @@ -1286,30 +1288,33 @@ func (fake *PeerLedger) GetTxValidationCodeByTxIDArgsForCall(i int) string { return argsForCall.arg1 } -func (fake *PeerLedger) GetTxValidationCodeByTxIDReturns(result1 peer.TxValidationCode, result2 error) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDReturns(result1 peer.TxValidationCode, result2 uint64, result3 error) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = nil fake.getTxValidationCodeByTxIDReturns = struct { result1 peer.TxValidationCode - result2 error - }{result1, result2} + result2 uint64 + result3 error + }{result1, result2, result3} } -func (fake *PeerLedger) GetTxValidationCodeByTxIDReturnsOnCall(i int, result1 peer.TxValidationCode, result2 error) { +func (fake *PeerLedger) GetTxValidationCodeByTxIDReturnsOnCall(i int, result1 peer.TxValidationCode, result2 uint64, result3 error) { fake.getTxValidationCodeByTxIDMutex.Lock() defer fake.getTxValidationCodeByTxIDMutex.Unlock() fake.GetTxValidationCodeByTxIDStub = nil if fake.getTxValidationCodeByTxIDReturnsOnCall == nil { fake.getTxValidationCodeByTxIDReturnsOnCall = make(map[int]struct { result1 peer.TxValidationCode - result2 error + result2 uint64 + result3 error }) } fake.getTxValidationCodeByTxIDReturnsOnCall[i] = struct { result1 peer.TxValidationCode - result2 error - }{result1, result2} + result2 uint64 + result3 error + }{result1, result2, result3} } func (fake *PeerLedger) NewHistoryQueryExecutor() (ledger.HistoryQueryExecutor, error) { diff --git a/internal/pkg/gateway/commit/commitadapter.go b/internal/pkg/gateway/commit/commitadapter.go index 465fd739a39..ff4051f0085 100644 --- a/internal/pkg/gateway/commit/commitadapter.go +++ b/internal/pkg/gateway/commit/commitadapter.go @@ -34,7 +34,8 @@ func (adapter *PeerAdapter) TransactionStatus(channelName string, transactionID return 0, err } - return channel.Ledger().GetTxValidationCodeByTxID(transactionID) + validationCode, _, err := channel.Ledger().GetTxValidationCodeByTxID(transactionID) + return validationCode, err } func (adapter *PeerAdapter) channel(name string) (*peer.Channel, error) {