-
Notifications
You must be signed in to change notification settings - Fork 26
Fix POS round state logic #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1044,13 +1044,27 @@ round_state goto_wait_for_next_block_and_clear_round_data(round_context &context | |
| return round_state::wait_for_next_block; | ||
| } | ||
|
|
||
| // Returns true if the blockchain's top block differs from the tip cached in | ||
| // the round context — either because a new block arrived (height changed) or | ||
| // because a same-height reorg replaced the top block (hash changed at the | ||
| // same height). | ||
| static bool chain_top_changed(round_context const &context, cryptonote::Blockchain const &blockchain) | ||
| { | ||
| uint64_t const chain_height = blockchain.get_current_blockchain_height(true /*lock*/); | ||
| if (context.wait_for_next_block.height != chain_height) | ||
| return true; | ||
| return context.wait_for_next_block.top_hash != blockchain.get_block_id_by_height(chain_height - 1); | ||
| } | ||
|
Comment on lines
+1047
to
+1057
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Inspect the lock lifetime and all chain-tip reads.
rg -n -C 12 \
'get_current_blockchain_height|get_block_id_by_height|get_tail_id|chain_top_changed|wait_for_next_block' \
src/cryptonote_core --glob '*.cpp' --glob '*.h'Repository: Beldex-Coin/beldex Length of output: 50375 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Inspect Blockchain tip read implementations and lock names.
fd -a 'blockchain\.(cpp|h)$' src | sed 's#^\./##' | while read -r f; do
echo "===== $f ====="
rg -n -C 8 'get_current_blockchain_height|get_tail_id|get_block_id_by_height' "$f" || true
done
# Focused slice around Blockchain implementation declarations/definitions.
rg -n -C 5 'Blockchain::(get_current_blockchain_height|get_tail_id(?:\b|\(.*\))|get_block_id_by_height)' src/cryptonote_core/blockchain.cpp src/cryptonote_core --glob '*.cpp' --glob '*.h'Repository: Beldex-Coin/beldex Length of output: 33330 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Focused slice around Blockchain implementation declarations/definitions.
rg -n -C 5 'Blockchain::(get_current_blockchain_height|get_tail_id(?:\b|\(.*\))|get_block_id_by_height)' src/cryptonote_core/blockchain.cpp src/cryptonote_core/blockchain.hRepository: Beldex-Coin/beldex Length of output: 3608 Use one locked chain-tip snapshot for POS state updates.
🧰 Tools🪛 Clang (14.0.6)[warning] 1051-1051: use a trailing return type for this function (modernize-use-trailing-return-type) [warning] 1054-1054: statement should be inside braces (readability-braces-around-statements) 🤖 Prompt for AI Agents |
||
|
|
||
| round_state wait_for_next_block(uint64_t hf17_height, round_context &context, cryptonote::Blockchain const &blockchain) | ||
| { | ||
| // | ||
| // NOTE: If already processing POS for height, wait for next height | ||
| // NOTE: If already processing POS for height, wait for next height. The top | ||
| // hash is compared too (not just the height) so that a same-height reorg | ||
| // re-arms the round context against the new tip | ||
| // | ||
| uint64_t chain_height = blockchain.get_current_blockchain_height(true /*lock*/); | ||
| if (context.wait_for_next_block.height == chain_height) | ||
| if (!chain_top_changed(context, blockchain)) | ||
| { | ||
| for (static uint64_t last_height = 0; last_height != chain_height; last_height = chain_height) | ||
| MDEBUG(log_prefix(context) << "Network is currently producing block " << chain_height << ", waiting until next block"); | ||
|
|
@@ -1119,9 +1133,9 @@ round_state prepare_for_round(round_context &context, master_nodes::master_node_ | |
| return goto_wait_for_next_block_and_clear_round_data(context); | ||
| } | ||
|
|
||
| // Also check if the blockchain has changed, in which case we stop and | ||
| // restart POS stages. | ||
| if (context.wait_for_next_block.height != blockchain.get_current_blockchain_height(true /*lock*/)) | ||
| // Also check if the blockchain has changed (new block, or same-height | ||
| // reorg), in which case we stop and restart POS stages. | ||
| if (chain_top_changed(context, blockchain)) | ||
| return goto_wait_for_next_block_and_clear_round_data(context); | ||
|
|
||
| // 'queue_for_next_round' is set when an intermediate POS stage has failed | ||
|
|
@@ -1161,6 +1175,11 @@ round_state prepare_for_round(round_context &context, master_nodes::master_node_ | |
| } | ||
|
|
||
| std::vector<crypto::hash> const entropy = master_nodes::get_POS_entropy_for_next_block(blockchain.get_db(), context.wait_for_next_block.top_hash, context.prepare_for_round.round); | ||
| if (entropy.empty()) | ||
| { | ||
| MDEBUG(log_prefix(context) << "Unable to prepare POS quorum for height " << context.wait_for_next_block.height << " because quorum entropy is unavailable; waiting for the next block"); | ||
| return goto_wait_for_next_block_and_clear_round_data(context); | ||
| } | ||
| auto const active_node_list = blockchain.get_master_node_list().active_master_nodes_infos(); | ||
| auto hf_version = blockchain.get_network_version(); | ||
| crypto::public_key const &block_leader = blockchain.get_master_node_list().get_block_leader().key; | ||
|
|
@@ -1212,10 +1231,9 @@ round_state prepare_for_round(round_context &context, master_nodes::master_node_ | |
|
|
||
| round_state wait_for_round(round_context &context, cryptonote::Blockchain const &blockchain) | ||
| { | ||
| const auto curr_height = blockchain.get_current_blockchain_height(true /*lock*/); | ||
| if (context.wait_for_next_block.height != curr_height) | ||
| if (chain_top_changed(context, blockchain)) | ||
| { | ||
| MTRACE(log_prefix(context) << "Block height changed whilst waiting for round " << +context.prepare_for_round.round << ", restarting POS stages"); | ||
| MTRACE(log_prefix(context) << "Chain tip changed whilst waiting for round " << +context.prepare_for_round.round << ", restarting POS stages"); | ||
| return goto_wait_for_next_block_and_clear_round_data(context); | ||
| } | ||
|
|
||
|
|
@@ -1231,7 +1249,7 @@ round_state wait_for_round(round_context &context, cryptonote::Blockchain const | |
| // For testing purposes: we apply possible random non-response and random delays to half of all | ||
| // blocks; we go in batches of 10: 10 maybe-faulty blocks followed by 10 well-behaved blocks. | ||
| // (Faulty blocks have an odd second-last height digit). | ||
| if (curr_height % 20 >= 10) | ||
| if (context.wait_for_next_block.height % 20 >= 10) | ||
| { | ||
| size_t faulty_chance = tools::uniform_distribution_portable(tools::rng, 100); | ||
| if (faulty_chance < 10) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -593,11 +593,11 @@ namespace nodetool | |
| } | ||
| else | ||
| { | ||
| full_addrs.insert("seed1.beldex.io:19090"); | ||
| full_addrs.insert("seed1.rpcnode.stream:19090"); | ||
| full_addrs.insert("seed2.rpcnode.stream:19090"); | ||
| full_addrs.insert("seed3.beldex.io:19090"); | ||
| full_addrs.insert("seed3.rpcnode.stream:19090"); | ||
| full_addrs.insert("seed4.rpcnode.stream:19090"); | ||
| full_addrs.insert("seed5.beldex.io:19090"); | ||
| full_addrs.insert("seed5.rpcnode.stream:19090"); | ||
|
Comment on lines
+596
to
+600
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🔵 Trivial Verify bootstrap redundancy before release. All five MAINNET seed entries now use 🤖 Prompt for AI Agents |
||
| } | ||
| return full_addrs; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Add braces around the new conditional branches.
Clang reports
readability-braces-around-statementsat both locations. Add braces before later edits change the controlled statement unintentionally.Proposed fix
Also applies to: 1138-1139
🧰 Tools
🪛 Clang (14.0.6)
[warning] 1054-1054: statement should be inside braces
(readability-braces-around-statements)
🤖 Prompt for AI Agents
Source: Linters/SAST tools