Skip to content

Commit

Permalink
Revert "Merge branch 'archbear/interfaces' into bls-into-sdk2"
Browse files Browse the repository at this point in the history
This reverts commit ab2d374, reversing
changes made to b9f58dc.
  • Loading branch information
archbear committed Jul 4, 2024
1 parent 545b8c0 commit 50c1ddf
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 152 deletions.
4 changes: 2 additions & 2 deletions runtime/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type AppI[T transaction.Tx] interface {
// done declaratively with an app config and the rest of it is done the old way.
// See simapp/app_v2.go for an example of this setup.
type App[T transaction.Tx] struct {
appmanager.AppManager[T]
*appmanager.AppManager[T]

// app manager dependencies
stf *stf.STF[T]
Expand Down Expand Up @@ -127,6 +127,6 @@ func (a *App[T]) ExecuteGenesisTx(_ []byte) error {
panic("App.ExecuteGenesisTx not supported in runtime/v2")
}

func (a *App[T]) GetAppManager() appmanager.AppManager[T] {
func (a *App[T]) GetAppManager() *appmanager.AppManager[T] {
return a.AppManager
}
13 changes: 6 additions & 7 deletions runtime/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ func ProvideModuleManager[T transaction.Tx](
}

// ProvideEnvironment provides the environment for keeper modules, while maintaining backward compatibility and provide services directly as well.
func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.Module, key depinject.ModuleKey) (
appBuilder *AppBuilder[T],
env appmodulev2.Environment,
kvss store.KVStoreService,
mss store.MemoryStoreService,
func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.Module, key depinject.ModuleKey, appBuilder *AppBuilder[T]) (
appmodulev2.Environment,
store.KVStoreService,
store.MemoryStoreService,
) {
var (
kvService store.KVStoreService = failingStoreService{}
Expand All @@ -208,7 +207,7 @@ func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.M
memKvService = stf.NewMemoryStoreService([]byte(memStoreKey))
}

env = appmodulev2.Environment{
env := appmodulev2.Environment{
Logger: logger,
BranchService: stf.BranchService{},
EventService: stf.NewEventService(),
Expand All @@ -221,7 +220,7 @@ func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.M
MemStoreService: memKvService,
}

return appBuilder, env, kvService, memKvService
return env, kvService, memKvService
}

func registerStoreKey[T transaction.Tx](wrapper *AppBuilder[T], key string) {
Expand Down
19 changes: 10 additions & 9 deletions server/v2/appmanager/appmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"cosmossdk.io/server/v2/appmanager/store"
)

// appManager is a coordinator for all things related to an application
type appManager[T transaction.Tx] struct {
// AppManager is a coordinator for all things related to an application
// TODO: add exportGenesis function
type AppManager[T transaction.Tx] struct {
config Config

db store.Store
Expand All @@ -24,7 +25,7 @@ type appManager[T transaction.Tx] struct {
stf StateTransitionFunction[T]
}

func (a appManager[T]) InitGenesis(
func (a AppManager[T]) InitGenesis(
ctx context.Context,
blockRequest *appmanager.BlockRequest[T],
initGenesisJSON []byte,
Expand Down Expand Up @@ -68,7 +69,7 @@ func (a appManager[T]) InitGenesis(
}

// ExportGenesis exports the genesis state of the application.
func (a appManager[T]) ExportGenesis(ctx context.Context, version uint64) ([]byte, error) {
func (a AppManager[T]) ExportGenesis(ctx context.Context, version uint64) ([]byte, error) {
bz, err := a.exportGenesis(ctx, version)
if err != nil {
return nil, fmt.Errorf("failed to export genesis state: %w", err)
Expand All @@ -77,7 +78,7 @@ func (a appManager[T]) ExportGenesis(ctx context.Context, version uint64) ([]byt
return bz, nil
}

func (a appManager[T]) DeliverBlock(
func (a AppManager[T]) DeliverBlock(
ctx context.Context,
block *appmanager.BlockRequest[T],
) (*appmanager.BlockResponse, corestore.WriterMap, error) {
Expand All @@ -101,7 +102,7 @@ func (a appManager[T]) DeliverBlock(
// ValidateTx will validate the tx against the latest storage state. This means that
// only the stateful validation will be run, not the execution portion of the tx.
// If full execution is needed, Simulate must be used.
func (a appManager[T]) ValidateTx(ctx context.Context, tx T) (appmanager.TxResult, error) {
func (a AppManager[T]) ValidateTx(ctx context.Context, tx T) (appmanager.TxResult, error) {
_, latestState, err := a.db.StateLatest()
if err != nil {
return appmanager.TxResult{}, err
Expand All @@ -110,7 +111,7 @@ func (a appManager[T]) ValidateTx(ctx context.Context, tx T) (appmanager.TxResul
}

// Simulate runs validation and execution flow of a Tx.
func (a appManager[T]) Simulate(ctx context.Context, tx T) (appmanager.TxResult, corestore.WriterMap, error) {
func (a AppManager[T]) Simulate(ctx context.Context, tx T) (appmanager.TxResult, corestore.WriterMap, error) {
_, state, err := a.db.StateLatest()
if err != nil {
return appmanager.TxResult{}, nil, err
Expand All @@ -121,7 +122,7 @@ func (a appManager[T]) Simulate(ctx context.Context, tx T) (appmanager.TxResult,

// Query queries the application at the provided version.
// CONTRACT: Version must always be provided, if 0, get latest
func (a appManager[T]) Query(ctx context.Context, version uint64, request transaction.Msg) (transaction.Msg, error) {
func (a AppManager[T]) Query(ctx context.Context, version uint64, request transaction.Msg) (transaction.Msg, error) {
// if version is provided attempt to do a height query.
if version != 0 {
queryState, err := a.db.StateAt(version)
Expand All @@ -142,7 +143,7 @@ func (a appManager[T]) Query(ctx context.Context, version uint64, request transa
// QueryWithState executes a query with the provided state. This allows to process a query
// independently of the db state. For example, it can be used to process a query with temporary
// and uncommitted state
func (a appManager[T]) QueryWithState(
func (a AppManager[T]) QueryWithState(
ctx context.Context,
state corestore.ReaderMap,
request transaction.Msg,
Expand Down
4 changes: 2 additions & 2 deletions server/v2/appmanager/appmanager_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type Builder[T transaction.Tx] struct {

// Build creates a new instance of AppManager with the provided configuration and returns it.
// It initializes the AppManager with the given database, export state, import state, initGenesis function, and state transition function.
func (b Builder[T]) Build() (AppManager[T], error) {
return &appManager[T]{
func (b Builder[T]) Build() (*AppManager[T], error) {
return &AppManager[T]{
config: Config{
ValidateTxGasLimit: b.ValidateTxGasLimit,
QueryGasLimit: b.QueryGasLimit,
Expand Down
54 changes: 0 additions & 54 deletions server/v2/appmanager/interfaces.go

This file was deleted.

62 changes: 19 additions & 43 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,10 @@ import (
consensustypes "cosmossdk.io/x/consensus/types"
)

var (
_ abci.Application = (*consensus[transaction.Tx])(nil)
_ Consensus[transaction.Tx] = (*consensus[transaction.Tx])(nil)
_ abci.Application = (Consensus[transaction.Tx])(nil)
)

// Consensus defines the interface for consensus operations in the CometBFT system.
type Consensus[T transaction.Tx] interface {
abci.Application
// GetStore returns the store used by the consensus.
GetStore() types.Store
// SetStreamingManager sets the streaming manager for the consensus.
SetStreamingManager(sm streaming.Manager)
// SetSnapshotManager sets the snapshot manager for the consensus.
SetSnapshotManager(sm *snapshots.Manager)
// RegisterExtensions registers snapshot extensions for the consensus.
RegisterExtensions(extensions ...snapshots.ExtensionSnapshotter)
// CheckTx checks the validity of a transaction.
CheckTx(ctx context.Context, req *abciproto.CheckTxRequest) (*abciproto.CheckTxResponse, error)
}
var _ abci.Application = (*Consensus[transaction.Tx])(nil)

type consensus[T transaction.Tx] struct {
app appmanager.AppManager[T]
type Consensus[T transaction.Tx] struct {
app *appmanager.AppManager[T]
cfg Config
store types.Store
logger log.Logger
Expand All @@ -73,14 +54,14 @@ type consensus[T transaction.Tx] struct {
}

func NewConsensus[T transaction.Tx](
app appmanager.AppManager[T],
app *appmanager.AppManager[T],
mp mempool.Mempool[T],
store types.Store,
cfg Config,
txCodec transaction.Codec[T],
logger log.Logger,
) *consensus[T] {
return &consensus[T]{
) *Consensus[T] {
return &Consensus[T]{
mempool: mp,
store: store,
app: app,
Expand All @@ -90,34 +71,29 @@ func NewConsensus[T transaction.Tx](
}
}

func (c *consensus[T]) SetStreamingManager(sm streaming.Manager) {
func (c *Consensus[T]) SetStreamingManager(sm streaming.Manager) {
c.streaming = sm
}

// SetSnapshotManager sets the snapshot manager for the Consensus.
// The snapshot manager is responsible for managing snapshots of the Consensus state.
// It allows for creating, storing, and restoring snapshots of the Consensus state.
// The provided snapshot manager will be used by the Consensus to handle snapshots.
func (c *consensus[T]) SetSnapshotManager(sm *snapshots.Manager) {
func (c *Consensus[T]) SetSnapshotManager(sm *snapshots.Manager) {
c.snapshotManager = sm
}

// GetStore returns the store used by the consensus.
func (c *consensus[T]) GetStore() types.Store {
return c.store
}

// RegisterExtensions registers the given extensions with the consensus module's snapshot manager.
// It allows additional snapshotter implementations to be used for creating and restoring snapshots.
func (c *consensus[T]) RegisterExtensions(extensions ...snapshots.ExtensionSnapshotter) {
func (c *Consensus[T]) RegisterExtensions(extensions ...snapshots.ExtensionSnapshotter) {
if err := c.snapshotManager.RegisterExtensions(extensions...); err != nil {
panic(fmt.Errorf("failed to register snapshot extensions: %w", err))
}
}

// CheckTx implements types.Application.
// It is called by cometbft to verify transaction validity
func (c *consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxRequest) (*abciproto.CheckTxResponse, error) {
func (c *Consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxRequest) (*abciproto.CheckTxResponse, error) {
decodedTx, err := c.txCodec.Decode(req.Tx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -146,7 +122,7 @@ func (c *consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxReques
}

// Info implements types.Application.
func (c *consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abciproto.InfoResponse, error) {
func (c *Consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abciproto.InfoResponse, error) {
version, _, err := c.store.StateLatest()
if err != nil {
return nil, err
Expand Down Expand Up @@ -174,7 +150,7 @@ func (c *consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abc

// Query implements types.Application.
// It is called by cometbft to query application state.
func (c *consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (*abciproto.QueryResponse, error) {
func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (*abciproto.QueryResponse, error) {
// follow the query path from here
decodedMsg, err := c.txCodec.Decode(req.Data)
protoMsg, ok := any(decodedMsg).(transaction.Msg)
Expand Down Expand Up @@ -228,7 +204,7 @@ func (c *consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
}

// InitChain implements types.Application.
func (c *consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRequest) (*abciproto.InitChainResponse, error) {
func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRequest) (*abciproto.InitChainResponse, error) {
c.logger.Info("InitChain", "initialHeight", req.InitialHeight, "chainID", req.ChainId)

// store chainID to be used later on in execution
Expand Down Expand Up @@ -313,7 +289,7 @@ func (c *consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe

// PrepareProposal implements types.Application.
// It is called by cometbft to prepare a proposal block.
func (c *consensus[T]) PrepareProposal(
func (c *Consensus[T]) PrepareProposal(
ctx context.Context,
req *abciproto.PrepareProposalRequest,
) (resp *abciproto.PrepareProposalResponse, err error) {
Expand Down Expand Up @@ -357,7 +333,7 @@ func (c *consensus[T]) PrepareProposal(

// ProcessProposal implements types.Application.
// It is called by cometbft to process/verify a proposal block.
func (c *consensus[T]) ProcessProposal(
func (c *Consensus[T]) ProcessProposal(
ctx context.Context,
req *abciproto.ProcessProposalRequest,
) (*abciproto.ProcessProposalResponse, error) {
Expand Down Expand Up @@ -395,7 +371,7 @@ func (c *consensus[T]) ProcessProposal(

// FinalizeBlock implements types.Application.
// It is called by cometbft to finalize a block.
func (c *consensus[T]) FinalizeBlock(
func (c *Consensus[T]) FinalizeBlock(
ctx context.Context,
req *abciproto.FinalizeBlockRequest,
) (*abciproto.FinalizeBlockResponse, error) {
Expand Down Expand Up @@ -515,7 +491,7 @@ func (c *consensus[T]) FinalizeBlock(

// Commit implements types.Application.
// It is called by cometbft to notify the application that a block was committed.
func (c *consensus[T]) Commit(ctx context.Context, _ *abciproto.CommitRequest) (*abciproto.CommitResponse, error) {
func (c *Consensus[T]) Commit(ctx context.Context, _ *abciproto.CommitRequest) (*abciproto.CommitResponse, error) {
lastCommittedHeight := c.lastCommittedHeight.Load()

c.snapshotManager.SnapshotIfApplicable(lastCommittedHeight)
Expand All @@ -532,7 +508,7 @@ func (c *consensus[T]) Commit(ctx context.Context, _ *abciproto.CommitRequest) (

// Vote extensions
// VerifyVoteExtension implements types.Application.
func (c *consensus[T]) VerifyVoteExtension(
func (c *Consensus[T]) VerifyVoteExtension(
ctx context.Context,
req *abciproto.VerifyVoteExtensionRequest,
) (*abciproto.VerifyVoteExtensionResponse, error) {
Expand Down Expand Up @@ -569,7 +545,7 @@ func (c *consensus[T]) VerifyVoteExtension(
}

// ExtendVote implements types.Application.
func (c *consensus[T]) ExtendVote(ctx context.Context, req *abciproto.ExtendVoteRequest) (*abciproto.ExtendVoteResponse, error) {
func (c *Consensus[T]) ExtendVote(ctx context.Context, req *abciproto.ExtendVoteRequest) (*abciproto.ExtendVoteResponse, error) {
// If vote extensions are not enabled, as a safety precaution, we return an
// error.
cp, err := c.GetConsensusParams(ctx)
Expand Down
4 changes: 2 additions & 2 deletions server/v2/cometbft/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func (s *CometBFTServer[AppT, T]) rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) {
if s.Config.Standalone {
if s.config.Standalone {
client, err := rpchttp.New(client.GetConfigFromCmd(cmd).RPC.ListenAddress)
if err != nil {
return nil, err
Expand Down Expand Up @@ -395,7 +395,7 @@ func (s *CometBFTServer[AppT, T]) BootstrapStateCmd() *cobra.Command {
return err
}
if height == 0 {
height, err = s.Consensus.GetStore().GetLatestVersion()
height, err = s.Consensus.store.GetLatestVersion()
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 50c1ddf

Please sign in to comment.