bug fixes
This commit is contained in:
parent
0845fd3ba6
commit
38dabfa27f
|
|
@ -167,6 +167,12 @@ impl NodeInfo {
|
||||||
match streams {
|
match streams {
|
||||||
streams if !streams.is_empty() => {
|
streams if !streams.is_empty() => {
|
||||||
for (peer_key, unlocked_stream) in streams {
|
for (peer_key, unlocked_stream) in streams {
|
||||||
|
let Some((peer_ip, _)) = peer_key.rsplit_once(':') else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if !remote_ip.is_empty() && peer_ip == remote_ip {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let hashmap_key = reserve_transient_entry_with_context(
|
let hashmap_key = reserve_transient_entry_with_context(
|
||||||
map.clone(),
|
map.clone(),
|
||||||
Some(message_type),
|
Some(message_type),
|
||||||
|
|
@ -185,12 +191,6 @@ impl NodeInfo {
|
||||||
for monitor in monitor_bytes.iter().take(monitor_count as usize) {
|
for monitor in monitor_bytes.iter().take(monitor_count as usize) {
|
||||||
message.extend_from_slice(monitor);
|
message.extend_from_slice(monitor);
|
||||||
}
|
}
|
||||||
let Some((peer_ip, _)) = peer_key.rsplit_once(':') else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
if !remote_ip.is_empty() && peer_ip == remote_ip {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
RpcResponse::send_raw(&unlocked_stream, Some(&peer_key), &message).await;
|
RpcResponse::send_raw(&unlocked_stream, Some(&peer_key), &message).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +255,7 @@ impl NodeInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut penalize_duplicate_ip = false;
|
let mut penalize_duplicate_ip = false;
|
||||||
let mut accepted_existing_node = false;
|
let mut state_changed = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut address_map = ADDRESS_MAP.lock().await;
|
let mut address_map = ADDRESS_MAP.lock().await;
|
||||||
|
|
@ -309,16 +309,18 @@ impl NodeInfo {
|
||||||
existing_node.monitoring = monitors.clone();
|
existing_node.monitoring = monitors.clone();
|
||||||
if existing_node.deleted_timestamp > 0 {
|
if existing_node.deleted_timestamp > 0 {
|
||||||
if existing_node.ip == edit.ip {
|
if existing_node.ip == edit.ip {
|
||||||
|
existing_node.added_by = edit.modified_by.clone();
|
||||||
|
existing_node.added_timestamp = edit.modified_timestamp;
|
||||||
|
existing_node.added_signature = edit.modified_signature.clone();
|
||||||
|
existing_node.blocks_mined = blocks_mined;
|
||||||
existing_node.deleted_timestamp = 0_u64;
|
existing_node.deleted_timestamp = 0_u64;
|
||||||
existing_node.deleted_block = 0_u32;
|
existing_node.deleted_block = 0_u32;
|
||||||
drop(address_map);
|
state_changed = true;
|
||||||
Self::persist_recovery_snapshot("node revive").await;
|
|
||||||
return RpcResponse::Binary(b"Success".to_vec());
|
|
||||||
} else {
|
} else {
|
||||||
address_map.remove(&edit.address);
|
address_map.remove(&edit.address);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if edit.modified_timestamp < existing_node.added_timestamp {
|
if edit.modified_timestamp > existing_node.added_timestamp {
|
||||||
*existing_node = NodeInfo::new(
|
*existing_node = NodeInfo::new(
|
||||||
edit.ip.clone(),
|
edit.ip.clone(),
|
||||||
blocks_mined,
|
blocks_mined,
|
||||||
|
|
@ -326,12 +328,13 @@ impl NodeInfo {
|
||||||
edit.modified_timestamp,
|
edit.modified_timestamp,
|
||||||
edit.modified_signature.clone(),
|
edit.modified_signature.clone(),
|
||||||
);
|
);
|
||||||
|
existing_node.monitoring = monitors.clone();
|
||||||
|
state_changed = true;
|
||||||
}
|
}
|
||||||
accepted_existing_node = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !accepted_existing_node {
|
if !address_map.contains_key(&edit.address) {
|
||||||
if let Some(existing_node) = address_map.values_mut().find(|node| node.ip == edit.ip) {
|
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 {
|
if existing_node.deleted_timestamp == 0 && edit.ip != GENESIS_IP {
|
||||||
penalize_duplicate_ip = true;
|
penalize_duplicate_ip = true;
|
||||||
|
|
@ -355,6 +358,7 @@ impl NodeInfo {
|
||||||
node
|
node
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
state_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -373,9 +377,11 @@ impl NodeInfo {
|
||||||
return RpcResponse::Binary(b"Error: Ip Already exists.".to_vec());
|
return RpcResponse::Binary(b"Error: Ip Already exists.".to_vec());
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::persist_recovery_snapshot("node add").await;
|
if state_changed {
|
||||||
|
Self::persist_recovery_snapshot("node add").await;
|
||||||
|
}
|
||||||
|
|
||||||
if !remote_ip.is_empty() {
|
if state_changed && !remote_ip.is_empty() {
|
||||||
let broadcast_map = map.clone();
|
let broadcast_map = map.clone();
|
||||||
let broadcast_edit = edit.clone();
|
let broadcast_edit = edit.clone();
|
||||||
let broadcast_remote_ip = remote_ip.clone();
|
let broadcast_remote_ip = remote_ip.clone();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue