feat: improve dev-local bootstrap behavior and add client defaults logging

This commit is contained in:
anonpenguin 2025-08-09 17:55:21 +03:00
parent cf36d301d5
commit fbfea68f02
3 changed files with 18 additions and 3 deletions

View File

@ -520,6 +520,7 @@ Notes:
- With `NETWORK_DEV_LOCAL`, `client.DefaultDatabaseEndpoints()` returns `http://127.0.0.1:$RQLITE_PORT`. - With `NETWORK_DEV_LOCAL`, `client.DefaultDatabaseEndpoints()` returns `http://127.0.0.1:$RQLITE_PORT`.
- `client.DefaultBootstrapPeers()` returns `LOCAL_BOOTSTRAP_MULTIADDR` if set, otherwise `/ip4/127.0.0.1/tcp/4001`. - `client.DefaultBootstrapPeers()` returns `LOCAL_BOOTSTRAP_MULTIADDR` if set, otherwise `/ip4/127.0.0.1/tcp/4001`.
- If you construct config via `client.DefaultClientConfig(...)`, DB endpoints are pinned to localhost and will override `RQLITE_NODES` automatically. - If you construct config via `client.DefaultClientConfig(...)`, DB endpoints are pinned to localhost and will override `RQLITE_NODES` automatically.
- When `NETWORK_DEV_LOCAL` is set and `LOCAL_BOOTSTRAP_MULTIADDR` is NOT set, the client attempts to auto-load the local bootstrap multiaddr (with peer ID) from `./data/bootstrap/peer.info` (or `LOCAL_BOOTSTRAP_INFO` path if provided). Only if no file is found does it fall back to `/ip4/127.0.0.1/tcp/4001`.
### Migration Guide for Apps (e.g., anchat) ### Migration Guide for Apps (e.g., anchat)

View File

@ -75,9 +75,9 @@ func MapFlagsAndEnvToConfig(cfg *config.Config, fv NodeFlagValues, isBootstrap b
if devLocal { if devLocal {
// In dev-local, run a primary bootstrap locally // In dev-local, run a primary bootstrap locally
cfg.Database.RQLiteJoinAddress = "" cfg.Database.RQLiteJoinAddress = ""
// Also prefer localhost bootstrap peers for any consumers reading cfg // Do not set bootstrap peers to avoid including self; clients can still
cfg.Discovery.BootstrapPeers = client.DefaultBootstrapPeers() // derive DB endpoints via DefaultDatabaseEndpoints in dev-local.
logger.Printf("Dev-local: Primary bootstrap node - localhost defaults enabled") logger.Printf("Dev-local: Primary bootstrap node - localhost defaults enabled (no bootstrap peers set to avoid self)")
return "" return ""
} }
bootstrapPeers := constants.GetBootstrapPeers() bootstrapPeers := constants.GetBootstrapPeers()

View File

@ -17,6 +17,7 @@ import (
"git.debros.io/DeBros/network/pkg/constants" "git.debros.io/DeBros/network/pkg/constants"
"git.debros.io/DeBros/network/pkg/logging" "git.debros.io/DeBros/network/pkg/logging"
"git.debros.io/DeBros/network/pkg/node" "git.debros.io/DeBros/network/pkg/node"
"git.debros.io/DeBros/network/pkg/client"
) )
func main() { func main() {
@ -112,6 +113,19 @@ func main() {
logger.Printf("RQLite HTTP port: %d", cfg.Database.RQLitePort) logger.Printf("RQLite HTTP port: %d", cfg.Database.RQLitePort)
logger.Printf("RQLite Raft port: %d", cfg.Database.RQLiteRaftPort) logger.Printf("RQLite Raft port: %d", cfg.Database.RQLiteRaftPort)
// For development visibility, print what the CLIENT library will return by default
clientBootstrap := client.DefaultBootstrapPeers()
clientDB := client.DefaultDatabaseEndpoints()
logger.Printf("[Client Defaults] Bootstrap peers: %v", clientBootstrap)
logger.Printf("[Client Defaults] Database endpoints: %v", clientDB)
// Also show node-configured values
logger.Printf("[Node Config] Bootstrap peers: %v", cfg.Discovery.BootstrapPeers)
if cfg.Database.RQLiteJoinAddress != "" {
logger.Printf("[Node Config] RQLite Raft join: %s", cfg.Database.RQLiteJoinAddress)
} else if isBootstrap {
logger.Printf("[Node Config] Bootstrap node: starting new RQLite cluster (no join)")
}
// Create context for graceful shutdown // Create context for graceful shutdown
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()