diff options
Diffstat (limited to 'src/federation/fold.rs')
| -rw-r--r-- | src/federation/fold.rs | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/federation/fold.rs b/src/federation/fold.rs index b96cf1f..b590f07 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -559,33 +559,44 @@ impl State { return Err(Refused::new("its proposal isn't proposed on that version")); } if *yes { - let backed: BTreeSet<Id> = self - .signed() - .filter_map(|(_, other, _)| match &other.does { - Does::Vote { - on: voted_on, - proposal: voted, - yes: true, - } if other.party == signed.party - && voted_on == on - && voted != proposal => - { - Some(*voted) - } - _ => None, - }) - .collect(); - if backed.iter().any(|other| !self.tally(current, other).dead) { - return Err(Refused::new( - "its party backs another proposal on that version, not dead", - )); - } + self.may_back(&signed.party, proposal, current)?; } Ok(()) } } } + /// Whether a `true` of `party` on the proposal of hash `proposal` on `current` is + /// taken here, as far as its party's other votes go: none of its `true`s on another + /// proposal on that version but on one dead here. A node asks it at the history its + /// vote would build on (`Store::state_at`), before it casts one. + pub(crate) fn may_back( + &self, + party: &str, + proposal: &Id, + current: &Version, + ) -> Result<(), Refused> { + let backed: BTreeSet<Id> = self + .signed() + .filter_map(|(_, other, _)| match &other.does { + Does::Vote { + on, + proposal: voted, + yes: true, + } if other.party == party && *on == current.hash && voted != proposal => { + Some(*voted) + } + _ => None, + }) + .collect(); + if backed.iter().any(|other| !self.tally(current, other).dead) { + return Err(Refused::new( + "its party backs another proposal on that version, not dead", + )); + } + Ok(()) + } + /// Whether a version event is taken here, at its history, `current` the version current /// there. One whose proposal passed but doesn't read as a version, it doesn't refuse: /// a later continuum may read it (`Fold::stops`). |
