Skip to content

Commit

Permalink
docs: v0.2.0 debug eth_call example (#25)
Browse files Browse the repository at this point in the history
* docs: v0.2.0 debug eth call example

* chore: update requirements
  • Loading branch information
hanchon authored Aug 15, 2024
1 parent 756c6fb commit 300f20e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 6 deletions.
15 changes: 14 additions & 1 deletion cmd/playground/query/erc20/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package erc20
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/hanchon/hanchond/lib/converter"
Expand All @@ -25,6 +26,8 @@ var balanceCmd = &cobra.Command{
fmt.Println("node not set")
os.Exit(1)
}

height, _ := cmd.Flags().GetString("height")
contract := strings.TrimSpace(args[0])
wallet := strings.TrimSpace(args[1])
wallet, err = converter.NormalizeAddressToHex(wallet)
Expand All @@ -35,7 +38,16 @@ var balanceCmd = &cobra.Command{

e := evmos.NewEvmosFromDB(queries, nodeID)
client := requester.NewClient().WithUnsecureWeb3Endpoint(fmt.Sprintf("http://localhost:%d", e.Ports.P8545))
balance, err := client.GetBalanceERC20(contract, wallet, erc20.Latest)
heightInt := erc20.Latest
if height != "latest" {
temp, err := strconv.ParseInt(height, 10, 64)
if err != nil {
fmt.Printf("invalid height: %s\n", err.Error())
os.Exit(1)
}
heightInt = int(temp)
}
balance, err := client.GetBalanceERC20(contract, wallet, heightInt)
if err != nil {
fmt.Println("could not get the balance:", err.Error())
os.Exit(1)
Expand All @@ -46,4 +58,5 @@ var balanceCmd = &cobra.Command{

func init() {
ERC20Cmd.AddCommand(balanceCmd)
balanceCmd.Flags().String("height", "latest", "Query at the given height.")
}
16 changes: 15 additions & 1 deletion cmd/playground/query/erc20/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package erc20
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/hanchon/hanchond/lib/requester"
Expand All @@ -27,7 +28,19 @@ var supplyCmd = &cobra.Command{
contract := strings.TrimSpace(args[0])
e := evmos.NewEvmosFromDB(queries, nodeID)
client := requester.NewClient().WithUnsecureWeb3Endpoint(fmt.Sprintf("http://localhost:%d", e.Ports.P8545))
supply, err := client.GetTotalSupply(contract, erc20.Latest)

height, _ := cmd.Flags().GetString("height")
heightInt := erc20.Latest
if height != "latest" {
temp, err := strconv.ParseInt(height, 10, 64)
if err != nil {
fmt.Printf("invalid height: %s\n", err.Error())
os.Exit(1)
}
heightInt = int(temp)
}

supply, err := client.GetTotalSupply(contract, heightInt)
if err != nil {
fmt.Println("could not get the supply:", err.Error())
os.Exit(1)
Expand All @@ -38,4 +51,5 @@ var supplyCmd = &cobra.Command{

func init() {
ERC20Cmd.AddCommand(supplyCmd)
supplyCmd.Flags().String("height", "latest", "Query at the given height.")
}
150 changes: 150 additions & 0 deletions docs/pages/hanchond/playground/examples/debugEthCall.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Debug `eth_call` for archive queries

:::info
This example is using `hanchond` v0.2.0. Some interfaces may change in the future
:::

## Requirements

```sh
$ hanchond p build-evmos v18.1.0
$ hanchond p build-evmos v19.1.0
$ hanchond p build-hermes
```

## Set up the chains

Create two chains with just one validator each using the `v18.1.0` Evmos version and start them

```bash
hanchond p remove-data && hanchond p init-chain 1 --version v18.1.0 && hanchond p init-chain 1 --version v18.1.0 && hanchond p start-chain 1 && hanchond p start-chain 2
```

## IBC config

- Create an IBC Channel and start the relayer

```bash
hanchond p hermes-add-channel 1 2 && hanchond p start-hermes
```

- Send an IBC transfer

```bash
hanchond p tx ibc-transfer evmos1x49lse4ykqrvntuancrdjdjzz75xzmsj5nn9p0 1000 --node 2
```

- Verify the balance:

```bash
hanchond p q balance evmos1x49lse4ykqrvntuancrdjdjzz75xzmsj5nn9p0
```

## Register the ERC20

```bash
hanchond playground tx str-v1-proposal ibc/8EAC8061F4499F03D2D1419A3E73D346289AE9DB89CAB1486B72539572B1915E
hanchond playground tx vote
hanchond p q evmos token-pairs | jq .
```

We have an ERC20 with the address: `0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd`

- Send another IBC transfer so all the balance is converted

```bash
hanchond p tx ibc-transfer evmos1x49lse4ykqrvntuancrdjdjzz75xzmsj5nn9p0 1000 --node 2
```

## Debug `eth_call`

-Get the current value

```bash
hanchond p q height
118

hanchond p q erc20 balance 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd 0x354bF866A4B006C9AF9d9e06d9364217A8616E12 --height 118
2000
```

- Upgrade the network

```bash
hanchond playground tx upgrade-proposal v19.1.0 --height-diff 50
hanchond playground tx vote
```

- Wait for the upgrade height

```bash
hanchond p q height
235
```

### Apply the upgrade

- Stop the node

```bash
hanchond p stop-node 1
```

- Change the version

```bash
hanchond p change-version 1 evmosdv19.1.0
```

- Restart the node

```bash
hanchond p start-node 1
```

### Query archive data

```bash
hanchond p q erc20 balance 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd 0x354bF866A4B006C9AF9d9e06d9364217A8616E12 --height 118

could not get the balance: rpc error: code = Internal desc = invalid opcode: PUSH0
```

## Create a patch

- Clone the repo locally and apply the needed changes.

- Build the binary locally

```bash
hanchond p build-evmos --path /Users/hanchon/devel/evmos/evmos
```

- Update the node to use the local fork

```bash
hanchond p change-version 1 evmosdlocal
```

- Stop the node

```bash
hanchond p stop-node 1
```

- Start the node

```bash
hanchond p start-node 1
```

- Test your patch

```bash
hanchond p q erc20 balance 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd 0x354bF866A4B006C9AF9d9e06d9364217A8616E12 --height 118
2000
```

:::info
Logs can be found at `~/hanchond/data/1-0/run.log`
:::
2 changes: 2 additions & 0 deletions docs/pages/hanchond/playground/queries/erc20/balance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ hanchond playground query erc20 balance 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aD

:::info
The command supports wallets in `Bech32` and `Hex` encoding

The `height` flag is available to query archive data, it defaults to `latest`
:::
4 changes: 4 additions & 0 deletions docs/pages/hanchond/playground/queries/erc20/supply.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ The command `erc20 supply [contract]` can be used to get the total supply of an
hanchond playground query erc20 supply 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd
5
```

:::info
The `height` flag is available to query archive data, it defaults to `latest`
:::
4 changes: 3 additions & 1 deletion playground/cosmosdaemon/config_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func (d *Daemon) UpdateAppFile() error {
if err != nil {
return err
}
appFile = d.SetPruningInAppFile(true, appFile)

// No pruning to use archive queries
appFile = d.SetPruningInAppFile(false, appFile)
appFile = d.SetMinGasPricesInAppFile(appFile)
return d.SaveAppFile(appFile)
}
Expand Down
6 changes: 3 additions & 3 deletions playground/evmos/command_gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (e *Evmos) CreateSTRv1Proposal(params STRv1) (string, error) {
"--from",
e.ValKeyName,
"--gas-prices",
fmt.Sprintf("100%s", e.BaseDenom),
fmt.Sprintf("100000000000000%s", e.BaseDenom),
"--gas-adjustment",
"4",
"--gas",
Expand Down Expand Up @@ -105,7 +105,7 @@ func (e *Evmos) VoteOnProposal(proposalID string, option string) (string, error)
"--from",
e.ValKeyName,
"--gas-prices",
fmt.Sprintf("100%s", e.BaseDenom),
fmt.Sprintf("100000000000000%s", e.BaseDenom),
"--gas-adjustment",
"4",
"-y",
Expand Down Expand Up @@ -189,7 +189,7 @@ func (e *Evmos) CreateUpgradeProposal(versionName string, upgradeHeight string)
"--from",
e.ValKeyName,
"--gas-prices",
fmt.Sprintf("100%s", e.BaseDenom),
fmt.Sprintf("100000000000000%s", e.BaseDenom),
"--gas-adjustment",
"4",
"--gas",
Expand Down
4 changes: 4 additions & 0 deletions vocs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ export default defineConfig({
text: "v19.1.0 Upgrade (v0.1.0)",
link: "/hanchond/playground/examples/upgradev19",
},
{
text: "Debug eth_call (v0.2.0)",
link: "/hanchond/playground/examples/debugEthCall",
},
],
},
],
Expand Down

0 comments on commit 300f20e

Please sign in to comment.