-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(sims): Integration with app v2 #23013
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to clean all the previous ones, they were commented out waiting for this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need as well to re-enable it on CI and call the right jobs for main and eventually both in the backport in 0.52 (.github/workflows/sims.yml)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix them when the CLI params are integrated (in a new PR)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create a tracking PR for it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package stf | ||
|
|
||
| import ( | ||
| "context" | ||
| "iter" | ||
|
|
||
| "cosmossdk.io/core/header" | ||
| "cosmossdk.io/core/server" | ||
| "cosmossdk.io/core/store" | ||
| "cosmossdk.io/core/transaction" | ||
| ) | ||
|
|
||
| // doSimsTXs constructs a function to simulate transactions in a block execution context using the provided simsBuilder. | ||
| func (s STF[T]) doSimsTXs(simsBuilder func(ctx context.Context) iter.Seq[T]) doInBlockDeliveryFn[T] { | ||
| return func( | ||
| exCtx context.Context, | ||
| _ []T, | ||
| newState store.WriterMap, | ||
| headerInfo header.Info, | ||
| ) ([]server.TxResult, error) { | ||
| const key = "sims.header.time" | ||
| simsCtx := context.WithValue(exCtx, key, headerInfo.Time) //nolint: staticcheck // using string key to decouple | ||
| var results []server.TxResult | ||
| var i int32 | ||
| for tx := range simsBuilder(simsCtx) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This calls the sims message factories that were setup in sims_runner.doMainLoop() |
||
| if err := isCtxCancelled(simsCtx); err != nil { | ||
| return nil, err | ||
| } | ||
| results = append(results, s.deliverTx(simsCtx, newState, tx, transaction.ExecModeFinalize, headerInfo, i+1)) | ||
| i++ | ||
| } | ||
| return results, nil | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "iter" | ||
| "strings" | ||
|
|
||
| appmodulev2 "cosmossdk.io/core/appmodule/v2" | ||
|
|
@@ -84,13 +85,40 @@ func New[T transaction.Tx]( | |
| }, nil | ||
| } | ||
|
|
||
| // DeliverSims entrypoint to processes sims transactions similar to DeliverBlock. | ||
| func (s STF[T]) DeliverSims( | ||
| ctx context.Context, | ||
| block *server.BlockRequest[T], | ||
| state store.ReaderMap, | ||
| simsBuilder func(ctx context.Context) iter.Seq[T], | ||
| ) (blockResult *server.BlockResponse, newState store.WriterMap, err error) { | ||
| return s.deliverBlock(ctx, block, state, s.doSimsTXs(simsBuilder)) | ||
| } | ||
|
|
||
| // DeliverBlock is our state transition function. | ||
| // It takes a read only view of the state to apply the block to, | ||
| // executes the block and returns the block results and the new state. | ||
| func (s STF[T]) DeliverBlock( | ||
| ctx context.Context, | ||
| block *server.BlockRequest[T], | ||
| state store.ReaderMap, | ||
| ) (blockResult *server.BlockResponse, newState store.WriterMap, err error) { | ||
| return s.deliverBlock(ctx, block, state, s.doDeliverTXs) | ||
| } | ||
|
|
||
| // common code path for DeliverSims and DeliverBlock | ||
| type doInBlockDeliveryFn[T transaction.Tx] func( | ||
| ctx context.Context, | ||
| txs []T, | ||
| newState store.WriterMap, | ||
| hi header.Info, | ||
| ) ([]server.TxResult, error) | ||
|
|
||
| func (s STF[T]) deliverBlock( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. common code used by DeliverBlock and DeliverSims |
||
| ctx context.Context, | ||
| block *server.BlockRequest[T], | ||
| state store.ReaderMap, | ||
| doInBlockDelivery doInBlockDeliveryFn[T], | ||
| ) (blockResult *server.BlockResponse, newState store.WriterMap, err error) { | ||
| // creates a new branchFn state, from the readonly view of the state | ||
| // that can be written to. | ||
|
|
@@ -141,14 +169,9 @@ func (s STF[T]) DeliverBlock( | |
| } | ||
|
|
||
| // execute txs | ||
| txResults := make([]server.TxResult, len(block.Txs)) | ||
| // TODO: skip first tx if vote extensions are enabled (marko) | ||
| for i, txBytes := range block.Txs { | ||
| // check if we need to return early or continue delivering txs | ||
| if err = isCtxCancelled(ctx); err != nil { | ||
| return nil, nil, err | ||
| } | ||
| txResults[i] = s.deliverTx(exCtx, newState, txBytes, transaction.ExecModeFinalize, hi, int32(i+1)) | ||
| txResults, err := doInBlockDelivery(exCtx, block.Txs, newState, hi) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| // reset events | ||
| exCtx.events = make([]event.Event, 0) | ||
|
|
@@ -167,6 +190,25 @@ func (s STF[T]) DeliverBlock( | |
| }, newState, nil | ||
| } | ||
|
|
||
| func (s STF[T]) doDeliverTXs( | ||
| exCtx context.Context, | ||
| txs []T, | ||
| newState store.WriterMap, | ||
| hi header.Info, | ||
| ) ([]server.TxResult, error) { | ||
| // execute txs | ||
| txResults := make([]server.TxResult, len(txs)) | ||
| // TODO: skip first tx if vote extensions are enabled (marko) | ||
| for i, txBytes := range txs { | ||
| // check if we need to return early or continue delivering txs | ||
| if err := isCtxCancelled(exCtx); err != nil { | ||
| return nil, err | ||
| } | ||
| txResults[i] = s.deliverTx(exCtx, newState, txBytes, transaction.ExecModeFinalize, hi, int32(i+1)) | ||
| } | ||
| return txResults, nil | ||
| } | ||
|
|
||
| // deliverTx executes a TX and returns the result. | ||
| func (s STF[T]) deliverTx( | ||
| ctx context.Context, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.