From a4e2af2b6535d2a2d8e829c7ef3a4a885ea7a8ea Mon Sep 17 00:00:00 2001 From: aakash4dev Date: Wed, 5 Jun 2024 16:59:42 +0530 Subject: [PATCH] Updated Transaction failure errors in DA and Junction codes, updated README.md to make tracks setup instructions more clear and accurate Made changes in initVRF, ValidateVRF, submitPod, and verifyPod for better error handling. Updated README.md file and added a new feature to create wallet.json file which contains Switchyard wallet's mnemonic key and air
--- .gitignore | 4 +- Makefile | 22 +------ README.md | 94 +++++++++++++++++++++++++----- cmd/command/init.go | 17 +++++- cmd/main.go | 4 +- da/eigen/eigen.go | 7 ++- junction/checkBalance.go | 15 ++++- junction/createStation.go | 4 +- junction/initVRF.go | 34 ++++++----- junction/submitPod.go | 31 +++++----- junction/validateVRF.go | 35 ++++++----- junction/verifyPod.go | 29 ++++----- p2p/podGenerator.go | 82 +++++++++++++++++--------- rpc/handler/podByNumber.handler.go | 1 + utils/common.go | 32 ++++++++++ 15 files changed, 277 insertions(+), 134 deletions(-) diff --git a/.gitignore b/.gitignore index cf782b9..8b1054f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ ./accounts/* ./.idea/* ./bin/* -./.tracks/* \ No newline at end of file +./.tracks/* +./.tracks +./build/* \ No newline at end of file diff --git a/Makefile b/Makefile index 7424cd9..f8d9373 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 2ef3a9e..4f5cb4d 100644 --- a/README.md +++ b/README.md @@ -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 `, 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 -``` \ No newline at end of file +./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. diff --git a/cmd/command/init.go b/cmd/command/init.go index c2ba4b6..8d28449 100644 --- a/cmd/command/init.go +++ b/cmd/command/init.go @@ -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) @@ -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 } @@ -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 } diff --git a/cmd/main.go b/cmd/main.go index 4ffac20..fc89597 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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" ) @@ -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) } diff --git a/da/eigen/eigen.go b/da/eigen/eigen.go index 2cd789c..ca70827 100644 --- a/da/eigen/eigen.go +++ b/da/eigen/eigen.go @@ -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" @@ -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 } diff --git a/junction/checkBalance.go b/junction/checkBalance.go index 78838c7..0132ed6 100644 --- a/junction/checkBalance.go +++ b/junction/checkBalance.go @@ -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 { diff --git a/junction/createStation.go b/junction/createStation.go index 994e94a..befd267 100644 --- a/junction/createStation.go +++ b/junction/createStation.go @@ -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 { @@ -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 { diff --git a/junction/initVRF.go b/junction/initVRF.go index ae4ba9d..f088e7e 100644 --- a/junction/initVRF.go +++ b/junction/initVRF.go @@ -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 } } diff --git a/junction/submitPod.go b/junction/submitPod.go index 2eb131d..1423e27 100644 --- a/junction/submitPod.go +++ b/junction/submitPod.go @@ -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 + } + } } diff --git a/junction/validateVRF.go b/junction/validateVRF.go index 82e07ab..b3abf47 100644 --- a/junction/validateVRF.go +++ b/junction/validateVRF.go @@ -77,23 +77,28 @@ func ValidateVRF(addr string) bool { SerializedRc: serializedRC, } - txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg) - if errTxRes != nil { - errStr := errTxRes.Error() - if strings.Contains(errStr, VRFValidatedErrorContains) { - log.Debug().Str("module", "junction").Msg("TxError: VRF already verified for this pod number") - return true + for { + txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &msg) + if errTxRes != nil { + errStr := errTxRes.Error() + if strings.Contains(errStr, VRFValidatedErrorContains) { + log.Debug().Str("module", "junction").Msg("VRF already verified for this pod number") + return true + } else { + log.Error().Str("module", "junction").Str("Error", errStr).Msg("Error in ValidateVRF transaction") + // retry transaction + log.Debug().Str("module", "junction").Msg("Retrying ValidateVRF transaction after 10 seconds..") + time.Sleep(10 * time.Second) + //return false + } } else { - log.Error().Str("module", "junction").Str("Error", errStr).Msg("TxError: Error in ValidateVRF transaction") - return false - } - } else { - // update VRN verified hash - currentPodState.VRFValidationTxHash = txRes.TxHash - shared.SetPodState(currentPodState) + // update VRN verified hash + currentPodState.VRFValidationTxHash = txRes.TxHash + shared.SetPodState(currentPodState) - log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("ValidateVRF") - return true + log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("ValidateVRF") + return true + } } } diff --git a/junction/verifyPod.go b/junction/verifyPod.go index b4ecb9f..d10cc7f 100644 --- a/junction/verifyPod.go +++ b/junction/verifyPod.go @@ -81,7 +81,6 @@ func VerifyCurrentPod() (success bool) { } // check if pod is already verified - fmt.Println(podNumber) podDetails := QueryPod(podNumber) if podDetails == nil { // pod already submitted @@ -93,19 +92,21 @@ func VerifyCurrentPod() (success bool) { return true } - txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &verifyPodStruct) - if errTxRes != nil { - errTxResStr := errTxRes.Error() - log.Error().Str("module", "junction").Str("Error", errTxResStr).Msg("TxError: Error in VerifyPod transaction") - return false - } else { - - VerifyPodTxHash := txRes.TxHash - currentPodState.VerifyPodTxHash = VerifyPodTxHash - shared.SetPodState(currentPodState) - log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("Verify Pod") - return true - + for { + txRes, errTxRes := accountClient.BroadcastTx(ctx, newTempAccount, &verifyPodStruct) + if errTxRes != nil { + errTxResStr := errTxRes.Error() + log.Error().Str("module", "junction").Str("Error", errTxResStr).Msg("Error in VerifyPod transaction") + log.Debug().Str("module", "junction").Msg("Retrying VerifyPod transaction after 10 seconds..") + time.Sleep(10 * time.Second) + //return false + } else { + VerifyPodTxHash := txRes.TxHash + currentPodState.VerifyPodTxHash = VerifyPodTxHash + shared.SetPodState(currentPodState) + log.Info().Str("module", "junction").Str("txHash", txRes.TxHash).Msg("Verify Pod") + return true + } } } diff --git a/p2p/podGenerator.go b/p2p/podGenerator.go index 7708a95..d05cc50 100644 --- a/p2p/podGenerator.go +++ b/p2p/podGenerator.go @@ -232,13 +232,13 @@ func GenerateUnverifiedPods() { if shared.GetPodState().LatestTxState == shared.TxStateSubmitPod { // DA submit - mdb := connection.GetDataAvailabilityDatabaseConnection() - dbName, err := mock.MockDA(mdb, daDataByte, PodNumber) - if err != nil { - logs.Log.Error("Error in submitting data to DA") - return - } - _ = dbName + //mdb := connection.GetDataAvailabilityDatabaseConnection() + //dbName, err := mock.MockDA(mdb, daDataByte, PodNumber) + //if err != nil { + // logs.Log.Error("Error in submitting data to DA") + // return + //} + //_ = dbName DaBatchSaver := connection.DataAvailabilityDatabaseConnection baseConfig, err := shared.LoadConfig() @@ -246,12 +246,23 @@ func GenerateUnverifiedPods() { fmt.Println("Error loading configuration") } Datype := baseConfig.DA.DaType + var ( + daCheck string + daCheckErr error + ) + if Datype == "mock" { mdb := connection.MockDatabaseConnection - daCheck, daCheckErr := mock.MockDA(mdb, daDataByte, PodNumber) - if daCheckErr != nil { - logs.Log.Error("Error in submitting data to DA") - return + + for { + daCheck, daCheckErr = mock.MockDA(mdb, daDataByte, PodNumber) + if daCheckErr != nil { + logs.Log.Error("Error in submitting data to DA") + logs.Log.Debug("Retrying Mock DA after 10 seconds") + time.Sleep(10 * time.Second) + } else { + break + } } da := types.DAStruct{ @@ -276,10 +287,16 @@ func GenerateUnverifiedPods() { log.Info().Str("module", "p2p").Msg("Data Saved in DA") } else if Datype == "avail" { - daCheck, daCheckErr := avail.Avail(daDataByte, baseConfig.DA.DaRPC) - if daCheckErr != nil { - logs.Log.Warn("Error in submitting data to DA") - return + + for { + daCheck, daCheckErr = avail.Avail(daDataByte, baseConfig.DA.DaRPC) + if daCheckErr != nil { + logs.Log.Warn("Error in submitting data to DA " + daCheckErr.Error()) + logs.Log.Debug("Retrying Avail DA after 10 seconds") + time.Sleep(10 * time.Second) + } else { + break + } } da := types.DAStruct{ @@ -294,21 +311,27 @@ func GenerateUnverifiedPods() { daStoreData, daStoreDataErr := json.Marshal(da) if daStoreDataErr != nil { logs.Log.Warn(fmt.Sprintf("Error in marshaling DA pointer : %s", daStoreDataErr.Error())) + return } storeErr := DaBatchSaver.Put([]byte(daStoreKey), daStoreData, nil) if storeErr != nil { logs.Log.Warn(fmt.Sprintf("Error in saving DA pointer in pod database : %s", storeErr.Error())) + return } log.Info().Str("module", "p2p").Msg("Data Saved in DA") } else if Datype == "celestia" { - daCheck, daCheckErr := celestia.Celestia(daDataByte, baseConfig.DA.DaRPC, baseConfig.DA.DaRPC) - - if daCheckErr != nil { - logs.Log.Warn("Error in submitting data to DA") - return + for { + daCheck, daCheckErr = celestia.Celestia(daDataByte, baseConfig.DA.DaRPC, baseConfig.DA.DaRPC) + if daCheckErr != nil { + logs.Log.Warn("Error in submitting data to DA " + daCheckErr.Error()) + logs.Log.Debug("Retrying Celestia DA after 10 seconds") + time.Sleep(10 * time.Second) + } else { + break + } } da := types.DAStruct{ @@ -323,23 +346,28 @@ func GenerateUnverifiedPods() { daStoreData, daStoreDataErr := json.Marshal(da) if daStoreDataErr != nil { logs.Log.Warn(fmt.Sprintf("Error in marshaling DA pointer : %s", daStoreDataErr.Error())) + return } storeErr := DaBatchSaver.Put([]byte(daStoreKey), daStoreData, nil) if storeErr != nil { logs.Log.Warn(fmt.Sprintf("Error in saving DA pointer in pod database : %s", storeErr.Error())) + return } log.Info().Str("module", "p2p").Msg("Data Saved in DA") } else if Datype == "eigen" { - daCheck, daCheckErr := eigen.Eigen(daDataByte, - baseConfig.DA.DaRPC, baseConfig.DA.DaRPC, - ) - if daCheckErr != nil { - logs.Log.Warn("Error in submitting data to DA") - return + for { + daCheck, daCheckErr = eigen.Eigen(daDataByte, baseConfig.DA.DaRPC, baseConfig.DA.DaRPC) + if daCheckErr != nil { + logs.Log.Warn("Error in submitting data to DA " + daCheckErr.Error()) + logs.Log.Debug("Retrying Eigen DA after 10 seconds") + time.Sleep(10 * time.Second) + } else { + break + } } da := types.DAStruct{ @@ -354,11 +382,13 @@ func GenerateUnverifiedPods() { daStoreData, daStoreDataErr := json.Marshal(da) if daStoreDataErr != nil { logs.Log.Warn(fmt.Sprintf("Error in marshaling DA pointer : %s", daStoreDataErr.Error())) + return } storeErr := DaBatchSaver.Put([]byte(daStoreKey), daStoreData, nil) if storeErr != nil { logs.Log.Warn(fmt.Sprintf("Error in saving DA pointer in pod database : %s", storeErr.Error())) + return } log.Info().Str("module", "p2p").Msg("Data Saved in DA") diff --git a/rpc/handler/podByNumber.handler.go b/rpc/handler/podByNumber.handler.go index 72468f1..9ea60f6 100644 --- a/rpc/handler/podByNumber.handler.go +++ b/rpc/handler/podByNumber.handler.go @@ -19,6 +19,7 @@ func HandleGetPodByNumber(c *gin.Context, Params []interface{}) { daDB := shared.Node.NodeConnections.GetDataAvailabilityDatabaseConnection() podKey := fmt.Sprintf("pod-%.0f", Params[0]) daKey := fmt.Sprintf("da-%.0f", Params[0]) + fmt.Println(daKey) podDataByte, err := batchDB.Get([]byte(podKey), nil) if err != nil { diff --git a/utils/common.go b/utils/common.go index cd39c5b..bca0f91 100644 --- a/utils/common.go +++ b/utils/common.go @@ -17,6 +17,7 @@ import ( "math/big" "math/rand" "net/http" + "os" "strconv" "strings" ) @@ -121,6 +122,37 @@ func CreateAccount(accountName string, accountPath string) { return } + // create "account.Name".wallet.json file + type AccountDetails struct { + Name string `json:"name"` + Mnemonic string `json:"mnemonic"` + NewAddress string `json:"address"` + } + acc := AccountDetails{ + Name: accountName, + Mnemonic: mnemonic, + NewAddress: newCreatedAccountAddr, + } + accountBytes, err := json.Marshal(acc) + if err != nil { + logs.Log.Error(fmt.Sprintf("Failed to marshal account details: %s\n", err)) + return + } + fileName := fmt.Sprintf("%s/%s.wallet.json", accountPath, accountName) + // Create and write the file. + file, err := os.Create(fileName) + if err != nil { + logs.Log.Error(fmt.Sprintf("Failed creating file: %s\n", err)) + return + } + defer file.Close() + _, err = file.Write(accountBytes) + if err != nil { + logs.Log.Error(fmt.Sprintf("Failed writing to file: %s\n", err)) + return + } + logs.Log.Info("File written successfully:" + fileName) + logs.Log.Info(fmt.Sprintf("Account created: %s", account.Name)) logs.Log.Info(fmt.Sprintf("Mnemonic: %s", mnemonic)) logs.Log.Info(fmt.Sprintf("Address: %s", newCreatedAccountAddr))