Skip to content

Commit

Permalink
Merge pull request #6 from airchains-network/development
Browse files Browse the repository at this point in the history
Updated Transaction failure errors in DA and Junction codes
  • Loading branch information
Noooblien authored Jun 5, 2024
2 parents 084dcb3 + a4e2af2 commit 0c0bfcf
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 134 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
./accounts/*
./.idea/*
./bin/*
./.tracks/*
./.tracks/*
./.tracks
./build/*
22 changes: 2 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ MAKEFLAGS += --silent
## Build the binary
build:
@echo " > Building binary..."
go build $(LDFLAGS) -o ./$(BINARYNAME) ./cmd/main.go
go build -o ./build/$(BINARYNAME) ./cmd/main.go
@echo " > Binary Build at ./build/tracks..."

# Install dependencies
.PHONY: install
## Install missing dependencies
install:
@echo " > Installing dependencies..."
go mod download

# Clean build files
.PHONY: clean
## Clean build cache
clean:
@echo " > Cleaning build cache..."
go clean

# Show help information
.PHONY: help
## Show this help screen
help:
@sed -n 's/^##//p' Makefile
94 changes: 78 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,95 @@

### Remove old data if present
# Tracks Setup Guide
This guide will help you set up and initialize the Tracks environment.

## Step 1: Remove Old Data

If you have previously set up Tracks, remove any old data to ensure a clean environment.

```shell
sudo rm -rf ~/.tracks
```
## Step 2: Build the Tracks

```bash
make build
```

## Step 3: Initialize the Tracks

Initialize the sequencer with the necessary parameters.

### Init sequencer
```shell
go run cmd/main.go init --daRpc "mock-rpc" --daKey "mockKey" --daType "mock" --moniker "monkey" --stationRpc "http://127.0.0.1:8545" --stationAPI "http://127.0.0.1:8545" --stationType "evm"
daRpc="mock-rpc"
daKey="mockKey"
daType="mock"
moniker="monkey"
stationRpc="http://127.0.0.1:8545"
stationAPI="http://127.0.0.1:8545"
stationType="evm"

./build/tracks init --daRpc "$daRpc" --daKey "$daKey" --daType "$daType" --moniker "$moniker" --stationRpc "$stationRpc" --stationAPI "$stationAPI" --stationType "$stationType"
```

### Create Keys for Junction
## Step 4: Initialize the Prover

Initialize the prover. Ensure you specify the correct version.

```shell
go run cmd/main.go keys junction --accountName dummy --accountPath .tracks/junction-accounts/keys
./build/tracks prover v1EVM
```
OR `Import with mnemonic`

## Step 5: Create Keys for Junction (If not already created)

Create keys for the junction account. If the keys are not already created, use the following command:

```shell
accountName="dummy"
accountPath=".tracks/junction-accounts/keys"

./build/tracks keys junction --accountName "$accountName" --accountPath "$accountPath"
```

Alternatively, you can import an account using a mnemonic:

```shell
go run cmd/main.go keys import --accountName dummy --accountPath .tracks/junction-accounts/keys --mnemonic "huge bounce thing settle diet mobile fruit skill call roast offer soap other upset toward sand dress moral pole smile limb round vacant ecology"
accountName="dummy"
accountPath=".tracks/junction-accounts/keys"
mnemonic="huge bounce thing settle diet mobile fruit skill call roast offer soap other upset toward sand dress moral pole smile limb round vacant ecology"

./build/tracks keys import --accountName "$accountName" --accountPath "$accountPath" --mnemonic "$mnemonic"
```

### Init Prover
## Step 6: Fund the wallet
- Join [Airchains Discord ](https://discord.gg/airchains)
- Goto `switchyard-faucet-bot` channel
- Type `$faucet <your_address>`, you will get 2AMF soon.

## Step 7: Create a Station on Junction

Create a station on the junction with the necessary parameters.
> NOTE: don't forget to replace `accountAddressArray` with the addresses you want to make track member. Replace it with your new address
```shell
go run cmd/main.go prover v1EVM
```
### Create station on junction
```sh
go run cmd/main.go create-station --tracks air1l9gjw7yklpx9tn74j328qwlmf7377rhle9hryc --accountName dummy --accountPath .tracks/junction-accounts/keys --jsonRPC "https://junction-testnet-rpc.synergynodes.com/" --info "EVM Track" --bootstrapNode "/ip4/192.168.1.24/tcp/2300/p2p/12D3KooWFoN66sCWotff1biUcnBE2vRTmYJRHJqZy27x1EpBB6AM"
accountAddressArray="air1knf2an5efl8d9t5w75uds4ty8uj0scxx9yg783" #! replace it with your address
accountName="dummy"
accountPath=".tracks/junction-accounts/keys"
#jsonRPC="http://0.0.0.0:26657" # localhost testing
jsonRPC="https://junction-testnet-rpc.synergynodes.com/" # junction testnet
bootstrapNode="/ip4/192.168.1.24/tcp/2300/p2p/12D3KooWFoN66sCWotff1biUcnBE2vRTmYJRHJqZy27x1EpBB6AM"
info="EVM Track"

./build/tracks create-station --tracks "$accountAddressArray" --accountName "$accountName" --accountPath "$accountPath" --jsonRPC "$jsonRPC" --info "$info" --bootstrapNode "$bootstrapNode"
```

### start node
## Step 8: Start the Tracks

Finally, start the node to begin interacting with the Tracks blockchain.

```shell
go run cmd/main.go start
```
./build/tracks start
```

## Troubleshooting

If you encounter any issues during setup, refer to [official documentation](https://docs.airchains.io/rollups/evm-zk-rollup/system-requirements) or reach out [Airchains discord](https://discord.gg/airchains) for support.
17 changes: 14 additions & 3 deletions cmd/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ func InitConfigs(cmd *cobra.Command) (*Configs, error) {
return nil, fmt.Errorf("failed to get flag 'daType': %w", err)
}

validTypes := map[string]bool{
"avail": true,
"celestia": true,
"eigen": true,
"mock": true,
}
if _, isValid := validTypes[configs.daType]; !isValid {
logs.Log.Error("invalid daType. Must be one of: avail, celestia, eigen, mock")
return nil, fmt.Errorf("invalid daType: %s", configs.daType)
}

configs.daRPC, err = cmd.Flags().GetString("daRpc")
if err != nil {
return nil, fmt.Errorf("failed to get flag 'daRpc': %w", err)
Expand Down Expand Up @@ -68,13 +79,13 @@ var InitCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
configs, err := InitConfigs(cmd)
if err != nil {
logs.Log.Warn(err.Error())
logs.Log.Error(err.Error())
return
}

homeDir, err := os.UserHomeDir()
if err != nil {
logs.Log.Warn("Failed to get user home directory:" + err.Error())
logs.Log.Error("Failed to get user home directory:" + err.Error())
return
}

Expand All @@ -96,7 +107,7 @@ var InitCmd = &cobra.Command{

success := config.CreateConfigFile(conf.BaseConfig.RootDir, conf)
if !success {
logs.Log.Warn("Unable to generate a config file. Please check the error and try again.")
logs.Log.Error("Unable to generate a config file. Please check the error and try again.")
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"fmt"
"github.com/airchains-network/decentralized-sequencer/cmd/command"
"github.com/airchains-network/decentralized-sequencer/cmd/command/keys"
"github.com/airchains-network/decentralized-sequencer/cmd/command/zkpCmd"
"github.com/ethereum/go-ethereum/log"
"github.com/spf13/cobra"
"os"
)
Expand Down Expand Up @@ -66,7 +66,7 @@ func main() {
command.CreateStation.MarkFlagRequired("tracks")

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
log.Error(err.Error())
os.Exit(1)
}

Expand Down
7 changes: 4 additions & 3 deletions da/eigen/eigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"fmt"
disperserGrpc "github.com/airchains-network/decentralized-sequencer/da/eigen/grpc"
"github.com/airchains-network/decentralized-sequencer/da/eigen/utils"
"github.com/rs/zerolog/log"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"time"
Expand All @@ -55,21 +56,21 @@ func Eigen(daData []byte, rpcUrl string, accountKey string) (string, error) {
dialOptions := grpc.WithTransportCredentials(credential)
conn, err := grpc.Dial(addr, dialOptions)
if err != nil {
fmt.Println(err)
log.Err(err).Msg("failed to dial")
return "nil", err
}
defer func() { _ = conn.Close() }()

d, de := DisperserBlob(ctx, conn, daData, accountKey)
if de != nil {
fmt.Printf("failed to disperse blob: %v", de)
log.Error().Err(de).Msg("failed to disperse blob")
return "nil", err
}

blobKey := string(d[:])

//TODO Add DA check Status
fmt.Println("Eigen DA Blob KEY", blobKey)
log.Info().Msg("Eigen DA Blob KEY: " + blobKey)
return blobKey, nil

}
Expand Down
15 changes: 12 additions & 3 deletions junction/checkBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ func CheckBalance(jsonRPC string, accountAddress string) (bool, int64, error) {

ctx := context.Background()
client, err := cosmosclient.New(ctx, cosmosclient.WithNodeAddress(jsonRPC))
if err != nil {
errorMsg := fmt.Errorf("Junction client connection failed, make sure jsonRPC is correct and active. JsonRPC: " + jsonRPC)
return false, 0, errorMsg
}
pageRequest := &query.PageRequest{} // Add this line to create a new PageRequest
fmt.Printf("accountAddress: %v\n", accountAddress)

balances, err := client.BankBalances(ctx, accountAddress, pageRequest) // Add pageRequest as the third argument
if err != nil {
fmt.Printf("Error querying bank balances: %v\n", err)
return false, 0, err
errorMsg := fmt.Errorf("error querying bank balances for RPC=%s Address=%s", jsonRPC, accountAddress)
return false, 0, errorMsg
}

if len(balances) == 0 {
errorMsg := fmt.Errorf("account do not have balance. Address: %s", accountAddress)
return false, 0, errorMsg
}

for _, balance := range balances {
Expand Down
4 changes: 2 additions & 2 deletions junction/createStation.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func CreateStation(extraArg junctionTypes.StationArg, stationId string, stationI

success, amount, err := CheckBalance(jsonRPC, newTempAddr)
if err != nil || !success {
logs.Log.Error("Error checking balance")
logs.Log.Error(err.Error())
return false
}
if amount < 100 {
Expand Down Expand Up @@ -107,7 +107,7 @@ func CreateStation(extraArg junctionTypes.StationArg, stationId string, stationI
}

ctx := context.Background()
gas := utilis.GenerateRandomWithFavour(611, 1200, [2]int{612, 1000}, 0.7)
gas := utilis.GenerateRandomWithFavour(1200, 2400, [2]int{1500, 2000}, 0.7)
gasFees := fmt.Sprintf("%damf", gas)
accountClient, err := cosmosclient.New(ctx, cosmosclient.WithAddressPrefix(addressPrefix), cosmosclient.WithNodeAddress(jsonRPC), cosmosclient.WithHome(accountPath), cosmosclient.WithGas("auto"), cosmosclient.WithFees(gasFees))
if err != nil {
Expand Down
34 changes: 19 additions & 15 deletions junction/initVRF.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,28 @@ func InitVRF() (success bool, addr string) {
ExtraArg: extraArgsByte,
}

txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
if errTxRes != nil {
errStr := errTxRes.Error()
if strings.Contains(errStr, VRFInitiatedErrorContains) {
log.Debug().Str("module", "junction").Msg("TxError: VRF already initiated for this pod number")
return true, newTempAddr
for {
txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
if errTxRes != nil {
errStr := errTxRes.Error()
if strings.Contains(errStr, VRFInitiatedErrorContains) {
log.Debug().Str("module", "junction").Msg("VRF already initiated for this pod number")
return true, newTempAddr
} else {
log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in InitVRF transaction")
// retry transaction
log.Debug().Str("module", "junction").Msg("Retrying InitVRF transaction after 10 seconds..")
time.Sleep(10 * time.Second)
//return false, ""
}
} else {
log.Error().Str("module", "junction").Str("Error", errStr).Msg("TxError: Error in InitVRF transaction")
// update transaction hash in current pod
currentPodState.VRFInitiationTxHash = txRes.TxHash
shared.SetPodState(currentPodState)

return false, ""
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("InitiateVRf")
return true, newTempAddr
}
} else {
// update transaction hash in current pod
currentPodState.VRFInitiationTxHash = txRes.TxHash
shared.SetPodState(currentPodState)

log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("InitiateVRf")
return true, newTempAddr
}
}

Expand Down
31 changes: 17 additions & 14 deletions junction/submitPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,27 @@ func SubmitCurrentPod() (success bool) {
podDetails := QueryPod(podNumber)
if podDetails != nil {
// pod already submitted
log.Debug().Str("module", "junction").Msg("TxError: Pod already submitted")
log.Debug().Str("module", "junction").Msg("Pod already submitted")
return true
} else {
log.Info().Str("module", "junction").Msg("Pod not submitted, Submitting pod")
}

txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
if errTxRes != nil {
errStr := errTxRes.Error()
log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in SubmitPod Transaction")
return false
} else {
//os.Exit(0)
// update txHash of submit pod in pod state
currentPodState.InitPodTxHash = txRes.TxHash
shared.SetPodState(currentPodState)
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("Pod Submitted")
return true
}
for {
txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
if errTxRes != nil {
errStr := errTxRes.Error()
log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in SubmitPod Transaction")

log.Debug().Str("module", "junction").Msg("Retrying SubmitPod transaction after 10 seconds..")
time.Sleep(10 * time.Second)
//return false
} else {
// update txHash of submit pod in pod state
currentPodState.InitPodTxHash = txRes.TxHash
shared.SetPodState(currentPodState)
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("Pod Submitted")
return true
}
}
}
Loading

0 comments on commit 0c0bfcf

Please sign in to comment.