From a34d0f95556b8b47e40411b6ccdb29e2ebe492e5 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Mon, 29 Jan 2024 12:53:36 +0100 Subject: [PATCH] chg: delete pulp related files / fix typo --- client/keys/output.go | 2 +- x/auth/ante/validator_tx_fee.go | 42 ++++++++-------- x/auth/types/pulp.go | 88 --------------------------------- x/auth/types/pulp_test.go | 27 ---------- 4 files changed, 23 insertions(+), 136 deletions(-) delete mode 100644 x/auth/types/pulp.go delete mode 100644 x/auth/types/pulp_test.go diff --git a/client/keys/output.go b/client/keys/output.go index 35ebf6e33a2a..3e671fa66e73 100644 --- a/client/keys/output.go +++ b/client/keys/output.go @@ -48,7 +48,7 @@ func MkConsKeyOutput(k *keyring.Record) (KeyOutput, error) { return NewKeyOutput(k.Name, k.GetType(), addr, pk) } -// MkValKeyOutput create a KeyOutput or Vals +// MkValKeyOutput create a KeyOutput for Vals func MkValKeyOutput(k *keyring.Record) (KeyOutput, error) { pk, err := k.GetPubKey() if err != nil { diff --git a/x/auth/ante/validator_tx_fee.go b/x/auth/ante/validator_tx_fee.go index adba6093538c..b52b6b6f02ce 100644 --- a/x/auth/ante/validator_tx_fee.go +++ b/x/auth/ante/validator_tx_fee.go @@ -19,7 +19,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx, params type return nil, 0, errorsmod.Wrap(sdkerrors.ErrInvalidTxFees, "must provide correct txFees") } - // TODO HV2: gas is retrieved from Params as currently done in heimdall. Can this be changed + // TODO HV2: gas is retrieved from Params as currently done in heimdall gas := params.GetMaxTxGas() feeCoins := sdk.Coins{sdk.Coin{Denom: types.FeeToken, Amount: amount}} @@ -27,25 +27,27 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx, params type // 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 // is only ran on check tx. - //if ctx.IsCheckTx() { - // - // minGasPrices := ctx.MinGasPrices() - // if !minGasPrices.IsZero() { - // requiredFees := make(sdk.Coins, len(minGasPrices)) - // - // // Determine the required fees by multiplying each required minimum gas - // // price by the gas limit, where fee = ceil(minGasPrice * gasLimit). - // glDec := sdkmath.LegacyNewDec(int64(gas)) - // for i, gp := range minGasPrices { - // fee := gp.Amount.Mul(glDec) - // requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) - // } - // - // if !feeCoins.IsAnyGTE(requiredFees) { - // return nil, 0, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) - // } - // } - //} + /* + if ctx.IsCheckTx() { + + minGasPrices := ctx.MinGasPrices() + if !minGasPrices.IsZero() { + requiredFees := make(sdk.Coins, len(minGasPrices)) + + // Determine the required fees by multiplying each required minimum gas + // price by the gas limit, where fee = ceil(minGasPrice * gasLimit). + glDec := sdkmath.LegacyNewDec(int64(gas)) + for i, gp := range minGasPrices { + fee := gp.Amount.Mul(glDec) + requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) + } + + if !feeCoins.IsAnyGTE(requiredFees) { + return nil, 0, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) + } + } + } + */ priority := getTxPriority(feeCoins, int64(gas)) return feeCoins, priority, nil diff --git a/x/auth/types/pulp.go b/x/auth/types/pulp.go deleted file mode 100644 index e27c2ffbb632..000000000000 --- a/x/auth/types/pulp.go +++ /dev/null @@ -1,88 +0,0 @@ -package types - -import ( - "encoding/hex" - "errors" - "reflect" - - "github.com/ethereum/go-ethereum/rlp" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" -) - -// TODO HV2: this is imported from heimdall, but not used anywhere (not heimdall, not cosmos). Can we delete it? -const ( - // PulpHashLength pulp hash length - PulpHashLength int = 4 -) - -// Pulp codec for RLP -type Pulp struct { - typeInfos map[string]reflect.Type -} - -// GetPulpHash returns string hash -func GetPulpHash(msg sdk.Msg) []byte { - // TODO HV2: msg.Route() and msg.Type() unavailable in cosmos. - // Anyway this function is not used anywhere in heimdall, hence I believe it can be deleted. - // return crypto.Keccak256([]byte(fmt.Sprintf("%s::%s", msg.Route(), msg.Type())))[:PulpHashLength] - return nil -} - -// RegisterConcrete should be used to register concrete types that will appear in -// interface fields/elements to be encoded/decoded by pulp. -func (p *Pulp) RegisterConcrete(msg sdk.Msg) { - rtype := reflect.TypeOf(msg) - p.typeInfos[hex.EncodeToString(GetPulpHash(msg))] = rtype -} - -// GetMsgTxInstance get new instance associated with base tx -func (p *Pulp) GetMsgTxInstance(hash []byte) interface{} { - rtype := p.typeInfos[hex.EncodeToString(hash[:PulpHashLength])] - - return reflect.New(rtype).Elem().Interface().(sdk.Msg) -} - -// EncodeToBytes encodes msg to bytes -func (p *Pulp) EncodeToBytes(tx legacytx.StdTx) ([]byte, error) { - msg := tx.GetMsgs()[0] - - txBytes, err := rlp.EncodeToBytes(tx) - if err != nil { - return nil, err - } - - return append(GetPulpHash(msg), txBytes[:]...), nil -} - -// DecodeBytes decodes bytes to msg -func (p *Pulp) DecodeBytes(data []byte) (interface{}, error) { - var txRaw legacytx.StdTxRaw - - if len(data) <= PulpHashLength { - return nil, errors.New("Invalid data length, should be greater than PulpPrefix") - } - - if err := rlp.DecodeBytes(data[PulpHashLength:], &txRaw); err != nil { - return nil, err - } - - rtype := p.typeInfos[hex.EncodeToString(data[:PulpHashLength])] - newMsg := reflect.New(rtype).Interface() - - if err := rlp.DecodeBytes(txRaw.Msg[:], newMsg); err != nil { - return nil, err - } - - // change pointer to non-pointer - vptr := reflect.New(reflect.TypeOf(newMsg).Elem()).Elem() - vptr.Set(reflect.ValueOf(newMsg).Elem()) - // return vptr.Interface(), nil - - return legacytx.StdTx{ - Msgs: []sdk.Msg{vptr.Interface().(sdk.Msg)}, - Signatures: []legacytx.StdSignature{txRaw.Signature}, - Memo: txRaw.Memo, - }, nil -} diff --git a/x/auth/types/pulp_test.go b/x/auth/types/pulp_test.go deleted file mode 100644 index 76ff57c7cefa..000000000000 --- a/x/auth/types/pulp_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package types - -import ( - "testing" - - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - assert "github.com/stretchr/testify/require" -) - -// TODO HV2: this is imported from heimdall, but not used anywhere (not heimdall, not cosmos). -// Can we delete it? Also the test fails because of the missing implementation of the GetPulpHash function - -func TestGetPulpHash(t *testing.T) { - t.Skip() - t.Parallel() - - tc := struct { - in sdk.Msg - out []byte - }{ - in: testdata.NewTestMsg(nil), - out: []byte{142, 88, 179, 79}, - } - out := GetPulpHash(tc.in) - assert.Equal(t, string(tc.out), string(out)) -}