bug fixes

This commit is contained in:
viraladmin 2026-06-12 19:01:49 -06:00
parent 7181cc4e26
commit a40ec3a06e
3 changed files with 65 additions and 8 deletions

View File

@ -122,6 +122,7 @@ async fn reconnect_replacement_inner(excluded_ip: &str) {
db: context.db, db: context.db,
map: context.map, map: context.map,
first: false, first: false,
run_startup_sync: false,
}; };
if let Err(err) = bootstrap_peer_discovery(bootstrap_params).await { if let Err(err) = bootstrap_peer_discovery(bootstrap_params).await {

View File

@ -55,6 +55,7 @@ pub struct BootstrapParams {
pub db: Db, pub db: Db,
pub map: Arc<Mutex<Command>>, pub map: Arc<Mutex<Command>>,
pub first: bool, pub first: bool,
pub run_startup_sync: bool,
} }
pub fn spawn_bootstrap_peer_discovery(params: BootstrapParams) { pub fn spawn_bootstrap_peer_discovery(params: BootstrapParams) {
@ -69,8 +70,10 @@ pub fn spawn_bootstrap_peer_discovery(params: BootstrapParams) {
} }
pub async fn bootstrap_peer_discovery(mut params: BootstrapParams) -> Result<(), String> { pub async fn bootstrap_peer_discovery(mut params: BootstrapParams) -> Result<(), String> {
set_node_mode(NodeMode::Syncing); if params.run_startup_sync {
request_mining_stop(); set_node_mode(NodeMode::Syncing);
request_mining_stop();
}
let (_, _, local_endpoint) = get_ip_and_port().await; let (_, _, local_endpoint) = get_ip_and_port().await;
let max = SETTINGS.outgoing_connections; let max = SETTINGS.outgoing_connections;
let mut no_progress_count = 0; let mut no_progress_count = 0;
@ -157,6 +160,10 @@ pub async fn bootstrap_peer_discovery(mut params: BootstrapParams) -> Result<(),
} }
} }
if !params.run_startup_sync {
return Ok(());
}
loop { loop {
let local_height = get_height(&params.db); let local_height = get_height(&params.db);
let remote_height = let remote_height =
@ -398,6 +405,7 @@ pub async fn process_handshake_response(
db: params.db.clone(), db: params.db.clone(),
map: params.map.clone(), map: params.map.clone(),
first: params.first, first: params.first,
run_startup_sync: true,
}; };
spawn_bootstrap_peer_discovery(bsparams); spawn_bootstrap_peer_discovery(bsparams);

View File

@ -19,6 +19,14 @@ fn prefix_successor(prefix: &[u8]) -> Option<Vec<u8>> {
None None
} }
fn history_bounds(address_bytes: &[u8]) -> (Bound<Vec<u8>>, Bound<Vec<u8>>) {
let start = Bound::Included(address_bytes.to_vec());
let end = prefix_successor(address_bytes)
.map(Bound::Excluded)
.unwrap_or(Bound::Unbounded);
(start, end)
}
pub async fn lookup(address_bytes: Vec<u8>, skip: u32, limit: u32, db: &Db) -> RpcResponse { pub async fn lookup(address_bytes: Vec<u8>, skip: u32, limit: u32, db: &Db) -> RpcResponse {
if address_bytes.len() != Wallet::SHORT_ADDRESS_BYTES_LENGTH { if address_bytes.len() != Wallet::SHORT_ADDRESS_BYTES_LENGTH {
return RpcResponse::Binary(b"error: Invalid wallet address bytes".to_vec()); return RpcResponse::Binary(b"error: Invalid wallet address bytes".to_vec());
@ -38,16 +46,13 @@ pub async fn lookup(address_bytes: Vec<u8>, skip: u32, limit: u32, db: &Db) -> R
} }
}; };
let start = Bound::Included(address_bytes.clone()); let (start, end) = history_bounds(&address_bytes);
let end = prefix_successor(&address_bytes)
.map(Bound::Excluded)
.unwrap_or(Bound::Unbounded);
let mut skipped = 0usize; let mut skipped = 0usize;
let mut found = 0usize; let mut found = 0usize;
let mut txids = Vec::with_capacity(limit * TXID_LENGTH); let mut txids = Vec::with_capacity(limit * TXID_LENGTH);
for entry in tree.range((start, end)).rev() { for entry in tree.range((start, end)) {
let (_key, value) = match entry { let (_key, value) = match entry {
Ok(entry) => entry, Ok(entry) => entry,
Err(err) => { Err(err) => {
@ -77,5 +82,48 @@ pub async fn lookup(address_bytes: Vec<u8>, skip: u32, limit: u32, db: &Db) -> R
} }
pub async fn latest(address_bytes: Vec<u8>, limit: u32, db: &Db) -> RpcResponse { pub async fn latest(address_bytes: Vec<u8>, limit: u32, db: &Db) -> RpcResponse {
lookup(address_bytes, 0, limit, db).await if address_bytes.len() != Wallet::SHORT_ADDRESS_BYTES_LENGTH {
return RpcResponse::Binary(b"error: Invalid wallet address bytes".to_vec());
}
let limit = (limit as usize).min(MAX_ADDRESS_HISTORY_TXIDS);
if limit == 0 {
return RpcResponse::Binary(Vec::new());
}
let tree = match db.open_tree(WALLET_TX_INDEX_TREE) {
Ok(tree) => tree,
Err(err) => {
return RpcResponse::Binary(
format!("error: Failed to open wallet transaction index: {err}").into_bytes(),
);
}
};
let (start, end) = history_bounds(&address_bytes);
let mut found = 0usize;
let mut txids = Vec::with_capacity(limit * TXID_LENGTH);
for entry in tree.range((start, end)).rev() {
let (_key, value) = match entry {
Ok(entry) => entry,
Err(err) => {
return RpcResponse::Binary(
format!("error: Failed to read wallet transaction index: {err}").into_bytes(),
);
}
};
if value.len() != TXID_LENGTH {
continue;
}
txids.extend_from_slice(&value);
found += 1;
if found >= limit {
break;
}
}
RpcResponse::Binary(txids)
} }