Skip to content
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

Miscellaneous fixes for the fork #1319

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/src/chain/chaintrust/asymptote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ where
const ALPHA: f64 = 0.025;

// We scale the weights by this factor to ensure that they are resolvable as integers, to avoid using floating-point numbers.
const SCALING_FACTOR: f64 = 1000000000.;
const SCALING_FACTOR: f64 = 1e18;

// The size of the precomputed weights
const VEC_SIZE: u64 = 240;
const VEC_SIZE: u64 = 1200;

// Epsilon is the smallest positive value that can be represented by the scaled weights.
const EPSILON: u64 = 1;
Expand Down
16 changes: 9 additions & 7 deletions p2p/src/sync/peer_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
mod known_transactions;

use chainstate::{ban_score::BanScore, chainstate_interface::ChainstateInterface};
use common::{chain::GenBlock, primitives::Id};
use common::{chain::GenBlock, primitives::Id, Uint256};
use logging::log;
use mempool::error::{Error as MempoolError, MempoolPolicyError};
use p2p_types::PeerId;
Expand Down Expand Up @@ -113,7 +113,7 @@ pub async fn handle_message_processing_result(
}

/// This function is used to update peers_best_block_that_we_have.
/// The "better" block is the one that is on the main chain and has bigger height.
/// The "better" block is the one that is on the main chain and has a higher chain-trust.
/// In the case of a tie, new_block_id is preferred.
pub fn choose_peers_best_block(
chainstate: &dyn ChainstateInterface,
Expand All @@ -124,11 +124,13 @@ pub fn choose_peers_best_block(
(None, None) => Ok(None),
(Some(id), None) | (None, Some(id)) => Ok(Some(id)),
(Some(old_id), Some(new_id)) => {
let old_height =
chainstate.get_block_height_in_main_chain(&old_id)?.unwrap_or(0.into());
let new_height =
chainstate.get_block_height_in_main_chain(&new_id)?.unwrap_or(0.into());
if new_height >= old_height {
let old_block_chain_trust = chainstate
.get_gen_block_index(&old_id)?
.map_or(Uint256::ZERO, |idx| idx.chain_trust());
let new_block_chain_trust = chainstate
.get_gen_block_index(&new_id)?
.map_or(Uint256::ZERO, |idx| idx.chain_trust());
if new_block_chain_trust >= old_block_chain_trust {
Ok(Some(new_id))
} else {
Ok(Some(old_id))
Expand Down