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:
co-authored by
mergify[bot]
Julián Toledano
Julien Robert
Tyler
Alex | Interchain Labs
Zachary Becker
parent
b65dd23bad
commit
b71d0894f0
@@ -18,12 +18,12 @@ var _ client.CometRPC = (*MockCometRPC)(nil)
|
||||
type MockCometRPC struct {
|
||||
rpcclientmock.Client
|
||||
|
||||
responseQuery abci.ResponseQuery
|
||||
responseQuery abci.QueryResponse
|
||||
}
|
||||
|
||||
// NewMockCometRPC returns a mock CometBFT RPC implementation.
|
||||
// It is used for CLI testing.
|
||||
func NewMockCometRPC(respQuery abci.ResponseQuery) MockCometRPC {
|
||||
func NewMockCometRPC(respQuery abci.QueryResponse) MockCometRPC {
|
||||
return MockCometRPC{responseQuery: respQuery}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
cmtabcitypes "github.com/cometbft/cometbft/abci/types"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
@@ -60,14 +60,14 @@ func NewIntegrationApp(
|
||||
bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), append(baseAppOptions, baseapp.SetChainID(appName))...)
|
||||
bApp.MountKVStores(keys)
|
||||
|
||||
bApp.SetInitChainer(func(_ sdk.Context, _ *cmtabcitypes.RequestInitChain) (*cmtabcitypes.ResponseInitChain, error) {
|
||||
bApp.SetInitChainer(func(_ sdk.Context, _ *cmtabcitypes.InitChainRequest) (*cmtabcitypes.InitChainResponse, error) {
|
||||
for _, mod := range modules {
|
||||
if m, ok := mod.(module.HasGenesis); ok {
|
||||
m.InitGenesis(sdkCtx, appCodec, m.DefaultGenesis(appCodec))
|
||||
}
|
||||
}
|
||||
|
||||
return &cmtabcitypes.ResponseInitChain{}, nil
|
||||
return &cmtabcitypes.InitChainResponse{}, nil
|
||||
})
|
||||
|
||||
bApp.SetBeginBlocker(func(_ sdk.Context) (sdk.BeginBlock, error) {
|
||||
@@ -90,7 +90,7 @@ func NewIntegrationApp(
|
||||
panic(fmt.Errorf("failed to load application version from store: %w", err))
|
||||
}
|
||||
|
||||
if _, err := bApp.InitChain(&cmtabcitypes.RequestInitChain{ChainId: appName, ConsensusParams: simtestutil.DefaultConsensusParams}); err != nil {
|
||||
if _, err := bApp.InitChain(&cmtabcitypes.InitChainRequest{ChainId: appName, ConsensusParams: simtestutil.DefaultConsensusParams}); err != nil {
|
||||
panic(fmt.Errorf("failed to initialize application: %w", err))
|
||||
}
|
||||
} else {
|
||||
@@ -98,7 +98,7 @@ func NewIntegrationApp(
|
||||
panic(fmt.Errorf("failed to load application version from store: %w", err))
|
||||
}
|
||||
|
||||
if _, err := bApp.InitChain(&cmtabcitypes.RequestInitChain{ChainId: appName}); err != nil {
|
||||
if _, err := bApp.InitChain(&cmtabcitypes.InitChainRequest{ChainId: appName}); err != nil {
|
||||
panic(fmt.Errorf("failed to initialize application: %w", err))
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) {
|
||||
|
||||
if cfg.AutomaticFinalizeBlock {
|
||||
height := app.LastBlockHeight() + 1
|
||||
if _, err := app.FinalizeBlock(&cmtabcitypes.RequestFinalizeBlock{Height: height}); err != nil {
|
||||
if _, err := app.FinalizeBlock(&cmtabcitypes.FinalizeBlockRequest{Height: height}); err != nil {
|
||||
return nil, fmt.Errorf("failed to run finalize block: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
"github.com/cometbft/cometbft/crypto"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
@@ -28,13 +28,21 @@ func (pv PV) GetPubKey() (crypto.PubKey, error) {
|
||||
}
|
||||
|
||||
// SignVote implements PrivValidator interface
|
||||
func (pv PV) SignVote(chainID string, vote *cmtproto.Vote) error {
|
||||
func (pv PV) SignVote(chainID string, vote *cmtproto.Vote, signExtension bool) error {
|
||||
signBytes := cmttypes.VoteSignBytes(chainID, vote)
|
||||
sig, err := pv.PrivKey.Sign(signBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vote.Signature = sig
|
||||
if signExtension {
|
||||
extSignBytes := cmttypes.VoteExtensionSignBytes(chainID, vote)
|
||||
extSig, err := pv.PrivKey.Sign(extSignBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
vote.ExtensionSignature = extSig
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package mock
|
||||
import (
|
||||
"testing"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestGetPubKey(t *testing.T) {
|
||||
func TestSignVote(t *testing.T) {
|
||||
pv := NewPV()
|
||||
v := cmtproto.Vote{}
|
||||
err := pv.SignVote("chain-id", &v)
|
||||
err := pv.SignVote("chain-id", &v, false)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, v.Signature)
|
||||
}
|
||||
|
||||
@@ -473,7 +473,12 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
|
||||
cmtCfg.P2P.AddrBookStrict = false
|
||||
cmtCfg.P2P.AllowDuplicateIP = true
|
||||
|
||||
nodeID, pubKey, err := genutil.InitializeNodeValidatorFiles(cmtCfg)
|
||||
var mnemonic string
|
||||
if i < len(cfg.Mnemonics) {
|
||||
mnemonic = cfg.Mnemonics[i]
|
||||
}
|
||||
|
||||
nodeID, pubKey, err := genutil.InitializeNodeValidatorFilesFromMnemonic(cmtCfg, mnemonic)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -492,11 +497,6 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var mnemonic string
|
||||
if i < len(cfg.Mnemonics) {
|
||||
mnemonic = cfg.Mnemonics[i]
|
||||
}
|
||||
|
||||
addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, mnemonic, true, algo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
pvm "github.com/cometbft/cometbft/privval"
|
||||
"github.com/cometbft/cometbft/proxy"
|
||||
"github.com/cometbft/cometbft/rpc/client/local"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
cmttime "github.com/cometbft/cometbft/types/time"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
@@ -47,19 +46,34 @@ func startInProcess(cfg Config, val *Validator) error {
|
||||
app := cfg.AppConstructor(*val)
|
||||
val.app = app
|
||||
|
||||
appGenesisProvider := func() (*cmttypes.GenesisDoc, error) {
|
||||
appGenesisProvider := func() (node.ChecksummedGenesisDoc, error) {
|
||||
appGenesis, err := genutiltypes.AppGenesisFromFile(cmtCfg.GenesisFile())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return node.ChecksummedGenesisDoc{
|
||||
Sha256Checksum: []byte{},
|
||||
}, err
|
||||
}
|
||||
|
||||
return appGenesis.ToGenesisDoc()
|
||||
gen, err := appGenesis.ToGenesisDoc()
|
||||
if err != nil {
|
||||
return node.ChecksummedGenesisDoc{
|
||||
Sha256Checksum: []byte{},
|
||||
}, err
|
||||
}
|
||||
return node.ChecksummedGenesisDoc{GenesisDoc: gen, Sha256Checksum: make([]byte, 0)}, nil
|
||||
}
|
||||
|
||||
cmtApp := server.NewCometABCIWrapper(app)
|
||||
|
||||
// CometBFT uses the ed25519 key generator as default if the given generator function is nil.
|
||||
pv, err := pvm.LoadOrGenFilePV(cmtCfg.PrivValidatorKeyFile(), cmtCfg.PrivValidatorStateFile(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tmNode, err := node.NewNode( //resleak:notresource
|
||||
context.TODO(),
|
||||
cmtCfg,
|
||||
pvm.LoadOrGenFilePV(cmtCfg.PrivValidatorKeyFile(), cmtCfg.PrivValidatorStateFile()),
|
||||
pv,
|
||||
nodeKey,
|
||||
proxy.NewLocalClientCreator(cmtApp),
|
||||
appGenesisProvider,
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
cmtjson "github.com/cometbft/cometbft/libs/json"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
|
||||
@@ -110,7 +110,7 @@ func SetupAtGenesis(appConfig depinject.Config, extraOutputs ...any) (*runtime.A
|
||||
|
||||
// NextBlock starts a new block.
|
||||
func NextBlock(app *runtime.App, ctx sdk.Context, jumpTime time.Duration) (sdk.Context, error) {
|
||||
_, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: ctx.BlockHeight(), Time: ctx.BlockTime()})
|
||||
_, err := app.FinalizeBlock(&abci.FinalizeBlockRequest{Height: ctx.BlockHeight(), Time: ctx.BlockTime()})
|
||||
if err != nil {
|
||||
return sdk.Context{}, err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon
|
||||
}
|
||||
|
||||
// init chain will set the validator set and initialize the genesis accounts
|
||||
_, err = app.InitChain(&abci.RequestInitChain{
|
||||
_, err = app.InitChain(&abci.InitChainRequest{
|
||||
Validators: []abci.ValidatorUpdate{},
|
||||
ConsensusParams: DefaultConsensusParams,
|
||||
AppStateBytes: stateBytes,
|
||||
@@ -195,7 +195,7 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon
|
||||
|
||||
// commit genesis changes
|
||||
if !startupConfig.AtGenesis {
|
||||
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
|
||||
_, err = app.FinalizeBlock(&abci.FinalizeBlockRequest{
|
||||
Height: app.LastBlockHeight() + 1,
|
||||
NextValidatorsHash: valSet.Hash(),
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
types2 "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
types "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
@@ -127,7 +127,7 @@ func SignCheckDeliver(
|
||||
bz, err := txCfg.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
resBlock, err := app.FinalizeBlock(&types2.RequestFinalizeBlock{
|
||||
resBlock, err := app.FinalizeBlock(&types2.FinalizeBlockRequest{
|
||||
Height: header.Height,
|
||||
Txs: [][]byte{bz},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user