Skip to content

Commit 0c0bfcf

Browse files
authored
Merge pull request #6 from airchains-network/development
Updated Transaction failure errors in DA and Junction codes
2 parents 084dcb3 + a4e2af2 commit 0c0bfcf

15 files changed

Lines changed: 277 additions & 134 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
./accounts/*
33
./.idea/*
44
./bin/*
5-
./.tracks/*
5+
./.tracks/*
6+
./.tracks
7+
./build/*

Makefile

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ MAKEFLAGS += --silent
1919
## Build the binary
2020
build:
2121
@echo " > Building binary..."
22-
go build $(LDFLAGS) -o ./$(BINARYNAME) ./cmd/main.go
22+
go build -o ./build/$(BINARYNAME) ./cmd/main.go
23+
@echo " > Binary Build at ./build/tracks..."
2324

24-
# Install dependencies
25-
.PHONY: install
26-
## Install missing dependencies
27-
install:
28-
@echo " > Installing dependencies..."
29-
go mod download
30-
31-
# Clean build files
32-
.PHONY: clean
33-
## Clean build cache
34-
clean:
35-
@echo " > Cleaning build cache..."
36-
go clean
37-
38-
# Show help information
39-
.PHONY: help
40-
## Show this help screen
41-
help:
42-
@sed -n 's/^##//p' Makefile

README.md

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,95 @@
11

2-
### Remove old data if present
2+
# Tracks Setup Guide
3+
This guide will help you set up and initialize the Tracks environment.
4+
5+
## Step 1: Remove Old Data
6+
7+
If you have previously set up Tracks, remove any old data to ensure a clean environment.
8+
39
```shell
410
sudo rm -rf ~/.tracks
511
```
12+
## Step 2: Build the Tracks
13+
14+
```bash
15+
make build
16+
```
17+
18+
## Step 3: Initialize the Tracks
19+
20+
Initialize the sequencer with the necessary parameters.
621

7-
### Init sequencer
822
```shell
9-
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"
23+
daRpc="mock-rpc"
24+
daKey="mockKey"
25+
daType="mock"
26+
moniker="monkey"
27+
stationRpc="http://127.0.0.1:8545"
28+
stationAPI="http://127.0.0.1:8545"
29+
stationType="evm"
30+
31+
./build/tracks init --daRpc "$daRpc" --daKey "$daKey" --daType "$daType" --moniker "$moniker" --stationRpc "$stationRpc" --stationAPI "$stationAPI" --stationType "$stationType"
1032
```
1133

12-
### Create Keys for Junction
34+
## Step 4: Initialize the Prover
35+
36+
Initialize the prover. Ensure you specify the correct version.
37+
1338
```shell
14-
go run cmd/main.go keys junction --accountName dummy --accountPath .tracks/junction-accounts/keys
39+
./build/tracks prover v1EVM
1540
```
16-
OR `Import with mnemonic`
41+
42+
## Step 5: Create Keys for Junction (If not already created)
43+
44+
Create keys for the junction account. If the keys are not already created, use the following command:
45+
46+
```shell
47+
accountName="dummy"
48+
accountPath=".tracks/junction-accounts/keys"
49+
50+
./build/tracks keys junction --accountName "$accountName" --accountPath "$accountPath"
51+
```
52+
53+
Alternatively, you can import an account using a mnemonic:
54+
1755
```shell
18-
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"
56+
accountName="dummy"
57+
accountPath=".tracks/junction-accounts/keys"
58+
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"
59+
60+
./build/tracks keys import --accountName "$accountName" --accountPath "$accountPath" --mnemonic "$mnemonic"
1961
```
2062

21-
### Init Prover
63+
## Step 6: Fund the wallet
64+
- Join [Airchains Discord ](https://discord.gg/airchains)
65+
- Goto `switchyard-faucet-bot` channel
66+
- Type `$faucet <your_address>`, you will get 2AMF soon.
67+
68+
## Step 7: Create a Station on Junction
69+
70+
Create a station on the junction with the necessary parameters.
71+
> NOTE: don't forget to replace `accountAddressArray` with the addresses you want to make track member. Replace it with your new address
72+
2273
```shell
23-
go run cmd/main.go prover v1EVM
24-
```
25-
### Create station on junction
26-
```sh
27-
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"
74+
accountAddressArray="air1knf2an5efl8d9t5w75uds4ty8uj0scxx9yg783" #! replace it with your address
75+
accountName="dummy"
76+
accountPath=".tracks/junction-accounts/keys"
77+
#jsonRPC="http://0.0.0.0:26657" # localhost testing
78+
jsonRPC="https://junction-testnet-rpc.synergynodes.com/" # junction testnet
79+
bootstrapNode="/ip4/192.168.1.24/tcp/2300/p2p/12D3KooWFoN66sCWotff1biUcnBE2vRTmYJRHJqZy27x1EpBB6AM"
80+
info="EVM Track"
81+
82+
./build/tracks create-station --tracks "$accountAddressArray" --accountName "$accountName" --accountPath "$accountPath" --jsonRPC "$jsonRPC" --info "$info" --bootstrapNode "$bootstrapNode"
2883
```
2984

30-
### start node
85+
## Step 8: Start the Tracks
86+
87+
Finally, start the node to begin interacting with the Tracks blockchain.
88+
3189
```shell
32-
go run cmd/main.go start
33-
```
90+
./build/tracks start
91+
```
92+
93+
## Troubleshooting
94+
95+
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.

cmd/command/init.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ func InitConfigs(cmd *cobra.Command) (*Configs, error) {
3939
return nil, fmt.Errorf("failed to get flag 'daType': %w", err)
4040
}
4141

42+
validTypes := map[string]bool{
43+
"avail": true,
44+
"celestia": true,
45+
"eigen": true,
46+
"mock": true,
47+
}
48+
if _, isValid := validTypes[configs.daType]; !isValid {
49+
logs.Log.Error("invalid daType. Must be one of: avail, celestia, eigen, mock")
50+
return nil, fmt.Errorf("invalid daType: %s", configs.daType)
51+
}
52+
4253
configs.daRPC, err = cmd.Flags().GetString("daRpc")
4354
if err != nil {
4455
return nil, fmt.Errorf("failed to get flag 'daRpc': %w", err)
@@ -68,13 +79,13 @@ var InitCmd = &cobra.Command{
6879
Run: func(cmd *cobra.Command, args []string) {
6980
configs, err := InitConfigs(cmd)
7081
if err != nil {
71-
logs.Log.Warn(err.Error())
82+
logs.Log.Error(err.Error())
7283
return
7384
}
7485

7586
homeDir, err := os.UserHomeDir()
7687
if err != nil {
77-
logs.Log.Warn("Failed to get user home directory:" + err.Error())
88+
logs.Log.Error("Failed to get user home directory:" + err.Error())
7889
return
7990
}
8091

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

97108
success := config.CreateConfigFile(conf.BaseConfig.RootDir, conf)
98109
if !success {
99-
logs.Log.Warn("Unable to generate a config file. Please check the error and try again.")
110+
logs.Log.Error("Unable to generate a config file. Please check the error and try again.")
100111
return
101112
}
102113

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package main
22

33
import (
4-
"fmt"
54
"github.com/airchains-network/decentralized-sequencer/cmd/command"
65
"github.com/airchains-network/decentralized-sequencer/cmd/command/keys"
76
"github.com/airchains-network/decentralized-sequencer/cmd/command/zkpCmd"
7+
"github.com/ethereum/go-ethereum/log"
88
"github.com/spf13/cobra"
99
"os"
1010
)
@@ -66,7 +66,7 @@ func main() {
6666
command.CreateStation.MarkFlagRequired("tracks")
6767

6868
if err := rootCmd.Execute(); err != nil {
69-
fmt.Println(err)
69+
log.Error(err.Error())
7070
os.Exit(1)
7171
}
7272

da/eigen/eigen.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"fmt"
4343
disperserGrpc "github.com/airchains-network/decentralized-sequencer/da/eigen/grpc"
4444
"github.com/airchains-network/decentralized-sequencer/da/eigen/utils"
45+
"github.com/rs/zerolog/log"
4546
"google.golang.org/grpc"
4647
"google.golang.org/grpc/credentials"
4748
"time"
@@ -55,21 +56,21 @@ func Eigen(daData []byte, rpcUrl string, accountKey string) (string, error) {
5556
dialOptions := grpc.WithTransportCredentials(credential)
5657
conn, err := grpc.Dial(addr, dialOptions)
5758
if err != nil {
58-
fmt.Println(err)
59+
log.Err(err).Msg("failed to dial")
5960
return "nil", err
6061
}
6162
defer func() { _ = conn.Close() }()
6263

6364
d, de := DisperserBlob(ctx, conn, daData, accountKey)
6465
if de != nil {
65-
fmt.Printf("failed to disperse blob: %v", de)
66+
log.Error().Err(de).Msg("failed to disperse blob")
6667
return "nil", err
6768
}
6869

6970
blobKey := string(d[:])
7071

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

7576
}

junction/checkBalance.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ func CheckBalance(jsonRPC string, accountAddress string) (bool, int64, error) {
1111

1212
ctx := context.Background()
1313
client, err := cosmosclient.New(ctx, cosmosclient.WithNodeAddress(jsonRPC))
14+
if err != nil {
15+
errorMsg := fmt.Errorf("Junction client connection failed, make sure jsonRPC is correct and active. JsonRPC: " + jsonRPC)
16+
return false, 0, errorMsg
17+
}
1418
pageRequest := &query.PageRequest{} // Add this line to create a new PageRequest
15-
fmt.Printf("accountAddress: %v\n", accountAddress)
19+
1620
balances, err := client.BankBalances(ctx, accountAddress, pageRequest) // Add pageRequest as the third argument
1721
if err != nil {
18-
fmt.Printf("Error querying bank balances: %v\n", err)
19-
return false, 0, err
22+
errorMsg := fmt.Errorf("error querying bank balances for RPC=%s Address=%s", jsonRPC, accountAddress)
23+
return false, 0, errorMsg
24+
}
25+
26+
if len(balances) == 0 {
27+
errorMsg := fmt.Errorf("account do not have balance. Address: %s", accountAddress)
28+
return false, 0, errorMsg
2029
}
2130

2231
for _, balance := range balances {

junction/createStation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func CreateStation(extraArg junctionTypes.StationArg, stationId string, stationI
6868

6969
success, amount, err := CheckBalance(jsonRPC, newTempAddr)
7070
if err != nil || !success {
71-
logs.Log.Error("Error checking balance")
71+
logs.Log.Error(err.Error())
7272
return false
7373
}
7474
if amount < 100 {
@@ -107,7 +107,7 @@ func CreateStation(extraArg junctionTypes.StationArg, stationId string, stationI
107107
}
108108

109109
ctx := context.Background()
110-
gas := utilis.GenerateRandomWithFavour(611, 1200, [2]int{612, 1000}, 0.7)
110+
gas := utilis.GenerateRandomWithFavour(1200, 2400, [2]int{1500, 2000}, 0.7)
111111
gasFees := fmt.Sprintf("%damf", gas)
112112
accountClient, err := cosmosclient.New(ctx, cosmosclient.WithAddressPrefix(addressPrefix), cosmosclient.WithNodeAddress(jsonRPC), cosmosclient.WithHome(accountPath), cosmosclient.WithGas("auto"), cosmosclient.WithFees(gasFees))
113113
if err != nil {

junction/initVRF.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,28 @@ func InitVRF() (success bool, addr string) {
120120
ExtraArg: extraArgsByte,
121121
}
122122

123-
txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
124-
if errTxRes != nil {
125-
errStr := errTxRes.Error()
126-
if strings.Contains(errStr, VRFInitiatedErrorContains) {
127-
log.Debug().Str("module", "junction").Msg("TxError: VRF already initiated for this pod number")
128-
return true, newTempAddr
123+
for {
124+
txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
125+
if errTxRes != nil {
126+
errStr := errTxRes.Error()
127+
if strings.Contains(errStr, VRFInitiatedErrorContains) {
128+
log.Debug().Str("module", "junction").Msg("VRF already initiated for this pod number")
129+
return true, newTempAddr
130+
} else {
131+
log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in InitVRF transaction")
132+
// retry transaction
133+
log.Debug().Str("module", "junction").Msg("Retrying InitVRF transaction after 10 seconds..")
134+
time.Sleep(10 * time.Second)
135+
//return false, ""
136+
}
129137
} else {
130-
log.Error().Str("module", "junction").Str("Error", errStr).Msg("TxError: Error in InitVRF transaction")
138+
// update transaction hash in current pod
139+
currentPodState.VRFInitiationTxHash = txRes.TxHash
140+
shared.SetPodState(currentPodState)
131141

132-
return false, ""
142+
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("InitiateVRf")
143+
return true, newTempAddr
133144
}
134-
} else {
135-
// update transaction hash in current pod
136-
currentPodState.VRFInitiationTxHash = txRes.TxHash
137-
shared.SetPodState(currentPodState)
138-
139-
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("InitiateVRf")
140-
return true, newTempAddr
141145
}
142146
}
143147

junction/submitPod.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,27 @@ func SubmitCurrentPod() (success bool) {
8989
podDetails := QueryPod(podNumber)
9090
if podDetails != nil {
9191
// pod already submitted
92-
log.Debug().Str("module", "junction").Msg("TxError: Pod already submitted")
92+
log.Debug().Str("module", "junction").Msg("Pod already submitted")
9393
return true
9494
} else {
9595
log.Info().Str("module", "junction").Msg("Pod not submitted, Submitting pod")
9696
}
9797

98-
txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
99-
if errTxRes != nil {
100-
errStr := errTxRes.Error()
101-
log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in SubmitPod Transaction")
102-
return false
103-
} else {
104-
//os.Exit(0)
105-
// update txHash of submit pod in pod state
106-
currentPodState.InitPodTxHash = txRes.TxHash
107-
shared.SetPodState(currentPodState)
108-
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("Pod Submitted")
109-
return true
110-
}
98+
for {
99+
txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg)
100+
if errTxRes != nil {
101+
errStr := errTxRes.Error()
102+
log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in SubmitPod Transaction")
111103

104+
log.Debug().Str("module", "junction").Msg("Retrying SubmitPod transaction after 10 seconds..")
105+
time.Sleep(10 * time.Second)
106+
//return false
107+
} else {
108+
// update txHash of submit pod in pod state
109+
currentPodState.InitPodTxHash = txRes.TxHash
110+
shared.SetPodState(currentPodState)
111+
log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("Pod Submitted")
112+
return true
113+
}
114+
}
112115
}

0 commit comments

Comments
 (0)