Revert journal changes from simulated transactions (#132)

This commit is contained in:
Austin Abell 2019-10-30 11:16:00 -04:00 committed by GitHub
parent 51ff5d48a9
commit 741dfeb461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,10 +44,13 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (*big.Int, sdk.Result)
// This gas limit the the transaction gas limit with intrinsic gas subtracted // This gas limit the the transaction gas limit with intrinsic gas subtracted
gasLimit := st.GasLimit - ctx.GasMeter().GasConsumed() gasLimit := st.GasLimit - ctx.GasMeter().GasConsumed()
var snapshot int
if st.Simulate { if st.Simulate {
// gasLimit is set here because stdTxs incur gaskv charges in the ante handler, but for eth_call // gasLimit is set here because stdTxs incur gaskv charges in the ante handler, but for eth_call
// the cost needs to be the same as an Ethereum transaction sent through the web3 API // the cost needs to be the same as an Ethereum transaction sent through the web3 API
gasLimit = st.GasLimit - cost gasLimit = st.GasLimit - cost
snapshot = st.Csdb.Snapshot()
} }
// Create context for evm // Create context for evm
@ -106,6 +109,10 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (*big.Int, sdk.Result)
return nil, res return nil, res
} }
if st.Simulate {
st.Csdb.RevertToSnapshot(snapshot)
}
// TODO: Refund unused gas here, if intended in future // TODO: Refund unused gas here, if intended in future
st.Csdb.Finalise(true) // Change to depend on config st.Csdb.Finalise(true) // Change to depend on config