Files
zeekayandHanzo Dev 304717c199 health: name the CHAIN that is unbootstrapped, not the net (v1.36.29)
/v1/health's `bootstrapped` check publishes chains.Nets.Bootstrapping()
verbatim as its message. Nets.chains is keyed by NET id, and the aggregate
appended the map key rather than asking the net which of its chains had not
converged. So every stuck primary-network chain surfaced as one ID,
11111111111111111111111111111111LpoYY — constants.PrimaryNetworkID, i.e.
ids.Empty — a "chain" the chain manager has never heard of. An operator who
went looking for it got "there is no chain with alias/ID", and N stuck chains
collapsed into a single indistinguishable entry that named none of them.

Measured on lux-devnet luxd-0 (v1.36.23), POST health.health:
  "bootstrapped":{"message":["11111111111111111111111111111111LpoYY"],
   "error":"chains not bootstrapped","contiguousFailures":3213}

The net owns the bootstrapping set, so the net is what can name those chains:
nets.Net grows Bootstrapping() []ids.ID and chains.Nets aggregates those
instead of its own keys. One place holds the set; one place reads it.

The existing TestNetsBootstrapping asserted the defect (require.Contains
bootstrapping, netID) — that assertion is why it survived review. It now
demands the chain ID and refuses the net ID.

This also cuts the first tag containing dada5a31, the GET /v1/health encoder
fix: apihealth.APIReply carries a time.Duration per check, jsonv2 has no
default representation for it, so every GET degraded to
{"healthy":…,"error":"health reply encode failed"} while the status code still
looked right. Reproduced here directly —
  json: cannot marshal from Go time.Duration within "/checks/network/duration"
That fix landed on main on 2026-07-25 but no tag ever carried it: v1.36.28
points at 52de3948, seven commits behind. The fleet runs v1.36.2/23/24, all of
which predate it.

Tests (GOWORK=off CGO_ENABLED=0):
  chains  ok  — TestNetsBootstrappingReportsChainsNotNets fails against the
                old aggregate with exactly ids.Empty in the list
  nets    ok  — TestNetBootstrappingNamesTheChains
  health  ok  — the three handler tests fail against the jsonv2 encoder
                (checks decode empty) and pass against encoding/json

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2026-07-26 17:36:07 -07:00

94 lines
3.4 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package nets
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/luxfi/ids"
"github.com/luxfi/math/set"
)
func TestNet(t *testing.T) {
require := require.New(t)
myNodeID := ids.GenerateTestNodeID()
chainID0 := ids.GenerateTestID()
chainID1 := ids.GenerateTestID()
chainID2 := ids.GenerateTestID()
s := New(myNodeID, Config{})
s.AddChain(chainID0)
require.False(s.IsBootstrapped(), "A net with one chain in bootstrapping shouldn't be considered bootstrapped")
s.Bootstrapped(chainID0)
require.True(s.IsBootstrapped(), "A net with only bootstrapped chains should be considered bootstrapped")
s.AddChain(chainID1)
require.False(s.IsBootstrapped(), "A net with one chain in bootstrapping shouldn't be considered bootstrapped")
s.AddChain(chainID2)
require.False(s.IsBootstrapped(), "A net with one chain in bootstrapping shouldn't be considered bootstrapped")
s.Bootstrapped(chainID1)
require.False(s.IsBootstrapped(), "A net with one chain in bootstrapping shouldn't be considered bootstrapped")
s.Bootstrapped(chainID2)
require.True(s.IsBootstrapped(), "A net with only bootstrapped chains should be considered bootstrapped")
}
func TestIsAllowed(t *testing.T) {
require := require.New(t)
myNodeID := ids.GenerateTestNodeID()
// Test with no rules
s := New(myNodeID, Config{})
require.True(s.IsAllowed(ids.GenerateTestNodeID(), true), "Validator should be allowed with no rules")
require.True(s.IsAllowed(ids.GenerateTestNodeID(), false), "Non-validator should be allowed with no rules")
// Test with validator only rules
s = New(myNodeID, Config{
ValidatorOnly: true,
})
require.True(s.IsAllowed(ids.GenerateTestNodeID(), true), "Validator should be allowed with validator only rules")
require.True(s.IsAllowed(myNodeID, false), "Self node should be allowed with validator only rules")
require.False(s.IsAllowed(ids.GenerateTestNodeID(), false), "Non-validator should not be allowed with validator only rules")
// Test with validator only rules and allowed nodes
allowedNodeID := ids.GenerateTestNodeID()
s = New(myNodeID, Config{
ValidatorOnly: true,
AllowedNodes: set.Of(allowedNodeID),
})
require.True(s.IsAllowed(allowedNodeID, true), "Validator should be allowed with validator only rules and allowed nodes")
require.True(s.IsAllowed(myNodeID, false), "Self node should be allowed with validator only rules")
require.False(s.IsAllowed(ids.GenerateTestNodeID(), false), "Non-validator should not be allowed with validator only rules and allowed nodes")
require.True(s.IsAllowed(allowedNodeID, true), "Non-validator allowed node should be allowed with validator only rules and allowed nodes")
}
// Bootstrapping must name the CHAINS still syncing. The net-level aggregate
// IsBootstrapped() only says "something here is unconverged"; only the chain
// IDs say what.
func TestNetBootstrappingNamesTheChains(t *testing.T) {
require := require.New(t)
chainID0 := ids.GenerateTestID()
chainID1 := ids.GenerateTestID()
s := New(ids.GenerateTestNodeID(), Config{})
require.Empty(s.Bootstrapping())
s.AddChain(chainID0)
s.AddChain(chainID1)
require.ElementsMatch([]ids.ID{chainID0, chainID1}, s.Bootstrapping())
s.Bootstrapped(chainID0)
require.Equal([]ids.ID{chainID1}, s.Bootstrapping())
s.Bootstrapped(chainID1)
require.Empty(s.Bootstrapping())
}