fix: batch signed log sync imports

This commit is contained in:
Eric Wendland 2026-07-05 22:47:42 +02:00
commit 02969ac7af
3 changed files with 185 additions and 55 deletions

View file

@ -3328,6 +3328,7 @@ async fn keychain_sync_from_peer_since(
.into_iter()
.map(|signature| (signature.op_id, signature.signer, signature.namespace))
.collect::<BTreeSet<_>>();
let mut accepted_imports = Vec::new();
let mut ops_imported = 0;
let mut signatures_imported = 0;
let mut invalid_ops_rejected = 0;
@ -3358,10 +3359,8 @@ async fn keychain_sync_from_peer_since(
invalid_ops_rejected += 1;
continue;
}
let existing = load_keychain_ops(&store)?
.into_iter()
.find(|existing| existing.id == op.id);
if existing.as_ref().is_some_and(|existing| existing != &op) {
let existing = local_ops.iter().find(|existing| existing.id == op.id);
if existing.as_ref().is_some_and(|existing| *existing != &op) {
invalid_ops_rejected += 1;
continue;
}
@ -3369,10 +3368,6 @@ async fn keychain_sync_from_peer_since(
.iter()
.map(stored_keychain_signature_from_signature)
.collect::<Vec<_>>();
store.insert_keychain_op_with_signatures(
&stored_keychain_op_from_op(&op)?,
&stored_signatures,
)?;
if existing.is_none() {
local_ops.push(op.clone());
trusted_admins = geth_keychain::reduce_keychain_ops(&local_ops).admin_keys;
@ -3386,7 +3381,9 @@ async fn keychain_sync_from_peer_since(
);
signatures_imported += usize::from(known_signatures.insert(signature_key));
}
accepted_imports.push((stored_keychain_op_from_op(&op)?, stored_signatures));
}
store.insert_keychain_ops_with_signatures(&accepted_imports)?;
store_live_sync_cursor(&store, peer_node, "keychain", high_water_ms)?;
Ok(ControlResponse::KeychainSynced {
peer_node_id: node_id,
@ -3447,6 +3444,8 @@ async fn auth_sync_from_peer_since(
.into_iter()
.map(|signature| (signature.op_id, signature.signer, signature.namespace))
.collect::<BTreeSet<_>>();
let mut local_ops = load_auth_ops(&store)?;
let mut accepted_imports = Vec::new();
let mut ops_imported = 0;
let mut signatures_imported = 0;
let mut invalid_ops_rejected = 0;
@ -3477,10 +3476,8 @@ async fn auth_sync_from_peer_since(
invalid_ops_rejected += 1;
continue;
}
let existing = load_auth_ops(&store)?
.into_iter()
.find(|existing| existing.id == op.id);
if existing.as_ref().is_some_and(|existing| existing != &op) {
let existing = local_ops.iter().find(|existing| existing.id == op.id);
if existing.as_ref().is_some_and(|existing| *existing != &op) {
invalid_ops_rejected += 1;
continue;
}
@ -3488,11 +3485,10 @@ async fn auth_sync_from_peer_since(
.iter()
.map(stored_auth_signature_from_signature)
.collect::<Vec<_>>();
store.insert_auth_op_with_signatures(
&stored_auth_op_from_op(&op)?,
&stored_signatures,
)?;
ops_imported += usize::from(existing.is_none());
if existing.is_none() {
local_ops.push(op.clone());
ops_imported += 1;
}
for signature in valid_signatures {
let signature_key = (
signature.op_id.to_string(),
@ -3501,7 +3497,9 @@ async fn auth_sync_from_peer_since(
);
signatures_imported += usize::from(known_signatures.insert(signature_key));
}
accepted_imports.push((stored_auth_op_from_op(&op)?, stored_signatures));
}
store.insert_auth_ops_with_signatures(&accepted_imports)?;
store_live_sync_cursor(&store, peer_node, "auth", high_water_ms)?;
Ok(ControlResponse::AuthSynced {
peer_node_id: node_id,