Skip to content

Commit 66dbd4e

Browse files
C0rWinyacovm
authored andcommitted
[FAB-1038] Rework commiter to be more general
Exract VSCC from LCCC, in this commit added logic to extract VSCC from LCCC using extHeader structure. Change-Id: Ida19204a5bfb0f43cfd5e36dba3dca613a26d990 Signed-off-by: Artem Barger <[email protected]>
1 parent af3a722 commit 66dbd4e

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

core/committer/noopssinglechain/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,15 @@ func (d *DeliverService) readUntilClose() {
192192
// Create new transactions validator
193193
validator := txvalidator.NewTxValidator(peer.GetLedger(d.chainID))
194194
// Validate and mark invalid transactions
195+
logger.Debug("Validating block, chainID", d.chainID)
195196
validator.Validate(t.Block)
196197

197198
numberOfPeers := len(service.GetGossipService().GetPeers())
198199
// Create payload with a block received
199200
payload := createPayload(seqNum, t.Block)
200201
// Use payload to create gossip message
201202
gossipMsg := createGossipMsg(payload)
203+
logger.Debug("Creating gossip message", gossipMsg)
202204

203205
logger.Debugf("Adding payload locally, buffer seqNum = [%d], peers number [%d]", seqNum, numberOfPeers)
204206
// Add payload to local state payloads buffer

core/committer/txvalidator/validator.go

+32-18
Original file line numberDiff line numberDiff line change
@@ -73,38 +73,35 @@ func NewTxValidator(ledger ledger.ValidatedLedger) Validator {
7373
}
7474

7575
func (v *txValidator) Validate(block *common.Block) {
76+
logger.Debug("START Block Validation")
77+
defer logger.Debug("END Block Validation")
7678
txsfltr := ledgerUtil.NewFilterBitArray(uint(len(block.Data.Data)))
7779
for tIdx, d := range block.Data.Data {
7880
if d != nil {
7981
if env, err := utils.GetEnvelopeFromBlock(d); err != nil {
8082
logger.Warningf("Error getting tx from block(%s)", err)
83+
txsfltr.Set(uint(tIdx))
8184
} else if env != nil {
8285
// validate the transaction: here we check that the transaction
8386
// is properly formed, properly signed and that the security
8487
// chain binding proposal to endorsements to tx holds. We do
8588
// NOT check the validity of endorsements, though. That's a
8689
// job for VSCC below
90+
logger.Debug("Validating transaction peer.ValidateTransaction()")
8791
if payload, _, err := peer.ValidateTransaction(env); err != nil {
88-
// TODO: this code needs to receive a bit more attention and discussion:
89-
// it's not clear what it means if a transaction which causes a failure
90-
// in validation is just dropped on the floor
9192
logger.Errorf("Invalid transaction with index %d, error %s", tIdx, err)
9293
txsfltr.Set(uint(tIdx))
9394
} else {
9495
//the payload is used to get headers
96+
logger.Debug("Validating transaction vscc tx validate")
9597
if err = v.vscc.VSCCValidateTx(payload, d); err != nil {
96-
// TODO: this code needs to receive a bit more attention and discussion:
97-
// it's not clear what it means if a transaction which causes a failure
98-
// in validation is just dropped on the floor
9998
txID := payload.Header.ChainHeader.TxID
100-
logger.Errorf("isTxValidForVscc for transaction txId = %s returned error %s", txID, err)
99+
logger.Errorf("VSCCValidateTx for transaction txId = %s returned error %s", txID, err)
101100
txsfltr.Set(uint(tIdx))
102101
continue
103102
}
104103

105-
if t, err := proto.Marshal(env); err == nil {
106-
block.Data.Data = append(block.Data.Data, t)
107-
} else {
104+
if _, err := proto.Marshal(env); err != nil {
108105
logger.Warningf("Cannot marshal transactoins %s", err)
109106
txsfltr.Set(uint(tIdx))
110107
}
@@ -132,6 +129,7 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
132129

133130
// Get transaction id
134131
txid := payload.Header.ChainHeader.TxID
132+
logger.Info("[XXX remove me XXX] Transaction type,", common.HeaderType(payload.Header.ChainHeader.Type))
135133
if txid == "" {
136134
err := fmt.Errorf("transaction header does not contain transaction ID")
137135
logger.Errorf("%s", err)
@@ -153,24 +151,40 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
153151
defer txsim.Done()
154152
ctxt := context.WithValue(context.Background(), chaincode.TXSimulatorKey, txsim)
155153

156-
//generate an internal txid for executing system chaincode calls below on behalf
157-
//of original txid
158-
vscctxid := coreUtil.GenerateUUID()
154+
// get header extensions so we have the visibility field
155+
hdrExt, err := utils.GetChaincodeHeaderExtension(payload.Header)
156+
if err != nil {
157+
return err
158+
}
159159

160-
// Extracting vscc from lccc
161-
/*
162-
data, err := chaincode.GetChaincodeDataFromLCCC(ctxt, vscctxid, nil, chainID, "vscc")
160+
// TODO: Temporary solution until FAB-1422 get resolved
161+
// Explanation: we actually deploying chaincode transaction,
162+
// hence no lccc yet to query for the data, therefore currently
163+
// introducing a workaround to skip obtaining LCCC data.
164+
var data *chaincode.ChaincodeData
165+
if hdrExt.ChaincodeID.Name != "lccc" {
166+
// Extracting vscc from lccc
167+
logger.Info("Extracting chaincode data from LCCC txid = ", txid, "chainID", chainID, "chaincode name", hdrExt.ChaincodeID.Name)
168+
data, err = chaincode.GetChaincodeDataFromLCCC(ctxt, txid, nil, chainID, hdrExt.ChaincodeID.Name)
163169
if err != nil {
164170
logger.Errorf("Unable to get chaincode data from LCCC for txid %s, due to %s", txid, err)
165171
return err
166172
}
167-
*/
173+
}
174+
175+
vscc := "vscc"
176+
// Check whenever VSCC defined for chaincode data
177+
if data != nil && data.Vscc != "" {
178+
vscc = data.Vscc
179+
}
168180

181+
vscctxid := coreUtil.GenerateUUID()
169182
// Get chaincode version
170183
version := coreUtil.GetSysCCVersion()
171-
cccid := chaincode.NewCCContext(chainID, "vscc", version, vscctxid, true, nil)
184+
cccid := chaincode.NewCCContext(chainID, vscc, version, vscctxid, true, nil)
172185

173186
// invoke VSCC
187+
logger.Info("Invoking VSCC txid", txid, "chaindID", chainID)
174188
_, _, err = chaincode.ExecuteChaincode(ctxt, cccid, args)
175189
if err != nil {
176190
logger.Errorf("VSCC check failed for transaction txid=%s, error %s", txid, err)

0 commit comments

Comments
 (0)