Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnteDecorator #5006

Merged
merged 42 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1960993
start decorator changes
AdityaSripal Aug 28, 2019
12244c5
start replacing ante logic with decorators
AdityaSripal Aug 30, 2019
5a46ceb
Fix build errors
AdityaSripal Sep 5, 2019
bdcf294
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ad…
AdityaSripal Sep 5, 2019
ac19f18
fix some tests
AdityaSripal Sep 6, 2019
9a0eac7
fix baseapp tests
AdityaSripal Sep 9, 2019
725f5cf
fix auth tests
AdityaSripal Sep 12, 2019
ff5f1f7
start individual decorator tests
AdityaSripal Sep 14, 2019
73e2739
add signature tests
AdityaSripal Sep 17, 2019
77bc7c6
complete sig tests
AdityaSripal Sep 17, 2019
baf5bfb
fix all test errors
AdityaSripal Sep 17, 2019
71e07ce
remove unnecessary &
AdityaSripal Sep 18, 2019
3b3a74f
fix linter errors
AdityaSripal Sep 18, 2019
6303bec
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ad…
AdityaSripal Sep 18, 2019
e52e89d
interface all decorators except sigs
AdityaSripal Sep 18, 2019
ac8209d
check signer lenght in sigverify
AdityaSripal Sep 19, 2019
b93ca36
Apply suggestions from bez code review
AdityaSripal Sep 22, 2019
5825e81
complete bez suggestions
AdityaSripal Sep 29, 2019
441c050
fix merge conflicts
AdityaSripal Sep 29, 2019
2f22251
create sigTx interface
AdityaSripal Oct 1, 2019
975ad0e
linting
AdityaSripal Oct 1, 2019
c5ede73
finish linting except TODO
AdityaSripal Oct 1, 2019
9a5cb61
make auth tx interfaces extend sdk.Tx
AdityaSripal Oct 1, 2019
e7ec478
Merge branch 'master' into aditya/ante-decorator
alexanderbez Oct 2, 2019
634c1aa
test docs, replace FeeCoins with GetFee
AdityaSripal Oct 2, 2019
66144bf
Merge branch 'aditya/ante-decorator' of https://github.com/cosmos/cos…
AdityaSripal Oct 2, 2019
0c39cd9
Apply suggestions from fede code review
AdityaSripal Oct 2, 2019
29e85bf
address tim comments
AdityaSripal Oct 3, 2019
f1964cf
Merge branch 'aditya/ante-decorator' of https://github.com/cosmos/cos…
AdityaSripal Oct 3, 2019
b6d9166
Merge branch 'master' into aditya/ante-decorator
fedekunze Oct 8, 2019
0fd1234
add order comments
AdityaSripal Oct 8, 2019
aad9673
Add Schwarzenegger art
AdityaSripal Oct 8, 2019
5ce99da
add assertions that StdTx implements all necessary decorator interfaces
AdityaSripal Oct 8, 2019
bd79e58
Merge branch 'aditya/ante-decorator' of https://github.com/cosmos/cos…
AdityaSripal Oct 8, 2019
2f54876
documentation and CHANGELOG
AdityaSripal Oct 9, 2019
a4ef3ec
Run goimports
alexanderbez Oct 9, 2019
33cc17a
Update ChainAnteDecorators godoc
alexanderbez Oct 10, 2019
882fac5
Changelog entries cleanup
alexanderbez Oct 10, 2019
163da7f
Changelog entries cleanup
alexanderbez Oct 10, 2019
492cf0d
Merge branch 'master' into aditya/ante-decorator
alexanderbez Oct 10, 2019
1b1a779
Fix formatter
alexanderbez Oct 10, 2019
440a05c
Merge branch 'master' into aditya/ante-decorator
alexanderbez Oct 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test docs, replace FeeCoins with GetFee
  • Loading branch information
AdityaSripal committed Oct 2, 2019
commit 634c1aa493a442dceacb96b8f64e50c72d3e48c9
35 changes: 0 additions & 35 deletions x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,41 +532,6 @@ func TestAnteHandlerSetPubKey(t *testing.T) {
require.Nil(t, acc2.GetPubKey())
}

// func TestProcessPubKey(t *testing.T) {
// app, ctx := createTestApp(true)

// // keys
// _, _, addr1 := types.KeyTestPubAddr()
// priv2, _, addr2 := types.KeyTestPubAddr()
// acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
// acc2 := app.AccountKeeper.NewAccountWithAddress(ctx, addr2)

// acc2.SetPubKey(priv2.PubKey())

// type args struct {
// acc exported.Account
// sig types.StdSignature
// simulate bool
// }
// tests := []struct {
// name string
// args args
// wantErr bool
// }{
// {"no sigs, simulate off", args{acc1, types.StdSignature{}, false}, true},
// {"no sigs, simulate on", args{acc1, types.StdSignature{}, true}, false},
// {"no sigs, account with pub, simulate on", args{acc2, types.StdSignature{}, true}, false},
// {"pubkey doesn't match addr, simulate off", args{acc1, types.StdSignature{PubKey: priv2.PubKey()}, false}, true},
// {"pubkey doesn't match addr, simulate on", args{acc1, types.StdSignature{PubKey: priv2.PubKey()}, true}, false},
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// _, err := ante.ProcessPubKey(tt.args.acc, tt.args.sig, tt.args.simulate)
// require.Equal(t, tt.wantErr, err != nil)
// })
// }
// }

func generatePubKeysAndSignatures(n int, msg []byte, keyTypeed25519 bool) (pubkeys []crypto.PubKey, signatures [][]byte) {
pubkeys = make([]crypto.PubKey, n)
signatures = make([][]byte, n)
Expand Down
4 changes: 3 additions & 1 deletion x/auth/ante/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestValidateMemo(t *testing.T) {
privs, accNums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
invalidTx := types.NewTestTxWithMemo(ctx, msgs, privs, accNums, seqs, fee, strings.Repeat("01234567890", 500))

// require that long memos get rejected
vmd := ante.NewValidateMemoDecorator(app.AccountKeeper)
antehandler := sdk.ChainAnteDecorators(vmd)
_, err := antehandler(ctx, invalidTx, false)
Expand All @@ -65,6 +66,7 @@ func TestValidateMemo(t *testing.T) {

validTx := types.NewTestTxWithMemo(ctx, msgs, privs, accNums, seqs, fee, strings.Repeat("01234567890", 10))

// require small memos pass ValidateMemo Decorator
_, err = antehandler(ctx, validTx, false)
require.Nil(t, err, "ValidateBasicDecorator returned error on valid tx. err: %v", err)
}
Expand All @@ -84,7 +86,6 @@ func TestConsumeGasForTxSize(t *testing.T) {
ctx = ctx.WithTxBytes(txBytes)

// track how much gas is necessary to retrieve parameters
//
beforeGas := ctx.GasMeter().GasConsumed()
app.AccountKeeper.GetParams(ctx)
afterGas := ctx.GasMeter().GasConsumed()
Expand All @@ -95,6 +96,7 @@ func TestConsumeGasForTxSize(t *testing.T) {
ctx, err := antehandler(ctx, nil, false)
require.Nil(t, err, "ConsumeTxSizeGasDecorator returned error: %v", err)

// require that decorator consumes expected amount of gas
consumedGas := ctx.GasMeter().GasConsumed() - beforeGas
require.Equal(t, expectedGas, consumedGas, "Decorator did not consume the correct amount of gas")
}
12 changes: 6 additions & 6 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
// Tx must implement FeeTx interface to use the FeeDecorators
type FeeTx interface {
sdk.Tx
Gas() uint64
FeeCoins() sdk.Coins
GetGas() uint64
GetFee() sdk.Coins
FeePayer() sdk.AccAddress
}

Expand All @@ -36,8 +36,8 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}
feeCoins := feeTx.FeeCoins()
gas := feeTx.Gas()
feeCoins := feeTx.GetFee()
gas := feeTx.GetGas()

// Ensure that the provided fees meet a minimum threshold for the validator,
// if this is a CheckTx. This is only for local mempool purposes, and thus
Expand Down Expand Up @@ -94,8 +94,8 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
feePayerAcc := dfd.ak.GetAccount(ctx, feePayer)

// deduct the fees
if !feeTx.FeeCoins().IsZero() {
err = DeductFees(dfd.supplyKeeper, ctx, feePayerAcc, feeTx.FeeCoins())
if !feeTx.GetFee().IsZero() {
err = DeductFees(dfd.supplyKeeper, ctx, feePayerAcc, feeTx.GetFee())
if err != nil {
return ctx, err
}
Expand Down
8 changes: 4 additions & 4 deletions x/auth/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// Tx with a Gas() method is needed to use SetUpContextDecorator
// Tx with a GetGas() method is needed to use SetUpContextDecorator
type GasTx interface {
sdk.Tx
Gas() uint64
GetGas() uint64
}

// SetUpContextDecorator sets the GasMeter in the Context and wraps the next AnteHandler with a defer clause
Expand All @@ -34,7 +34,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
}

newCtx = SetGasMeter(simulate, ctx, gasTx.Gas())
newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas())

// Decorator will catch an OutOfGasPanic caused in the next antehandler
// AnteHandlers must have their own defer/recover in order for the BaseApp
Expand All @@ -47,7 +47,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
case sdk.ErrorOutOfGas:
log := fmt.Sprintf(
"out of gas in location: %v; gasWanted: %d, gasUsed: %d",
rType.Descriptor, gasTx.Gas(), newCtx.GasMeter().GasConsumed())
rType.Descriptor, gasTx.GetGas(), newCtx.GasMeter().GasConsumed())

err = sdkerrors.Wrap(sdkerrors.ErrOutOfGas, log)
default:
Expand Down
8 changes: 4 additions & 4 deletions x/auth/types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) []byte {
)
}

// Gas returns the Gas in StdFee
func (tx StdTx) Gas() uint64 { return tx.Fee.Gas }
// GetGas returns the Gas in StdFee
func (tx StdTx) GetGas() uint64 { return tx.Fee.Gas }

// FeeCoins returns the FeeAmount in StdFee
func (tx StdTx) FeeCoins() sdk.Coins { return tx.Fee.Amount }
// GetFee returns the FeeAmount in StdFee
func (tx StdTx) GetFee() sdk.Coins { return tx.Fee.Amount }

// FeePayer returns the address that is responsible for paying fee
// StdTx returns the first signer as the fee payer
Expand Down