Add chain_tip to handshake message
This commit is contained in:
parent
7fea1d923e
commit
0543b6974a
@ -7,7 +7,7 @@ use std::{
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
sync::{Mutex, MutexGuard, OnceLock},
|
||||
sync::{atomic::AtomicU64, Mutex, MutexGuard, OnceLock},
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
static CHAIN_TIP: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub static FREEZED_UTXOS: OnceLock<Mutex<HashSet<OutPoint>>> = OnceLock::new();
|
||||
|
||||
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 members = lock_members().unwrap().clone();
|
||||
let current_tip = CHAIN_TIP.load(std::sync::atomic::Ordering::SeqCst);
|
||||
|
||||
let init_msg = HandshakeMessage::new(
|
||||
our_sp_address.to_string(),
|
||||
OutPointMemberMap(members),
|
||||
OutPointProcessMap(processes),
|
||||
current_tip,
|
||||
);
|
||||
|
||||
if let Err(e) = broadcast_message(
|
||||
@ -471,6 +475,9 @@ async fn main() -> Result<()> {
|
||||
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
|
||||
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::Commit => process_commit_message(ank_msg, addr),
|
||||
AnkFlag::Unknown => process_unknown_message(ank_msg, addr),
|
||||
AnkFlag::Sync => todo!(),
|
||||
AnkFlag::Handshake => log::debug!("Received init message from {}", addr),
|
||||
},
|
||||
Err(_) => log::error!("Failed to parse network message"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user