Skip to content

Commit

Permalink
Merge branch 'main' into ud/evm
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Jul 8, 2024
2 parents 1f834d6 + 2a6c81a commit 97f21cf
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 930 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1947](https://github.com/NibiruChain/nibiru/pull/1947) - fix(evm): fix FunToken state marshalling
- [#1949](https://github.com/NibiruChain/nibiru/pull/1949) - feat(evm): add fungible token mapping queries
- [#1950](https://github.com/NibiruChain/nibiru/pull/1950) - feat(evm): Tx to create FunToken mapping from ERC20, contract embeds, and ERC20 queries.
- [#1958](https://github.com/NibiruChain/nibiru/pull/1958) - chore(evm): wiped deprecated evm apis: miner, personal

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

Expand Down
4 changes: 2 additions & 2 deletions app/server/config/server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func GetDefaultAPINamespaces() []string {

// GetAPINamespaces returns the all the available JSON-RPC API namespaces.
func GetAPINamespaces() []string {
return []string{"web3", "eth", "personal", "net", "txpool", "debug", "miner"}
return []string{"web3", "eth", "net", "txpool", "debug"}
}

// DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
Expand Down Expand Up @@ -397,7 +397,7 @@ address = "{{ .JSONRPC.Address }}"
ws-address = "{{ .JSONRPC.WsAddress }}"
# API defines a list of JSON-RPC namespaces that should be enabled
# Example: "eth,txpool,personal,net,debug,web3"
# Example: "eth,txpool,net,debug,web3"
api = "{{range $index, $elmt := .JSONRPC.API}}{{if $index}},{{$elmt}}{{else}}{{$elmt}}{{end}}{{end}}"
# GasCap sets a cap on gas that can be used in eth_call/estimateGas (0=infinite). Default: 25,000,000.
Expand Down
38 changes: 23 additions & 15 deletions contrib/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ echo_success() {

echo_info "Parsing flags for the script..."

# $FLAG_NO_BUILD: toggles whether to build from source. The default
# behavior of the script is to run make install if the flag --no-build is not present.
FLAG_NO_BUILD=false
# $FLAG_SKIP_BUILD: toggles whether to build from source. The default
# behavior of the script is to run make install if the flag --no-build is omitted.
FLAG_SKIP_BUILD=false


build_from_source() {
Expand All @@ -81,7 +81,7 @@ enable_feature_flag() {
while [[ $# -gt 0 ]]; do
case $1 in
--no-build)
FLAG_NO_BUILD=true
FLAG_SKIP_BUILD=true
shift
;;
--features)
Expand All @@ -96,13 +96,13 @@ while [[ $# -gt 0 ]]; do
done


# Check if FLAG_NO_BUILD was set to true
if ! $FLAG_NO_BUILD; then
# Check if FLAG_SKIP_BUILD was set to true
if ! $FLAG_SKIP_BUILD; then
build_from_source
fi

echo_info "Features flags:"
echo "FLAG_NO_BUILD: $FLAG_NO_BUILD"
echo "FLAG_SKIP_BUILD: $FLAG_SKIP_BUILD"

SEDOPTION=""
if [[ "$OSTYPE" == "darwin"* ]]; then
Expand All @@ -119,9 +119,11 @@ if pgrep -x "$BINARY" >/dev/null; then
killall nibid
fi

# Remove previous data
# Remove previous data, preserving keyring and config files
echo_info "Removing previous chain data from $CHAIN_DIR..."
rm -rf "$CHAIN_DIR"
$BINARY tendermint unsafe-reset-all
rm -f "$CHAIN_DIR/config/genesis.json"
rm -rf "$CHAIN_DIR/config/gentx/"

# Add directory for chain, exit if error
if ! mkdir -p "$CHAIN_DIR" 2>/dev/null; then
Expand All @@ -135,6 +137,7 @@ if $BINARY init $CHAIN_ID --chain-id $CHAIN_ID --overwrite; then
echo_success "Successfully initialized $CHAIN_ID"
else
echo_error "Failed to initialize $CHAIN_ID"
exit 1
fi

# nibid config
Expand All @@ -143,6 +146,7 @@ $BINARY config keyring-backend test
$BINARY config chain-id $CHAIN_ID
$BINARY config broadcast-mode sync
$BINARY config output json
$BINARY config node "http://localhost:26657"
$BINARY config # Prints config.

# Enable API Server
Expand All @@ -165,15 +169,19 @@ echo_info "Adding genesis accounts..."

val_key_name="validator"

echo "$MNEMONIC" | $BINARY keys add $val_key_name --recover
$BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS
# EVM encrypted nibi address for the same account
$BINARY add-genesis-account nibi1cr6tg4cjvux00pj6zjqkh6d0jzg7mksaywxyl3 $GENESIS_COINS
echo_success "Successfully added genesis account: $val_key_name"
if ! $BINARY keys show $val_key_name; then
echo "$MNEMONIC" | $BINARY keys add $val_key_name --recover
echo_success "Successfully added key: $val_key_name"
fi

val_address=$($BINARY keys list | jq -r '.[] | select(.name == "validator") | .address')
val_address=$($BINARY keys show $val_key_name -a)
val_address=${val_address:-"nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"}

$BINARY add-genesis-account $val_address $GENESIS_COINS
# EVM encoded nibi address for the same account
$BINARY add-genesis-account nibi1cr6tg4cjvux00pj6zjqkh6d0jzg7mksaywxyl3 $GENESIS_COINS
echo_success "Successfully added genesis account: $val_key_name"

# ------------------------------------------------------------------------
# Configure genesis params
# ------------------------------------------------------------------------
Expand Down
9 changes: 0 additions & 9 deletions eth/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cometbft/cometbft/libs/log"
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -48,12 +47,6 @@ type EVMBackend interface {
// Node specific queries
Accounts() ([]common.Address, error)
Syncing() (interface{}, error)
SetEtherbase(etherbase common.Address) bool
SetGasPrice(gasPrice hexutil.Big) bool
ImportRawKey(privkey, password string) (common.Address, error)
ListAccounts() ([]common.Address, error)
NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (*keyring.Record, error)
UnprotectedAllowed() bool
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection
RPCTxFeeCap() float64 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for send-transaction variants. The unit is ether.
Expand Down Expand Up @@ -94,11 +87,9 @@ type EVMBackend interface {
ChainID() (*hexutil.Big, error)
ChainConfig() *params.ChainConfig
// TODO: feat: Dynamic fees
// GlobalMinGasPrice() (math.LegacyDec, error)
BaseFee(blockRes *tmrpctypes.ResultBlockResults) (*big.Int, error)
CurrentHeader() (*gethcore.Header, error)
PendingTransactions() ([]*sdk.Tx, error)
GetCoinbase() (sdk.AccAddress, error)
FeeHistory(blockCount gethrpc.DecimalOrHex, lastBlock gethrpc.BlockNumber, rewardPercentiles []float64) (*rpc.FeeHistoryResult, error)
SuggestGasTipCap(baseFee *big.Int) (*big.Int, error)

Expand Down
25 changes: 0 additions & 25 deletions eth/rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,6 @@ func (b *Backend) PendingTransactions() ([]*sdk.Tx, error) {
return result, nil
}

// GetCoinbase is the address that staking rewards will be send to (alias for Etherbase).
func (b *Backend) GetCoinbase() (sdk.AccAddress, error) {
node, err := b.clientCtx.GetNode()
if err != nil {
return nil, err
}

status, err := node.Status(b.ctx)
if err != nil {
return nil, err
}

req := &evm.QueryValidatorAccountRequest{
ConsAddress: sdk.ConsAddress(status.ValidatorInfo.Address).String(),
}

res, err := b.queryClient.ValidatorAccount(b.ctx, req)
if err != nil {
return nil, err
}

address, _ := sdk.AccAddressFromBech32(res.AccountAddress) // #nosec G703
return address, nil
}

// FeeHistory returns data relevant for fee estimation based on the specified range of blocks.
func (b *Backend) FeeHistory(
userBlockCount gethrpc.DecimalOrHex, // number blocks to fetch, maximum is 100
Expand Down
57 changes: 0 additions & 57 deletions eth/rpc/backend/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,63 +136,6 @@ func (s *BackendSuite) TestChainId() {
}
}

func (s *BackendSuite) TestGetCoinbase() {
validatorAcc := sdk.AccAddress(evmtest.NewEthAccInfo().EthAddr.Bytes())
testCases := []struct {
name string
registerMock func()
accAddr sdk.AccAddress
expPass bool
}{
{
"fail - Can't retrieve status from node",
func() {
client := s.backend.clientCtx.Client.(*mocks.Client)
RegisterStatusError(client)
},
validatorAcc,
false,
},
{
"fail - Can't query validator account",
func() {
client := s.backend.clientCtx.Client.(*mocks.Client)
queryClient := s.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterStatus(client)
RegisterValidatorAccountError(queryClient)
},
validatorAcc,
false,
},
{
"pass - Gets coinbase account",
func() {
client := s.backend.clientCtx.Client.(*mocks.Client)
queryClient := s.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterStatus(client)
RegisterValidatorAccount(queryClient, validatorAcc)
},
validatorAcc,
true,
},
}

for _, tc := range testCases {
s.Run(fmt.Sprintf("case %s", tc.name), func() {
s.SetupTest() // reset test and queries
tc.registerMock()

accAddr, err := s.backend.GetCoinbase()

if tc.expPass {
s.Require().Equal(tc.accAddr, accAddr)
} else {
s.Require().Error(err)
}
})
}
}

func (s *BackendSuite) TestSuggestGasTipCap() {
testCases := []struct {
name string
Expand Down
Loading

0 comments on commit 97f21cf

Please sign in to comment.