Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow triple memory only #594

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions node/src/protocol/presignature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ impl PresignatureManager {
pub fn take_mine(&mut self) -> Option<Presignature> {
tracing::info!(mine = ?self.mine, "my presignatures");
let my_presignature_id = self.mine.pop_front()?;
self.taken.insert(my_presignature_id, Instant::now());
Some(self.presignatures.remove(&my_presignature_id).unwrap())
self.take(my_presignature_id)
}

pub fn take(&mut self, id: PresignatureId) -> Option<Presignature> {
Expand Down
34 changes: 30 additions & 4 deletions node/src/protocol/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,15 @@ impl TripleManager {
Err(GenerationError::TripleIsMissing(id1))
}
} else {
self.delete_triple_from_storage(id0).await?;
self.delete_triple_from_storage(id1).await?;
// if we cannot find triples from storage, but we still have triples in memory, then we should still be able to take
// them, so the following storage errors can just be handled directly and warned to our logs.
if let Err(err) = self.delete_triple_from_storage(id0).await {
tracing::warn!(triple_id = id0, ?err, "unable to delete triple: potentially missing from datastore; deleting from memory only");
}
if let Err(err) = self.delete_triple_from_storage(id1).await {
tracing::warn!(triple_id = id1, ?err, "unable to delete triple: potentially missing from datastore; deleting from memory only");
}

self.taken.insert(id0, Instant::now());
self.taken.insert(id1, Instant::now());

Expand Down Expand Up @@ -301,12 +308,31 @@ impl TripleManager {

let take_two_result = self.take_two(id0, id1).await;
match take_two_result {
Err(error) => {
tracing::warn!(?error, "take_two failed in take_two_mine.");
Err(error)
if matches!(
error,
GenerationError::TripleIsMissing(_) | GenerationError::TripleIsGenerating(_)
) =>
{
tracing::warn!(
triple_id0 = id0,
triple_id1 = id1,
?error,
"unable to take two triples: one or both of the triples are missing/not-generated",
);
self.mine.push_front(id1);
self.mine.push_front(id0);
None
}
Err(error) => {
tracing::warn!(
triple_id0 = id0,
triple_id1 = id1,
?error,
"unexpected error encountered while taking two triples"
);
None
}
Ok(val) => Some(val),
}
}
Expand Down
13 changes: 2 additions & 11 deletions node/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,8 @@ impl ReshareProtocol {
me: Participant,
contract_state: &ResharingContractState,
) -> Result<Self, InitializationError> {
let old_participants = contract_state
.old_participants
.keys()
.cloned()
.collect::<Vec<_>>();

let new_participants = contract_state
.new_participants
.keys()
.cloned()
.collect::<Vec<_>>();
let old_participants = contract_state.old_participants.keys_vec();
let new_participants = contract_state.new_participants.keys_vec();

Ok(Self {
protocol: Arc::new(RwLock::new(Box::new(cait_sith::reshare::<Secp256k1>(
Expand Down
Loading