Skip to content

Commit

Permalink
feat: upgrade cometbft to v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 committed Jul 24, 2024
1 parent 227afa8 commit eb9b21f
Show file tree
Hide file tree
Showing 32 changed files with 719 additions and 756 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- [11266](https://github.com/vegaprotocol/vega/issues/11266) - Include derived parties rewards API
- [11357](https://github.com/vegaprotocol/vega/issues/11357) - Support historical game scores
- [11023](https://github.com/vegaprotocol/vega/issues/11023) - Add proposed fees to `vAMM` data.
- [11393](https://github.com/vegaprotocol/vega/issues/11393) - Upgrade cometbft to `v1`.
- [11028](https://github.com/vegaprotocol/vega/issues/11028) - Add API to estimate order book depth based on `vAMM`.
- [11400](https://github.com/vegaprotocol/vega/issues/11400) - Add support for long block auction.
- [11026](https://github.com/vegaprotocol/vega/issues/11026) - Add API flag to get paid liquidity fees for a `vAMM` using the parent key.
Expand Down
7 changes: 4 additions & 3 deletions cmd/vega/commands/cometbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func (opts *cometbftCmd) Execute(_ []string) error {
cmtcmd.GenValidatorCmd,
cmtcmd.InitFilesCmd,
cmtcmd.LightCmd,
cmtcmd.ReplayCmd,
cmtcmd.ReplayConsoleCmd,
// unsupported
// cmtcmd.ReplayCmd,
// cmtcmd.ReplayConsoleCmd,
cmtcmd.ResetAllCmd,
cmtcmd.ResetPrivValidatorCmd,
cmtcmd.ResetStateCmd,
Expand All @@ -85,7 +86,7 @@ func (opts *cometbftCmd) Execute(_ []string) error {
cmtcli.NewCompletionCmd(rootCmd, true),
)

baseCmd := cmtcli.PrepareBaseCmd(rootCmd, "CMT", os.ExpandEnv(filepath.Join("$HOME", cmtcfg.DefaultTendermintDir)))
baseCmd := cmtcli.PrepareBaseCmd(rootCmd, "CMT", os.ExpandEnv(filepath.Join("$HOME", cmtcfg.DefaultCometDir)))
if err := baseCmd.Execute(); err != nil {
return err
}
Expand Down
16 changes: 10 additions & 6 deletions cmd/vega/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ import (
"code.vegaprotocol.io/vega/core/config/encoding"
"code.vegaprotocol.io/vega/core/nodewallets/registry"
vgjson "code.vegaprotocol.io/vega/libs/json"
vgrand "code.vegaprotocol.io/vega/libs/rand"
"code.vegaprotocol.io/vega/logging"
"code.vegaprotocol.io/vega/paths"

tmcfg "github.com/cometbft/cometbft/config"
tmos "github.com/cometbft/cometbft/libs/os"
tmrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/p2p"
"github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -153,12 +152,17 @@ func (opts *InitCmd) Execute(args []string) error {
return nil
}

func FileExists(filePath string) bool {
_, err := os.Stat(filePath)
return !os.IsNotExist(err)
}

func initTendermintConfiguration(output config.Output, logger *logging.Logger, config *tmcfg.Config) error {
// private validator
privValKeyFile := config.PrivValidatorKeyFile()
privValStateFile := config.PrivValidatorStateFile()
var pv *privval.FilePV
if tmos.FileExists(privValKeyFile) {
if FileExists(privValKeyFile) {
pv = privval.LoadFilePV(privValKeyFile, privValStateFile)
if output.IsHuman() {
logger.Info("Found private validator",
Expand All @@ -178,7 +182,7 @@ func initTendermintConfiguration(output config.Output, logger *logging.Logger, c
}

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

// genesis file
genFile := config.GenesisFile()
if tmos.FileExists(genFile) {
if FileExists(genFile) {
if output.IsHuman() {
logger.Info("Found genesis file", logging.String("path", genFile))
}
} else {
genDoc := types.GenesisDoc{
ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)),
ChainID: fmt.Sprintf("test-chain-%v", vgrand.RandomStr(6)),
GenesisTime: time.Now().Round(0).UTC(),
ConsensusParams: types.DefaultConsensusParams(),
}
Expand Down
28 changes: 14 additions & 14 deletions cmd/vega/commands/node/app_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func newAppW(app types.Application) *appW {
}
}

func (app *appW) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
func (app *appW) Info(ctx context.Context, req *types.InfoRequest) (*types.InfoResponse, error) {
return app.impl.Info(ctx, req)
}

func (app *appW) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
func (app *appW) CheckTx(ctx context.Context, req *types.CheckTxRequest) (*types.CheckTxResponse, error) {
return app.impl.CheckTx(ctx, req)
}

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

func (app *appW) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) {
func (app *appW) Query(ctx context.Context, req *types.QueryRequest) (*types.QueryResponse, error) {
return app.impl.Query(ctx, req)
}

func (app *appW) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
func (app *appW) InitChain(ctx context.Context, req *types.InitChainRequest) (*types.InitChainResponse, error) {
return app.impl.InitChain(ctx, req)
}

func (app *appW) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
func (app *appW) ListSnapshots(ctx context.Context, req *types.ListSnapshotsRequest) (*types.ListSnapshotsResponse, error) {
return app.impl.ListSnapshots(ctx, req)
}

func (app *appW) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
func (app *appW) OfferSnapshot(ctx context.Context, req *types.OfferSnapshotRequest) (*types.OfferSnapshotResponse, error) {
return app.impl.OfferSnapshot(ctx, req)
}

func (app *appW) LoadSnapshotChunk(ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
func (app *appW) LoadSnapshotChunk(ctx context.Context, req *types.LoadSnapshotChunkRequest) (*types.LoadSnapshotChunkResponse, error) {
return app.impl.LoadSnapshotChunk(ctx, req)
}

func (app *appW) ApplySnapshotChunk(ctx context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
func (app *appW) ApplySnapshotChunk(ctx context.Context, req *types.ApplySnapshotChunkRequest) (*types.ApplySnapshotChunkResponse, error) {
return app.impl.ApplySnapshotChunk(ctx, req)
}

func (app *appW) PrepareProposal(ctx context.Context, proposal *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
func (app *appW) PrepareProposal(ctx context.Context, proposal *types.PrepareProposalRequest) (*types.PrepareProposalResponse, error) {
return app.impl.PrepareProposal(ctx, proposal)
}

func (app *appW) ProcessProposal(ctx context.Context, proposal *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
func (app *appW) ProcessProposal(ctx context.Context, proposal *types.ProcessProposalRequest) (*types.ProcessProposalResponse, error) {
return app.impl.ProcessProposal(ctx, proposal)
}

func (app *appW) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
func (app *appW) FinalizeBlock(ctx context.Context, req *types.FinalizeBlockRequest) (*types.FinalizeBlockResponse, error) {
return app.impl.FinalizeBlock(ctx, req)
}

func (app *appW) ExtendVote(ctx context.Context, req *types.RequestExtendVote) (*types.ResponseExtendVote, error) {
func (app *appW) ExtendVote(ctx context.Context, req *types.ExtendVoteRequest) (*types.ExtendVoteResponse, error) {
return app.impl.ExtendVote(ctx, req)
}

func (app *appW) VerifyVoteExtension(ctx context.Context, req *types.RequestVerifyVoteExtension) (*types.ResponseVerifyVoteExtension, error) {
func (app *appW) VerifyVoteExtension(ctx context.Context, req *types.VerifyVoteExtensionRequest) (*types.VerifyVoteExtensionResponse, error) {
return app.impl.VerifyVoteExtension(ctx, req)
}
50 changes: 25 additions & 25 deletions core/blockchain/abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import (
"github.com/cometbft/cometbft/abci/types"
)

func (app *App) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
func (app *App) Info(ctx context.Context, req *types.InfoRequest) (*types.InfoResponse, error) {
if fn := app.OnInfo; fn != nil {
return fn(ctx, req)
}
return app.BaseApplication.Info(ctx, req)
}

func (app *App) InitChain(_ context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
func (app *App) InitChain(_ context.Context, req *types.InitChainRequest) (*types.InitChainResponse, error) {
_, err := LoadGenesisState(req.AppStateBytes)
if err != nil {
panic(err)
Expand All @@ -43,7 +43,7 @@ func (app *App) InitChain(_ context.Context, req *types.RequestInitChain) (*type
if fn := app.OnInitChain; fn != nil {
return fn(req)
}
return &types.ResponseInitChain{}, nil
return &types.InitChainResponse{}, nil
}

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

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

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

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

func (app *App) Commit(_ context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) {
func (app *App) Commit(_ context.Context, req *types.CommitRequest) (*types.CommitResponse, error) {
if fn := app.OnCommit; fn != nil {
return fn()
}
return &types.ResponseCommit{}, nil
return &types.CommitResponse{}, nil
}

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

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

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

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

hash := app.OnFinalize()
return &types.ResponseFinalizeBlock{
return &types.FinalizeBlockResponse{
TxResults: results,
ValidatorUpdates: valUpdates,
ConsensusParamUpdates: &consensusUpdates,
Expand All @@ -214,35 +214,35 @@ func (app *App) FinalizeBlock(_ context.Context, req *types.RequestFinalizeBlock
}, nil
}

func (app *App) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
func (app *App) ListSnapshots(ctx context.Context, req *types.ListSnapshotsRequest) (*types.ListSnapshotsResponse, error) {
if app.OnListSnapshots != nil {
return app.OnListSnapshots(ctx, req)
}
return &types.ResponseListSnapshots{}, nil
return &types.ListSnapshotsResponse{}, nil
}

func (app *App) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
func (app *App) OfferSnapshot(ctx context.Context, req *types.OfferSnapshotRequest) (*types.OfferSnapshotResponse, error) {
if app.OnOfferSnapshot != nil {
return app.OnOfferSnapshot(ctx, req)
}
return &types.ResponseOfferSnapshot{}, nil
return &types.OfferSnapshotResponse{}, nil
}

func (app *App) LoadSnapshotChunk(ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
func (app *App) LoadSnapshotChunk(ctx context.Context, req *types.LoadSnapshotChunkRequest) (*types.LoadSnapshotChunkResponse, error) {
if app.OnLoadSnapshotChunk != nil {
return app.OnLoadSnapshotChunk(ctx, req)
}
return &types.ResponseLoadSnapshotChunk{}, nil
return &types.LoadSnapshotChunkResponse{}, nil
}

func (app *App) ApplySnapshotChunk(_ context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
func (app *App) ApplySnapshotChunk(_ context.Context, req *types.ApplySnapshotChunkRequest) (*types.ApplySnapshotChunkResponse, error) {
if app.OnApplySnapshotChunk != nil {
return app.OnApplySnapshotChunk(app.ctx, req)
}
return &types.ResponseApplySnapshotChunk{}, nil
return &types.ApplySnapshotChunkResponse{}, nil
}

func AddCommonCheckTxEvents(resp *types.ResponseCheckTx, tx Tx) *types.ResponseCheckTx {
func AddCommonCheckTxEvents(resp *types.CheckTxResponse, tx Tx) *types.CheckTxResponse {
resp.Events = getBaseTxEvents(tx)
return resp
}
Expand Down
10 changes: 5 additions & 5 deletions core/blockchain/abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func TestABCICheckTx(t *testing.T) {
return errors.New("boom")
})

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

t.Run("CommandWithNoError", func(t *testing.T) {
Expand All @@ -110,7 +110,7 @@ func TestABCICheckTx(t *testing.T) {
command: testCommandA,
})

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

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

req := types.RequestCheckTx{Tx: tx}
req := types.CheckTxRequest{Tx: tx}
resp, _ := app.CheckTx(context.Background(), &req)
require.True(t, resp.IsErr())
require.Equal(t, blockchain.AbciTxnDecodingFailure, resp.Code)
Expand Down
5 changes: 2 additions & 3 deletions core/blockchain/abci/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
tmquery "github.com/cometbft/cometbft/libs/pubsub/query"
tmclihttp "github.com/cometbft/cometbft/rpc/client/http"
tmctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"
tmtypes "github.com/cometbft/cometbft/types"
)

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

clt, err := tmclihttp.New(addr, "/websocket")
clt, err := tmclihttp.New(addr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -253,7 +252,7 @@ func (c *cachedGenesisDoc) cacheGenesis(
buf = append(buf, decoded...)
}

genDoc := types.GenesisDoc{}
genDoc := tmtypes.GenesisDoc{}
err = cmtjson.Unmarshal(buf, &genDoc)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit eb9b21f

Please sign in to comment.