diff --git a/cosmos/abci/abci.go b/cosmos/abci/abci.go index 24456cb5a..52d32f556 100644 --- a/cosmos/abci/abci.go +++ b/cosmos/abci/abci.go @@ -1,3 +1,23 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + package abci import ( diff --git a/cosmos/abci/prepare/default.go b/cosmos/abci/prepare/default.go index 1acefa3f8..7cb15dd74 100644 --- a/cosmos/abci/prepare/default.go +++ b/cosmos/abci/prepare/default.go @@ -1,9 +1,30 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + package prepare import ( "errors" abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool" ) @@ -12,7 +33,7 @@ type ( // ProposalTxVerifier defines the interface that is implemented by BaseApp, // that any custom ABCI PrepareProposal and ProcessProposal handler can use // to verify a transaction. - ProposalTxVerifier interface { + TxVerifier interface { PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) } @@ -25,17 +46,20 @@ type ( type Handler struct { mempool sdkmempool.Mempool - txVerifier ProposalTxVerifier + txVerifier TxVerifier } -func NewHandler(mempool sdkmempool.Mempool, txVerifier ProposalTxVerifier) Handler { +func NewHandler(mempool sdkmempool.Mempool, txVerifier TxVerifier) Handler { return Handler{ - mempool: mempool, + mempool: mempool, txVerifier: txVerifier, } } -func (h *Handler) PrepareProposal(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { +//nolint:gocognit // from sdk. +func (h *Handler) PrepareProposal( + ctx sdk.Context, req *abci.RequestPrepareProposal, +) (*abci.ResponsePrepareProposal, error) { var maxBlockGas int64 if b := ctx.ConsensusParams().Block; b != nil { maxBlockGas = b.MaxGas @@ -57,9 +81,9 @@ func (h *Handler) PrepareProposal(ctx sdk.Context, req *abci.RequestPreparePropo // valid. But some mempool implementations may insert invalid txs, so we // check again. bz, err := h.txVerifier.PrepareProposalVerifyTx(memTx) - if err != nil { - err := h.mempool.Remove(memTx) - if err != nil && !errors.Is(err, sdkmempool.ErrTxNotFound) { + if err != nil { //nolint:nestif // from sdk. + err2 := h.mempool.Remove(memTx) + if err2 != nil && !errors.Is(err2, sdkmempool.ErrTxNotFound) { return nil, err } } else { @@ -89,7 +113,8 @@ func (h *Handler) PrepareProposal(ctx sdk.Context, req *abci.RequestPreparePropo // Check if we've reached capacity. If so, we cannot select any more // transactions. - if totalTxBytes >= req.MaxTxBytes || (maxBlockGas > 0 && (totalTxGas >= uint64(maxBlockGas))) { + if totalTxBytes >= req.MaxTxBytes || + (maxBlockGas > 0 && (totalTxGas >= uint64(maxBlockGas))) { break } } diff --git a/cosmos/abci/process/default.go b/cosmos/abci/process/default.go index 268107f0a..1cc77474d 100644 --- a/cosmos/abci/process/default.go +++ b/cosmos/abci/process/default.go @@ -1,7 +1,28 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + package proposal import ( abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -9,7 +30,7 @@ type ( // ProposalTxVerifier defines the interface that is implemented by BaseApp, // that any custom ABCI PrepareProposal and ProcessProposal handler can use // to verify a transaction. - ProposalTxVerifier interface { + TxVerifier interface { PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) } @@ -21,16 +42,18 @@ type ( ) type Handler struct { - txVerifier ProposalTxVerifier + txVerifier TxVerifier } -func NewHandler(txVerifier ProposalTxVerifier) Handler { +func NewHandler(txVerifier TxVerifier) Handler { return Handler{ txVerifier: txVerifier, } } -func (h *Handler) ProcessProposal(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { +func (h *Handler) ProcessProposal( + ctx sdk.Context, req *abci.RequestProcessProposal, +) (*abci.ResponseProcessProposal, error) { var totalTxGas uint64 var maxBlockGas int64 @@ -41,7 +64,10 @@ func (h *Handler) ProcessProposal(ctx sdk.Context, req *abci.RequestProcessPropo for _, txBytes := range req.Txs { tx, err := h.txVerifier.ProcessProposalVerifyTx(txBytes) if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil + //nolint:nolintlint,nilerr // intentional. + return &abci.ResponseProcessProposal{ + Status: abci.ResponseProcessProposal_REJECT, + }, nil } if maxBlockGas > 0 {