Files
zeekayandHanzo Dev 974d0d5422 rename: drop the upstream protocol name from the tree
The module is luxfi/bft and that is now the only name it answers to.

- simplex/ -> engine/. Upstream's module is named for the protocol, so its root
  package and its engine package shared that name; under luxfi/bft the engine
  package would have collided with the module's own root package. It is the
  consensus engine, so engine.Epoch and engine.NewEpoch read without stutter.
- Identifiers keep the qualifier where it carries meaning and only change the
  word: a block produced by this protocol as against a pre-existing chain's block
  is a real distinction, so makeNonSimplexBlock became makeNonBFTBlock,
  lastNonSimplexInnerBlockHeight became lastNonBFTInnerBlockHeight,
  newSnowToSimplexChain became newSnowToBFTChain. Dropping the qualifier outright
  would have left names that assert nothing.
- The canoto-tagged fields of StateMachineMetadata lose the prefix entirely:
  EpochInfo, ProtocolMetadata, Blacklist. The wire format is unchanged — canoto
  keys off the tag numbers, which still read 1,2,3,4,5, and the generated
  .canoto.go files were renamed in step with the source. The msm fuzz and
  encoding round-trip tests cover this.
- Prose cites the protocol paper by reference number instead of by name, so the
  origin stays findable without the name. The HyperSDK sentence still says
  Avalanche because that sentence is about Avalanche's VM and is true.

Also here, from review of the logger port:
- monitor_test's Fatal panics instead of returning. It reported a state the
  caller had declared impossible and then carried on regardless, which made it
  the one Fatal in the tree that was weaker than the original.
- TestInstanceNonValidatorBootstraps asserts the property it is named for — that
  the node was still a non-validator when the bootstrap finished — rather than
  counting how many times a debug line was emitted. The count tracks how often
  onEpochChange happened to observe the branch, so transitions can coalesce; it
  measured 2 here where it had been reliably 3, and a logger-cost explanation was
  tested and refuted. The count never checked the property either way: a node
  that wrongly became a validator mid-bootstrap would still have counted 3.
- SilenceExceptKeywords documents last-call-wins, and Trace/Verbo now reaching
  hooks is recorded where a future hook author will see it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-06 05:16:49 -07:00

6.9 KiB

bft

Leader-rotation BFT consensus, published as github.com/luxfi/bft. The design follows the protocol described in the paper cited as [1] in the README; that paper's own name for it is not used anywhere in this tree, in code or in prose. The citation stays so the origin is findable.

Layout

.              package bft  — orchestration: instance, config, adapters, external
engine/        the core engine: epoch, notarization, replication, monitor, requestor
common/        shared types: Logger, Message, NodeID, block scheduler, sched, WAL consts
msm/           multi-state-machine reconfiguration — epoch changes, approvals, encoding
nonvalidator/  nodes that follow finalized state without voting
host/          types the host node supplies (NodeID, VMBlock, Bitmask) plus size limits,
               vendored so this module does not pull in a whole node
wal/           write-ahead log, with pruning and garbage collection
testutil/      test harness: TestLogger, nodes, random_network, long_running

Two directories are renamed from upstream. engine/ was simplex/ — upstream's module is named for the protocol, so its root package and its engine package shared that name, which under luxfi/bft would have collided with the module's own root package. host/ was avalanchego/: it holds NodeID, VMBlock, Bitmask and size limits, so it is named for what it holds. A brand in a package name says nothing about the code, and swapping one brand for another would say just as little.

Fork delta from upstream

Upstream is ava-labs/simplex. The fork carries no consensus logic of its own — every difference is one of these, and that is deliberate:

  1. Module path github.com/luxfi/bft; root package bft; engine package engine.
  2. go.uber.org/zap → github.com/luxfi/log. common.Logger therefore takes ...log.Field. zap.Error(err) maps to log.Err(err) — log.Error is luxfi/log's package-level logging function, not a field constructor, and only the compiler catches the confusion. Needs luxfi/log v1.6.1 for Stringers.
  3. avalanchego/ → host/.
  4. The upstream protocol name is absent from identifiers, comments and strings; where it qualified something load-bearing — a block produced by this protocol as against a pre-existing chain's block — the qualifier is now BFT (makeNonBFTBlock, lastNonBFTInnerBlockHeight, newSnowToBFTChain). The canoto-tagged fields of StateMachineMetadata lost the prefix entirely (EpochInfo, ProtocolMetadata, Blacklist); the wire format is unchanged because canoto keys off the tag NUMBERS (1,2,3,…), not the Go field names, and the generated .canoto.go files were renamed in step with the source.
  5. Go toolchain pinned to the version in go.mod.
  6. testutil/logger.go and engine/monitor_test.go reimplemented without zapcore.

The test logger

Upstream layers policy as zapcore constructs — a keyword-filtering Core, a debug-swallowing Encoder, a Tee, an AtomicLevel, plus a second hook-free logger for Trace/Verbo — because that is zap's extension model. luxfi/log has no such seam, so TestLogger applies policy in one emit. One funnel, but two gates, and that distinction is the whole lesson:

  • Reporting and writing are different questions. Whether an observer SEES an entry is decided by level and keywords. Whether a sink RECORDS it additionally depends on the sink. Upstream expressed these at different depths — a level on the core, debug suppression in the encoder, which runs after hooks. Collapsing them into one predicate blinds every Intercept hook the moment debug output is quieted, which is exactly what unit-tests.sh does (LOG_LEVEL=info). That mistake was made here and caught in review: it broke ten tests, two by hanging and one by a nil-pointer panic, and every one of them passes upstream. If you touch emit, keep the gates separate.
  • LOG_LEVEL=info quiets debug on stdout only; a file sink keeps full fidelity, because a post-mortem log is read precisely because something went wrong. Upstream got this by accident — it read LOG_LEVEL for stdout and log_level for the file, and only the former is ever set — so the asymmetry is kept but stated as one deliberate rule.
  • Intercept receives testutil.LogEntry{Level, Message}; that is all any caller reads. Hooks fire only for entries passing level and keywords, matching upstream's check-before-write ordering. The hook runs outside the lock, so a hook that logs fails the test instead of deadlocking it.
  • Trace/Verbo now reach hooks. Upstream routed them through a second logger that carried no hooks — except after SilenceExceptKeywords, which rebuilt it from a hook-carrying core and started delivering them. This is uniform instead. No hook predicate in the tree matches a Trace or Verbo message today; a future one must tolerate delivery, since several hooks close channels or call WaitGroup.Done.
  • SilenceExceptKeywords is last-call-wins; upstream nested a filter per call, so successive calls intersected. Its only caller is BasicNode, which nothing calls. Contrary to an earlier claim in this file, upstream did not lose an installed hook when it rebuilt — Logger.Core() returns the hook-carrying core. What it actually dropped was AddCallerSkip(1).
  • Fatal panics rather than exiting: the one production caller reports an impossible node role, and os.Exit would take the suite down with no attribution.
  • engine/monitor_test.go keeps its own minimal logger because testutil imports engine, so an internal test in package engine cannot import testutil back.

Syncing upstream

git remote add up https://github.com/ava-labs/simplex   # once
git fetch up main
git merge up/main

Take upstream's tree wholesale and reapply the transform as its own commit — the fork holds no consensus logic, so there is nothing to defend in a three-way resolution. Conflicts land on log call sites, since the field constructors are the one thing the transform touches in every file. Then:

go build ./... && go vet ./... && gofmt -l .
LOG_LEVEL=info go test -race ./...          # what CI runs

gofmt matters: swapping go.uber.org/zap for github.com/luxfi/log in place leaves imports unsorted, because the paths sort differently. Upstream is gofmt-clean, so any dirt is yours.

Confirm any failure against a pristine upstream checkout before treating it as ours. Upstream carries a real hang in TestReplicationRequestTimeoutCancels, and attributing that to the fork wastes a day. Do not sed prose — a blanket rename produced sentences here claiming upstream was ava-labs/bft and that the protocol paper's authors named it BFT.

Consumers

Nothing imports this module yet. luxfi/consensus used to expose a dormant NewBFT facade over it; that facade is gone. A first real consumer should implement common.Logger and supply its own Storage, Communication, Signer, BlockBuilder and WAL.