-
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
Conversation
@@ -191,13 +189,15 @@ | |||
// BeginBlock returns the begin blocker for the staking module. | |||
func (am AppModule) BeginBlock(ctx context.Context) error { | |||
c := sdk.UnwrapSDKContext(ctx) | |||
BeginBlocker(c, am.keeper) | |||
|
|||
am.keeper.BeginBlocker(c) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
baseapp/abci.go
Outdated
} | ||
} | ||
|
||
// set the validator set for the next block | ||
res.ValidatorUpdates = app.updatedValidators | ||
|
||
return res |
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.
Change potentially affects state.
Call sequence:
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).EndBlock (baseapp/abci.go:229)
This comment has been minimized.
This comment has been minimized.
runtime/app.go
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
baseapp/abci.go
Outdated
@@ -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 comment
The 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
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 level of abstraction doesn't make sense to me personally.
baseapp/abci.go
Outdated
@@ -252,6 +252,9 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc | |||
} | |||
} | |||
|
|||
// set the validator set for the next block |
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 become err = app.endBlocker(app.deliverState.ctx, req)
? i.e. when are we removing the ResponseEndBlock
types from core's EndBlock
API?
baseapp/valset_update.go
Outdated
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 comment
The 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 runtime
? Why is this being defined in BaseApp
?
return sh.Ctx | ||
} | ||
|
||
// TurnBlockTimeDiff calls EndBlocker and updates the block time by adding the | ||
// duration to the current block time | ||
func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) sdk.Context { | ||
sh.Ctx = sh.Ctx.WithBlockTime(sh.Ctx.BlockHeader().Time.Add(diff)) | ||
staking.EndBlocker(sh.Ctx, sh.k) | ||
sh.k.EndBlocker(sh.Ctx) |
Check warning
Code scanning / gosec
Errors unhandled.
@@ -127,15 +126,15 @@ | |||
// TurnBlock calls EndBlocker and updates the block time | |||
func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context { | |||
sh.Ctx = sh.Ctx.WithBlockTime(newTime) | |||
staking.EndBlocker(sh.Ctx, sh.k) | |||
sh.k.EndBlocker(sh.Ctx) |
Check warning
Code scanning / gosec
Errors unhandled.
message ValidatorUpdate { | ||
option (gogoproto.stringer) = true; | ||
|
||
tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false]; | ||
int64 power = 2; | ||
} |
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.
we only need this type to make it work, should we just depend on comet for it? @aaronc @alexanderbez
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.
The pubkey? I think that's fine
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.
The validator update type
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.
If we're defining parts of ABCI ourselves, I would say let's define the entire type, no?
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.
since this endblock is tied to comet i may leave it for now.
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) | ||
|
||
return k.BlockValidatorUpdates(ctx) | ||
return k.BlockValidatorUpdates(sdk.UnwrapSDKContext(ctx)), nil |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { | ||
return EndBlocker(ctx, am.keeper) | ||
func (am AppModule) EndBlock(ctx context.Context) ([]sdk.ValidatorUpdate, error) { | ||
return am.keeper.EndBlocker(ctx) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
@@ -695,6 +701,22 @@ | |||
if err != nil { | |||
return abci.ResponseEndBlock{}, err | |||
} | |||
} else if module, ok := m.Modules[moduleName].(HasABCIEndblock); ok { | |||
moduleValUpdates, err := module.EndBlock(ctx) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
message ValidatorUpdate { | ||
option (gogoproto.stringer) = true; | ||
|
||
tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false]; | ||
int64 power = 2; | ||
} |
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.
The pubkey? I think that's fine
@@ -212,6 +213,11 @@ type EndBlockAppModule interface { | |||
EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate | |||
} | |||
|
|||
type HasABCIEndblock interface { |
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.
Do we have somewhere something that explains the difference between:
HasABCIEndblock, EndBlockAppModule and HasEndBlocker?
Those 3 extension interfaces doing seemingly the same thing (I know they don't but still) could get confusing.
Small nit on that new extension interface, I think it should have had a capital B for block for consistency with the other 2.
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.
the one above gets removed in another pr. Left a todo for when we do docs on core api
Description
This pr adds valset updating to the module manager in the shape of a endblocker interface
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change