Skip to content

Commit

Permalink
feat(core): add Branch.ExecuteWithGasLimit API (#18457)
Browse files Browse the repository at this point in the history
Co-authored-by: unknown unknown <unknown@unknown>
  • Loading branch information
testinginprod and unknown unknown committed Nov 14, 2023
1 parent 912390d commit 569e3ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion core/branch/branch.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
}

0 comments on commit 569e3ff

Please sign in to comment.