mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
Follow-up docs cleanup from the snow-removal audit — these two files still referenced 'snowball configuration' and 'Snowball' engine names even though the consensus code itself is 100% Quasar family. Aligns docs with the code.
3.1 KiB
3.1 KiB
Error Propagation Tests for Lux Consensus
Overview
Successfully ported error propagation tests from upstream chain consensus to Lux consensus engine.
Tests Implemented
Core Error Tests
- TestErrorOnAccept - Tests that errors during block acceptance are properly propagated
- TestErrorOnRejectSibling - Tests that errors during sibling rejection are properly propagated
- TestMetricsProcessingError - Tests that metric registration errors are handled properly
- TestErrorOnAddDecidedBlock - Tests that adding an already decided block results in error
- TestTransitiveRejectionError - Tests error propagation during transitive block rejection
Metrics Error Tests
- TestMetricsAcceptedError - Tests that accepted counter metric conflicts are handled
- TestMetricsRejectedError - Tests that rejected counter metric conflicts are handled
Graceful Failure Tests
- TestGracefulFailureHandling - Tests that the consensus engine handles failures gracefully
- TestMetricsAccuracyDuringErrors - Tests that metrics remain accurate even when errors occur
Implementation Details
Key Components
- ErrorBlock - Test block implementation that can inject errors on Accept/Reject/Verify
- Consensus - Simplified consensus engine for testing with proper error propagation
- ConsensusContext - Context with Prometheus registerer for metrics testing
- Parameters - Consensus parameters matching Quasar/Wave configuration
Adaptations from upstream
- Used Lux's
bag.Bagfromnode/utils/baginstead of upstream's bag implementation - Adapted to Lux's block interfaces in
engine/chain/block - Used Lux's test utilities from
engine/chain/chaintest - Fixed bag initialization issues (requires SetThreshold to avoid nil set bug)
- Used separate Prometheus registries per test to avoid metric conflicts
Test Results
All 9 error propagation tests pass successfully:
=== RUN TestErrorOnAccept
--- PASS: TestErrorOnAccept (0.00s)
=== RUN TestErrorOnRejectSibling
--- PASS: TestErrorOnRejectSibling (0.00s)
=== RUN TestMetricsProcessingError
--- PASS: TestMetricsProcessingError (0.00s)
=== RUN TestErrorOnAddDecidedBlock
--- PASS: TestErrorOnAddDecidedBlock (0.00s)
=== RUN TestTransitiveRejectionError
--- PASS: TestTransitiveRejectionError (0.00s)
=== RUN TestMetricsAcceptedError
--- PASS: TestMetricsAcceptedError (0.00s)
=== RUN TestMetricsRejectedError
--- PASS: TestMetricsRejectedError (0.00s)
=== RUN TestGracefulFailureHandling
--- PASS: TestGracefulFailureHandling (0.00s)
=== RUN TestMetricsAccuracyDuringErrors
--- PASS: TestMetricsAccuracyDuringErrors (0.00s)
File Location
/Users/z/work/lux/consensus/engine/chain/error_propagation_test.go
Known Issues
- The
bag.Bagimplementation has a bug wheremetThresholdset is not properly initialized when threshold is 0 - Worked around by setting threshold to 2 before adding elements
- This should be fixed in the bag implementation itself
Future Work
- Consider fixing the bag initialization bug in
/Users/z/work/lux/node/utils/bag/bag.go - Add more comprehensive error scenarios
- Add benchmarks for error handling performance