doTransaction中调用setContractState或setContractCoder

这两个操作无法在合约预执行之后回滚状态,会导致脏状态,
This commit is contained in:
c4w 2019-03-27 13:44:41 +08:00
parent 91f5ca6518
commit 806d90495b
2 changed files with 4 additions and 12 deletions

View File

@ -236,9 +236,10 @@ class TransProcessor(name: String, da:String, parent: ActorRef) extends Actor {
}
}
case Transaction.Type.CHAINCODE_DEPLOY =>
//检查合约名+版本是否已存在
if(Sandbox.getContractState(tx_cid)!=None)
//检查合约名+版本是否已存在,API预执行导致sandbox实例化紧接着共识预执行
if(Sandbox.getContractState(tx_cid)!=None){
throw new SandboxException(ERR_REPEATED_CID)
}
else{
val key_tx_state = WorldStateKeyPreFix+ tx_cid + PRE_STATE
val sr = ImpDataAccess.GetDataAccess(sTag)

View File

@ -80,15 +80,7 @@ class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
val coder_bytes = serialise(coder)
shim.sr.Put(key_coder,coder_bytes)
shim.ol.append(new Oper(key_coder, null, coder_bytes))
Sandbox.setContractCoder(cn,coder)
Sandbox.setContractState(tx_cid,true)
}else{
//从区块数据恢复合约实例,非新部署合约
Sandbox.setContractCoder(key_coder,coder)
val key_tx_state = WorldStateKeyPreFix+ tx_cid + PRE_STATE
val state = deserialise(shim.sr.Get(key_tx_state)).asInstanceOf[Boolean]
Sandbox.setContractState(tx_cid,state)
}
}
new ActionResult(1,None)
//由于Invoke为最频繁调用因此应尽量避免在处理中I/O读写,比如合约状态的检查就最好在内存中处理
//TODO case Transaction.Type.CHAINCODE_DESC 增加对合约描述的处理
@ -102,7 +94,6 @@ class SandboxScala(cid:ChaincodeId) extends Sandbox(cid){
case Transaction.Type.CHAINCODE_SET_STATE =>
val key_tx_state = WorldStateKeyPreFix+ tx_cid + PRE_STATE
val state = t.para.state.get
Sandbox.setContractState(tx_cid, state)
val state_bytes = serialise(state)
shim.sr.Put(key_tx_state,state_bytes)
shim.ol.append(new Oper(key_tx_state, null, state_bytes))