Add Fee granter field (#7418)

* WIP on adding Fee granter field

* WIP on adding Fee granter field

* WIP on adding Fee granter field

* Update comments, add tests
This commit is contained in:
Aaron Craelius 2020-10-05 17:56:09 -04:00 committed by GitHub
parent 435fc83ba7
commit 4a1b2fba43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 227 additions and 53 deletions

View File

@ -174,4 +174,9 @@ message Fee {
// the payer must be a tx signer (and thus have signed this field in AuthInfo).
// setting this field does *not* change the ordering of required signers for the transaction.
string payer = 3;
// if set, the fee payer (either the first signer or the value of the payer field) requests that a fee grant be used
// to pay fees instead of the fee payer's own balance. If an appropriate fee grant does not exist or the chain does
// not support fee grants, this will fail
string granter = 4;
}

View File

@ -676,6 +676,10 @@ type Fee struct {
// the payer must be a tx signer (and thus have signed this field in AuthInfo).
// setting this field does *not* change the ordering of required signers for the transaction.
Payer string `protobuf:"bytes,3,opt,name=payer,proto3" json:"payer,omitempty"`
// if set, the fee payer (either the first signer or the value of the payer field) requests that a fee grant be used
// to pay fees instead of the fee payer's own balance. If an appropriate fee grant does not exist or the chain does
// not support fee grants, this will fail
Granter string `protobuf:"bytes,4,opt,name=granter,proto3" json:"granter,omitempty"`
}
func (m *Fee) Reset() { *m = Fee{} }
@ -732,6 +736,13 @@ func (m *Fee) GetPayer() string {
return ""
}
func (m *Fee) GetGranter() string {
if m != nil {
return m.Granter
}
return ""
}
func init() {
proto.RegisterType((*Tx)(nil), "cosmos.tx.v1beta1.Tx")
proto.RegisterType((*TxRaw)(nil), "cosmos.tx.v1beta1.TxRaw")
@ -748,59 +759,60 @@ func init() {
func init() { proto.RegisterFile("cosmos/tx/v1beta1/tx.proto", fileDescriptor_96d1575ffde80842) }
var fileDescriptor_96d1575ffde80842 = []byte{
// 830 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4d, 0x6f, 0xdc, 0x44,
0x18, 0x5e,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x12, 0x19, 0x2d, 0x59, 0xc6, 0x94, 0x29, 0x44, 0x1f, 0xbb, 0x29, 0x91, 0xdf,
0xea, 0x3b, 0xda, 0x81, 0xc1, 0x8a, 0x54, 0x34, 0xb7, 0x5b, 0xa5, 0xbe, 0xcc, 0xbe, 0x7c, 0x73,
0xee, 0x39, 0x6f, 0xcf, 0x3d, 0xe7, 0xdd, 0xb9, 0xe7, 0xbc, 0xbe, 0xf0, 0x3a, 0x6f, 0x2f, 0xbc,
0xce, 0x1f, 0x17, 0x5e, 0xe7, 0xc5, 0xfd, 0x9b, 0xc3, 0x87, 0xaa, 0x8c, 0x87, 0xa6, 0x65, 0x1f,
0xfd, 0x13, 0x00, 0x00, 0xff, 0xff, 0xfa, 0xdf, 0x9b, 0x65, 0xe3, 0x06, 0x00, 0x00,
// 843 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xdd, 0x6e, 0xdc, 0x44,
0x14, 0x5e, 0xef, 0x5f, 0xd6, 0x27, 0x49, 0x4b, 0x47, 0x11, 0xda, 0x6c, 0x54, 0x37, 0x18, 0x15,
0xf6, 0x26, 0x76, 0x9b, 0x5e, 0xf0, 0x23, 0x24, 0xc8, 0x16, 0xaa, 0x54, 0xa5, 0x20, 0x4d, 0x72,
0xd5, 0x1b, 0x6b, 0xec, 0x9d, 0x78, 0x47, 0x5d, 0xcf, 0x2c, 0x9e, 0x71, 0xb1, 0x1f, 0x02, 0xa9,
0x42, 0x42, 0xbc, 0x03, 0x2f, 0xc0, 0x2b, 0xf4, 0xb2, 0x97, 0x5c, 0x41, 0x95, 0x3c, 0x08, 0x68,
0xc6, 0x63, 0x27, 0x82, 0x55, 0x72, 0xc3, 0x95, 0xe7, 0x9c, 0xf9, 0xce, 0x37, 0x9f, 0xcf, 0x1f,
0x4c, 0x12, 0x21, 0x33, 0x21, 0x43, 0x55, 0x86, 0xaf, 0x1e, 0xc6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 0x00, 0x00,
}
func (m *Tx) Marshal() (dAtA []byte, err error) {
@ -1307,6 +1319,13 @@ func (m *Fee) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.Granter) > 0 {
i -= len(m.Granter)
copy(dAtA[i:], m.Granter)
i = encodeVarintTx(dAtA, i, uint64(len(m.Granter)))
i--
dAtA[i] = 0x22
}
if len(m.Payer) > 0 {
i -= len(m.Payer)
copy(dAtA[i:], m.Payer)
@ -1576,6 +1595,10 @@ func (m *Fee) Size() (n int) {
if l > 0 {
n += 1 + l + sovTx(uint64(l))
}
l = len(m.Granter)
if l > 0 {
n += 1 + l + sovTx(uint64(l))
}
return n
}
@ -2972,6 +2995,38 @@ func (m *Fee) Unmarshal(dAtA []byte) error {
}
m.Payer = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Granter", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTx
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTx
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTx
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Granter = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTx(dAtA[iNdEx:])

View File

@ -62,6 +62,7 @@ type (
GetGas() uint64
GetFee() Coins
FeePayer() AccAddress
FeeGranter() AccAddress
}
// Tx must have GetMemo() method to use ValidateMemoDecorator

View File

@ -22,6 +22,7 @@ func NewAnteHandler(
TxTimeoutHeightDecorator{},
NewValidateMemoDecorator(ak),
NewConsumeGasForTxSizeDecorator(ak),
NewRejectFeeGranterDecorator(),
NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
NewValidateSigCountDecorator(ak),
NewDeductFeeDecorator(ak, bankKeeper),

27
x/auth/ante/fee_grant.go Normal file
View File

@ -0,0 +1,27 @@
package ante
import (
"github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// RejectFeeGranterDecorator is an AnteDecorator which rejects transactions which
// have the Fee.granter field set. It is to be used by chains which do not support
// fee grants.
type RejectFeeGranterDecorator struct{}
// NewRejectFeeGranterDecorator returns a new RejectFeeGranterDecorator.
func NewRejectFeeGranterDecorator() RejectFeeGranterDecorator {
return RejectFeeGranterDecorator{}
}
var _ types.AnteDecorator = RejectFeeGranterDecorator{}
func (d RejectFeeGranterDecorator) AnteHandle(ctx types.Context, tx types.Tx, simulate bool, next types.AnteHandler) (newCtx types.Context, err error) {
feeTx, ok := tx.(types.FeeTx)
if ok && len(feeTx.FeeGranter()) != 0 {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not supported")
}
return next(ctx, tx, simulate)
}

View File

@ -0,0 +1,32 @@
package ante_test
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)
type setFeeGranter interface {
SetFeeGranter(feeGranter sdk.AccAddress)
}
func (suite *AnteTestSuite) TestRejectFeeGranter() {
suite.SetupTest(true) // setup
txConfig := tx.NewTxConfig(codec.NewProtoCodec(types.NewInterfaceRegistry()), tx.DefaultSignModes)
txBuilder := txConfig.NewTxBuilder()
d := ante.NewRejectFeeGranterDecorator()
antehandler := sdk.ChainAnteDecorators(d)
_, err := antehandler(suite.ctx, txBuilder.GetTx(), false)
suite.Require().NoError(err)
setGranterTx := txBuilder.(setFeeGranter)
_, _, addr := testdata.KeyTestPubAddr()
setGranterTx.SetFeeGranter(addr)
_, err = antehandler(suite.ctx, txBuilder.GetTx(), false)
suite.Require().Error(err)
}

View File

@ -264,6 +264,11 @@ func (tx StdTx) FeePayer() sdk.AccAddress {
return sdk.AccAddress{}
}
// FeeGranter always returns nil for StdTx
func (tx StdTx) FeeGranter() sdk.AccAddress {
return nil
}
func (tx StdTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
for _, m := range tx.Msgs {
err := codectypes.UnpackInterfaces(m, unpacker)

View File

@ -67,6 +67,9 @@ func TestStdTx(t *testing.T) {
feePayer := tx.GetSigners()[0]
require.Equal(t, addr, feePayer)
feeGranter := tx.FeeGranter()
require.Empty(t, feeGranter)
}
func TestStdSignBytes(t *testing.T) {

View File

@ -144,6 +144,18 @@ func (w *wrapper) FeePayer() sdk.AccAddress {
return w.GetSigners()[0]
}
func (w *wrapper) FeeGranter() sdk.AccAddress {
feePayer := w.tx.AuthInfo.Fee.Granter
if feePayer != "" {
granterAddr, err := sdk.AccAddressFromBech32(feePayer)
if err != nil {
panic(err)
}
return granterAddr
}
return nil
}
func (w *wrapper) GetMemo() string {
return w.tx.Body.Memo
}
@ -255,6 +267,17 @@ func (w *wrapper) SetFeePayer(feePayer sdk.AccAddress) {
w.authInfoBz = nil
}
func (w *wrapper) SetFeeGranter(feeGranter sdk.AccAddress) {
if w.tx.AuthInfo.Fee == nil {
w.tx.AuthInfo.Fee = &tx.Fee{}
}
w.tx.AuthInfo.Fee.Granter = feeGranter.String()
// set authInfoBz to nil because the cached authInfoBz no longer matches tx.AuthInfo
w.authInfoBz = nil
}
func (w *wrapper) SetSignatures(signatures ...signing.SignatureV2) error {
n := len(signatures)
signerInfos := make([]*tx.SignerInfo, n)

View File

@ -289,3 +289,25 @@ func TestBuilderFeePayer(t *testing.T) {
})
}
}
func TestBuilderFeeGranter(t *testing.T) {
// keys and addresses
_, _, addr1 := testdata.KeyTestPubAddr()
// msg and signatures
msg1 := testdata.NewTestMsg(addr1, addr2)
feeAmount := testdata.NewTestFeeAmount()
msgs := []sdk.Msg{msg1}
txBuilder := newBuilder()
err := txBuilder.SetMsgs(msgs...)
require.NoError(t, err)
txBuilder.SetGasLimit(200000)
txBuilder.SetFeeAmount(feeAmount)
require.Empty(t, txBuilder.GetTx().FeeGranter())
// set fee granter
txBuilder.SetFeeGranter(addr1)
require.Equal(t, addr1, txBuilder.GetTx().FeeGranter())
}