mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
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.
57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package chains
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// *blockHandler must satisfy ancestorRequester, or the catch-up wire silently
|
|
// loses its transport. Catch it at compile time, not in production.
|
|
var _ ancestorRequester = (*blockHandler)(nil)
|
|
|
|
// catchupSpy records the requestContext calls networkCatchup bridges to.
|
|
type catchupSpy struct {
|
|
calls int
|
|
lastFrom ids.NodeID
|
|
lastBlock ids.ID
|
|
}
|
|
|
|
func (s *catchupSpy) requestContext(_ context.Context, from ids.NodeID, blockID ids.ID) {
|
|
s.calls++
|
|
s.lastFrom = from
|
|
s.lastBlock = blockID
|
|
}
|
|
|
|
// TestNetworkCatchup_BridgesEngineSignalToWire is the regression for the
|
|
// stranded-follower bug: node never set netCfg.Catchup, so the engine's
|
|
// requestCatchup hit a nil interface and a follower that fell behind during
|
|
// consensus never fetched the missing ancestors — it looped on an unfinalizable
|
|
// orphan forever, falling further behind the peers it can still hear with
|
|
// nothing able to converge it. The wire must (a) be nil-safe before its handler is
|
|
// late-bound and (b) route the engine's RequestAncestors to the handler's
|
|
// GetAncestors transport (requestContext), once, for the right block and peer.
|
|
func TestNetworkCatchup_BridgesEngineSignalToWire(t *testing.T) {
|
|
missing := ids.GenerateTestID()
|
|
peer := ids.GenerateTestNodeID()
|
|
|
|
// (a) Before late-binding (handler nil): a harmless no-op, never a panic.
|
|
c := &networkCatchup{}
|
|
require.NoError(t, c.RequestAncestors(ids.Empty, ids.Empty, missing, peer))
|
|
|
|
// (b) Once wired: the engine's catch-up signal reaches the GetAncestors wire
|
|
// exactly once — for the missing block, addressed to the peer that advertised
|
|
// its child. RED before the fix: handler is never set, calls stays 0.
|
|
spy := &catchupSpy{}
|
|
c.handler = spy
|
|
require.NoError(t, c.RequestAncestors(ids.Empty, ids.Empty, missing, peer))
|
|
require.Equal(t, 1, spy.calls, "RequestAncestors must route to requestContext — a nil wire IS the stranded-follower bug")
|
|
require.Equal(t, missing, spy.lastBlock)
|
|
require.Equal(t, peer, spy.lastFrom)
|
|
}
|