Skip to content

Commit 8a87b8a

Browse files
committedAug 10, 2017
[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

+1-1
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

+28-4
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
}

0 commit comments

Comments
 (0)
Please sign in to comment.