Skip to content

Commit

Permalink
Merge branch 'main' into ud/funtoken-fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Jul 12, 2024
2 parents d6db062 + 8970a6c commit 09afe2d
Show file tree
Hide file tree
Showing 38 changed files with 66 additions and 197 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1959](https://github.com/NibiruChain/nibiru/pull/1959) - feat(evm): Add precompile to the EVM that enables trasnfers of ERC20 tokens to "nibi" accounts as regular Ethereum transactions
- [#1960](https://github.com/NibiruChain/nibiru/pull/1960) - test(network): graceful cleanup for more consistent CI runs
- [#1961](https://github.com/NibiruChain/nibiru/pull/1961) - chore(test): reverted funtoken precompile test back to the isolated state
<<<<<<< HEAD
- [#1963](https://github.com/NibiruChain/nibiru/pull/1963) - feat(evm): Deduct a fee during the creation of a FunToken mapping. Implemented by `deductCreateFunTokenFee` inside of the `eth.evm.v1.MsgCreateFunToken` transaction.
- [#1962](https://github.com/NibiruChain/nibiru/pull/1962) - chore(evm): code cleanup, unused code, typos, styles, warnings

#### Dapp modules: perp, spot, oracle, etc

Expand Down
9 changes: 4 additions & 5 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func NewAnteHandler(
var anteHandler sdk.AnteHandler
hasExt, typeUrl := TxHasExtensions(tx)
if hasExt && typeUrl != "" {
anteHandler = AnteHandlerExtendedTx(typeUrl, keepers, opts, ctx)
anteHandler = AnteHandlerExtendedTx(typeUrl, keepers, opts)
return anteHandler(ctx, tx, sim)
}

switch tx.(type) {
case sdk.Tx:
anteHandler = NewAnteHandlerNonEVM(keepers, opts)
anteHandler = NewAnteHandlerNonEVM(opts)
default:
return ctx, fmt.Errorf("invalid tx type (%T) in AnteHandler", tx)
}
Expand All @@ -50,13 +50,12 @@ func AnteHandlerExtendedTx(
typeUrl string,
keepers AppKeepers,
opts ante.AnteHandlerOptions,
ctx sdk.Context,
) (anteHandler sdk.AnteHandler) {
switch typeUrl {
case evm.TYPE_URL_ETHEREUM_TX:
anteHandler = NewAnteHandlerEVM(keepers, opts)
case eth.TYPE_URL_DYNAMIC_FEE_TX:
anteHandler = NewAnteHandlerNonEVM(keepers, opts)
anteHandler = NewAnteHandlerNonEVM(opts)
default:
errUnsupported := fmt.Errorf(
`encountered tx with unsupported extension option, "%s"`, typeUrl)
Expand All @@ -71,7 +70,7 @@ func AnteHandlerExtendedTx(

// NewAnteHandlerNonEVM: Default ante handler for non-EVM transactions.
func NewAnteHandlerNonEVM(
k AppKeepers, opts ante.AnteHandlerOptions,
opts ante.AnteHandlerOptions,
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
AnteDecoratorPreventEtheruemTxMsgs{}, // reject MsgEthereumTxs
Expand Down
1 change: 0 additions & 1 deletion app/evmante_sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

var (
InvalidChainID = big.NewInt(987654321)
RandomAddress = evmtest.NewEthAccInfo().EthAddr.Hex()
)

func (s *TestSuite) TestEthSigVerificationDecorator() {
Expand Down
3 changes: 2 additions & 1 deletion app/server/json_rpc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -87,7 +88,7 @@ func StartJSONRPC(ctx *server.Context,
go func() {
ctx.Logger.Info("Starting JSON-RPC server", "address", config.JSONRPC.Address)
if err := httpSrv.Serve(ln); err != nil {
if err == http.ErrServerClosed {
if errors.Is(err, http.ErrServerClosed) {
close(httpSrvDone)
return
}
Expand Down
10 changes: 0 additions & 10 deletions eth/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
package eth

import (
"math/big"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -64,11 +62,3 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&ExtensionOptionDynamicFeeTx{},
)
}

func ParseEIP155ChainIDNumber(chainId string) *big.Int {
idNum, err := ParseEthChainID(chainId)
if err != nil {
panic(err)
}
return idNum
}
27 changes: 0 additions & 27 deletions eth/rpc/backend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import (
"context"
"testing"

"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/bytes"
tmrpcclient "github.com/cometbft/cometbft/rpc/client"
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
mock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -42,11 +39,6 @@ func RegisterTxSearchEmpty(client *mocks.Client, query string) {
Return(&tmrpctypes.ResultTxSearch{}, nil)
}

func RegisterTxSearchError(client *mocks.Client, query string) {
client.On("TxSearch", rpc.NewContextWithHeight(1), query, false, (*int)(nil), (*int)(nil), "").
Return(nil, errortypes.ErrInvalidRequest)
}

// Broadcast Tx
func RegisterBroadcastTx(client *mocks.Client, tx types.Tx) {
client.On("BroadcastTxSync", context.Background(), tx).
Expand Down Expand Up @@ -265,22 +257,3 @@ func RegisterABCIQueryWithOptions(client *mocks.Client, height int64, path strin
},
}, nil)
}

func RegisterABCIQueryWithOptionsError(clients *mocks.Client, path string, data bytes.HexBytes, opts tmrpcclient.ABCIQueryOptions) {
clients.On("ABCIQueryWithOptions", context.Background(), path, data, opts).
Return(nil, errortypes.ErrInvalidRequest)
}

func RegisterABCIQueryAccount(clients *mocks.Client, data bytes.HexBytes, opts tmrpcclient.ABCIQueryOptions, acc client.Account) {
baseAccount := authtypes.NewBaseAccount(acc.GetAddress(), acc.GetPubKey(), acc.GetAccountNumber(), acc.GetSequence())
accAny, _ := codectypes.NewAnyWithValue(baseAccount)
accResponse := authtypes.QueryAccountResponse{Account: accAny}
respBz, _ := accResponse.Marshal()
clients.On("ABCIQueryWithOptions", context.Background(), "/cosmos.auth.v1beta1.Query/Account", data, opts).
Return(&tmrpctypes.ResultABCIQuery{
Response: abci.ResponseQuery{
Value: respBz,
Height: 1,
},
}, nil)
}
12 changes: 0 additions & 12 deletions eth/rpc/rpcapi/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
package rpcapi

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"

Expand Down Expand Up @@ -137,13 +135,3 @@ func GetRPCAPIs(ctx *server.Context,

return apis
}

// RegisterAPINamespace registers a new API namespace with the API creator.
// This function fails if the namespace is already registered.
func RegisterAPINamespace(ns string, creator APICreator) error {
if _, ok := apiCreators[ns]; ok {
return fmt.Errorf("duplicated api namespace %s", ns)
}
apiCreators[ns] = creator
return nil
}
7 changes: 4 additions & 3 deletions x/common/testutil/testnetwork/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var lock = new(sync.Mutex)
// creates an ABCI Application to provide to Tendermint.
type AppConstructor = func(val Validator) servertypes.Application

// Network defines a in-process testing network. It is primarily intended
// Network defines an in-process testing network. It is primarily intended
// for client and integration testing. The Network struct can spawn any
// number of validators, each with its own RPC and API clients.
//
Expand Down Expand Up @@ -593,14 +593,15 @@ func (n *Network) Cleanup() {

waitGroup.Wait()

// TODO: Is there a cleaner way to do this with a synchronous check?
// TODO: Is there a cleaner way to do this with a guarnteed synchronous on
// each "Validator.tmNode"?
// https://github.com/NibiruChain/nibiru/issues/1955

// Give a brief pause for things to finish closing in other processes.
// Hopefully this helps with the address-in-use errors.
// Timeout of 100ms chosen randomly.
// Timeout of 250ms chosen because 100ms was not enough. | 2024-07-02
maxRetries := 5
maxRetries := 20
stopped := false
for i := 0; i < maxRetries; i++ {
if ValidatorsStopped(n.Validators) {
Expand Down
8 changes: 6 additions & 2 deletions x/common/testutil/testnetwork/validator_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ func stopValidatorNode(v *Validator) {
// accepting new connections and RPCs and blocks until all the pending RPCs are
// finished.
v.grpc.GracefulStop()
if v.grpcWeb != nil {
_ = v.grpcWeb.Close()
}

if v.grpcWeb != nil {
err := v.grpcWeb.Close()
if err != nil {
v.Logger.Logf("❌ Error closing the gRPC web server: %w", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/devgas/v1/ante/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ante

// Interfaces needed for the for the Nibiru Chain ante handler
// Interfaces needed for the Nibiru Chain ante handler

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
2 changes: 1 addition & 1 deletion x/devgas/v1/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Keeper struct {
wasmKeeper wasmkeeper.Keeper
accountKeeper devgastypes.AccountKeeper

// feeCollectorName is the name of of x/auth module's fee collector module
// feeCollectorName is the name of x/auth module's fee collector module
// account, "fee_collector", which collects transaction fees for distribution
// to all stakers.
//
Expand Down
4 changes: 2 additions & 2 deletions x/devgas/v1/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewMsgRegisterFeeShare(
// Route returns the name of the module
func (msg MsgRegisterFeeShare) Route() string { return RouterKey }

// Type returns the the action
// Type returns the action
func (msg MsgRegisterFeeShare) Type() string { return TypeMsgRegisterFeeShare }

// ValidateBasic runs stateless checks on the message
Expand Down Expand Up @@ -129,7 +129,7 @@ func NewMsgUpdateFeeShare(
// Route returns the name of the module
func (msg MsgUpdateFeeShare) Route() string { return RouterKey }

// Type returns the the action
// Type returns the action
func (msg MsgUpdateFeeShare) Type() string { return TypeMsgUpdateFeeShare }

// ValidateBasic runs stateless checks on the message
Expand Down
4 changes: 2 additions & 2 deletions x/evm/access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewAccessList(ethAccessList *gethcore.AccessList) AccessList {
return al
}

// ToEthAccessList is an utility function to convert the protobuf compatible
// ToEthAccessList is a utility function to convert the protobuf compatible
// AccessList to eth core AccessList from go-ethereum
func (al AccessList) ToEthAccessList() *gethcore.AccessList {
var ethAccessList gethcore.AccessList
Expand Down Expand Up @@ -140,7 +140,7 @@ func (tx *AccessListTx) GetAccessList() gethcore.AccessList {
return *tx.Accesses.ToEthAccessList()
}

// GetData returns the a copy of the input data bytes.
// GetData returns a copy of the input data bytes.
func (tx *AccessListTx) GetData() []byte {
return common.CopyBytes(tx.Data)
}
Expand Down
2 changes: 1 addition & 1 deletion x/evm/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func EthereumConfig(chainID *big.Int) *params.ChainConfig {
}

// Validate performs a basic validation of the ChainConfig params. The function will return an error
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
// if any of the block values is uninitialized (i.e. nil) or if the EIP150Hash is an invalid hash.
func Validate() error {
// NOTE: chain ID is not needed to check config order
if err := EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
Expand Down
8 changes: 2 additions & 6 deletions x/evm/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ import (
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/types/tx"
proto "github.com/cosmos/gogoproto/proto"
"github.com/cosmos/gogoproto/proto"
)

var (
amino = codec.NewLegacyAmino()
// ModuleCdc references the global evm module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding.
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())

// AminoCdc is a amino codec created to support amino JSON compatible msgs.
AminoCdc = codec.NewAminoCodec(amino)
)
Expand Down Expand Up @@ -57,7 +53,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
}

// PackTxData constructs a new Any packed with the given tx data value. It returns
// an error if the client state can't be casted to a protobuf message or if the concrete
// an error if the client state can't be cast to a protobuf message or if the concrete
// implementation is not registered to the protobuf codec.
func PackTxData(txData TxData) (*codectypes.Any, error) {
msg, ok := txData.(proto.Message)
Expand Down
14 changes: 3 additions & 11 deletions x/evm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ const (

const (
codeErrInvalidState = uint32(iota) + 2 // NOTE: code 1 is reserved for internal errors
codeErrInvalidChainConfig
codeErrZeroAddress
codeErrCreateDisabled
codeErrCallDisabled
codeErrInvalidAmount
codeErrInvalidGasPrice
codeErrInvalidGasFee
codeErrVMExecution
codeErrInvalidRefund
codeErrInvalidGasCap
codeErrInvalidBaseFee
Expand All @@ -42,9 +40,6 @@ var (
// ErrInvalidState returns an error resulting from an invalid Storage State.
ErrInvalidState = errorsmod.Register(ModuleName, codeErrInvalidState, "invalid storage state")

// ErrInvalidChainConfig returns an error resulting from an invalid ChainConfig.
ErrInvalidChainConfig = errorsmod.Register(ModuleName, codeErrInvalidChainConfig, "invalid chain configuration")

// ErrZeroAddress returns an error resulting from an zero (empty) ethereum Address.
ErrZeroAddress = errorsmod.Register(ModuleName, codeErrZeroAddress, "invalid zero address")

Expand All @@ -63,16 +58,13 @@ var (
// ErrInvalidGasFee returns an error if the tx gas fee is out of bound.
ErrInvalidGasFee = errorsmod.Register(ModuleName, codeErrInvalidGasFee, "invalid gas fee")

// ErrVMExecution returns an error resulting from an error in EVM execution.
ErrVMExecution = errorsmod.Register(ModuleName, codeErrVMExecution, "evm transaction execution failed")

// ErrInvalidRefund returns an error if a the gas refund value is invalid.
// ErrInvalidRefund returns an error if the gas refund value is invalid.
ErrInvalidRefund = errorsmod.Register(ModuleName, codeErrInvalidRefund, "invalid gas refund amount")

// ErrInvalidGasCap returns an error if a the gas cap value is negative or invalid
// ErrInvalidGasCap returns an error if the gas cap value is negative or invalid
ErrInvalidGasCap = errorsmod.Register(ModuleName, codeErrInvalidGasCap, "invalid gas cap")

// ErrInvalidBaseFee returns an error if a the base fee cap value is invalid
// ErrInvalidBaseFee returns an error if the base fee cap value is invalid
ErrInvalidBaseFee = errorsmod.Register(ModuleName, codeErrInvalidBaseFee, "invalid base fee")

// ErrGasOverflow returns an error if gas computation overlow/underflow
Expand Down
Loading

0 comments on commit 09afe2d

Please sign in to comment.