From 06663267f4b95a6036891688cae7332fe28c21d5 Mon Sep 17 00:00:00 2001 From: Jorge Silva Date: Wed, 25 Oct 2023 16:01:25 +0100 Subject: [PATCH] refactor: modify CoreCallbackFunc to pass gasBurned as a parameter --- packages/isc/sandbox_interface.go | 2 +- packages/vm/core/evm/evmimpl/impl.go | 8 ++++---- packages/vm/vmimpl/internal.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/isc/sandbox_interface.go b/packages/isc/sandbox_interface.go index b939155e00..2334737811 100644 --- a/packages/isc/sandbox_interface.go +++ b/packages/isc/sandbox_interface.go @@ -148,7 +148,7 @@ type Privileged interface { SendOnBehalfOf(caller ContractIdentity, metadata RequestParameters) } -type CoreCallbackFunc func(contractPartition kv.KVStore) +type CoreCallbackFunc func(contractPartition kv.KVStore, gasBurned uint64) // RequestParameters represents parameters of the on-ledger request. The output is build from these parameters type RequestParameters struct { diff --git a/packages/vm/core/evm/evmimpl/impl.go b/packages/vm/core/evm/evmimpl/impl.go index b52c39c0c4..76d18cb095 100644 --- a/packages/vm/core/evm/evmimpl/impl.go +++ b/packages/vm/core/evm/evmimpl/impl.go @@ -154,7 +154,7 @@ func applyTransaction(ctx isc.Sandbox) dict.Dict { // make sure we always store the EVM tx/receipt in the BlockchainDB, even // if the ISC request is reverted - ctx.Privileged().OnWriteReceipt(func(evmPartition kv.KVStore) { + ctx.Privileged().OnWriteReceipt(func(evmPartition kv.KVStore, _ uint64) { saveExecutedTx(evmPartition, chainInfo, tx, receipt) }) // revert the changes in the state / txbuilder in case of error @@ -465,9 +465,9 @@ func newL1Deposit(ctx isc.Sandbox) dict.Dict { } receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) - ctx.Privileged().OnWriteReceipt(func(evmPartition kv.KVStore) { - receipt.GasUsed = gas.ISCGasBurnedToEVM(ctx.Gas().Burned(), &chainInfo.GasFeePolicy.EVMGasRatio) - receipt.CumulativeGasUsed = createBlockchainDB(ctx.State(), chainInfo).GetPendingCumulativeGasUsed() + receipt.GasUsed + ctx.Privileged().OnWriteReceipt(func(evmPartition kv.KVStore, gasBurned uint64) { + receipt.GasUsed = gas.ISCGasBurnedToEVM(gasBurned, &chainInfo.GasFeePolicy.EVMGasRatio) + receipt.CumulativeGasUsed = createBlockchainDB(evmPartition, chainInfo).GetPendingCumulativeGasUsed() + receipt.GasUsed createBlockchainDB(evmPartition, ctx.ChainInfo()).AddTransaction(tx, receipt) }) diff --git a/packages/vm/vmimpl/internal.go b/packages/vm/vmimpl/internal.go index 5648f6ddfd..9c30b3520d 100644 --- a/packages/vm/vmimpl/internal.go +++ b/packages/vm/vmimpl/internal.go @@ -170,7 +170,7 @@ func (reqctx *requestContext) writeReceiptToBlockLog(vmError *isc.VMError) *bloc } for _, f := range reqctx.onWriteReceipt { reqctx.callCore(corecontracts.All[f.contract], func(s kv.KVStore) { - f.callback(s) + f.callback(s, receipt.GasBurned) }) } return receipt