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]>
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:
- Module path
github.com/luxfi/bft; root packagebft; engine packageengine. go.uber.org/zap→github.com/luxfi/log.common.Loggertherefore takes...log.Field.zap.Error(err)maps tolog.Err(err)—log.Erroris luxfi/log's package-level logging function, not a field constructor, and only the compiler catches the confusion. Needs luxfi/log v1.6.1 forStringers.avalanchego/→host/.- 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 ofStateMachineMetadatalost 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.gofiles were renamed in step with the source. - Go toolchain pinned to the version in
go.mod. testutil/logger.goandengine/monitor_test.goreimplemented 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
Intercepthook the moment debug output is quieted, which is exactly whatunit-tests.shdoes (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 touchemit, keep the gates separate. LOG_LEVEL=infoquiets 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 readLOG_LEVELfor stdout andlog_levelfor the file, and only the former is ever set — so the asymmetry is kept but stated as one deliberate rule.Interceptreceivestestutil.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 callWaitGroup.Done. SilenceExceptKeywordsis last-call-wins; upstream nested a filter per call, so successive calls intersected. Its only caller isBasicNode, 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 wasAddCallerSkip(1).Fatalpanics rather than exiting: the one production caller reports an impossible node role, andos.Exitwould take the suite down with no attribution.engine/monitor_test.gokeeps its own minimal logger becausetestutilimportsengine, so an internal test inpackage enginecannot importtestutilback.
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.