Skip to content

Commit

Permalink
fix: broadcast witness receipts to all witnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak committed Apr 30, 2024
1 parent 61a48fc commit 925fdb0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 2 additions & 3 deletions components/controller/src/identifier/broadcast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use keri_core::{
error::Error,
event_message::{
signature::Nontransferable,
signed_event_message::{Message, Notice, SignedNontransferableReceipt},
Expand Down Expand Up @@ -80,7 +81,7 @@ impl Identifier {
fn get_wit_ids_of_rct(
&self,
rct: &SignedNontransferableReceipt,
) -> Result<Vec<BasicPrefix>, ControllerError> {
) -> Result<Vec<BasicPrefix>, Error> {
let mut wit_ids = Vec::new();
for sig in &rct.signatures {
match sig {
Expand Down Expand Up @@ -213,8 +214,6 @@ mod test {
}

assert_eq!(identifier.notify_witnesses().await?, 0);
assert_eq!(identifier.broadcast_receipts(&wit_ids).await?, 2);
assert_eq!(identifier.broadcast_receipts(&wit_ids).await?, 0);

assert!(matches!(
witness1.witness_data.event_storage.get_kel_messages_with_receipts(&identifier.id, None)?.unwrap().as_slice(),
Expand Down
8 changes: 6 additions & 2 deletions components/controller/src/identifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ impl Identifier {
self.known_events.current_public_keys(&self.id)
}

pub fn witnesses(&self) -> Vec<BasicPrefix> {
self.cached_state.witness_config.witnesses.clone()
pub fn witnesses(&self) -> impl Iterator<Item = BasicPrefix> {
self.cached_state
.witness_config
.witnesses
.clone()
.into_iter()
}

pub fn watchers(&self) -> Result<Vec<IdentifierPrefix>, ControllerError> {
Expand Down
7 changes: 6 additions & 1 deletion components/controller/src/identifier/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Identifier {
/// process its response. If user action is needed to finalize process,
/// returns proper notification.
pub async fn finalize_query(
&self,
&mut self,
queries: Vec<(QueryEvent, SelfSigningPrefix)>,
) -> Result<Vec<ActionRequired>, ControllerError> {
let self_id = self.id.clone();
Expand Down Expand Up @@ -128,6 +128,11 @@ impl Identifier {
.mailbox_response(&recipient.unwrap(), from_who, about_who, &mbx)
.await?,
);
let witnesses = self
.witnesses()
.map(|bp| IdentifierPrefix::Basic(bp))
.collect::<Vec<_>>();
self.broadcast_receipts(&witnesses).await?;
}
}
PossibleResponse::Ksn(_) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion keriox_tests/tests/test_witness_rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async fn test_witness_rotation() -> Result<(), ControllerError> {
.finalize_event(rotation_event.as_bytes(), signature)
.await?;

let cached_witnesses = &identifier.witnesses();
let cached_witnesses = &identifier.witnesses().collect::<Vec<_>>();
// dbg!(&cached_witnesses);
let state = identifier.find_state(identifier.id())?;
// Missing witness receipts, so rotation is not accepted yet.
Expand Down

0 comments on commit 925fdb0

Please # to comment.