Files
node/chains/bootstrap_divergent_heads_test.go
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

58 lines
1.9 KiB
Go

package chains
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
// TestRefute_DivergentHeadsStillNameAFrontier models a live chain whose five validators sit
// on five different heads, none of them a majority, with the deciding node below all but one.
// The claim "such a chain never fetches a single block" is false: the ancestor-tolerant tally
// names the highest ⅔-backed common block above the node's own height, so syncOnce gets
// FrontierNamed and descends.
func TestRefute_DivergentHeadsStillNameAFrontier(t *testing.T) {
const w uint64 = 100
const own = 36060
refs, byID := refChain(own) // genesis..36060, the deciding node's own accepted chain
prev := refs[own]
var at36169, at36841 BlockRef
for h := own + 1; h <= 36841; h++ {
c := childRef(prev)
byID[c.ID] = c
prev = c
if h == 36169 {
at36169 = c
}
}
at36841 = prev
require.Equal(t, uint64(36841), at36841.Height)
require.Equal(t, uint64(36169), at36169.Height)
beacons := nodeIDs(4) // the four peers the live node had connected (connectedPeers=4)
policy := &BootstrapPolicy{
TrustedBeacons: equalBeacons(beacons, w),
MinResponses: 3,
MinResponders: bootstrapMinAgreeingBeacons,
MinFrontierHeight: own,
Tip: refs[own].ID,
NamingWindow: bootstrapNamingWindow,
MaxAnchors: maxNamingAnchors,
Source: &stubAncestry{byID: byID},
}
replies := []BeaconReply{
reply(beacons[0], at36169.ID, w),
reply(beacons[1], at36841.ID, w),
reply(beacons[2], at36841.ID, w),
reply(beacons[3], refs[30622].ID, w), // the lagging node, below own height
}
f, err := policy.AcceptsFrontier(context.Background(), replies)
require.NoError(t, err, "four peers on FOUR different heads must still name a frontier")
require.NotNil(t, f)
require.Equal(t, at36169.ID, f.ID, "the highest ⅔-backed common block is 36169")
require.Equal(t, uint64(36169), f.Height)
}