feat(core): add Branch.ExecuteWithGasLimit API (#18457)

Co-authored-by: unknown unknown <unknown@unknown>
This commit is contained in:
testinginprod 2023-11-14 11:07:55 +01:00 committed by GitHub
parent 912390d5fc
commit 569e3ff6a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
* [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service.
* [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit.
## [v0.12.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0)

View File

@ -1,7 +1,14 @@
// Package branch contains the core branch service interface.
package branch
import "context"
import (
"context"
"errors"
)
// ErrGasLimitExceeded is returned when the gas limit is exceeded in a
// Service.ExecuteWithGasLimit call.
var ErrGasLimitExceeded = errors.New("branch: gas limit exceeded")
// Service is the branch service interface. It can be used to execute
// code paths in an isolated execution context that can be reverted.
@ -16,4 +23,12 @@ type Service interface {
// passed to the Execute function, and is what should be used with other
// core services in order to ensure the execution remains isolated.
Execute(ctx context.Context, f func(ctx context.Context) error) error
// ExecuteWithGasLimit executes the given function `f` in an isolated context,
// with the provided gas limit, this is advanced usage and is used to disallow
// an execution path to consume an indefinite amount of gas.
// If the execution fails or succeeds the gas limit is still applied to the
// parent context, the function returns a gasUsed value which is the amount
// of gas used by the execution path. If the execution path exceeds the gas
// ErrGasLimitExceeded is returned.
ExecuteWithGasLimit(ctx context.Context, gasLimit uint64, f func(ctx context.Context) error) (gasUsed uint64, err error)
}