Skip to content

Commit 6c82a50

Browse files
author
Devon Bear
authored
feat(runtime): Remove preblock and end block -> finalize blcok (#1870)
1 parent a4ebb22 commit 6c82a50

File tree

25 files changed

+288
-520
lines changed

25 files changed

+288
-520
lines changed

mod/consensus/pkg/cometbft/consensus.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
package cometbft
2222

2323
import (
24-
"context"
25-
2624
cmtabci "github.com/cometbft/cometbft/abci/types"
2725
sdk "github.com/cosmos/cosmos-sdk/types"
28-
"github.com/sourcegraph/conc/iter"
2926
)
3027

3128
// ConsensusEngine is used to decouple the Comet consensus engine from
@@ -76,18 +73,6 @@ func NewConsensusEngine[
7673
}
7774
}
7875

79-
func (c *ConsensusEngine[_, _, _, _, _, ValidatorUpdateT]) InitGenesis(
80-
ctx context.Context,
81-
genesisBz []byte,
82-
) ([]ValidatorUpdateT, error) {
83-
updates, err := c.Middleware.InitGenesis(ctx, genesisBz)
84-
if err != nil {
85-
return nil, err
86-
}
87-
// Convert updates into the Cosmos SDK format.
88-
return iter.MapErr(updates, convertValidatorUpdate[ValidatorUpdateT])
89-
}
90-
9176
// TODO: Decouple Comet Types
9277
func (c *ConsensusEngine[_, _, _, _, _, _]) PrepareProposal(
9378
ctx sdk.Context,
@@ -123,21 +108,3 @@ func (c *ConsensusEngine[_, _, _, _, _, ValidatorUpdateT]) ProcessProposal(
123108
}
124109
return resp.(*cmtabci.ProcessProposalResponse), nil
125110
}
126-
127-
// TODO: Decouple Comet Types
128-
func (c *ConsensusEngine[_, _, _, _, _, ValidatorUpdateT]) PreBlock(
129-
ctx sdk.Context,
130-
req *cmtabci.FinalizeBlockRequest,
131-
) error {
132-
return c.Middleware.PreBlock(ctx, req)
133-
}
134-
135-
func (c *ConsensusEngine[_, _, _, _, _, ValidatorUpdateT]) EndBlock(
136-
ctx context.Context,
137-
) ([]ValidatorUpdateT, error) {
138-
updates, err := c.Middleware.EndBlock(ctx)
139-
if err != nil {
140-
return nil, err
141-
}
142-
return iter.MapErr(updates, convertValidatorUpdate[ValidatorUpdateT])
143-
}

mod/consensus/pkg/cometbft/helpers.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,12 @@ package cometbft
2323
import (
2424
"sort"
2525

26-
appmodulev2 "cosmossdk.io/core/appmodule/v2"
27-
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
2826
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
29-
"github.com/berachain/beacon-kit/mod/primitives/pkg/transition"
3027
cmtabci "github.com/cometbft/cometbft/abci/types"
3128
v1 "github.com/cometbft/cometbft/api/cometbft/abci/v1"
3229
sdk "github.com/cosmos/cosmos-sdk/types"
3330
)
3431

35-
// convertValidatorUpdate abstracts the conversion of a
36-
// transition.ValidatorUpdate to an appmodulev2.ValidatorUpdate.
37-
// TODO: this is so hood, bktypes -> sdktypes -> generic is crazy
38-
// maybe make this some kind of codec/func that can be passed in?
39-
func convertValidatorUpdate[ValidatorUpdateT any](
40-
u **transition.ValidatorUpdate,
41-
) (ValidatorUpdateT, error) {
42-
var valUpdate ValidatorUpdateT
43-
update := *u
44-
if update == nil {
45-
return valUpdate, ErrUndefinedValidatorUpdate
46-
}
47-
return any(appmodulev2.ValidatorUpdate{
48-
PubKey: update.Pubkey[:],
49-
PubKeyType: crypto.CometBLSType,
50-
//#nosec:G701 // this is safe.
51-
Power: int64(update.EffectiveBalance.Unwrap()),
52-
}).(ValidatorUpdateT), nil
53-
}
54-
5532
// convertPrepareProposalToSlotData converts a prepare proposal request to
5633
// a slot data.
5734
func (c *ConsensusEngine[

mod/consensus/pkg/cometbft/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ type Middleware[
6060
ProcessProposal(
6161
ctx context.Context, req proto.Message,
6262
) (proto.Message, error)
63-
PreBlock(_ context.Context, req proto.Message) error
64-
EndBlock(ctx context.Context) (transition.ValidatorUpdates, error)
63+
FinalizeBlock(
64+
ctx context.Context,
65+
req proto.Message,
66+
) (transition.ValidatorUpdates, error)
6567
}
6668

6769
// SlashingInfo is an interface for accessing the slashing info.

mod/node-core/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ require (
1919
github.com/berachain/beacon-kit/mod/beacon v0.0.0-20240718074353-1a991cfeed63
2020
github.com/berachain/beacon-kit/mod/cli v0.0.0-20240806160829-cde2d1347e7e
2121
github.com/berachain/beacon-kit/mod/config v0.0.0-20240705193247-d464364483df
22-
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240723155519-565f208d5482
23-
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240806160829-cde2d1347e7e
22+
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240809163303-a4ebb22fd018
23+
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240809163303-a4ebb22fd018
2424
github.com/berachain/beacon-kit/mod/da v0.0.0-20240705193247-d464364483df
2525
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197
2626
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240705193247-d464364483df

mod/node-core/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ github.com/berachain/beacon-kit/mod/cli v0.0.0-20240806160829-cde2d1347e7e h1:sP
8282
github.com/berachain/beacon-kit/mod/cli v0.0.0-20240806160829-cde2d1347e7e/go.mod h1:Sm5yEcVlCChGKhzVWYRYbQ8Z6EU9qDRp00UoGlC5HHQ=
8383
github.com/berachain/beacon-kit/mod/config v0.0.0-20240705193247-d464364483df h1:I0qrcOnLkWjruhCWJMY04Cc9KT78WaY4aXCIoUj9+V4=
8484
github.com/berachain/beacon-kit/mod/config v0.0.0-20240705193247-d464364483df/go.mod h1:xTHttdHtO63VauLvYve/J3DBLtXJKNk0dw5RhAo636k=
85-
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240723155519-565f208d5482 h1:o0JB2+luyAGmNF0B2byfAXcAXD/vA2x881miqwyPlAQ=
86-
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240723155519-565f208d5482/go.mod h1:LuuhwwOod5wfpPJpHhp+QdxkVcNLeadoCSSI32gp6vE=
87-
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240806160829-cde2d1347e7e h1:GTeZshNZaH5MnVhSSGj//vxJfv1kM9d6w2CA7O64gJk=
88-
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240806160829-cde2d1347e7e/go.mod h1:ZU1bq1BMt6b0kPRAw+A3kP7FlSd5DSQNYePD5qL9zfQ=
85+
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240809163303-a4ebb22fd018 h1:LvqiLOa8L5CKacYyphFHv363Y07nH4DJObuik0qSJ8c=
86+
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240809163303-a4ebb22fd018/go.mod h1:AabKi0yGSwa1FW9fZnuQXJi6OUcUzIWa4o4e8zm/5RM=
87+
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240809163303-a4ebb22fd018 h1:VN+glgL0JqQXf/N/8toDa9EnehltgBD4DbsHx65Macc=
88+
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240809163303-a4ebb22fd018/go.mod h1:A3Ohrylv4Dx2sf8EKJImC7ii091dUaWEAMp/AK5N6+s=
8989
github.com/berachain/beacon-kit/mod/da v0.0.0-20240705193247-d464364483df h1:yZtRZBkhDJ2xMlMLx5DdUFtrtH9iWyPNl4HSW2uJyb8=
9090
github.com/berachain/beacon-kit/mod/da v0.0.0-20240705193247-d464364483df/go.mod h1:iGTR+iYsqpj79WLX1RUVbV7hDs0rQtr+Iqa/VkAF4x8=
9191
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197 h1:wVWkiiERY/7kaXvE/VNPPUtYp/l8ky6QSuKM3ThVMXU=

mod/node-core/pkg/builder/baseapp_options.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ func WithProcessProposal(
6969
}
7070
}
7171

72-
// WithPreBlocker sets the pre-blocker to the baseapp.
73-
func WithPreBlocker(
74-
preBlocker sdk.PreBlocker,
75-
) func(bApp *baseapp.BaseApp) {
76-
return func(bApp *baseapp.BaseApp) {
77-
bApp.SetPreBlocker(preBlocker)
78-
}
79-
}
80-
8172
// DefaultBaseappOptions returns the default baseapp options provided by the
8273
// Cosmos SDK.
8374
func DefaultBaseappOptions(

mod/node-core/pkg/builder/builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,12 @@ func (nb *NodeBuilder[NodeT]) Build(
113113
// set the application to a new BeaconApp with necessary ABCI handlers
114114
nb.node.RegisterApp(
115115
runtime.NewBeaconKitApp(
116-
db, traceStore, true, appBuilder,
116+
db, traceStore, true, appBuilder, abciMiddleware,
117117
append(
118118
DefaultBaseappOptions(appOpts),
119119
WithCometParamStore(chainSpec),
120120
WithPrepareProposal(consensusEngine.PrepareProposal),
121121
WithProcessProposal(consensusEngine.ProcessProposal),
122-
WithPreBlocker(consensusEngine.PreBlock),
123122
)...,
124123
),
125124
)

mod/node-core/pkg/builder/config.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ func DefaultDepInjectConfig() depinject.Config {
3636
appconfig.Compose(&appv1alpha1.Config{
3737
Modules: []*appv1alpha1.ModuleConfig{
3838
{
39-
Name: "runtime",
40-
Config: appconfig.WrapAny(&runtimev1alpha1.Module{
41-
AppName: "BeaconKit",
42-
PreBlockers: []string{},
43-
BeginBlockers: []string{},
44-
EndBlockers: []string{beacon.ModuleName},
45-
InitGenesis: []string{beacon.ModuleName},
46-
}),
39+
Name: "runtime",
40+
Config: appconfig.WrapAny(&runtimev1alpha1.Module{}),
4741
},
4842
{
4943
Name: beacon.ModuleName,

mod/node-core/pkg/components/module/module.go

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ import (
2626
"cosmossdk.io/core/appmodule/v2"
2727
"cosmossdk.io/core/registry"
2828
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
29-
"github.com/berachain/beacon-kit/mod/consensus/pkg/cometbft"
30-
consruntimetypes "github.com/berachain/beacon-kit/mod/consensus/pkg/types"
3129
"github.com/berachain/beacon-kit/mod/node-core/pkg/components"
3230
"github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/json"
33-
"github.com/cosmos/cosmos-sdk/types/module"
3431
)
3532

3633
const (
@@ -41,9 +38,7 @@ const (
4138
)
4239

4340
var (
44-
_ appmodule.AppModule = AppModule{}
45-
_ module.HasABCIGenesis = AppModule{}
46-
_ module.HasABCIEndBlock = AppModule{}
41+
_ appmodule.AppModule = AppModule{}
4742
)
4843

4944
// AppModule implements an application module for the beacon module.
@@ -113,45 +108,3 @@ func (am AppModule) ExportGenesis(
113108
]{},
114109
)
115110
}
116-
117-
// InitGenesis initializes the beacon module's state from a provided genesis
118-
// state.
119-
func (am AppModule) InitGenesis(
120-
ctx context.Context,
121-
bz json.RawMessage,
122-
) ([]appmodule.ValidatorUpdate, error) {
123-
return cometbft.NewConsensusEngine[
124-
*types.AttestationData,
125-
*components.BeaconState,
126-
*types.SlashingInfo,
127-
*consruntimetypes.SlotData[
128-
*types.AttestationData,
129-
*types.SlashingInfo,
130-
],
131-
components.StorageBackend,
132-
appmodule.ValidatorUpdate,
133-
](
134-
am.ABCIMiddleware,
135-
*am.StorageBackend,
136-
).InitGenesis(ctx, bz)
137-
}
138-
139-
// EndBlock returns the validator set updates from the beacon state.
140-
func (am AppModule) EndBlock(
141-
ctx context.Context,
142-
) ([]appmodule.ValidatorUpdate, error) {
143-
return cometbft.NewConsensusEngine[
144-
*types.AttestationData,
145-
*components.BeaconState,
146-
*types.SlashingInfo,
147-
*consruntimetypes.SlotData[
148-
*types.AttestationData,
149-
*types.SlashingInfo,
150-
],
151-
components.StorageBackend,
152-
appmodule.ValidatorUpdate,
153-
](
154-
am.ABCIMiddleware,
155-
*am.StorageBackend,
156-
).EndBlock(ctx)
157-
}

mod/node-core/pkg/components/module/proto/buf.gen.gogo.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

mod/node-core/pkg/components/module/proto/buf.gen.pulsar.yaml

Lines changed: 0 additions & 42 deletions
This file was deleted.

mod/node-core/pkg/components/module/proto/buf.lock

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)