Skip to content

Commit

Permalink
refactor: modify CoreCallbackFunc to pass gasBurned as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemmsilva committed Oct 25, 2023
1 parent acda2a7 commit 0666326
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/isc/sandbox_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions packages/vm/core/evm/evmimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/vmimpl/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0666326

Please sign in to comment.