Skip to content

Commit

Permalink
feat: set DoNotFailFast inside context in consensus code
Browse files Browse the repository at this point in the history
so permissions module fails do not panic
  • Loading branch information
kakysha committed Jun 12, 2024
1 parent b2463e2 commit 5cd942f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type (
// particular, if a module changed the substore key name (or removed a substore)
// between two versions of the software.
StoreLoader func(ms storetypes.CommitMultiStore) error

contextKeyT string
)

const (
Expand All @@ -54,6 +56,8 @@ const (
execModeVoteExtension // Extend or verify a pre-commit vote
execModeVerifyVoteExtension // Verify a vote extension
execModeFinalize // Finalize a block proposal

DoNotFailFastContextKey contextKeyT = "DoNotFailFast"
)

var _ servertypes.ABCI = (*BaseApp)(nil)
Expand Down Expand Up @@ -708,7 +712,7 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context

func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) error {
if app.preBlocker != nil {
ctx := app.finalizeBlockState.Context()
ctx := app.finalizeBlockState.Context().WithValue(DoNotFailFastContextKey, struct{}{})
rsp, err := app.preBlocker(ctx, req)
if err != nil {
return err
Expand All @@ -733,7 +737,8 @@ func (app *BaseApp) beginBlock(req *abci.RequestFinalizeBlock) (sdk.BeginBlock,
)

if app.beginBlocker != nil {
resp, err = app.beginBlocker(app.finalizeBlockState.Context())
ctx := app.finalizeBlockState.Context().WithValue(DoNotFailFastContextKey, struct{}{})
resp, err = app.beginBlocker(ctx)
if err != nil {
return resp, err
}
Expand All @@ -746,7 +751,6 @@ func (app *BaseApp) beginBlock(req *abci.RequestFinalizeBlock) (sdk.BeginBlock,
)
}

ctx := app.finalizeBlockState.ctx
app.AddStreamEvents(ctx.BlockHeight(), ctx.BlockTime(), resp.Events, true)

resp.Events = sdk.MarkEventsToIndex(resp.Events, app.indexEvents)
Expand Down Expand Up @@ -797,11 +801,12 @@ func (app *BaseApp) deliverTx(tx []byte) *abci.ExecTxResult {

// endBlock is an application-defined function that is called after transactions
// have been processed in FinalizeBlock.
func (app *BaseApp) endBlock(ctx context.Context) (sdk.EndBlock, error) {
func (app *BaseApp) endBlock(_ context.Context) (sdk.EndBlock, error) {
var endblock sdk.EndBlock

if app.endBlocker != nil {
eb, err := app.endBlocker(app.finalizeBlockState.Context())
ctx := app.finalizeBlockState.Context().WithValue(DoNotFailFastContextKey, struct{}{})
eb, err := app.endBlocker(ctx)
if err != nil {
return endblock, err
}
Expand All @@ -814,7 +819,6 @@ func (app *BaseApp) endBlock(ctx context.Context) (sdk.EndBlock, error) {
)
}

ctx := app.finalizeBlockState.ctx
app.AddStreamEvents(ctx.BlockHeight(), ctx.BlockTime(), eb.Events, true)

eb.Events = sdk.MarkEventsToIndex(eb.Events, app.indexEvents)
Expand Down

0 comments on commit 5cd942f

Please sign in to comment.