Skip to content

Commit 42b0c22

Browse files
authored
Merge pull request #183 from algorandfoundation/release/v1.5.0
Release/v1.5.0
2 parents aa66ae3 + 78680e7 commit 42b0c22

File tree

38 files changed

+956
-178
lines changed

38 files changed

+956
-178
lines changed

api/catchpoint.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
MainNet CatchPointUrl = "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint"
1717
)
1818

19-
const InvalidNetworkParamMsg = "invalid network"
19+
var ErrInvalidNetwork = errors.New("invalid network")
2020

2121
type LatestCatchpointResponse struct {
2222
HTTPResponse *http.Response
@@ -45,9 +45,8 @@ func GetLatestCatchpointWithResponse(http HttpPkgInterface, network string) (Lat
4545
url = TestNet
4646
case "mainnet-v1.0", "mainnet":
4747
url = MainNet
48-
}
49-
if url == "" {
50-
return response, errors.New(InvalidNetworkParamMsg)
48+
default:
49+
return response, ErrInvalidNetwork
5150
}
5251
res, err := http.Get(string(url))
5352
response.HTTPResponse = res

cmd/bootstrap.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cmd
33
import (
44
"context"
55
"fmt"
6+
"time"
7+
68
"github.com/algorandfoundation/nodekit/api"
79
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
810
"github.com/algorandfoundation/nodekit/internal/algod"
@@ -15,7 +17,6 @@ import (
1517
"github.com/charmbracelet/lipgloss"
1618
"github.com/charmbracelet/log"
1719
"github.com/spf13/cobra"
18-
"time"
1920
)
2021

2122
const CheckAlgodInterval = 10 * time.Second
@@ -60,9 +61,9 @@ var bootstrapCmd = &cobra.Command{
6061
model := bootstrap.NewModel()
6162
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))
6263
// Try to launch the TUI if it's already running and configured
63-
if algod.IsInitialized() {
64+
if algod.IsInitialized(algodData) {
6465
// Parse the data directory
65-
dir, err := algod.GetDataDir("")
66+
dir, err := algod.GetDataDir(algodData)
6667
if err != nil {
6768
log.Fatal(err)
6869
}
@@ -97,7 +98,7 @@ var bootstrapCmd = &cobra.Command{
9798

9899
// Exit the application in an invalid state
99100
if algod.IsInstalled() && !algod.IsService() {
100-
dataDir, _ := algod.GetDataDir("")
101+
dataDir, _ := algod.GetDataDir(algodData)
101102
if dataDir == "" {
102103
dataDir = "<Path to data directory>"
103104
}
@@ -119,7 +120,7 @@ var bootstrapCmd = &cobra.Command{
119120

120121
// Ensure it the service is started,
121122
// in this case we won't be able to query state without the node running
122-
if algod.IsInstalled() && algod.IsService() && !algod.IsRunning() {
123+
if algod.IsInstalled() && algod.IsService() && !algod.IsRunning(algodData) {
123124
log.Debug("Algorand is installed, but not running. Attempting to start it automatically.")
124125
log.Warn(style.Yellow.Render(explanations.SudoWarningMsg))
125126
err := algod.Start()
@@ -168,7 +169,7 @@ var bootstrapCmd = &cobra.Command{
168169
}
169170
} else {
170171
// This should not happen but just in case, ensure it is running
171-
if !algod.IsRunning() {
172+
if !algod.IsRunning(algodData) {
172173
log.Info(style.Green.Render("Starting Algod 🚀"))
173174
err := algod.Start()
174175
if err != nil {
@@ -178,7 +179,7 @@ var bootstrapCmd = &cobra.Command{
178179
}
179180

180181
// Parse the data directory
181-
dataDir, err := algod.GetDataDir("")
182+
dataDir, err := algod.GetDataDir(algodData)
182183
if err != nil {
183184
log.Fatal(err)
184185
}
@@ -189,7 +190,7 @@ var bootstrapCmd = &cobra.Command{
189190
log.Fatal(err)
190191
}
191192

192-
if !algod.IsRunning() {
193+
if !algod.IsRunning(algodData) {
193194
log.Fatal("algod is not running. Something went wrong with installation")
194195
}
195196

@@ -205,7 +206,7 @@ var bootstrapCmd = &cobra.Command{
205206
}
206207
// Get the latest catchpoint
207208
catchpoint, _, err := algod.GetLatestCatchpoint(httpPkg, network)
208-
if err != nil && err.Error() == api.InvalidNetworkParamMsg {
209+
if err != nil && err == api.ErrInvalidNetwork {
209210
log.Fatal("This network does not support fast-catchup.")
210211
} else {
211212
log.Info(style.Green.Render("Latest Catchpoint: " + catchpoint))

cmd/catchup/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var debugCmd = utils.WithAlgodFlags(&cobra.Command{
6666

6767
var isSupported bool
6868
catchpoint, _, err := algod.GetLatestCatchpoint(httpPkg, status.Network)
69-
if err != nil && err.Error() == api.InvalidNetworkParamMsg {
69+
if err != nil && err == api.ErrInvalidNetwork {
7070
isSupported = false
7171
} else {
7272
isSupported = true

cmd/catchup/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var startCmd = utils.WithAlgodFlags(&cobra.Command{
4646

4747
// Get the latest catchpoint
4848
catchpoint, _, err := algod.GetLatestCatchpoint(httpPkg, status.Network)
49-
if err != nil && err.Error() == api.InvalidNetworkParamMsg {
49+
if err != nil && err == api.ErrInvalidNetwork {
5050
log.Fatal("This network does not support fast-catchup.")
5151
} else {
5252
log.Info(style.Green.Render("Latest Catchpoint: " + catchpoint))

cmd/configure/algod.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package configure
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
cmdutils "github.com/algorandfoundation/nodekit/cmd/utils"
8+
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
9+
"github.com/algorandfoundation/nodekit/internal/algod"
10+
"github.com/algorandfoundation/nodekit/internal/algod/config"
11+
"github.com/algorandfoundation/nodekit/internal/algod/utils"
12+
"github.com/algorandfoundation/nodekit/ui/style"
13+
"github.com/charmbracelet/lipgloss"
14+
"github.com/charmbracelet/lipgloss/table"
15+
"github.com/charmbracelet/log"
16+
"github.com/spf13/cobra"
17+
)
18+
19+
var enableHybrid bool
20+
21+
// algodShort provides a brief description of the algod command, emphasizing its role in installing algod files.
22+
var algodShort = "Configure options for the Algorand daemon."
23+
24+
// algodLong provides a detailed description of the algod command, its purpose, and an experimental warning note.
25+
var algodLong = lipgloss.JoinVertical(
26+
lipgloss.Left,
27+
style.Purple(style.BANNER),
28+
"",
29+
style.Bold(algodShort),
30+
"",
31+
style.BoldUnderline("Overview:"),
32+
"Modify various configuration options available for the Algorand daemon.",
33+
)
34+
35+
// TODO: Check if we should enforce sudo for this.
36+
// algodCmd is a Cobra command for managing Algorand configuration
37+
var algodCmd = cmdutils.WithAlgodFlags(&cobra.Command{
38+
Use: "algod",
39+
Short: algodShort,
40+
Long: algodLong,
41+
RunE: func(cmd *cobra.Command, args []string) error {
42+
dataDir, err := algod.GetDataDir(algodData)
43+
if err != nil {
44+
log.Fatal(err)
45+
}
46+
47+
// Current Node Configuration
48+
currentConfig, _ := utils.GetConfigFromDataDir(dataDir)
49+
50+
// OR (`||`) additional flags for `hasFlags` when adding something new.
51+
hasHybrid := cmd.Flags().Lookup("hybrid").Changed
52+
hasFlags := hasHybrid
53+
54+
restartRequired := false
55+
56+
// Are we doing something? If not, just display the current configuration.
57+
if hasFlags {
58+
newConfig := &config.Config{
59+
// EnableP2PHybridMode: currentConfig.EnableP2PHybridMode,
60+
}
61+
62+
if hasHybrid {
63+
newConfig.EnableP2PHybridMode = &enableHybrid
64+
}
65+
66+
mergedConfig := config.MergeAlgodConfigs(*currentConfig, *newConfig)
67+
if currentConfig.IsEqual(mergedConfig) {
68+
log.Debug("Configuration up to date, nothing to do")
69+
} else {
70+
err := utils.WriteConfigToDataDir(dataDir, &mergedConfig)
71+
if err != nil {
72+
log.Warnf("%s", err)
73+
log.Fatalf("%s", explanations.AlgorandPermissionErrorMsg)
74+
}
75+
restartRequired = true
76+
}
77+
78+
} else {
79+
80+
hybridModeStatus := "Disabled"
81+
if currentConfig.EnableP2PHybridMode != nil && *currentConfig.EnableP2PHybridMode {
82+
hybridModeStatus = "Enabled"
83+
}
84+
85+
rows := [][]string{
86+
{"EnableP2PHybridMode:", hybridModeStatus},
87+
}
88+
89+
var (
90+
cellStyle = lipgloss.NewStyle().Padding(0)
91+
optionRowStyle = cellStyle.Align(lipgloss.Right)
92+
valueRowStyle = cellStyle.Align(lipgloss.Left)
93+
)
94+
95+
configurationTable := table.New().
96+
Border(lipgloss.HiddenBorder()).
97+
StyleFunc(func(row, col int) lipgloss.Style {
98+
if col == 0 {
99+
return optionRowStyle
100+
}
101+
return valueRowStyle
102+
}).
103+
Rows(rows...)
104+
105+
currentConfiguration := lipgloss.JoinVertical(
106+
lipgloss.Left,
107+
style.BoldUnderline("Current Configuration:"),
108+
configurationTable.String(),
109+
)
110+
111+
fmt.Println(currentConfiguration)
112+
}
113+
114+
if restartRequired {
115+
log.Debug("Restarting node...")
116+
err = algod.Stop()
117+
if err != nil {
118+
log.Fatal(err)
119+
}
120+
121+
// Wait 1 second.
122+
// Calling stop & start too quickly on Mac (launchctl) appears to
123+
// result in a false successfully start. Haven't investigated why.
124+
time.Sleep(1 * time.Second)
125+
126+
err = algod.Start()
127+
if err != nil {
128+
log.Fatal(err)
129+
}
130+
log.Debug("Node restarted successfully.")
131+
}
132+
return nil
133+
},
134+
}, &algodData)
135+
136+
func init() {
137+
algodCmd.Flags().BoolVar(&enableHybrid, "hybrid", true, "Enable or Disable P2P Hybrid Mode")
138+
}

cmd/configure/configure.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package configure
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
7-
"github.com/algorandfoundation/nodekit/internal/algod"
8-
"github.com/algorandfoundation/nodekit/internal/algod/utils"
9-
"github.com/algorandfoundation/nodekit/ui/style"
10-
"github.com/charmbracelet/lipgloss"
116
"os"
127
"os/exec"
138
"runtime"
149
"strings"
1510
"text/template"
1611

12+
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
13+
"github.com/algorandfoundation/nodekit/internal/algod"
14+
"github.com/algorandfoundation/nodekit/internal/algod/utils"
15+
"github.com/algorandfoundation/nodekit/ui/style"
16+
"github.com/charmbracelet/lipgloss"
1717
"github.com/spf13/cobra"
1818
)
1919

@@ -33,6 +33,8 @@ var long = lipgloss.JoinVertical(
3333
style.Yellow.Render(explanations.ExperimentalWarning),
3434
)
3535

36+
var algodData = ""
37+
3638
var Cmd = &cobra.Command{
3739
Use: "configure",
3840
Short: short,
@@ -42,6 +44,7 @@ var Cmd = &cobra.Command{
4244
func init() {
4345
Cmd.AddCommand(serviceCmd)
4446
Cmd.AddCommand(telemetryCmd)
47+
Cmd.AddCommand(algodCmd)
4548
}
4649

4750
const RunningErrorMsg = "algorand is currently running. Please stop the node with *node stop* before configuring"
@@ -50,7 +53,7 @@ const RunningErrorMsg = "algorand is currently running. Please stop the node wit
5053
func configureNode() error {
5154
var systemServiceConfigure bool
5255

53-
if algod.IsRunning() {
56+
if algod.IsRunning(algodData) {
5457
return fmt.Errorf(RunningErrorMsg)
5558
}
5659

@@ -140,9 +143,7 @@ func configureNode() error {
140143
}
141144
os.Exit(0)
142145
}
143-
144146
} else {
145-
146147
if promptWrapperYes("Do you want to set one of these directories as the new data directory? (y/N)") {
147148

148149
selectedPath := promptWrapperSelection("Select an Algorand data directory", paths)
@@ -200,7 +201,6 @@ func editAlgorandServiceFile(dataDirectoryPath string) {
200201
}
201202

202203
func editLaunchdAlgorandServiceFile(dataDirectoryPath string) {
203-
204204
algodPath, err := exec.LookPath("algod")
205205
if err != nil {
206206
fmt.Printf("Failed to find algod binary: %v\n", err)
@@ -253,7 +253,7 @@ func editLaunchdAlgorandServiceFile(dataDirectoryPath string) {
253253
}
254254

255255
// Write the override content to the file
256-
err = os.WriteFile(overwriteFilePath, overwriteContent.Bytes(), 0644)
256+
err = os.WriteFile(overwriteFilePath, overwriteContent.Bytes(), 0o644)
257257
if err != nil {
258258
fmt.Printf("Failed to write override file: %v\n", err)
259259
os.Exit(1)
@@ -282,7 +282,6 @@ func editLaunchdAlgorandServiceFile(dataDirectoryPath string) {
282282

283283
// Update the algorand.service file
284284
func editSystemdAlgorandServiceFile(dataDirectoryPath string) {
285-
286285
algodPath, err := exec.LookPath("algod")
287286
if err != nil {
288287
fmt.Printf("Failed to find algod binary: %v\n", err)
@@ -294,7 +293,7 @@ func editSystemdAlgorandServiceFile(dataDirectoryPath string) {
294293
overrideFilePath := "/etc/systemd/system/algorand.service.d/override.conf"
295294

296295
// Create the override directory if it doesn't exist
297-
err = os.MkdirAll("/etc/systemd/system/algorand.service.d", 0755)
296+
err = os.MkdirAll("/etc/systemd/system/algorand.service.d", 0o755)
298297
if err != nil {
299298
fmt.Printf("Failed to create override directory: %v\n", err)
300299
os.Exit(1)
@@ -328,7 +327,7 @@ ExecStart={{.AlgodPath}} -d {{.DataDirectoryPath}}`
328327
}
329328

330329
// Write the override content to the file
331-
err = os.WriteFile(overrideFilePath, overrideContent.Bytes(), 0644)
330+
err = os.WriteFile(overrideFilePath, overrideContent.Bytes(), 0o644)
332331
if err != nil {
333332
fmt.Printf("Failed to write override file: %v\n", err)
334333
os.Exit(1)

0 commit comments

Comments
 (0)