feat: Upgrade to CometBFT v1.x series (#24114)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
Co-authored-by: Zachary Becker <zachary@interchainlabs.io>
This commit is contained in:
Fabiana Cecin
2025-05-13 12:57:22 +00:00
committed by GitHub
co-authored by mergify[bot] Julián Toledano Julien Robert Tyler Alex | Interchain Labs Zachary Becker
parent b65dd23bad
commit b71d0894f0
315 changed files with 83967 additions and 4548 deletions
+14 -14
View File
@@ -16,58 +16,58 @@ func NewCometABCIWrapper(app servertypes.ABCI) abci.Application {
return cometABCIWrapper{app: app}
}
func (w cometABCIWrapper) Info(_ context.Context, req *abci.RequestInfo) (*abci.ResponseInfo, error) {
func (w cometABCIWrapper) Info(_ context.Context, req *abci.InfoRequest) (*abci.InfoResponse, error) {
return w.app.Info(req)
}
func (w cometABCIWrapper) Query(ctx context.Context, req *abci.RequestQuery) (*abci.ResponseQuery, error) {
func (w cometABCIWrapper) Query(ctx context.Context, req *abci.QueryRequest) (*abci.QueryResponse, error) {
return w.app.Query(ctx, req)
}
func (w cometABCIWrapper) CheckTx(_ context.Context, req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
func (w cometABCIWrapper) CheckTx(_ context.Context, req *abci.CheckTxRequest) (*abci.CheckTxResponse, error) {
return w.app.CheckTx(req)
}
func (w cometABCIWrapper) InitChain(_ context.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
func (w cometABCIWrapper) InitChain(_ context.Context, req *abci.InitChainRequest) (*abci.InitChainResponse, error) {
return w.app.InitChain(req)
}
func (w cometABCIWrapper) PrepareProposal(_ context.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
func (w cometABCIWrapper) PrepareProposal(_ context.Context, req *abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error) {
return w.app.PrepareProposal(req)
}
func (w cometABCIWrapper) ProcessProposal(_ context.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
func (w cometABCIWrapper) ProcessProposal(_ context.Context, req *abci.ProcessProposalRequest) (*abci.ProcessProposalResponse, error) {
return w.app.ProcessProposal(req)
}
func (w cometABCIWrapper) FinalizeBlock(_ context.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
func (w cometABCIWrapper) FinalizeBlock(_ context.Context, req *abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error) {
return w.app.FinalizeBlock(req)
}
func (w cometABCIWrapper) ExtendVote(ctx context.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
func (w cometABCIWrapper) ExtendVote(ctx context.Context, req *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) {
return w.app.ExtendVote(ctx, req)
}
func (w cometABCIWrapper) VerifyVoteExtension(_ context.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
func (w cometABCIWrapper) VerifyVoteExtension(_ context.Context, req *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) {
return w.app.VerifyVoteExtension(req)
}
func (w cometABCIWrapper) Commit(_ context.Context, _ *abci.RequestCommit) (*abci.ResponseCommit, error) {
func (w cometABCIWrapper) Commit(_ context.Context, _ *abci.CommitRequest) (*abci.CommitResponse, error) {
return w.app.Commit()
}
func (w cometABCIWrapper) ListSnapshots(_ context.Context, req *abci.RequestListSnapshots) (*abci.ResponseListSnapshots, error) {
func (w cometABCIWrapper) ListSnapshots(_ context.Context, req *abci.ListSnapshotsRequest) (*abci.ListSnapshotsResponse, error) {
return w.app.ListSnapshots(req)
}
func (w cometABCIWrapper) OfferSnapshot(_ context.Context, req *abci.RequestOfferSnapshot) (*abci.ResponseOfferSnapshot, error) {
func (w cometABCIWrapper) OfferSnapshot(_ context.Context, req *abci.OfferSnapshotRequest) (*abci.OfferSnapshotResponse, error) {
return w.app.OfferSnapshot(req)
}
func (w cometABCIWrapper) LoadSnapshotChunk(_ context.Context, req *abci.RequestLoadSnapshotChunk) (*abci.ResponseLoadSnapshotChunk, error) {
func (w cometABCIWrapper) LoadSnapshotChunk(_ context.Context, req *abci.LoadSnapshotChunkRequest) (*abci.LoadSnapshotChunkResponse, error) {
return w.app.LoadSnapshotChunk(req)
}
func (w cometABCIWrapper) ApplySnapshotChunk(_ context.Context, req *abci.RequestApplySnapshotChunk) (*abci.ResponseApplySnapshotChunk, error) {
func (w cometABCIWrapper) ApplySnapshotChunk(_ context.Context, req *abci.ApplySnapshotChunkRequest) (*abci.ApplySnapshotChunkResponse, error) {
return w.app.ApplySnapshotChunk(req)
}
+5 -3
View File
@@ -155,7 +155,7 @@ func VersionCmd() *cobra.Command {
BlockProtocol uint64
P2PProtocol uint64
}{
CometBFT: cmtversion.TMCoreSemVer,
CometBFT: cmtversion.CMTSemVer,
ABCI: cmtversion.ABCIVersion,
BlockProtocol: cmtversion.BlockProtocol,
P2PProtocol: cmtversion.P2PProtocol,
@@ -384,8 +384,10 @@ func BootstrapStateCmd(appCreator types.AppCreator) *cobra.Command {
app := appCreator(logger, db, nil, serverCtx.Viper)
height = app.CommitMultiStore().LastCommitID().Version
}
return node.BootstrapStateWithGenProvider(cmd.Context(), cfg, cmtcfg.DefaultDBProvider, getGenDocProvider(cfg), uint64(height), nil)
if height < 0 {
return fmt.Errorf("height must be non-negative, got %d", height)
}
return node.BootstrapState(cmd.Context(), cfg, cmtcfg.DefaultDBProvider, getGenDocProvider(cfg), uint64(height), nil)
},
}
+1 -1
View File
@@ -10,8 +10,8 @@ import (
"testing"
"time"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cmtcfg "github.com/cometbft/cometbft/config"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/rs/zerolog"
+4 -4
View File
@@ -102,21 +102,21 @@ type GenesisJSON struct {
// InitChainer returns a function that can initialize the chain
// with key/value pairs
func InitChainer(key storetypes.StoreKey) func(sdk.Context, *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
return func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
func InitChainer(key storetypes.StoreKey) func(sdk.Context, *abci.InitChainRequest) (*abci.InitChainResponse, error) {
return func(ctx sdk.Context, req *abci.InitChainRequest) (*abci.InitChainResponse, error) {
stateJSON := req.AppStateBytes
genesisState := new(GenesisJSON)
err := json.Unmarshal(stateJSON, genesisState)
if err != nil {
return &abci.ResponseInitChain{}, err
return &abci.InitChainResponse{}, err
}
for _, val := range genesisState.Values {
store := ctx.KVStore(key)
store.Set([]byte(val.Key), []byte(val.Value))
}
return &abci.ResponseInitChain{}, nil
return &abci.InitChainResponse{}, nil
}
}
+5 -5
View File
@@ -37,12 +37,12 @@ func TestInitApp(t *testing.T) {
appState, err := AppGenState(nil, genutiltypes.AppGenesis{}, nil)
require.NoError(t, err)
res, err := app.InitChain(&abci.RequestInitChain{
res, err := app.InitChain(&abci.InitChainRequest{
AppStateBytes: appState,
})
require.NoError(t, err)
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
_, err = app.FinalizeBlock(&abci.FinalizeBlockRequest{
Hash: res.AppHash,
Height: 1,
})
@@ -52,7 +52,7 @@ func TestInitApp(t *testing.T) {
require.NoError(t, err)
// make sure we can query these values
query := abci.RequestQuery{
query := abci.QueryRequest{
Path: "/store/main/key",
Data: []byte("foo"),
}
@@ -75,7 +75,7 @@ func TestDeliverTx(t *testing.T) {
tx := NewTx(key, value, randomAccounts[0].Address)
txBytes := tx.GetSignBytes()
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
res, err := app.FinalizeBlock(&abci.FinalizeBlockRequest{
Hash: []byte("apphash"),
Height: 1,
Txs: [][]byte{txBytes},
@@ -87,7 +87,7 @@ func TestDeliverTx(t *testing.T) {
require.NoError(t, err)
// make sure we can query these values
query := abci.RequestQuery{
query := abci.QueryRequest{
Path: "/store/main/key",
Data: []byte(key),
}
+68 -32
View File
@@ -3,6 +3,8 @@ package server
import (
"bufio"
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"net"
@@ -13,14 +15,14 @@ import (
"time"
"github.com/cometbft/cometbft/abci/server"
cmtstate "github.com/cometbft/cometbft/api/cometbft/state/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
cmtcfg "github.com/cometbft/cometbft/config"
cmtjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/node"
"github.com/cometbft/cometbft/p2p"
pvm "github.com/cometbft/cometbft/privval"
cmtstate "github.com/cometbft/cometbft/proto/tendermint/state"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/proxy"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cometbft/cometbft/rpc/client/local"
@@ -178,12 +180,12 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
_, err := GetPruningOptionsFromFlags(serverCtx.Viper)
if err != nil {
return err
return fmt.Errorf("failed to get pruning options: %w", err)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
return fmt.Errorf("failed to get client context: %w", err)
}
withCMT, _ := cmd.Flags().GetBool(flagWithComet)
@@ -215,18 +217,18 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
func start(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreator, withCmt bool, opts StartCmdOptions) error {
svrCfg, err := getAndValidateConfig(svrCtx)
if err != nil {
return err
return fmt.Errorf("failed to get and validate config: %w", err)
}
app, appCleanupFn, err := startApp(svrCtx, appCreator, opts)
if err != nil {
return err
return fmt.Errorf("failed to start app: %w", err)
}
defer appCleanupFn()
metrics, err := startTelemetry(svrCfg)
if err != nil {
return err
return fmt.Errorf("failed to start telemetry: %w", err)
}
emitServerInfoMetrics()
@@ -257,7 +259,7 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie
if svrCfg.API.Enable || svrCfg.GRPC.Enable {
// create tendermint client
// assumes the rpc listen address is where tendermint has its rpc server
rpcclient, err := rpchttp.New(svrCtx.Config.RPC.ListenAddress, "/websocket")
rpcclient, err := rpchttp.New(svrCtx.Config.RPC.ListenAddress)
if err != nil {
return err
}
@@ -273,12 +275,12 @@ func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clie
grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app)
if err != nil {
return err
return fmt.Errorf("failed to start grpc server: %w", err)
}
err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, svrCtx.Config.RootDir, grpcSrv, metrics)
if err != nil {
return err
return fmt.Errorf("failed to start api server: %w", err)
}
if opts.PostSetupStandalone != nil {
@@ -339,12 +341,12 @@ func startInProcess(svrCtx *Context, svrCfg serverconfig.Config, clientCtx clien
grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app)
if err != nil {
return err
return fmt.Errorf("failed to start grpc server: %w", err)
}
err = startAPIServer(ctx, g, svrCfg, clientCtx, svrCtx, app, cmtCfg.RootDir, grpcSrv, metrics)
if err != nil {
return err
return fmt.Errorf("failed to start api server: %w", err)
}
if opts.PostSetup != nil {
@@ -367,14 +369,20 @@ func startCmtNode(
) (tmNode *node.Node, cleanupFn func(), err error) {
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
if err != nil {
return nil, cleanupFn, err
return nil, cleanupFn, fmt.Errorf("failed to load or generate node key: %w", err)
}
// CometBFT uses the ed25519 key generator as default if the given generator function is nil.
pv, err := pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile(), nil)
if err != nil {
return nil, cleanupFn, fmt.Errorf("failed to load or generate priv_validator: %w", err)
}
cmtApp := NewCometABCIWrapper(app)
tmNode, err = node.NewNodeWithContext(
tmNode, err = node.NewNode(
ctx,
cfg,
pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile()),
pv,
nodeKey,
proxy.NewLocalClientCreator(cmtApp),
getGenDocProvider(cfg),
@@ -383,11 +391,11 @@ func startCmtNode(
servercmtlog.CometLoggerWrapper{Logger: svrCtx.Logger},
)
if err != nil {
return tmNode, cleanupFn, err
return tmNode, cleanupFn, fmt.Errorf("failed to create new comet node: %w", err)
}
if err := tmNode.Start(); err != nil {
return tmNode, cleanupFn, err
return tmNode, cleanupFn, fmt.Errorf("failed to start comet node: %w", err)
}
cleanupFn = func() {
@@ -411,15 +419,38 @@ func getAndValidateConfig(svrCtx *Context) (serverconfig.Config, error) {
return config, nil
}
// returns a function which returns the genesis doc from the genesis file.
func getGenDocProvider(cfg *cmtcfg.Config) func() (*cmttypes.GenesisDoc, error) {
return func() (*cmttypes.GenesisDoc, error) {
appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile())
if err != nil {
return nil, err
// getGenDocProvider returns a function which returns the genesis doc from the genesis file.
func getGenDocProvider(cfg *cmtcfg.Config) func() (node.ChecksummedGenesisDoc, error) {
return func() (node.ChecksummedGenesisDoc, error) {
defaultGenesisDoc := node.ChecksummedGenesisDoc{
Sha256Checksum: []byte{},
}
return appGenesis.ToGenesisDoc()
appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile())
if err != nil {
return defaultGenesisDoc, err
}
gen, err := appGenesis.ToGenesisDoc()
if err != nil {
return defaultGenesisDoc, err
}
genbz, err := gen.AppState.MarshalJSON()
if err != nil {
return defaultGenesisDoc, err
}
bz, err := json.Marshal(genbz)
if err != nil {
return defaultGenesisDoc, err
}
sum := sha256.Sum256(bz)
return node.ChecksummedGenesisDoc{
GenesisDoc: gen,
Sha256Checksum: sum[:],
}, nil
}
}
@@ -775,7 +806,12 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
defer blockStore.Close()
defer stateDB.Close()
privValidator := pvm.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
// CometBFT uses the ed25519 key generator as default if the given generator function is nil.
privValidator, err := pvm.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile(), nil)
if err != nil {
return nil, err
}
userPubKey, err := privValidator.GetPubKey()
if err != nil {
return nil, err
@@ -786,7 +822,7 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
DiscardABCIResponses: config.Storage.DiscardABCIResponses,
})
state, genDoc, err := node.LoadStateFromDBOrGenesisDocProvider(stateDB, genDocProvider)
state, genDoc, err := node.LoadStateFromDBOrGenesisDocProvider(stateDB, genDocProvider, "")
if err != nil {
return nil, err
}
@@ -802,12 +838,12 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
_, context := getCtx(ctx, true)
clientCreator := proxy.NewLocalClientCreator(cmtApp)
metrics := node.DefaultMetricsProvider(cmtcfg.DefaultConfig().Instrumentation)
_, _, _, _, proxyMetrics, _, _ := metrics(genDoc.ChainID)
_, _, _, _, _, proxyMetrics, _, _ := metrics(genDoc.ChainID) //nolint: dogsled // function from comet
proxyApp := proxy.NewAppConns(clientCreator, proxyMetrics)
if err := proxyApp.Start(); err != nil {
return nil, fmt.Errorf("error starting proxy app connections: %w", err)
}
res, err := proxyApp.Query().Info(context, proxy.RequestInfo)
res, err := proxyApp.Query().Info(context, proxy.InfoRequest)
if err != nil {
return nil, fmt.Errorf("error calling Info: %w", err)
}
@@ -821,7 +857,7 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
var block *cmttypes.Block
switch {
case appHeight == blockStore.Height():
block = blockStore.LoadBlock(blockStore.Height())
block, _ = blockStore.LoadBlock(blockStore.Height())
// If the state's last blockstore height does not match the app and blockstore height, we likely stopped with the halt height flag.
if state.LastBlockHeight != appHeight {
state.LastBlockHeight = appHeight
@@ -840,10 +876,10 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
if err != nil {
return nil, err
}
block = blockStore.LoadBlock(blockStore.Height())
block, _ = blockStore.LoadBlock(blockStore.Height())
default:
// If there is any other state, we just load the block
block = blockStore.LoadBlock(blockStore.Height())
block, _ = blockStore.LoadBlock(blockStore.Height())
}
block.ChainID = newChainID
@@ -866,7 +902,7 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
// Sign the vote, and copy the proto changes from the act of signing to the vote itself
voteProto := vote.ToProto()
err = privValidator.SignVote(newChainID, voteProto)
err = privValidator.SignVote(newChainID, voteProto, false)
if err != nil {
return nil, err
}
+14 -14
View File
@@ -10,28 +10,28 @@ import (
// to be driven by a blockchain-based replication engine via the ABCI.
type ABCI interface {
// Info/Query Connection
Info(*abci.RequestInfo) (*abci.ResponseInfo, error) // Return application info
Query(context.Context, *abci.RequestQuery) (*abci.ResponseQuery, error) // Query for state
Info(*abci.InfoRequest) (*abci.InfoResponse, error) // Return application info
Query(context.Context, *abci.QueryRequest) (*abci.QueryResponse, error) // Query for state
// Mempool Connection
CheckTx(*abci.RequestCheckTx) (*abci.ResponseCheckTx, error) // Validate a tx for the mempool
CheckTx(*abci.CheckTxRequest) (*abci.CheckTxResponse, error) // Validate a tx for the mempool
// Consensus Connection
InitChain(*abci.RequestInitChain) (*abci.ResponseInitChain, error) // Initialize blockchain w validators/other info from CometBFT
PrepareProposal(*abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error)
ProcessProposal(*abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error)
InitChain(*abci.InitChainRequest) (*abci.InitChainResponse, error) // Initialize blockchain w validators/other info from CometBFT
PrepareProposal(*abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error)
ProcessProposal(*abci.ProcessProposalRequest) (*abci.ProcessProposalResponse, error)
// Deliver the decided block with its txs to the Application
FinalizeBlock(*abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error)
FinalizeBlock(*abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error)
// Create application specific vote extension
ExtendVote(context.Context, *abci.RequestExtendVote) (*abci.ResponseExtendVote, error)
ExtendVote(context.Context, *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error)
// Verify application's vote extension data
VerifyVoteExtension(*abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error)
VerifyVoteExtension(*abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error)
// Commit the state and return the application Merkle root hash
Commit() (*abci.ResponseCommit, error)
Commit() (*abci.CommitResponse, error)
// State Sync Connection
ListSnapshots(*abci.RequestListSnapshots) (*abci.ResponseListSnapshots, error) // List available snapshots
OfferSnapshot(*abci.RequestOfferSnapshot) (*abci.ResponseOfferSnapshot, error) // Offer a snapshot to the application
LoadSnapshotChunk(*abci.RequestLoadSnapshotChunk) (*abci.ResponseLoadSnapshotChunk, error) // Load a snapshot chunk
ApplySnapshotChunk(*abci.RequestApplySnapshotChunk) (*abci.ResponseApplySnapshotChunk, error) // Apply a shapshot chunk
ListSnapshots(*abci.ListSnapshotsRequest) (*abci.ListSnapshotsResponse, error) // List available snapshots
OfferSnapshot(*abci.OfferSnapshotRequest) (*abci.OfferSnapshotResponse, error) // Offer a snapshot to the application
LoadSnapshotChunk(*abci.LoadSnapshotChunkRequest) (*abci.LoadSnapshotChunkResponse, error) // Load a snapshot chunk
ApplySnapshotChunk(*abci.ApplySnapshotChunkRequest) (*abci.ApplySnapshotChunkResponse, error) // Apply a shapshot chunk
}
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"encoding/json"
"io"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cmttypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/grpc"