mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
The live guard refused to start a chain whose K was below the number of validators that existed. But sampling is stake-weighted: a validator is drawn in proportion to what it staked, however many validators there are, and K only sets how many draws a poll makes. Tying K to the headcount gave a validator holding a billionth of the stake the same standing as one holding a fifth, and refused to boot a producing chain because a small staker had joined. The guard keeps what makes a committee safe — the overlap bound and at least single-fault tolerance — and stops counting heads. The tier floor stays a reported target: refusing to start does not add validators, it pins every node on whatever it last booted. Co-authored-by: Hanzo Dev <[email protected]>
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
// Every preset a chain can be started with has to name a quorum that a
|
|
// two-thirds-honest network can actually reach and that a one-third adversary
|
|
// cannot: Alpha in [0.66, 1.0], and the integer AlphaPreference at least 66% of
|
|
// the sample K. A preset below the bound finalizes without agreement; one above
|
|
// 1.0 can never finalize at all. These are the values node ships, so an edit
|
|
// that drifts any of them must fail here.
|
|
func TestPresetsHoldTheByzantineBound(t *testing.T) {
|
|
for name, params := range map[string]Parameters{
|
|
"Default": DefaultParams(),
|
|
"Mainnet": MainnetParams(),
|
|
"Testnet": TestnetParams(),
|
|
"Local": LocalParams(),
|
|
"LocalBFT": LocalBFTParams(),
|
|
"XChain": XChainParams(),
|
|
"Single": SingleValidatorParams(),
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
if params.Alpha < 0.66 || params.Alpha > 1.0 {
|
|
t.Errorf("Alpha %.3f outside [0.66, 1.0]", params.Alpha)
|
|
}
|
|
if ratio := float64(params.AlphaPreference) / float64(params.K); ratio < 0.66 {
|
|
t.Errorf("AlphaPreference %d of K=%d is %.1f%%, under 66%%",
|
|
params.AlphaPreference, params.K, ratio*100)
|
|
}
|
|
if err := params.Valid(); err != nil {
|
|
t.Errorf("preset does not validate: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|