From aa0566759c43be4298091371d7f26ed572a6583f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 10 Jun 2024 18:32:19 +0200 Subject: [PATCH] lint --- baseapp/abci.go | 1 - baseapp/genesis.go | 3 ++- core/context/context.go | 2 -- orm/encoding/ormfield/duration.go | 12 +++++------ orm/encoding/ormfield/timestamp.go | 12 +++++------ server/cmt_abci.go | 31 ++++++++++++++-------------- server/v2/cometbft/abci.go | 33 +++++++++++++++--------------- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index dd3c3d390f0f..30e47214b3dc 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -10,7 +10,6 @@ import ( abcitypes "github.com/cometbft/cometbft/abci/types" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" - cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" "github.com/cosmos/gogoproto/proto" "google.golang.org/grpc/codes" diff --git a/baseapp/genesis.go b/baseapp/genesis.go index 564b9f4ec713..4662d1187b4a 100644 --- a/baseapp/genesis.go +++ b/baseapp/genesis.go @@ -3,8 +3,9 @@ package baseapp import ( "errors" - "cosmossdk.io/core/genesis" "github.com/cometbft/cometbft/abci/types" + + "cosmossdk.io/core/genesis" ) var _ genesis.TxHandler = (*BaseApp)(nil) diff --git a/core/context/context.go b/core/context/context.go index b330cb48b22f..6803bd7eb44b 100644 --- a/core/context/context.go +++ b/core/context/context.go @@ -1,7 +1,5 @@ package context -type contextKey uint8 - type ( execModeKey struct{} cometInfoKey struct{} diff --git a/orm/encoding/ormfield/duration.go b/orm/encoding/ormfield/duration.go index 572b6e21e612..7d7f25b5c7e6 100644 --- a/orm/encoding/ormfield/duration.go +++ b/orm/encoding/ormfield/duration.go @@ -16,12 +16,12 @@ const ( // DurationCodec encodes google.protobuf.Duration values with the following // encoding: -// - nil is encoded as []byte{0xFF} -// - seconds (which can range from -315,576,000,000 to +315,576,000,000) is encoded as 5 fixed bytes -// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such -// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, -// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is -// preserved when comparing the encoded values of two Durations: +// - nil is encoded as []byte{0xFF} +// - seconds (which can range from -315,576,000,000 to +315,576,000,000) is encoded as 5 fixed bytes +// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such +// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, +// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is +// preserved when comparing the encoded values of two Durations: // - []byte{0xBB, 0x9A, 0xC9, 0xFF} for zero nanos // - 4 fixed bytes with the bit mask 0x80 applied to the first byte, with negative nanos scaled so that -999,999,999 // is encoded as 0 and -1 is encoded as 999,999,998 diff --git a/orm/encoding/ormfield/timestamp.go b/orm/encoding/ormfield/timestamp.go index 4788f390848a..d643a1c1d026 100644 --- a/orm/encoding/ormfield/timestamp.go +++ b/orm/encoding/ormfield/timestamp.go @@ -9,12 +9,12 @@ import ( // TimestampCodec encodes google.protobuf.Timestamp values with the following // encoding: -// - nil is encoded as []byte{0xFF} -// - seconds (which can range from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z) is encoded as 5 fixed bytes -// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such -// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, -// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is -// preserved when comparing the encoded values of two Timestamps. +// - nil is encoded as []byte{0xFF} +// - seconds (which can range from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z) is encoded as 5 fixed bytes +// - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) are encoded such +// that 999,999,999 is always added to nanos. This ensures that the encoded nanos are always >= 0. Additionally, +// by adding 999,999,999 to both positive and negative nanos, we guarantee that the lexicographical order is +// preserved when comparing the encoded values of two Timestamps. // // When iterating over timestamp indexes, nil values will always be ordered last. // diff --git a/server/cmt_abci.go b/server/cmt_abci.go index 727ea996df6e..2e2ca9f0a8ca 100644 --- a/server/cmt_abci.go +++ b/server/cmt_abci.go @@ -3,7 +3,8 @@ package server import ( "context" - abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + abci "github.com/cometbft/cometbft/abci/types" + abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) @@ -16,58 +17,58 @@ func NewCometABCIWrapper(app servertypes.ABCI) abci.Application { return cometABCIWrapper{app: app} } -func (w cometABCIWrapper) Info(_ context.Context, req *abci.InfoRequest) (*abci.InfoResponse, error) { +func (w cometABCIWrapper) Info(_ context.Context, req *abciproto.InfoRequest) (*abciproto.InfoResponse, error) { return w.app.Info(req) } -func (w cometABCIWrapper) Query(ctx context.Context, req *abci.QueryRequest) (*abci.QueryResponse, error) { +func (w cometABCIWrapper) Query(ctx context.Context, req *abciproto.QueryRequest) (*abciproto.QueryResponse, error) { return w.app.Query(ctx, req) } -func (w cometABCIWrapper) CheckTx(_ context.Context, req *abci.CheckTxRequest) (*abci.CheckTxResponse, error) { +func (w cometABCIWrapper) CheckTx(_ context.Context, req *abciproto.CheckTxRequest) (*abciproto.CheckTxResponse, error) { return w.app.CheckTx(req) } -func (w cometABCIWrapper) InitChain(_ context.Context, req *abci.InitChainRequest) (*abci.InitChainResponse, error) { +func (w cometABCIWrapper) InitChain(_ context.Context, req *abciproto.InitChainRequest) (*abciproto.InitChainResponse, error) { return w.app.InitChain(req) } -func (w cometABCIWrapper) PrepareProposal(_ context.Context, req *abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error) { +func (w cometABCIWrapper) PrepareProposal(_ context.Context, req *abciproto.PrepareProposalRequest) (*abciproto.PrepareProposalResponse, error) { return w.app.PrepareProposal(req) } -func (w cometABCIWrapper) ProcessProposal(_ context.Context, req *abci.ProcessProposalRequest) (*abci.ProcessProposalResponse, error) { +func (w cometABCIWrapper) ProcessProposal(_ context.Context, req *abciproto.ProcessProposalRequest) (*abciproto.ProcessProposalResponse, error) { return w.app.ProcessProposal(req) } -func (w cometABCIWrapper) FinalizeBlock(_ context.Context, req *abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error) { +func (w cometABCIWrapper) FinalizeBlock(_ context.Context, req *abciproto.FinalizeBlockRequest) (*abciproto.FinalizeBlockResponse, error) { return w.app.FinalizeBlock(req) } -func (w cometABCIWrapper) ExtendVote(ctx context.Context, req *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) { +func (w cometABCIWrapper) ExtendVote(ctx context.Context, req *abciproto.ExtendVoteRequest) (*abciproto.ExtendVoteResponse, error) { return w.app.ExtendVote(ctx, req) } -func (w cometABCIWrapper) VerifyVoteExtension(_ context.Context, req *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) { +func (w cometABCIWrapper) VerifyVoteExtension(_ context.Context, req *abciproto.VerifyVoteExtensionRequest) (*abciproto.VerifyVoteExtensionResponse, error) { return w.app.VerifyVoteExtension(req) } -func (w cometABCIWrapper) Commit(_ context.Context, _ *abci.CommitRequest) (*abci.CommitResponse, error) { +func (w cometABCIWrapper) Commit(_ context.Context, _ *abciproto.CommitRequest) (*abciproto.CommitResponse, error) { return w.app.Commit() } -func (w cometABCIWrapper) ListSnapshots(_ context.Context, req *abci.ListSnapshotsRequest) (*abci.ListSnapshotsResponse, error) { +func (w cometABCIWrapper) ListSnapshots(_ context.Context, req *abciproto.ListSnapshotsRequest) (*abciproto.ListSnapshotsResponse, error) { return w.app.ListSnapshots(req) } -func (w cometABCIWrapper) OfferSnapshot(_ context.Context, req *abci.OfferSnapshotRequest) (*abci.OfferSnapshotResponse, error) { +func (w cometABCIWrapper) OfferSnapshot(_ context.Context, req *abciproto.OfferSnapshotRequest) (*abciproto.OfferSnapshotResponse, error) { return w.app.OfferSnapshot(req) } -func (w cometABCIWrapper) LoadSnapshotChunk(_ context.Context, req *abci.LoadSnapshotChunkRequest) (*abci.LoadSnapshotChunkResponse, error) { +func (w cometABCIWrapper) LoadSnapshotChunk(_ context.Context, req *abciproto.LoadSnapshotChunkRequest) (*abciproto.LoadSnapshotChunkResponse, error) { return w.app.LoadSnapshotChunk(req) } -func (w cometABCIWrapper) ApplySnapshotChunk(_ context.Context, req *abci.ApplySnapshotChunkRequest) (*abci.ApplySnapshotChunkResponse, error) { +func (w cometABCIWrapper) ApplySnapshotChunk(_ context.Context, req *abciproto.ApplySnapshotChunkRequest) (*abciproto.ApplySnapshotChunkResponse, error) { return w.app.ApplySnapshotChunk(req) } diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index cad780b41994..a14a793a00ac 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -6,7 +6,8 @@ import ( "fmt" "sync/atomic" - abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + abci "github.com/cometbft/cometbft/abci/types" + abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1" coreappmgr "cosmossdk.io/core/app" "cosmossdk.io/core/comet" @@ -125,7 +126,7 @@ type BlockData struct { // CheckTx implements types.Application. // It is called by cometbft to verify transaction validity -func (c *Consensus[T]) CheckTx(ctx context.Context, req *abci.CheckTxRequest) (*abci.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 @@ -154,7 +155,7 @@ func (c *Consensus[T]) CheckTx(ctx context.Context, req *abci.CheckTxRequest) (* } // Info implements types.Application. -func (c *Consensus[T]) Info(ctx context.Context, _ *abci.InfoRequest) (*abci.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 @@ -182,7 +183,7 @@ func (c *Consensus[T]) Info(ctx context.Context, _ *abci.InfoRequest) (*abci.Inf // Query implements types.Application. // It is called by cometbft to query application state. -func (c *Consensus[T]) Query(ctx context.Context, req *abci.QueryRequest) (*abci.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) @@ -208,7 +209,7 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abci.QueryRequest) (*abci return QueryResult(errorsmod.Wrap(cometerrors.ErrUnknownRequest, "no query path provided"), c.cfg.Trace), nil } - var resp *abci.QueryResponse + var resp *abciproto.QueryResponse switch path[0] { case QueryPathApp: @@ -232,7 +233,7 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abci.QueryRequest) (*abci } // InitChain implements types.Application. -func (c *Consensus[T]) InitChain(ctx context.Context, req *abci.InitChainRequest) (*abci.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 @@ -304,8 +305,8 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abci.InitChainRequest // It is called by cometbft to prepare a proposal block. func (c *Consensus[T]) PrepareProposal( ctx context.Context, - req *abci.PrepareProposalRequest, -) (resp *abci.PrepareProposalResponse, err error) { + req *abciproto.PrepareProposalRequest, +) (resp *abciproto.PrepareProposalResponse, err error) { if req.Height < 1 { return nil, errors.New("PrepareProposal called with invalid height") } @@ -347,8 +348,8 @@ func (c *Consensus[T]) PrepareProposal( // It is called by cometbft to process/verify a proposal block. func (c *Consensus[T]) ProcessProposal( ctx context.Context, - req *abci.ProcessProposalRequest, -) (*abci.ProcessProposalResponse, error) { + req *abciproto.ProcessProposalRequest, +) (*abciproto.ProcessProposalResponse, error) { decodedTxs := make([]T, len(req.Txs)) for _, tx := range req.Txs { decTx, err := c.txCodec.Decode(tx) @@ -384,8 +385,8 @@ func (c *Consensus[T]) ProcessProposal( // It is called by cometbft to finalize a block. func (c *Consensus[T]) FinalizeBlock( ctx context.Context, - req *abci.FinalizeBlockRequest, -) (*abci.FinalizeBlockResponse, error) { + req *abciproto.FinalizeBlockRequest, +) (*abciproto.FinalizeBlockResponse, error) { if err := c.validateFinalizeBlockHeight(req); err != nil { return nil, err } @@ -494,7 +495,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, _ *abci.CommitRequest) (*abci.CommitResponse, error) { +func (c *Consensus[T]) Commit(ctx context.Context, _ *abciproto.CommitRequest) (*abciproto.CommitResponse, error) { lastCommittedBlock := c.lastCommittedBlock.Load() c.snapshotManager.SnapshotIfApplicable(lastCommittedBlock.Height) @@ -513,8 +514,8 @@ func (c *Consensus[T]) Commit(ctx context.Context, _ *abci.CommitRequest) (*abci // VerifyVoteExtension implements types.Application. func (c *Consensus[T]) VerifyVoteExtension( ctx context.Context, - req *abci.VerifyVoteExtensionRequest, -) (*abci.VerifyVoteExtensionResponse, error) { + req *abciproto.VerifyVoteExtensionRequest, +) (*abciproto.VerifyVoteExtensionResponse, error) { // If vote extensions are not enabled, as a safety precaution, we return an // error. cp, err := c.GetConsensusParams(ctx) @@ -548,7 +549,7 @@ func (c *Consensus[T]) VerifyVoteExtension( } // ExtendVote implements types.Application. -func (c *Consensus[T]) ExtendVote(ctx context.Context, req *abci.ExtendVoteRequest) (*abci.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)