bootstrap fixes
This commit is contained in:
parent
7e4fff6830
commit
2bdebd1fd9
|
|
@ -87,18 +87,16 @@ impl NodeInfo {
|
|||
}
|
||||
}
|
||||
|
||||
let inherited_blocks_mined = match address_map.values().find(|node| node.ip == edit.ip) {
|
||||
Some(node) if node.deleted_timestamp == 0 && edit.ip != GENESIS_IP => {
|
||||
if let Some(node) = address_map.values().find(|node| node.ip == edit.ip) {
|
||||
if node.deleted_timestamp == 0 && edit.ip != GENESIS_IP {
|
||||
return Err("ip already exists".to_string());
|
||||
}
|
||||
Some(node) => node.blocks_mined,
|
||||
None => 0,
|
||||
};
|
||||
}
|
||||
|
||||
address_map.insert(edit.address, {
|
||||
let mut node = NodeInfo::new(
|
||||
edit.ip,
|
||||
inherited_blocks_mined,
|
||||
0,
|
||||
edit.modified_by,
|
||||
edit.modified_timestamp,
|
||||
edit.modified_signature,
|
||||
|
|
@ -386,14 +384,11 @@ impl NodeInfo {
|
|||
}
|
||||
|
||||
if !address_map.contains_key(&edit.address) {
|
||||
let mut inherited_blocks_mined = 0;
|
||||
if let Some(existing_node) =
|
||||
address_map.values_mut().find(|node| node.ip == edit.ip)
|
||||
{
|
||||
if existing_node.deleted_timestamp == 0 && edit.ip != GENESIS_IP {
|
||||
penalize_duplicate_ip = true;
|
||||
} else {
|
||||
inherited_blocks_mined = existing_node.blocks_mined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -403,7 +398,7 @@ impl NodeInfo {
|
|||
address_map.insert(edit.address.clone(), {
|
||||
let mut node = NodeInfo::new(
|
||||
edit.ip.clone(),
|
||||
inherited_blocks_mined,
|
||||
0,
|
||||
edit.modified_by.clone(),
|
||||
edit.modified_timestamp,
|
||||
edit.modified_signature.clone(),
|
||||
|
|
|
|||
|
|
@ -20,10 +20,15 @@ pub async fn ensure_compatible_genesis(
|
|||
remote_height: u32,
|
||||
) -> Result<(), String> {
|
||||
let local_hash = local_genesis_hash().await?;
|
||||
if local_hash.is_none() && remote_height == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let remote_hash =
|
||||
match request_block_hash_at_height(stream, map, connections_key.clone(), 0).await {
|
||||
Ok(hash) => Some(hash),
|
||||
Err(err) if err.contains("Block 0 not found") => None,
|
||||
Err(err) if remote_height == 0 && err.contains("Node is syncing") => None,
|
||||
Err(err) => {
|
||||
return Err(format!(
|
||||
"remote genesis compatibility check failed for {connections_key}: {err}"
|
||||
|
|
@ -35,7 +40,7 @@ pub async fn ensure_compatible_genesis(
|
|||
(Some(local), Some(remote)) if local != remote => Err(format!(
|
||||
"incompatible genesis from peer {connections_key}: local={local} remote={remote}"
|
||||
)),
|
||||
(Some(_), None) => Err(format!(
|
||||
(Some(_), None) if remote_height > 0 => Err(format!(
|
||||
"peer {connections_key} has no genesis while local chain already has one"
|
||||
)),
|
||||
(None, None) if remote_height > 0 => Err(format!(
|
||||
|
|
|
|||
Loading…
Reference in New Issue