fix(witness): resolve infinite fork collision deferral and stuck head…#93
Merged
fix(witness): resolve infinite fork collision deferral and stuck head…#93
Conversation
… issue - Add compare_fork_branches() to database for vote-weighted fork branch comparison with +10% bonus - Refactor _push_block() to use compare_fork_branches() for HF12 fork switching logic - Add remove_blocks_by_number() to fork_database to remove stale blocks by height - Prune dead-fork competing blocks after successful block application to prevent false collisions - Implement two-level fork collision resolution in witness plugin: - Level 1: vote-weighted comparison when competing forks exist in fork_db to decide production or defer - Level 2: stuck-head timeout after 21 deferrals bypasses collision and removes dead forks to resume production - Add CLI option --fork-collision-timeout-blocks to configure deferral timeout (default 21 blocks) - Reset fork collision defer count on successful block production or sync skips to avoid false timeout - Fix bug where pre-HF12 nodes deferred infinitely by moving timeout check before HF12-specific logic - Preserve emergency consensus behavior by deferring on any competing block but still applying timeout logic
- Log peer disconnect reasons at info level for better debugging - Include error details when disconnect caused by error - Dump potential peer database showing failed, rejected, and banned peers - Log detailed status of each potential peer including last attempt time and errors - Provide summary count of peers with failed or rejected status in p2p plugin
…ages - Replace fc_ilog with fc_dlog to reduce log verbosity - Target log output to 'sync' logger category - Maintain existing message format with block details and peer info
- Change peer disconnect logs from warning and info to debug for less verbosity - Modify p2p plugin peer_db status and failure count logs from warning/info to debug - Keep essential logging but reduce log level to avoid noisy output during normal operation
- Replaced fc_ilog with fc_dlog for pushing sync block log message - Adjusted logging verbosity to reduce infrequent log noise during sync - Maintained logging context with block number and block hash details
- Change default SOFT_BAN_DURATION_SEC from 3600 seconds to 900 seconds - Maintain TRUSTED_SOFT_BAN_DURATION_SEC at 300 seconds for trusted peers - Adjust ban timing to improve network node responsiveness and recovery
…ared memory resizing - Implement resize barrier in chainbase::database to safely handle shared memory remapping - Use atomic operation counter, flag, and condition variable to pause all operations during resize - Wrap lockless read code paths with operation_guard to participate in resize barrier - Apply resize barrier in deferred resize to block lockless reads and thread operations during remap - Explicitly skip barrier for immediate resize during reindex to avoid deadlocks - Update witness plugin and block generation to acquire operation_guard on lockless reads - Add detailed documentation on resize barrier protocol and historical race condition issues - Adjust configuration safety rules to emphasize avoiding cascading resizes and latency impact - Log resize barrier state transitions and size changes for diagnostic clarity
- Add second operation guard in database.cpp to cover lockless reads before push_block - Release the second operation guard before calling push_block - Add operation guard in p2p_plugin.cpp when accessing witness signing key to guard against concurrent resize - Release operation guard after verifying recovered public key matches witness key - Add operation guard in witness.cpp around time calculations and private key checks - Release operation guard before returning when private key is found and scheduled soon
…etails - Added witness and p2p plugin files to lockless read table with operation_guard usage - Distinguished pre- and post-write-lock lockless reads in _generate_block() with separate operation_guard scopes - Documented operation_guard usage in witness plugin methods: maybe_produce_block() and is_witness_scheduled_soon() - Included operation_guard usage in p2p plugin block post-validation phase - Expanded code comments with operation_guard examples for _generate_block(), witness scheduling, and p2p plugin validation
… pruning systems - Add compare_fork_branches() for vote-weighted fork comparison using witness votes with +10% bonus for longer chains - Introduce two-level fork collision resolution combining vote-weighted comparison and stuck-head timeout mechanism - Implement stuck-head timeout to remove stale competing blocks after 21 consecutive deferrals - Add remove_blocks_by_number() for automatic stale fork pruning of dead forks at specific heights - Enhance fork_database pruning with set_max_size() cleaning both linked and unlinked indices - Update witness scheduling with emergency mode awareness, fork collision handling, and two-level resolution integration - Improve chain reorganization with HF12 fork comparison logic for robust fork switching decisions - Extend emergency consensus system to support sophisticated tie-breaking and advanced fork collision recovery - Enhance documentation detailing new fork collision resolution, vote-weighted comparison, and pruning algorithms - Refactor internal error handling, duplicate detection, and early rejection logic for seamless HF12 compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… issue