Skip to content

Commit eb9b21f

Browse files
committed
feat: upgrade cometbft to v1.0
1 parent 227afa8 commit eb9b21f

32 files changed

Lines changed: 719 additions & 756 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
- [11266](https://github.com/vegaprotocol/vega/issues/11266) - Include derived parties rewards API
6262
- [11357](https://github.com/vegaprotocol/vega/issues/11357) - Support historical game scores
6363
- [11023](https://github.com/vegaprotocol/vega/issues/11023) - Add proposed fees to `vAMM` data.
64+
- [11393](https://github.com/vegaprotocol/vega/issues/11393) - Upgrade cometbft to `v1`.
6465
- [11028](https://github.com/vegaprotocol/vega/issues/11028) - Add API to estimate order book depth based on `vAMM`.
6566
- [11400](https://github.com/vegaprotocol/vega/issues/11400) - Add support for long block auction.
6667
- [11026](https://github.com/vegaprotocol/vega/issues/11026) - Add API flag to get paid liquidity fees for a `vAMM` using the parent key.

cmd/vega/commands/cometbft.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func (opts *cometbftCmd) Execute(_ []string) error {
6969
cmtcmd.GenValidatorCmd,
7070
cmtcmd.InitFilesCmd,
7171
cmtcmd.LightCmd,
72-
cmtcmd.ReplayCmd,
73-
cmtcmd.ReplayConsoleCmd,
72+
// unsupported
73+
// cmtcmd.ReplayCmd,
74+
// cmtcmd.ReplayConsoleCmd,
7475
cmtcmd.ResetAllCmd,
7576
cmtcmd.ResetPrivValidatorCmd,
7677
cmtcmd.ResetStateCmd,
@@ -85,7 +86,7 @@ func (opts *cometbftCmd) Execute(_ []string) error {
8586
cmtcli.NewCompletionCmd(rootCmd, true),
8687
)
8788

88-
baseCmd := cmtcli.PrepareBaseCmd(rootCmd, "CMT", os.ExpandEnv(filepath.Join("$HOME", cmtcfg.DefaultTendermintDir)))
89+
baseCmd := cmtcli.PrepareBaseCmd(rootCmd, "CMT", os.ExpandEnv(filepath.Join("$HOME", cmtcfg.DefaultCometDir)))
8990
if err := baseCmd.Execute(); err != nil {
9091
return err
9192
}

cmd/vega/commands/init.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ import (
2626
"code.vegaprotocol.io/vega/core/config/encoding"
2727
"code.vegaprotocol.io/vega/core/nodewallets/registry"
2828
vgjson "code.vegaprotocol.io/vega/libs/json"
29+
vgrand "code.vegaprotocol.io/vega/libs/rand"
2930
"code.vegaprotocol.io/vega/logging"
3031
"code.vegaprotocol.io/vega/paths"
3132

3233
tmcfg "github.com/cometbft/cometbft/config"
33-
tmos "github.com/cometbft/cometbft/libs/os"
34-
tmrand "github.com/cometbft/cometbft/libs/rand"
3534
"github.com/cometbft/cometbft/p2p"
3635
"github.com/cometbft/cometbft/privval"
3736
"github.com/cometbft/cometbft/types"
@@ -153,12 +152,17 @@ func (opts *InitCmd) Execute(args []string) error {
153152
return nil
154153
}
155154

155+
func FileExists(filePath string) bool {
156+
_, err := os.Stat(filePath)
157+
return !os.IsNotExist(err)
158+
}
159+
156160
func initTendermintConfiguration(output config.Output, logger *logging.Logger, config *tmcfg.Config) error {
157161
// private validator
158162
privValKeyFile := config.PrivValidatorKeyFile()
159163
privValStateFile := config.PrivValidatorStateFile()
160164
var pv *privval.FilePV
161-
if tmos.FileExists(privValKeyFile) {
165+
if FileExists(privValKeyFile) {
162166
pv = privval.LoadFilePV(privValKeyFile, privValStateFile)
163167
if output.IsHuman() {
164168
logger.Info("Found private validator",
@@ -178,7 +182,7 @@ func initTendermintConfiguration(output config.Output, logger *logging.Logger, c
178182
}
179183

180184
nodeKeyFile := config.NodeKeyFile()
181-
if tmos.FileExists(nodeKeyFile) {
185+
if FileExists(nodeKeyFile) {
182186
if output.IsHuman() {
183187
logger.Info("Found node key", logging.String("path", nodeKeyFile))
184188
}
@@ -193,13 +197,13 @@ func initTendermintConfiguration(output config.Output, logger *logging.Logger, c
193197

194198
// genesis file
195199
genFile := config.GenesisFile()
196-
if tmos.FileExists(genFile) {
200+
if FileExists(genFile) {
197201
if output.IsHuman() {
198202
logger.Info("Found genesis file", logging.String("path", genFile))
199203
}
200204
} else {
201205
genDoc := types.GenesisDoc{
202-
ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)),
206+
ChainID: fmt.Sprintf("test-chain-%v", vgrand.RandomStr(6)),
203207
GenesisTime: time.Now().Round(0).UTC(),
204208
ConsensusParams: types.DefaultConsensusParams(),
205209
}

cmd/vega/commands/node/app_wrapper.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ func newAppW(app types.Application) *appW {
3636
}
3737
}
3838

39-
func (app *appW) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
39+
func (app *appW) Info(ctx context.Context, req *types.InfoRequest) (*types.InfoResponse, error) {
4040
return app.impl.Info(ctx, req)
4141
}
4242

43-
func (app *appW) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
43+
func (app *appW) CheckTx(ctx context.Context, req *types.CheckTxRequest) (*types.CheckTxResponse, error) {
4444
return app.impl.CheckTx(ctx, req)
4545
}
4646

47-
func (app *appW) Commit(ctx context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) {
47+
func (app *appW) Commit(ctx context.Context, req *types.CommitRequest) (*types.CommitResponse, error) {
4848
resp, err := app.impl.Commit(ctx, req)
4949
// if we are scheduled for an upgrade of the protocol
5050
// let's do it now.
@@ -55,46 +55,46 @@ func (app *appW) Commit(ctx context.Context, req *types.RequestCommit) (*types.R
5555
return resp, err
5656
}
5757

58-
func (app *appW) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) {
58+
func (app *appW) Query(ctx context.Context, req *types.QueryRequest) (*types.QueryResponse, error) {
5959
return app.impl.Query(ctx, req)
6060
}
6161

62-
func (app *appW) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
62+
func (app *appW) InitChain(ctx context.Context, req *types.InitChainRequest) (*types.InitChainResponse, error) {
6363
return app.impl.InitChain(ctx, req)
6464
}
6565

66-
func (app *appW) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
66+
func (app *appW) ListSnapshots(ctx context.Context, req *types.ListSnapshotsRequest) (*types.ListSnapshotsResponse, error) {
6767
return app.impl.ListSnapshots(ctx, req)
6868
}
6969

70-
func (app *appW) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
70+
func (app *appW) OfferSnapshot(ctx context.Context, req *types.OfferSnapshotRequest) (*types.OfferSnapshotResponse, error) {
7171
return app.impl.OfferSnapshot(ctx, req)
7272
}
7373

74-
func (app *appW) LoadSnapshotChunk(ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
74+
func (app *appW) LoadSnapshotChunk(ctx context.Context, req *types.LoadSnapshotChunkRequest) (*types.LoadSnapshotChunkResponse, error) {
7575
return app.impl.LoadSnapshotChunk(ctx, req)
7676
}
7777

78-
func (app *appW) ApplySnapshotChunk(ctx context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
78+
func (app *appW) ApplySnapshotChunk(ctx context.Context, req *types.ApplySnapshotChunkRequest) (*types.ApplySnapshotChunkResponse, error) {
7979
return app.impl.ApplySnapshotChunk(ctx, req)
8080
}
8181

82-
func (app *appW) PrepareProposal(ctx context.Context, proposal *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
82+
func (app *appW) PrepareProposal(ctx context.Context, proposal *types.PrepareProposalRequest) (*types.PrepareProposalResponse, error) {
8383
return app.impl.PrepareProposal(ctx, proposal)
8484
}
8585

86-
func (app *appW) ProcessProposal(ctx context.Context, proposal *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
86+
func (app *appW) ProcessProposal(ctx context.Context, proposal *types.ProcessProposalRequest) (*types.ProcessProposalResponse, error) {
8787
return app.impl.ProcessProposal(ctx, proposal)
8888
}
8989

90-
func (app *appW) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
90+
func (app *appW) FinalizeBlock(ctx context.Context, req *types.FinalizeBlockRequest) (*types.FinalizeBlockResponse, error) {
9191
return app.impl.FinalizeBlock(ctx, req)
9292
}
9393

94-
func (app *appW) ExtendVote(ctx context.Context, req *types.RequestExtendVote) (*types.ResponseExtendVote, error) {
94+
func (app *appW) ExtendVote(ctx context.Context, req *types.ExtendVoteRequest) (*types.ExtendVoteResponse, error) {
9595
return app.impl.ExtendVote(ctx, req)
9696
}
9797

98-
func (app *appW) VerifyVoteExtension(ctx context.Context, req *types.RequestVerifyVoteExtension) (*types.ResponseVerifyVoteExtension, error) {
98+
func (app *appW) VerifyVoteExtension(ctx context.Context, req *types.VerifyVoteExtensionRequest) (*types.VerifyVoteExtensionResponse, error) {
9999
return app.impl.VerifyVoteExtension(ctx, req)
100100
}

core/blockchain/abci/abci.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import (
2727
"github.com/cometbft/cometbft/abci/types"
2828
)
2929

30-
func (app *App) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
30+
func (app *App) Info(ctx context.Context, req *types.InfoRequest) (*types.InfoResponse, error) {
3131
if fn := app.OnInfo; fn != nil {
3232
return fn(ctx, req)
3333
}
3434
return app.BaseApplication.Info(ctx, req)
3535
}
3636

37-
func (app *App) InitChain(_ context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
37+
func (app *App) InitChain(_ context.Context, req *types.InitChainRequest) (*types.InitChainResponse, error) {
3838
_, err := LoadGenesisState(req.AppStateBytes)
3939
if err != nil {
4040
panic(err)
@@ -43,7 +43,7 @@ func (app *App) InitChain(_ context.Context, req *types.RequestInitChain) (*type
4343
if fn := app.OnInitChain; fn != nil {
4444
return fn(req)
4545
}
46-
return &types.ResponseInitChain{}, nil
46+
return &types.InitChainResponse{}, nil
4747
}
4848

4949
func (app *App) GetTx(tx []byte) (Tx, error) {
@@ -53,7 +53,7 @@ func (app *App) GetTx(tx []byte) (Tx, error) {
5353

5454
// PrepareProposal will take the given transactions from the mempool and attempts to prepare a
5555
// proposal from them when it's our turn to do so while keeping the size, gas, pow, and spam constraints.
56-
func (app *App) PrepareProposal(_ context.Context, req *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
56+
func (app *App) PrepareProposal(_ context.Context, req *types.PrepareProposalRequest) (*types.PrepareProposalResponse, error) {
5757
txs := make([]Tx, 0, len(req.Txs))
5858
rawTxs := make([][]byte, 0, len(req.Txs))
5959
for _, v := range req.Txs {
@@ -71,47 +71,47 @@ func (app *App) PrepareProposal(_ context.Context, req *types.RequestPrepareProp
7171
}
7272

7373
// let the application decide on the order and the number of transactions it wants to pick up for this block
74-
res := &types.ResponsePrepareProposal{Txs: app.OnPrepareProposal(uint64(req.Height), txs, rawTxs)}
74+
res := &types.PrepareProposalResponse{Txs: app.OnPrepareProposal(uint64(req.Height), txs, rawTxs)}
7575
return res, nil
7676
}
7777

7878
// ProcessProposal implements part of the Application interface.
7979
// It accepts any proposal that does not contain a malformed transaction.
8080
// NB: processProposal will not be called if the node is fast-sync-ing so no state change is allowed here!!!.
81-
func (app *App) ProcessProposal(_ context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
81+
func (app *App) ProcessProposal(_ context.Context, req *types.ProcessProposalRequest) (*types.ProcessProposalResponse, error) {
8282
// check transaction signatures if any is wrong, reject the block
8383
txs := make([]Tx, 0, len(req.Txs))
8484
for _, v := range req.Txs {
8585
tx, _, err := app.getTx(v)
8686
if err != nil {
8787
// if there's a transaction we can't decode or verify, reject it
88-
return &types.ResponseProcessProposal{Status: types.ResponseProcessProposal_REJECT}, err
88+
return &types.ProcessProposalResponse{Status: types.PROCESS_PROPOSAL_STATUS_REJECT}, err
8989
}
9090
// if there's no handler for a transaction, reject it
9191
if _, ok := app.deliverTxs[tx.Command()]; !ok {
92-
return &types.ResponseProcessProposal{Status: types.ResponseProcessProposal_REJECT}, nil
92+
return &types.ProcessProposalResponse{Status: types.PROCESS_PROPOSAL_STATUS_REJECT}, nil
9393
}
9494
txs = append(txs, tx)
9595
}
9696
// let the application verify the block
9797
if !app.OnProcessProposal(uint64(req.Height), txs) {
98-
return &types.ResponseProcessProposal{Status: types.ResponseProcessProposal_REJECT}, nil
98+
return &types.ProcessProposalResponse{Status: types.PROCESS_PROPOSAL_STATUS_REJECT}, nil
9999
}
100-
return &types.ResponseProcessProposal{Status: types.ResponseProcessProposal_ACCEPT}, nil
100+
return &types.ProcessProposalResponse{Status: types.PROCESS_PROPOSAL_STATUS_ACCEPT}, nil
101101
}
102102

103-
func (app *App) Commit(_ context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) {
103+
func (app *App) Commit(_ context.Context, req *types.CommitRequest) (*types.CommitResponse, error) {
104104
if fn := app.OnCommit; fn != nil {
105105
return fn()
106106
}
107-
return &types.ResponseCommit{}, nil
107+
return &types.CommitResponse{}, nil
108108
}
109109

110-
func (app *App) CheckTx(_ context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
110+
func (app *App) CheckTx(_ context.Context, req *types.CheckTxRequest) (*types.CheckTxResponse, error) {
111111
// first, only decode the transaction but don't validate
112112
tx, code, err := app.getTx(req.GetTx())
113113

114-
var resp *types.ResponseCheckTx
114+
var resp *types.CheckTxResponse
115115
if err != nil {
116116
// TODO I think we need to return error in this case as now the API allows for it
117117
// return blockchain.NewResponseCheckTxError(code, err), err
@@ -150,7 +150,7 @@ func (app *App) CheckTx(_ context.Context, req *types.RequestCheckTx) (*types.Re
150150
}
151151

152152
// FinalizeBlock lets the application process a whole block end to end.
153-
func (app *App) FinalizeBlock(_ context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
153+
func (app *App) FinalizeBlock(_ context.Context, req *types.FinalizeBlockRequest) (*types.FinalizeBlockResponse, error) {
154154
blockHeight := uint64(req.Height)
155155
blockTime := req.Time
156156

@@ -205,7 +205,7 @@ func (app *App) FinalizeBlock(_ context.Context, req *types.RequestFinalizeBlock
205205
)
206206

207207
hash := app.OnFinalize()
208-
return &types.ResponseFinalizeBlock{
208+
return &types.FinalizeBlockResponse{
209209
TxResults: results,
210210
ValidatorUpdates: valUpdates,
211211
ConsensusParamUpdates: &consensusUpdates,
@@ -214,35 +214,35 @@ func (app *App) FinalizeBlock(_ context.Context, req *types.RequestFinalizeBlock
214214
}, nil
215215
}
216216

217-
func (app *App) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
217+
func (app *App) ListSnapshots(ctx context.Context, req *types.ListSnapshotsRequest) (*types.ListSnapshotsResponse, error) {
218218
if app.OnListSnapshots != nil {
219219
return app.OnListSnapshots(ctx, req)
220220
}
221-
return &types.ResponseListSnapshots{}, nil
221+
return &types.ListSnapshotsResponse{}, nil
222222
}
223223

224-
func (app *App) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
224+
func (app *App) OfferSnapshot(ctx context.Context, req *types.OfferSnapshotRequest) (*types.OfferSnapshotResponse, error) {
225225
if app.OnOfferSnapshot != nil {
226226
return app.OnOfferSnapshot(ctx, req)
227227
}
228-
return &types.ResponseOfferSnapshot{}, nil
228+
return &types.OfferSnapshotResponse{}, nil
229229
}
230230

231-
func (app *App) LoadSnapshotChunk(ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
231+
func (app *App) LoadSnapshotChunk(ctx context.Context, req *types.LoadSnapshotChunkRequest) (*types.LoadSnapshotChunkResponse, error) {
232232
if app.OnLoadSnapshotChunk != nil {
233233
return app.OnLoadSnapshotChunk(ctx, req)
234234
}
235-
return &types.ResponseLoadSnapshotChunk{}, nil
235+
return &types.LoadSnapshotChunkResponse{}, nil
236236
}
237237

238-
func (app *App) ApplySnapshotChunk(_ context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
238+
func (app *App) ApplySnapshotChunk(_ context.Context, req *types.ApplySnapshotChunkRequest) (*types.ApplySnapshotChunkResponse, error) {
239239
if app.OnApplySnapshotChunk != nil {
240240
return app.OnApplySnapshotChunk(app.ctx, req)
241241
}
242-
return &types.ResponseApplySnapshotChunk{}, nil
242+
return &types.ApplySnapshotChunkResponse{}, nil
243243
}
244244

245-
func AddCommonCheckTxEvents(resp *types.ResponseCheckTx, tx Tx) *types.ResponseCheckTx {
245+
func AddCommonCheckTxEvents(resp *types.CheckTxResponse, tx Tx) *types.CheckTxResponse {
246246
resp.Events = getBaseTxEvents(tx)
247247
return resp
248248
}

core/blockchain/abci/abci_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func TestABCICheckTx(t *testing.T) {
100100
return errors.New("boom")
101101
})
102102

103-
app.OnCheckTx = func(ctx context.Context, _ *types.RequestCheckTx, _ abci.Tx) (context.Context, *types.ResponseCheckTx) {
104-
return context.WithValue(ctx, testKey, "val"), &types.ResponseCheckTx{}
103+
app.OnCheckTx = func(ctx context.Context, _ *types.CheckTxRequest, _ abci.Tx) (context.Context, *types.CheckTxResponse) {
104+
return context.WithValue(ctx, testKey, "val"), &types.CheckTxResponse{}
105105
}
106106

107107
t.Run("CommandWithNoError", func(t *testing.T) {
@@ -110,7 +110,7 @@ func TestABCICheckTx(t *testing.T) {
110110
command: testCommandA,
111111
})
112112

113-
req := types.RequestCheckTx{Tx: tx}
113+
req := types.CheckTxRequest{Tx: tx}
114114
resp, _ := app.CheckTx(context.Background(), &req)
115115
require.True(t, resp.IsOK())
116116
})
@@ -121,7 +121,7 @@ func TestABCICheckTx(t *testing.T) {
121121
command: testCommandB,
122122
})
123123

124-
req := types.RequestCheckTx{Tx: tx}
124+
req := types.CheckTxRequest{Tx: tx}
125125
resp, _ := app.CheckTx(context.Background(), &req)
126126
require.True(t, resp.IsErr())
127127
require.Equal(t, blockchain.AbciTxnInternalError, resp.Code)
@@ -130,7 +130,7 @@ func TestABCICheckTx(t *testing.T) {
130130
t.Run("TxDecodingError", func(t *testing.T) {
131131
tx := []byte("tx-not-registered-on-the-codec")
132132

133-
req := types.RequestCheckTx{Tx: tx}
133+
req := types.CheckTxRequest{Tx: tx}
134134
resp, _ := app.CheckTx(context.Background(), &req)
135135
require.True(t, resp.IsErr())
136136
require.Equal(t, blockchain.AbciTxnDecodingFailure, resp.Code)

core/blockchain/abci/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
tmquery "github.com/cometbft/cometbft/libs/pubsub/query"
2929
tmclihttp "github.com/cometbft/cometbft/rpc/client/http"
3030
tmctypes "github.com/cometbft/cometbft/rpc/core/types"
31-
"github.com/cometbft/cometbft/types"
3231
tmtypes "github.com/cometbft/cometbft/types"
3332
)
3433

@@ -44,7 +43,7 @@ func NewClient(addr string) (*Client, error) {
4443
return nil, ErrEmptyClientAddr
4544
}
4645

47-
clt, err := tmclihttp.New(addr, "/websocket")
46+
clt, err := tmclihttp.New(addr)
4847
if err != nil {
4948
return nil, err
5049
}
@@ -253,7 +252,7 @@ func (c *cachedGenesisDoc) cacheGenesis(
253252
buf = append(buf, decoded...)
254253
}
255254

256-
genDoc := types.GenesisDoc{}
255+
genDoc := tmtypes.GenesisDoc{}
257256
err = cmtjson.Unmarshal(buf, &genDoc)
258257
if err != nil {
259258
return nil, err

0 commit comments

Comments
 (0)