Skip to content

Commit

Permalink
Better loggin and include stable_filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticTempest committed Aug 7, 2024
1 parent eae6420 commit e967e83
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 107 deletions.
15 changes: 4 additions & 11 deletions chain-signatures/node/src/mesh/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,13 @@ impl Pool {
continue;
};

let mut req = self
.http
.get(url.clone());
let mut req = self.http.get(url.clone());

if !params.is_empty() {
req = req
.header("content-type", "application/json")
.json(&params);
req = req.header("content-type", "application/json").json(&params);
}

let resp = match req
.send()
.await
{
let resp = match req.send().await {
Ok(resp) => resp,
Err(err) => {
tracing::warn!(
Expand Down Expand Up @@ -187,7 +180,7 @@ impl Pool {
.get(participant)
.map_or(false, |state| match state {
StateView::Running { is_stable, .. } => *is_stable,
StateView::Resharing { is_stable,.. } => *is_stable,
StateView::Resharing { is_stable, .. } => *is_stable,
_ => false,
})
}
Expand Down
166 changes: 91 additions & 75 deletions chain-signatures/node/src/protocol/presignature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,95 +260,111 @@ impl PresignatureManager {
triple_manager: &mut TripleManager,
cfg: &ProtocolConfig,
) -> Result<(), InitializationError> {
let not_enough_presignatures = {
let enough_presignatures = {
// Stopgap to prevent too many presignatures in the system. This should be around min_presig*nodes*2
// for good measure so that we have enough presignatures to do sig generation while also maintain
// the minimum number of presignature where a single node can't flood the system.
if self.potential_len() >= cfg.presignature.max_presignatures as usize {
if self.potential_len() < cfg.presignature.max_presignatures as usize {
false
} else {
// We will always try to generate a new triple if we have less than the minimum
self.my_len() < cfg.presignature.min_presignatures as usize
&& self.introduced.len() < cfg.max_concurrent_introduction as usize
self.my_len() >= cfg.presignature.min_presignatures as usize
|| self.introduced.len() >= cfg.max_concurrent_introduction as usize
}
};

if not_enough_presignatures {
// To ensure there is no contention between different nodes we are only using triples
// that we proposed. This way in a non-BFT environment we are guaranteed to never try
// to use the same triple as any other node.
if let Some((triple0, triple1)) = triple_manager.peek_two_mine() {
let id0 = triple0.id;
let id1 = triple1.id;
let presig_participants = active
.intersection(&[&triple0.public.participants, &triple1.public.participants]);
if presig_participants.len() < self.threshold {
tracing::warn!(
id0,
id1,
participants = ?presig_participants.keys_vec(),
"running: participants are not above threshold for presignature generation"
);
return Ok(());
}

let state_views = presig_participants
.iter()
.filter_map(|(p, _)| Some((*p, state_views.get(p)?)));

// Filter out the active participants with the state views that have the triples we want to use.
let active_filtered = state_views
.filter(|(_, state_view)| {
if let StateView::Running {
triple_postview, ..
} = state_view
{
triple_postview.contains(&triple0.id)
&& triple_postview.contains(&triple1.id)
} else {
false
}
})
.map(|(p, _)| p)
.collect::<Vec<_>>();

if active_filtered.len() < self.threshold {
tracing::debug!(
id0,
id1,
participants = ?presig_participants.keys_vec(),
"running: we don't have enough participants to generate a presignature"
);
return Ok(());
}
if enough_presignatures {
return Ok(());
}

// Actually take the triples now that we have done the necessary checks.
let Some((triple0, triple1)) = triple_manager.take_two_mine().await else {
tracing::warn!("running: popping after peeking should have succeeded");
return Ok(());
};
// To ensure there is no contention between different nodes we are only using triples
// that we proposed. This way in a non-BFT environment we are guaranteed to never try
// to use the same triple as any other node.
let Some((triple0, triple1)) = triple_manager.peek_two_mine() else {
tracing::debug!(
triple_mine = triple_manager.my_len(),
triple_potential = triple_manager.potential_len(),
"running: we don't have enough triples to generate a presignature"
);
return Ok(());
};
let id0 = triple0.id;
let id1 = triple1.id;
let presig_participants =
active.intersection(&[&triple0.public.participants, &triple1.public.participants]);
if presig_participants.len() < self.threshold {
tracing::warn!(
id0,
id1,
threshold = self.threshold,
triple0 = ?triple0.public.participants,
triple1 = ?triple1.public.participants,
active = ?active.keys_vec(),
"running: participants are not above threshold for presignature generation"
);
return Ok(());
}

if let Err(err @ InitializationError::BadParameters(_)) = self.generate(
&active_filtered,
triple0,
triple1,
pk,
sk_share,
cfg.presignature.generation_timeout,
) {
tracing::warn!(
id0,
id1,
?err,
"we had to trash two triples due to bad parameters"
);
return Err(err);
// Filter out the active participants with the state views that have the triples we want to use.
let active_filtered = presig_participants
.iter()
.filter_map(|(p, _)| Some((*p, state_views.get(p)?)))
.filter(|(_, state_view)| {
if let StateView::Running {
triple_postview, ..
} = state_view
{
triple_postview.contains(&triple0.id) && triple_postview.contains(&triple1.id)
} else {
false
}
} else {
tracing::debug!("running: we don't have enough triples to generate a presignature");
}
})
.map(|(p, _)| p)
.collect::<Vec<_>>();

if active_filtered.len() < self.threshold {
tracing::warn!(
id0,
id1,
threshold = self.threshold,
triple0 = ?triple0.public.participants,
triple1 = ?triple1.public.participants,
active = ?active.keys_vec(),
?active_filtered,
?state_views,
"running: we don't have enough participants to generate a presignature"
);
return Ok(());
}

// Actually take the triples now that we have done the necessary checks.
let Some((triple0, triple1)) = triple_manager.take_two_mine().await else {
tracing::warn!(
id0,
id1,
potential = triple_manager.potential_len(),
"running: popping after peeking should have succeeded",
);
return Ok(());
};

if let Err(err @ InitializationError::BadParameters(_)) = self.generate(
&active_filtered,
triple0,
triple1,
pk,
sk_share,
cfg.presignature.generation_timeout,
) {
tracing::warn!(
id0,
id1,
?err,
?active_filtered,
"we had to trash two triples due to bad parameters"
);
return Err(err);
}
Ok(())
}

Expand Down
Loading

0 comments on commit e967e83

Please sign in to comment.