如果在 invokeChaincode 中更改 Chaincode 状态,会发生什么可怕的事情?
Any terrible thing will happen if change Chaincode state in invokeChaincode?
假设我在 Hyperledger Fabric 中有两个链码,ChaincodeA 和 ChaincodeB。
ChaincodeA 中的某些事件必须更改 ChaincodeB 中的状态,例如,更改其余额。如果在 ChaincodeA 中使用 invokeChaincode()
来调用 ChaincodeB 中的某些逻辑,后者调用 putState()
来更改 ChaincodeB 的状态,那么在获得共识时可能会发生任何竞争条件吗?处理此问题的最佳做法是什么?
调用 chaincode you do not change the state you only simulate transaction execution based on the current state. Only once transaction placed into the block by ordering service and reaches the peer where it has to pass VSCC and MVCC checks it gonna be eventually committed. MVCC will take care of possible race condition. Transaction execution 时如下所示:
- 客户端向节点发送交易提议
- Peer模拟交易对结果进行签名,放入已签名的交易提案中
- 客户必须根据预期的背书政策重复步骤 #2
- 一旦客户收集到足够多的背书,他就会将它们发送到订购服务
- 排序服务切块并排序所有交易
- 块传送给同行
- Peer 验证并最终提交块
正如我低估了部署在两个不同通道上的两个链码。 chaincodeA 想调用 chaincodeB 的方法。根据规范,它可能但仅适用于读取操作。
https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.InvokeChaincode
你能分享一下你如何从 chaincodeA 调用另一个 chaincodeB 的代码吗?
假设我在 Hyperledger Fabric 中有两个链码,ChaincodeA 和 ChaincodeB。
ChaincodeA 中的某些事件必须更改 ChaincodeB 中的状态,例如,更改其余额。如果在 ChaincodeA 中使用 invokeChaincode()
来调用 ChaincodeB 中的某些逻辑,后者调用 putState()
来更改 ChaincodeB 的状态,那么在获得共识时可能会发生任何竞争条件吗?处理此问题的最佳做法是什么?
调用 chaincode you do not change the state you only simulate transaction execution based on the current state. Only once transaction placed into the block by ordering service and reaches the peer where it has to pass VSCC and MVCC checks it gonna be eventually committed. MVCC will take care of possible race condition. Transaction execution 时如下所示:
- 客户端向节点发送交易提议
- Peer模拟交易对结果进行签名,放入已签名的交易提案中
- 客户必须根据预期的背书政策重复步骤 #2
- 一旦客户收集到足够多的背书,他就会将它们发送到订购服务
- 排序服务切块并排序所有交易
- 块传送给同行
- Peer 验证并最终提交块
正如我低估了部署在两个不同通道上的两个链码。 chaincodeA 想调用 chaincodeB 的方法。根据规范,它可能但仅适用于读取操作。 https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.InvokeChaincode
你能分享一下你如何从 chaincodeA 调用另一个 chaincodeB 的代码吗?