Skip to content

Commit 9a6676c

Browse files
authored
Merge pull request #169 from algorandfoundation/v1.4.1
V1.4.1
2 parents 7ba86e0 + 5a343e2 commit 9a6676c

File tree

7 files changed

+45
-28
lines changed

7 files changed

+45
-28
lines changed

cmd/bootstrap.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package cmd
33
import (
44
"context"
55
"fmt"
6-
"time"
7-
86
"github.com/algorandfoundation/nodekit/api"
97
"github.com/algorandfoundation/nodekit/cmd/utils/explanations"
108
"github.com/algorandfoundation/nodekit/internal/algod"
@@ -17,6 +15,7 @@ import (
1715
"github.com/charmbracelet/lipgloss"
1816
"github.com/charmbracelet/log"
1917
"github.com/spf13/cobra"
18+
"time"
2019
)
2120

2221
const CheckAlgodInterval = 10 * time.Second
@@ -69,7 +68,6 @@ var bootstrapCmd = &cobra.Command{
6968
}
7069

7170
// Wait for the client to respond
72-
log.Warn(style.Yellow.Render("Waiting for the node to start..."))
7371
client, err = algod.WaitForClient(context.Background(), dir, CheckAlgodInterval, CheckAlgodTimeout)
7472
if err != nil {
7573
log.Fatal(err)
@@ -168,22 +166,6 @@ var bootstrapCmd = &cobra.Command{
168166
if err != nil {
169167
return err
170168
}
171-
172-
// Parse the data directory
173-
dir, err := algod.GetDataDir("")
174-
if err != nil {
175-
log.Fatal(err)
176-
}
177-
178-
// Wait for the client to respond
179-
client, err = algod.WaitForClient(context.Background(), dir, CheckAlgodInterval, CheckAlgodTimeout)
180-
if err != nil {
181-
log.Fatal(err)
182-
}
183-
184-
if !algod.IsRunning() {
185-
log.Fatal("algod is not running. Something went wrong with installation")
186-
}
187169
} else {
188170
// This should not happen but just in case, ensure it is running
189171
if !algod.IsRunning() {
@@ -192,19 +174,27 @@ var bootstrapCmd = &cobra.Command{
192174
if err != nil {
193175
log.Fatal(err)
194176
}
195-
log.Info(style.Green.Render("Algorand started successfully 🎉"))
196-
time.Sleep(2 * time.Second)
197177
}
198178
}
199179

200-
// Find the data directory automatically
180+
// Parse the data directory
201181
dataDir, err := algod.GetDataDir("")
182+
if err != nil {
183+
log.Fatal(err)
184+
}
185+
202186
// Wait for the client to respond
203187
client, err = algod.WaitForClient(context.Background(), dataDir, CheckAlgodInterval, CheckAlgodTimeout)
204188
if err != nil {
205189
log.Fatal(err)
206190
}
207191

192+
if !algod.IsRunning() {
193+
log.Fatal("algod is not running. Something went wrong with installation")
194+
}
195+
196+
log.Info(style.Green.Render("Algorand node started successfully 🎉"))
197+
208198
// User answer for catchup question
209199
if msg.Catchup {
210200
ctx := context.Background()

cmd/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var debugCmd = cmdutils.WithAlgodFlags(&cobra.Command{
9090
folderDebug, err := utils.ToDataFolderConfig(dataDir)
9191
if err != nil {
9292
folderDebug.Token = fmt.Sprint(err)
93-
} else {
93+
} else if len(folderDebug.Token) > 3 {
9494
folderDebug.Token = folderDebug.Token[:3] + "..."
9595
}
9696

cmd/telemetry/enable/nodely.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ var nodelyCmd = cmdutils.WithAlgodFlags(&cobra.Command{
8585
if err != nil {
8686
log.Fatal(err)
8787
}
88+
89+
log.Info("Telemetry enabled. To see your Nodely dashboard URL, run:\n ./nodekit telemetry status")
8890
}
8991
},
9092
}, &dataDir)

internal/algod/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package algod
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"github.com/algorandfoundation/nodekit/api"
78
"github.com/algorandfoundation/nodekit/internal/algod/utils"
9+
"github.com/charmbracelet/log"
810
"github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider"
911
"os"
1012
"path/filepath"
@@ -13,7 +15,7 @@ import (
1315
)
1416

1517
const InvalidDataDirMsg = "invalid data directory"
16-
const ClientTimeoutMsg = "the client has timed out"
18+
const ClientTimeoutMsg = "timed out while waiting for the node"
1719

1820
func GetDataDir(dataDir string) (string, error) {
1921
envDataDir := os.Getenv("ALGORAND_DATA")
@@ -64,6 +66,7 @@ func GetClient(dataDir string) (*api.ClientWithResponses, error) {
6466
func WaitForClient(ctx context.Context, dataDir string, interval time.Duration, timeout time.Duration) (*api.ClientWithResponses, error) {
6567
var client *api.ClientWithResponses
6668
var err error
69+
log.Info(fmt.Sprintf("Waiting for the node (up to %s)", timeout))
6770
dataDir, err = GetDataDir(dataDir)
6871
if err != nil {
6972
return client, err
@@ -78,6 +81,7 @@ func WaitForClient(ctx context.Context, dataDir string, interval time.Duration,
7881
}
7982
}
8083
// Wait for client to respond
84+
timeoutTimer := time.After(timeout)
8185
for {
8286
select {
8387
case <-ctx.Done():
@@ -91,9 +95,8 @@ func WaitForClient(ctx context.Context, dataDir string, interval time.Duration,
9195
return client, nil
9296
}
9397
}
94-
case <-time.After(timeout):
98+
case <-timeoutTimer:
9599
return client, errors.New(ClientTimeoutMsg)
96100
}
97-
98101
}
99102
}

internal/algod/linux/linux.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"github.com/charmbracelet/log"
99
"os"
1010
"os/exec"
11+
"os/user"
1112
"runtime"
13+
"strconv"
1214
"strings"
1315
"text/template"
1416
)
@@ -24,6 +26,20 @@ type Algod struct {
2426
DataDirectoryPath string
2527
}
2628

29+
func hasConflictingUser() bool {
30+
if runtime.GOOS != "linux" {
31+
return false
32+
}
33+
algorandUser, _ := user.Lookup("algorand")
34+
if algorandUser != nil {
35+
uid, _ := strconv.Atoi(algorandUser.Uid)
36+
if uid >= 1000 {
37+
return true
38+
}
39+
}
40+
return false
41+
}
42+
2743
// InstallRequirements generates installation commands for "sudo" based on the detected package manager and system state.
2844
func InstallRequirements() system.CmdsList {
2945
var cmds system.CmdsList
@@ -47,7 +63,12 @@ func InstallRequirements() system.CmdsList {
4763

4864
// Install installs Algorand development tools or node software depending on the package manager.
4965
func Install() error {
66+
if hasConflictingUser() {
67+
return fmt.Errorf("Your system has a user called \"algorand\". The algorand node requires the \"algorand\" username for internal usage. Rename or remove the algorand user to continue.")
68+
}
69+
5070
log.Info("Installing Algod on Linux")
71+
5172
// Based off of https://developer.algorand.org/docs/run-a-node/setup/install/#installation-with-a-package-manager
5273
if system.CmdExists("apt-get") { // On some Debian systems we use apt-get
5374
log.Info("Installing with apt-get")

internal/algod/mac/mac.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func IsService() bool {
3636
// configures necessary directories, and ensures it
3737
// runs as a background service.
3838
func Install() error {
39-
log.Info("Installing Algod on macOS...")
39+
log.Info("Installing Algod on macOS")
4040

4141
// Homebrew is our package manager of choice
4242
if !system.CmdExists("brew") {

internal/algod/participation/participation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func GenerateKeys(
7777
}
7878

7979
// 😠 - Zero 2024
80+
timeoutTimer := time.After(20 * time.Minute)
8081
for {
8182
select {
8283
case <-ctx.Done():
@@ -96,7 +97,7 @@ func GenerateKeys(
9697
return &k, nil
9798
}
9899
}
99-
case <-time.After(20 * time.Minute):
100+
case <-timeoutTimer:
100101
return nil, errors.New("timeout waiting for key to be created")
101102
}
102103
}

0 commit comments

Comments
 (0)