@@ -2840,7 +2840,7 @@ public Transaction triggerContract(TriggerSmartContract
28402840 triggerSmartContract .getData ().toByteArray ());
28412841
28422842 if (isConstant (abi , selector )) {
2843- return callConstantContract (trxCap , builder , retBuilder );
2843+ return callConstantContract (trxCap , builder , retBuilder , false );
28442844 } else {
28452845 return trxCap .getInstance ();
28462846 }
@@ -2958,13 +2958,19 @@ private Transaction cleanContextAndTriggerConstantContract(
29582958 txExtBuilder .clear ();
29592959 txRetBuilder .clear ();
29602960 transaction = triggerConstantContract (
2961- triggerSmartContract , txCap , txExtBuilder , txRetBuilder );
2961+ triggerSmartContract , txCap , txExtBuilder , txRetBuilder , true );
29622962 return transaction ;
29632963 }
29642964
29652965 public Transaction triggerConstantContract (TriggerSmartContract triggerSmartContract ,
29662966 TransactionCapsule trxCap , Builder builder , Return .Builder retBuilder )
29672967 throws ContractValidateException , ContractExeException , HeaderNotFound , VMIllegalException {
2968+ return triggerConstantContract (triggerSmartContract , trxCap , builder , retBuilder , false );
2969+ }
2970+
2971+ public Transaction triggerConstantContract (TriggerSmartContract triggerSmartContract ,
2972+ TransactionCapsule trxCap , Builder builder , Return .Builder retBuilder , boolean isEstimating )
2973+ throws ContractValidateException , ContractExeException , HeaderNotFound , VMIllegalException {
29682974
29692975 if (triggerSmartContract .getContractAddress ().isEmpty ()) { // deploy contract
29702976 CreateSmartContract .Builder deployBuilder = CreateSmartContract .newBuilder ();
@@ -2989,11 +2995,11 @@ public Transaction triggerConstantContract(TriggerSmartContract triggerSmartCont
29892995 throw new ContractValidateException ("Smart contract is not exist." );
29902996 }
29912997 }
2992- return callConstantContract (trxCap , builder , retBuilder );
2998+ return callConstantContract (trxCap , builder , retBuilder , isEstimating );
29932999 }
29943000
29953001 public Transaction callConstantContract (TransactionCapsule trxCap ,
2996- Builder builder , Return .Builder retBuilder )
3002+ Builder builder , Return .Builder retBuilder , boolean isEstimating )
29973003 throws ContractValidateException , ContractExeException , HeaderNotFound , VMIllegalException {
29983004
29993005 if (!Args .getInstance ().isSupportConstant ()) {
@@ -3009,15 +3015,17 @@ public Transaction callConstantContract(TransactionCapsule trxCap,
30093015 headBlock = blockCapsuleList .get (0 ).getInstance ();
30103016 }
30113017
3012- TransactionContext context = new TransactionContext (new BlockCapsule (headBlock ), trxCap ,
3018+ BlockCapsule headBlockCapsule = new BlockCapsule (headBlock );
3019+ TransactionContext context = new TransactionContext (headBlockCapsule , trxCap ,
30133020 StoreFactory .getInstance (), true , false );
30143021 VMActuator vmActuator = new VMActuator (true );
30153022
30163023 vmActuator .validate (context );
30173024 vmActuator .execute (context );
30183025
30193026 ProgramResult result = context .getProgramResult ();
3020- if (result .getException () != null ) {
3027+ if (!isEstimating && result .getException () != null
3028+ || result .getException () instanceof Program .OutOfTimeException ) {
30213029 RuntimeException e = result .getException ();
30223030 logger .warn ("Constant call has an error {}" , e .getMessage ());
30233031 throw e ;
@@ -3026,6 +3034,9 @@ public Transaction callConstantContract(TransactionCapsule trxCap,
30263034 TransactionResultCapsule ret = new TransactionResultCapsule ();
30273035 builder .setEnergyUsed (result .getEnergyUsed ());
30283036 builder .setEnergyPenalty (result .getEnergyPenaltyTotal ());
3037+ builder .setBlockNumber (headBlockCapsule .getNum ());
3038+ builder .setBlockHash (ByteString .copyFrom (headBlockCapsule .getBlockId ().getBytes ()));
3039+ builder .setEnergyPenalty (result .getEnergyPenaltyTotal ());
30293040 builder .addConstantResult (ByteString .copyFrom (result .getHReturn ()));
30303041 result .getLogInfoList ().forEach (logInfo ->
30313042 builder .addLogs (LogInfo .buildLog (logInfo )));
0 commit comments