-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: add endblocker with valsetupdate type #15829
Changes from 2 commits
7e297f4
2adba9d
7afe9b9
8d970e7
b2e6188
ccfe454
475a4c2
c4d0e22
74ecd2a
68bf01a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,9 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc | |
} | ||
} | ||
|
||
// set the validator set for the next block | ||
res.ValidatorUpdates = app.updatedValidators | ||
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. The challenge is that this overwrites updates in the case where the app is not using the update service. So we need to have some bool flag on the update service to indicate that updates have been set I think |
||
|
||
return res | ||
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. Change potentially affects state. Call sequence:
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package baseapp | ||
|
||
import ( | ||
"context" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
) | ||
|
||
// ValidatorUpdateService is the service that runtime will provide to the module that sets validator updates. | ||
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 thought BaseApp would just have a reference to the service, which is defined in |
||
type ValidatorUpdateService interface { | ||
SetValidatorUpdates(context.Context, []abci.ValidatorUpdate) | ||
} | ||
|
||
var _ = (ValidatorUpdateService)(&ValidatorSetUpdate{}) | ||
|
||
type ValidatorSetUpdate struct { | ||
updatedValidators []abci.ValidatorUpdate | ||
} | ||
|
||
func (v *ValidatorSetUpdate) SetValidatorUpdates(ctx context.Context, updates []abci.ValidatorUpdate) { | ||
v.updatedValidators = updates | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
package runtime | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
"golang.org/x/exp/slices" | ||
|
||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" | ||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
"golang.org/x/exp/slices" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
|
@@ -52,6 +51,8 @@ type App struct { | |
// initChainer is the init chainer function defined by the app config. | ||
// this is only required if the chain wants to add special InitChainer logic. | ||
initChainer sdk.InitChainer | ||
|
||
ValSetUpdate []abci.ValidatorUpdate | ||
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. why is this needed? |
||
} | ||
|
||
// RegisterModules registers the provided modules with the module manager and | ||
|
@@ -125,6 +126,12 @@ func (a *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) (abci.Respon | |
return a.ModuleManager.EndBlock(ctx, req) | ||
} | ||
|
||
// SetValidatorUpdates sets the validator updates for the next block. | ||
// CONTRACT: this must be called for modules that are updating the validator set | ||
func (a *App) SetValidatorUpdates(ctx context.Context, updates []abci.ValidatorUpdate) { | ||
a.BaseApp.SetValidatorUpdates(ctx, updates) | ||
} | ||
|
||
// InitChainer initializes the chain. | ||
func (a *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) (abci.ResponseInitChain, error) { | ||
var genesisState map[string]json.RawMessage | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
// BeginBlocker will persist the current header and validator set as a historical entry | ||
// and prune the oldest entry based on the HistoricalEntries parameter | ||
func (k *Keeper) BeginBlocker(ctx sdk.Context) { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) | ||
|
||
k.TrackHistoricalInfo(ctx) | ||
|
||
} | ||
|
||
// Called every block, update validator set | ||
func (k *Keeper) EndBlocker(ctx context.Context) { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) | ||
|
||
k.validatorService.SetValidatorUpdates(ctx, k.BlockValidatorUpdates(sdk.UnwrapSDKContext(ctx))) | ||
|
||
} |
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.
Nice!
QQ: When is
res, err = app.endBlocker(app.deliverState.ctx, req)
going to becomeerr = app.endBlocker(app.deliverState.ctx, req)
? i.e. when are we removing theResponseEndBlock
types from core'sEndBlock
API?