Skip to content

Commit 9826d54

Browse files
committed
FAB-491 Ledger not using correct protobuf
Change-Id: Ic6803b6f19d4ce28774b53aad4abd4d9c6b849da Signed-off-by: denyeart <[email protected]>
1 parent a069514 commit 9826d54

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

core/ledgernext/kvledger/example/app.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ func (app *App) QueryBalances(accounts []string) ([]int, error) {
111111
}
112112

113113
func constructTransaction(simulationResults []byte) *protos.Transaction2 {
114+
action := &protos.Action{ProposalHash: []byte{}, SimulationResult: simulationResults}
115+
actionBytes, _ := proto.Marshal(action)
116+
114117
tx := &protos.Transaction2{}
115118
tx.EndorsedActions = []*protos.EndorsedAction{
116-
&protos.EndorsedAction{ActionBytes: simulationResults, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
119+
&protos.EndorsedAction{ActionBytes: actionBytes, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
117120
return tx
118121
}
119122

core/ledgernext/kvledger/txmgmt/lockbasedtxmgmt/lockbased_txmgr.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,33 @@ func (txmgr *LockBasedTxMgr) ValidateAndPrepare(block *protos.Block2) (*protos.B
106106
if err != nil {
107107
return nil, nil, err
108108
}
109-
txRWSet := &txmgmt.TxReadWriteSet{}
110109
numEndorsements := len(tx.EndorsedActions)
111110
if numEndorsements == 0 {
112111
return nil, nil, fmt.Errorf("Tx contains no EndorsedActions")
113112
}
113+
114+
// Eventually we'll want to support multiple EndorsedActions in a tran, see FAB-445
115+
// But for now, we'll return an error if there are multiple EndorsedActions
114116
if numEndorsements > 1 {
115117
return nil, nil, fmt.Errorf("Tx contains more than one [%d] EndorsedActions", numEndorsements)
116118
}
117-
if err = txRWSet.Unmarshal(tx.EndorsedActions[0].ActionBytes); err != nil {
119+
120+
// Get the actionBytes from the EndorsedAction
121+
// and then Unmarshal it into an Action using protobuf unmarshalling
122+
action := &protos.Action{}
123+
actionBytes := tx.EndorsedActions[0].ActionBytes
124+
err = proto.Unmarshal(actionBytes, action)
125+
if err != nil {
118126
return nil, nil, err
119127
}
128+
129+
// Get the SimulationResult from the Action
130+
// and then Unmarshal it into a TxReadWriteSet using custom unmarshalling
131+
txRWSet := &txmgmt.TxReadWriteSet{}
132+
if err = txRWSet.Unmarshal(action.SimulationResult); err != nil {
133+
return nil, nil, err
134+
}
135+
120136
logger.Debugf("validating txRWSet:[%s]", txRWSet)
121137
if valid, err = txmgr.validateTx(txRWSet); err != nil {
122138
return nil, nil, err

core/ledgernext/testutil/test_helper.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ func ConstructTestBlock(t *testing.T, numTx int, startingTxID int) *protos.Block
5656

5757
// ConstructTestTransaction constructs a transaction for testing
5858
func ConstructTestTransaction(t *testing.T, simulationResults []byte) *protos.Transaction2 {
59+
60+
action := &protos.Action{ProposalHash: []byte{}, SimulationResult: simulationResults}
61+
actionBytes, _ := proto.Marshal(action)
62+
5963
tx := &protos.Transaction2{}
6064
tx.EndorsedActions = []*protos.EndorsedAction{
61-
&protos.EndorsedAction{ActionBytes: simulationResults, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
65+
&protos.EndorsedAction{ActionBytes: actionBytes, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
6266
return tx
6367
}
6468

0 commit comments

Comments
 (0)