Skip to content

Commit

Permalink
Merge pull request #9051 from Agoric/9036-antefix-cosmos
Browse files Browse the repository at this point in the history
fix: eliminate fee double-charge by using configurable decorator
  • Loading branch information
mergify[bot] committed Mar 11, 2024
2 parents 5d5ee65 + 9ac6222 commit 177a8d0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 108 deletions.
74 changes: 74 additions & 0 deletions a3p-integration/proposals/a:upgrade-next/ante-fees.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import test from 'ava';

import { CHAINID, GOV1ADDR, GOV2ADDR, agd } from '@agoric/synthetic-chain';

test(`ante handler sends fee only to vbank/reserve`, async t => {
const [feeCollector, vbankReserve] = await Promise.all(
// Look up addresses for fee collector and reserve accounts.
['fee_collector', 'vbank/reserve'].map(async name => {
const {
account: {
'@type': moduleAcct,
base_account: { address },
},
} = await agd.query('auth', 'module-account', name);

t.is(
moduleAcct,
'/cosmos.auth.v1beta1.ModuleAccount',
`${name} is a module account`,
);
return address;
}),
);

const getBalances = addresses =>
Promise.all(
addresses.map(async address => {
const { balances } = await agd.query('bank', 'balances', address);
return balances;
}),
);

const [feeCollectorStartBalances, vbankReserveStartBalances] =
await getBalances([feeCollector, vbankReserve]);

// Send a transaction with a known fee.
const feeAmount = 999n;
const feeDenom = 'uist';
const result = await agd.tx(
`bank send ${GOV1ADDR} ${GOV2ADDR} 1234ubld --fees=${feeAmount}${feeDenom} \
--from=${GOV1ADDR} --chain-id=${CHAINID} --keyring-backend=test --yes`,
);
t.like(result, { code: 0 });

const [feeCollectorEndBalances, vbankReserveEndBalances] = await getBalances([
feeCollector,
vbankReserve,
]);
t.deepEqual(feeCollectorEndBalances, feeCollectorStartBalances);

// The reserve balances should have increased by exactly the fee (possibly
// from zero, in which case start balances wouldn't include its denomination).
const feeDenomIndex = vbankReserveStartBalances.findIndex(
({ denom }) => denom === feeDenom,
);
const preFeeAmount =
feeDenomIndex < 0
? 0n
: BigInt(vbankReserveStartBalances[feeDenomIndex].amount);
const beforeCount =
feeDenomIndex < 0 ? vbankReserveStartBalances.length : feeDenomIndex;

const vbankReserveExpectedBalances = [
...vbankReserveStartBalances.slice(0, beforeCount),
{ amount: String(preFeeAmount + feeAmount), denom: feeDenom },
...vbankReserveStartBalances.slice(beforeCount + 1),
];

t.deepEqual(
vbankReserveEndBalances,
vbankReserveExpectedBalances,
'vbank/reserve should receive the fee',
);
});
5 changes: 1 addition & 4 deletions golang/cosmos/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
ante.NewExtensionOptionsDecorator(nil), // reject all extensions
// former ante.NewMempoolFeeDecorator()
// replaced as in https://github.com/provenance-io/provenance/pull/1016
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, nil),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
NewInboundDecorator(opts.SwingsetKeeper),
NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.FeeCollectorName),
ante.NewDeductFeeDecoratorWithName(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, nil, opts.FeeCollectorName),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(opts.AccountKeeper),
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
Expand Down
97 changes: 0 additions & 97 deletions golang/cosmos/ante/fee.go

This file was deleted.

2 changes: 1 addition & 1 deletion golang/cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ replace (
// Agoric-specific replacements:
replace (
// We need a fork of cosmos-sdk until all of the differences are merged.
github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2
github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.1

// Async version negotiation
github.com/cosmos/ibc-go/v6 => github.com/agoric-labs/ibc-go/v6 v6.2.1-alpha.agoric.3
Expand Down
4 changes: 2 additions & 2 deletions golang/cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agoric-labs/cometbft v0.34.30-alpha.agoric.1 h1:tqCNL72pQXdUmBzgv1md5SN2U3K/PaYQ4qZ5pFv8v6w=
github.com/agoric-labs/cometbft v0.34.30-alpha.agoric.1/go.mod h1:myvkihZD8eg9jKE3WFaugkNoL5nvEqlP7Jbjg98pCek=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2 h1:iHHqpYC0JzMbH4UYnQrcwVjLyHJuQphB0ogHbuLz44c=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2/go.mod h1:zUe5lsg/X7SeSO1nGkzOh9EGKO295szfrxIxYmeLYic=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.1 h1:VZFX9Mogwt4cVTnkdt9zA6UJue4XYXdBURNhlTWw71Q=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.1/go.mod h1:zUe5lsg/X7SeSO1nGkzOh9EGKO295szfrxIxYmeLYic=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1 h1:2jvHI/2d+psWAZy6FQ0vXJCHUtfU3ZbbW+pQFL04arQ=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/agoric-labs/ibc-go/v6 v6.2.1-alpha.agoric.3 h1:YqvVwK+Lg/ZsuwyVm9UbPs8K55fg00R3Y9KnmaTBdgc=
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate-a3p-submission-dir.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
set -ueo pipefail

SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
SCRIPT_DIR=$( cd "${0%/*}" && pwd -P )

for proposal in ./proposals/?:*
do
cd $proposal
args=`jq -r < package.json '.agoricProposal["sdk-generate"][0]'`
$SCRIPT_DIR/generate-a3p-submission.sh $proposal $args
cd "$proposal"
args=$(jq -r < package.json '.agoricProposal["sdk-generate"][0]')
"$SCRIPT_DIR/generate-a3p-submission.sh" "$proposal" $args
cd -
done

0 comments on commit 177a8d0

Please sign in to comment.