From 806d90495b18af0181da9bce1923a29ca2e99aef Mon Sep 17 00:00:00 2001 From: c4w <“chen4w@sina.com”> Date: Wed, 27 Mar 2019 13:44:41 +0800 Subject: [PATCH] =?UTF-8?q?doTransaction=E4=B8=AD=E8=B0=83=E7=94=A8setCont?= =?UTF-8?q?ractState=E6=88=96setContractCoder=20=E8=BF=99=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E6=93=8D=E4=BD=9C=E6=97=A0=E6=B3=95=E5=9C=A8=E5=90=88?= =?UTF-8?q?=E7=BA=A6=E9=A2=84=E6=89=A7=E8=A1=8C=E4=B9=8B=E5=90=8E=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A=E7=8A=B6=E6=80=81,=E4=BC=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=84=8F=E7=8A=B6=E6=80=81=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/scala/rep/sc/TransProcessor.scala | 5 +++-- src/main/scala/rep/sc/scalax/SandboxScala.scala | 11 +---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/scala/rep/sc/TransProcessor.scala b/src/main/scala/rep/sc/TransProcessor.scala index 21214ba5..a88d555d 100644 --- a/src/main/scala/rep/sc/TransProcessor.scala +++ b/src/main/scala/rep/sc/TransProcessor.scala @@ -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) diff --git a/src/main/scala/rep/sc/scalax/SandboxScala.scala b/src/main/scala/rep/sc/scalax/SandboxScala.scala index a37e40b5..228658ac 100644 --- a/src/main/scala/rep/sc/scalax/SandboxScala.scala +++ b/src/main/scala/rep/sc/scalax/SandboxScala.scala @@ -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))