-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(stf): remove RunWithCtx #21739
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a977338
refactor(stf): rm RunWithCtx
kocubinski 30814ac
migrate export genesis and remove stf.RunWithCtx
kocubinski ef50b4f
revert line wrapping
kocubinski 177a0da
small refactor move genesis services
kocubinski 25f0244
Merge branch 'main' of github.com:cosmos/cosmos-sdk into kocu/rm-stf-…
kocubinski 45ff83a
go mod tidy all
kocubinski 16a0e99
revert vscode change
kocubinski 8d1014e
Merge branch 'main' into kocu/rm-stf-run-with-ctx
kocubinski 9fe1020
update genesis service
kocubinski 80db042
clean up
kocubinski 57ec239
fix typo
kocubinski c20649d
fix test
kocubinski ea930ac
fix test
kocubinski 2489e8d
docs
kocubinski a2ce376
Merge branch 'main' of github.com:cosmos/cosmos-sdk into kocu/rm-stf-…
kocubinski 28016f6
Merge branch 'main' into kocu/rm-stf-run-with-ctx
kocubinski e19452b
Merge branch 'main' into kocu/rm-stf-run-with-ctx
kocubinski 4671926
Merge branch 'main' of github.com:cosmos/cosmos-sdk into kocu/rm-stf-…
kocubinski 284ba57
go mod tidy all
kocubinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"cosmossdk.io/core/header" | ||
"cosmossdk.io/core/store" | ||
) | ||
|
||
var ( | ||
_ store.KVStoreService = (*GenesisKVStoreService)(nil) | ||
_ header.Service = (*GenesisHeaderService)(nil) | ||
) | ||
|
||
type genesisContextKeyType struct{} | ||
|
||
var genesisContextKey = genesisContextKeyType{} | ||
|
||
// genesisContext is a context that is used during genesis initialization. | ||
// it backs the store.KVStoreService and header.Service interface implementations | ||
// defined in this file. | ||
type genesisContext struct { | ||
state store.WriterMap | ||
} | ||
|
||
// NewGenesisContext creates a new genesis context. | ||
func NewGenesisContext(state store.WriterMap) genesisContext { | ||
return genesisContext{ | ||
state: state, | ||
} | ||
} | ||
|
||
// Run runs the provided function within the genesis context and returns an | ||
// updated store.WriterMap containing the state modifications made during InitGenesis. | ||
func (g *genesisContext) Run( | ||
ctx context.Context, | ||
fn func(ctx context.Context) error, | ||
) (store.WriterMap, error) { | ||
ctx = context.WithValue(ctx, genesisContextKey, g) | ||
err := fn(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return g.state, nil | ||
} | ||
|
||
// GenesisKVStoreService is a store.KVStoreService implementation that is used during | ||
// genesis initialization. It wraps an inner execution context store.KVStoreService. | ||
type GenesisKVStoreService struct { | ||
actor []byte | ||
executionService store.KVStoreService | ||
} | ||
|
||
// NewGenesisKVService creates a new GenesisKVStoreService. | ||
// - actor is the module store key. | ||
// - executionService is the store.KVStoreService to use when the genesis context is not active. | ||
func NewGenesisKVService( | ||
actor []byte, | ||
executionService store.KVStoreService, | ||
) *GenesisKVStoreService { | ||
return &GenesisKVStoreService{ | ||
actor: actor, | ||
executionService: executionService, | ||
} | ||
} | ||
|
||
// OpenKVStore implements store.KVStoreService. | ||
func (g *GenesisKVStoreService) OpenKVStore(ctx context.Context) store.KVStore { | ||
v := ctx.Value(genesisContextKey) | ||
if v == nil { | ||
return g.executionService.OpenKVStore(ctx) | ||
} | ||
genCtx, ok := v.(*genesisContext) | ||
if !ok { | ||
panic(fmt.Errorf("unexpected genesis context type: %T", v)) | ||
|
||
} | ||
state, err := genCtx.state.GetWriter(g.actor) | ||
if err != nil { | ||
panic(err) | ||
|
||
} | ||
return state | ||
} | ||
|
||
// GenesisHeaderService is a header.Service implementation that is used during | ||
// genesis initialization. It wraps an inner execution context header.Service. | ||
type GenesisHeaderService struct { | ||
executionService header.Service | ||
} | ||
|
||
// HeaderInfo implements header.Service. | ||
// During genesis initialization, it returns an empty header.Info. | ||
func (g *GenesisHeaderService) HeaderInfo(ctx context.Context) header.Info { | ||
v := ctx.Value(genesisContextKey) | ||
if v == nil { | ||
return g.executionService.HeaderInfo(ctx) | ||
} | ||
return header.Info{} | ||
} | ||
|
||
// NewGenesisHeaderService creates a new GenesisHeaderService. | ||
// - executionService is the header.Service to use when the genesis context is not active. | ||
func NewGenesisHeaderService(executionService header.Service) *GenesisHeaderService { | ||
return &GenesisHeaderService{ | ||
executionService: executionService, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looked valid @kocubinski btw.