Add chain_tip to handshake message
This commit is contained in:
parent
7633c07e2f
commit
c3a58ed020
@ -7,7 +7,7 @@ use std::{
|
|||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
sync::{Mutex, MutexGuard, OnceLock},
|
sync::{atomic::AtomicU64, Mutex, MutexGuard, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use bitcoincore_rpc::{
|
use bitcoincore_rpc::{
|
||||||
@ -77,6 +77,8 @@ pub(crate) static PEERMAP: OnceLock<PeerMap> = OnceLock::new();
|
|||||||
|
|
||||||
pub(crate) static DAEMON: OnceLock<Mutex<Box<dyn RpcCall>>> = OnceLock::new();
|
pub(crate) static DAEMON: OnceLock<Mutex<Box<dyn RpcCall>>> = OnceLock::new();
|
||||||
|
|
||||||
|
static CHAIN_TIP: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
pub static FREEZED_UTXOS: OnceLock<Mutex<HashSet<OutPoint>>> = OnceLock::new();
|
pub static FREEZED_UTXOS: OnceLock<Mutex<HashSet<OutPoint>>> = OnceLock::new();
|
||||||
|
|
||||||
pub fn lock_freezed_utxos() -> Result<MutexGuard<'static, HashSet<OutPoint>>, Error> {
|
pub fn lock_freezed_utxos() -> Result<MutexGuard<'static, HashSet<OutPoint>>, Error> {
|
||||||
@ -197,11 +199,13 @@ async fn handle_connection(
|
|||||||
|
|
||||||
let processes = lock_processes().unwrap().clone();
|
let processes = lock_processes().unwrap().clone();
|
||||||
let members = lock_members().unwrap().clone();
|
let members = lock_members().unwrap().clone();
|
||||||
|
let current_tip = CHAIN_TIP.load(std::sync::atomic::Ordering::SeqCst);
|
||||||
|
|
||||||
let init_msg = HandshakeMessage::new(
|
let init_msg = HandshakeMessage::new(
|
||||||
our_sp_address.to_string(),
|
our_sp_address.to_string(),
|
||||||
OutPointMemberMap(members),
|
OutPointMemberMap(members),
|
||||||
OutPointProcessMap(processes),
|
OutPointProcessMap(processes),
|
||||||
|
current_tip,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Err(e) = broadcast_message(
|
if let Err(e) = broadcast_message(
|
||||||
@ -471,6 +475,9 @@ async fn main() -> Result<()> {
|
|||||||
scan_blocks(current_tip - last_scan, &config.electrum_url)?;
|
scan_blocks(current_tip - last_scan, &config.electrum_url)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set CHAIN_TIP
|
||||||
|
CHAIN_TIP.store(current_tip as u64, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
|
||||||
// Subscribe to Bitcoin Core
|
// Subscribe to Bitcoin Core
|
||||||
tokio::spawn(handle_zmq(config.zmq_url, config.electrum_url));
|
tokio::spawn(handle_zmq(config.zmq_url, config.electrum_url));
|
||||||
|
|
||||||
|
@ -226,6 +226,7 @@ pub fn process_message(raw_msg: &str, addr: SocketAddr) {
|
|||||||
AnkFlag::Cipher => process_cipher_message(ank_msg, addr),
|
AnkFlag::Cipher => process_cipher_message(ank_msg, addr),
|
||||||
AnkFlag::Commit => process_commit_message(ank_msg, addr),
|
AnkFlag::Commit => process_commit_message(ank_msg, addr),
|
||||||
AnkFlag::Unknown => process_unknown_message(ank_msg, addr),
|
AnkFlag::Unknown => process_unknown_message(ank_msg, addr),
|
||||||
|
AnkFlag::Sync => todo!(),
|
||||||
AnkFlag::Handshake => log::debug!("Received init message from {}", addr),
|
AnkFlag::Handshake => log::debug!("Received init message from {}", addr),
|
||||||
},
|
},
|
||||||
Err(_) => log::error!("Failed to parse network message"),
|
Err(_) => log::error!("Failed to parse network message"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user