-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: chain-initiator include submit software upgrade proposal logic
- Loading branch information
Showing
13 changed files
with
346 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
func getArgs(args []string) (snapshotUrl, newVersion string) { | ||
snapshotUrl = args[0] // https://snapshots.polkachu.com/snapshots/sifchain/sifchain_15048938.tar.lz4 | ||
if snapshotUrl == "" { | ||
log.Fatalf("snapshot url is required") | ||
} | ||
|
||
newVersion = args[1] // v0.1.0 | ||
if newVersion == "" { | ||
log.Fatalf("new version is required") | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
flagHome = "home" | ||
flagCmd = "cmd" | ||
) | ||
|
||
func getFlags(cmd *cobra.Command) (homePath, cmdPath string) { | ||
homePath, _ = cmd.Flags().GetString(flagHome) | ||
if homePath == "" { | ||
log.Fatalf("home path is required") | ||
} | ||
|
||
cmdPath, _ = cmd.Flags().GetString(flagCmd) | ||
if cmdPath == "" { | ||
log.Fatalf("cmd path is required") | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func isNodeRunning(node string) bool { | ||
// Remove the "tcp://" prefix if present | ||
if strings.HasPrefix(node, "tcp://") { | ||
node = strings.TrimPrefix(node, "tcp://") | ||
} | ||
|
||
// Attempt to make a TCP connection | ||
conn, err := net.Dial("tcp", node) | ||
if err == nil { | ||
conn.Close() | ||
return true | ||
} | ||
|
||
// If TCP connection fails, attempt an HTTP GET request | ||
resp, err := http.Get("http://" + node) | ||
if err == nil { | ||
resp.Body.Close() | ||
return resp.StatusCode == http.StatusOK | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/exec" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func listenForSignals(cmd *exec.Cmd) { | ||
// Set up channel to listen for signals | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) | ||
|
||
// Block until a signal is received | ||
<-sigChan | ||
|
||
// Stop the process when a signal is received | ||
if cmd != nil && cmd.Process != nil { | ||
err := cmd.Process.Kill() | ||
if err != nil { | ||
log.Fatalf("Failed to kill process: %v", err) | ||
} | ||
log.Println("Process killed successfully") | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
scripts/chain-initiator/query-and-calc-upgrade-block-height.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
) | ||
|
||
func queryAndCalcUpgradeBlockHeight(cmdPath, node string) string { | ||
// query block height | ||
blockHeight := queryBlockHeight(cmdPath, node) | ||
|
||
// Convert blockHeight from string to int | ||
blockHeightInt, err := strconv.Atoi(blockHeight) | ||
if err != nil { | ||
log.Fatalf("Failed to convert blockHeight to integer: %v", err) | ||
} | ||
|
||
// set upgrade block height | ||
upgradeBlockHeight := blockHeightInt + 100 | ||
|
||
// return upgrade block height as a string | ||
return strconv.Itoa(upgradeBlockHeight) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os/exec" | ||
) | ||
|
||
func queryBlockHeight(cmdPath, node string) string { | ||
// Command and arguments | ||
args := []string{"status", "--node", node} | ||
|
||
// Execute the command | ||
output, err := exec.Command(cmdPath, args...).CombinedOutput() | ||
if err != nil { | ||
log.Fatalf("Command execution failed: %v", err) | ||
} | ||
|
||
// Unmarshal the JSON output | ||
var statusOutput StatusOutput | ||
if err := json.Unmarshal(output, &statusOutput); err != nil { | ||
log.Fatalf("Failed to unmarshal JSON output: %v", err) | ||
} | ||
|
||
return statusOutput.SyncInfo.LatestBlockHeight | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.