diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 4098e12dacf2..3b80170d78aa 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +* [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service. + ## [v0.12.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0) :::note diff --git a/core/branch/branch.go b/core/branch/branch.go new file mode 100644 index 000000000000..c5af0087fc20 --- /dev/null +++ b/core/branch/branch.go @@ -0,0 +1,19 @@ +// Package branch contains the core branch service interface. +package branch + +import "context" + +// Service is the branch service interface. It can be used to execute +// code paths in an isolated execution context that can be reverted. +// A revert typically means a rollback on events and state changes. +type Service interface { + // Execute executes the given function in an isolated context. If the + // `f` function returns an error, the execution is considered failed, + // and every change made affecting the execution context is rolled back. + // If the function returns nil, the execution is considered successful, and + // committed. + // The context.Context passed to the `f` function is a child of the context + // 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 +}