Skip to content

Commit 8a87b8a

Browse files
committed
[FAB-5654] SideDB - Tx simulation/validation/commit
This CR modifies the tranaction simulation, validation, and commit code and delivers the end-to-end transaction flow that treats the private data in a special manner. This CR mainly leverages the earlier submitted independent CRs for sidedb feature for accomplishing this behavior. This CR also allows ledger to receive the blocks and the pvt data from another peer on the same channel (i.e., a peer catching up via state) This CR is exceptionally large becasue of manily two reasons 1) The way currently the code (and specially the tests) is organized in simulation/validation/commit flow, its not easy to submit such kind of changes independently that cuase the change in the whole transaction processing flow. 2) This CR causes a change in the existing ledger APIs which are used widely across other packages (specially in the tests) and hence many files are included for fixing the broken dependencies Change-Id: Id29575176575f4c01793efd3476b68f8364cb592 Signed-off-by: manish <manish.sethi@gmail.com>
1 parent d9e0004 commit 8a87b8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1885
-697
lines changed

common/ledger/blkstorage/fsblkstorage/block_serialization_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestBlockSerialization(t *testing.T) {
3434
}
3535

3636
func TestExtractTxid(t *testing.T) {
37-
txEnv, txid, _ := testutil.ConstructTransaction(t, testutil.ConstructRandomBytes(t, 50), false)
37+
txEnv, txid, _ := testutil.ConstructTransaction(t, testutil.ConstructRandomBytes(t, 50), "", false)
3838
txEnvBytes, _ := putils.GetBytesEnvelope(txEnv)
3939
extractedTxid, err := extractTxID(txEnvBytes)
4040
testutil.AssertNoError(t, err, "")

common/ledger/testutil/test_helper.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ func (bg *BlockGenerator) NextBlock(simulationResults [][]byte) *common.Block {
5353
return block
5454
}
5555

56+
// NextBlock constructs next block in sequence that includes a number of transactions - one per simulationResults
57+
func (bg *BlockGenerator) NextBlockWithTxid(simulationResults [][]byte, txids []string) *common.Block {
58+
// Length of simulationResults should be same as the length of txids.
59+
if len(simulationResults) != len(txids) {
60+
return nil
61+
}
62+
block := ConstructBlockWithTxid(bg.t, bg.blockNum, bg.previousHash, simulationResults, txids, bg.signTxs)
63+
bg.blockNum++
64+
bg.previousHash = block.Header.Hash()
65+
return block
66+
}
67+
5668
// NextTestBlock constructs next block in sequence block with 'numTx' number of transactions for testing
5769
func (bg *BlockGenerator) NextTestBlock(numTx int, txSize int) *common.Block {
5870
simulationResults := [][]byte{}
@@ -72,7 +84,7 @@ func (bg *BlockGenerator) NextTestBlocks(numBlocks int) []*common.Block {
7284
}
7385

7486
// ConstructTransaction constructs a transaction for testing
75-
func ConstructTransaction(_ *testing.T, simulationResults []byte, sign bool) (*common.Envelope, string, error) {
87+
func ConstructTransaction(_ *testing.T, simulationResults []byte, txid string, sign bool) (*common.Envelope, string, error) {
7688
ccid := &pb.ChaincodeID{
7789
Name: "foo",
7890
Version: "v1",
@@ -82,18 +94,30 @@ func ConstructTransaction(_ *testing.T, simulationResults []byte, sign bool) (*c
8294
var txEnv *common.Envelope
8395
var err error
8496
if sign {
85-
txEnv, txID, err = ptestutils.ConstructSingedTxEnvWithDefaultSigner(util.GetTestChainID(), ccid, nil, simulationResults, nil, nil)
97+
txEnv, txID, err = ptestutils.ConstructSingedTxEnvWithDefaultSigner(util.GetTestChainID(), ccid, nil, simulationResults, txid, nil, nil)
8698
} else {
87-
txEnv, txID, err = ptestutils.ConstructUnsingedTxEnv(util.GetTestChainID(), ccid, nil, simulationResults, nil, nil)
99+
txEnv, txID, err = ptestutils.ConstructUnsingedTxEnv(util.GetTestChainID(), ccid, nil, simulationResults, txid, nil, nil)
88100
}
89101
return txEnv, txID, err
90102
}
91103

104+
func ConstructBlockWithTxid(t *testing.T, blockNum uint64, previousHash []byte, simulationResults [][]byte, txids []string, sign bool) *common.Block {
105+
envs := []*common.Envelope{}
106+
for i := 0; i < len(simulationResults); i++ {
107+
env, _, err := ConstructTransaction(t, simulationResults[i], txids[i], sign)
108+
if err != nil {
109+
t.Fatalf("ConstructTestTransaction failed, err %s", err)
110+
}
111+
envs = append(envs, env)
112+
}
113+
return newBlock(envs, blockNum, previousHash)
114+
}
115+
92116
// ConstructBlock constructs a single block
93117
func ConstructBlock(t *testing.T, blockNum uint64, previousHash []byte, simulationResults [][]byte, sign bool) *common.Block {
94118
envs := []*common.Envelope{}
95119
for i := 0; i < len(simulationResults); i++ {
96-
env, _, err := ConstructTransaction(t, simulationResults[i], sign)
120+
env, _, err := ConstructTransaction(t, simulationResults[i], "", sign)
97121
if err != nil {
98122
t.Fatalf("ConstructTestTransaction failed, err %s", err)
99123
}

common/mocks/ledger/queryexecutor.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ func (m *MockQueryExecutor) ExecuteQuery(namespace, query string) (ledger.Result
5656
return nil, nil
5757
}
5858

59-
func (m *MockQueryExecutor) Done() {
59+
func (m *MockQueryExecutor) GetPrivateData(namespace, collection, key string) ([]byte, error) {
60+
return nil, nil
61+
}
6062

63+
func (m *MockQueryExecutor) GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error) {
64+
return nil, nil
65+
}
66+
67+
func (m *MockQueryExecutor) GetPrivateDataRangeScanIterator(namespace, collection, startKey, endKey string) (ledger.ResultsIterator, error) {
68+
return nil, nil
69+
}
70+
71+
func (m *MockQueryExecutor) ExecuteQueryOnPrivateData(namespace, collection, query string) (ledger.ResultsIterator, error) {
72+
return nil, nil
73+
}
74+
75+
func (m *MockQueryExecutor) Done() {
6176
}

core/chaincode/ccproviderimpl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ type ccProviderContextImpl struct {
5353
}
5454

5555
// GetContext returns a context for the supplied ledger, with the appropriate tx simulator
56-
func (c *ccProviderImpl) GetContext(ledger ledger.PeerLedger) (context.Context, error) {
56+
func (c *ccProviderImpl) GetContext(ledger ledger.PeerLedger, txid string) (context.Context, error) {
5757
var err error
5858
// get context for the chaincode execution
59-
c.txsim, err = ledger.NewTxSimulator()
59+
c.txsim, err = ledger.NewTxSimulator(txid)
6060
if err != nil {
6161
return nil, err
6262
}

0 commit comments

Comments
 (0)