Skip to content

Commit 030b19c

Browse files
authored
Merge pull request #9 from dfns/into_iter_including_me
Add `rounds_router::simple_store::RoundMsgs::into_iter_including_me()`
2 parents 53fca7f + 3d25bb9 commit 030b19c

File tree

7 files changed

+95
-3
lines changed

7 files changed

+95
-3
lines changed

.github/changelog.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
m_branch=m;
4+
changelog_file=CHANGELOG.md;
5+
6+
# fetch master since we might be in a shallow clone
7+
git fetch origin "$m_branch:$m_branch" --depth=1
8+
9+
changed=0;
10+
for log in */"$changelog_file"; do
11+
dir=$(dirname "$log");
12+
# check if version changed
13+
if git diff "$m_branch" -- "$dir/Cargo.toml" | grep -q "^-version = "; then
14+
# check if changelog updated
15+
if git diff --exit-code --no-patch "$m_branch" -- "$log"; then
16+
echo "$dir version changed, but $log is not updated"
17+
changed=1;
18+
fi
19+
fi
20+
done
21+
22+
exit "$changed";

.github/workflows/rust.yml

+7
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ jobs:
7474
- name: Build on wasm32-unknown-unknown (no_std)
7575
run:
7676
(cd wasm/no_std && cargo build --target wasm32-unknown-unknown)
77+
78+
check-changelog:
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v3
82+
- name: Check changelogs
83+
run: ./.github/changelog.sh

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

round-based/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.3.1
2+
* Add `rounds_router::simple_store::RoundMsgs::into_iter_including_me()` [#9]
3+
4+
[#9] https://github.com/dfns/round-based/pull/9
5+
16
## v0.3.0
27
* Add no_std and wasm support [#6]
38
* Add state machine wrapper that provides sync API to carry out the protocol defined as async function [#7]

round-based/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "round-based"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "Driver for MPC protocols"

round-based/src/rounds_router/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,6 @@ mod tests {
646646
let round1 = rounds.add_round(Store);
647647
let mut rounds = rounds.listen(incomings);
648648

649-
let _ = rounds.complete(round1).await.unwrap();
649+
rounds.complete(round1).await.unwrap();
650650
}
651651
}

round-based/src/rounds_router/simple_store.rs

+58
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,34 @@ impl<M> RoundMsgs<M> {
200200
.chain(self.messages.iter().skip(usize::from(self.i)))
201201
}
202202

203+
/// Returns iterator over received messages plus party's own message
204+
pub fn into_iter_including_me(self, my_msg: M) -> impl Iterator<Item = M> {
205+
struct InsertsAfter<T, It> {
206+
offset: usize,
207+
inner: It,
208+
item: Option<T>,
209+
}
210+
impl<T, It: Iterator<Item = T>> Iterator for InsertsAfter<T, It> {
211+
type Item = T;
212+
fn next(&mut self) -> Option<Self::Item> {
213+
if self.offset == 0 {
214+
match self.item.take() {
215+
Some(x) => Some(x),
216+
None => self.inner.next(),
217+
}
218+
} else {
219+
self.offset -= 1;
220+
self.inner.next()
221+
}
222+
}
223+
}
224+
InsertsAfter {
225+
offset: usize::from(self.i),
226+
inner: self.messages.into_iter(),
227+
item: Some(my_msg),
228+
}
229+
}
230+
203231
/// Returns iterator over messages with sender indexes
204232
///
205233
/// Iterator yields `(sender_index, msg_id, message)`
@@ -458,4 +486,34 @@ mod tests {
458486
})
459487
.unwrap();
460488
}
489+
490+
#[test]
491+
fn into_iter_including_me() {
492+
let me = -10_isize;
493+
let messages = alloc::vec![1, 2, 3];
494+
495+
let me_first = super::RoundMsgs {
496+
i: 0,
497+
ids: alloc::vec![1, 2, 3],
498+
messages: messages.clone(),
499+
};
500+
let all = me_first.into_iter_including_me(me).collect::<Vec<_>>();
501+
assert_eq!(all, [-10, 1, 2, 3]);
502+
503+
let me_second = super::RoundMsgs {
504+
i: 1,
505+
ids: alloc::vec![0, 2, 3],
506+
messages: messages.clone(),
507+
};
508+
let all = me_second.into_iter_including_me(me).collect::<Vec<_>>();
509+
assert_eq!(all, [1, -10, 2, 3]);
510+
511+
let me_last = super::RoundMsgs {
512+
i: 3,
513+
ids: alloc::vec![0, 1, 2],
514+
messages: messages.clone(),
515+
};
516+
let all = me_last.into_iter_including_me(me).collect::<Vec<_>>();
517+
assert_eq!(all, [1, 2, 3, -10]);
518+
}
461519
}

0 commit comments

Comments
 (0)