diff options
Diffstat (limited to 'src/federation/version.rs')
| -rw-r--r-- | src/federation/version.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/federation/version.rs b/src/federation/version.rs index d714a47..378e122 100644 --- a/src/federation/version.rs +++ b/src/federation/version.rs @@ -16,6 +16,11 @@ pub(crate) const KEYS: usize = 16; /// Nodes a node list may name. pub(crate) const NODES: usize = 64; +/// Parties a version may name: a version event names the votes passing a proposal, two +/// thirds of its version's parties, and an event names no more than 64 events +/// (`event::DEPENDENCIES`). +pub(crate) const PARTIES: usize = 96; + /// Segments a path may have, and bytes a segment. pub(crate) const SEGMENTS: usize = 32; pub(crate) const SEGMENT_BYTES: usize = 255; @@ -210,6 +215,12 @@ impl Version { if keys.names().is_empty() { return Err("no party".to_owned()); } + if keys.names().len() > PARTIES { + return Err(format!( + "{} parties, more than {PARTIES}", + keys.names().len() + )); + } let mut parties = BTreeMap::new(); let mut every_key = BTreeSet::new(); for name in keys.names() { @@ -534,6 +545,20 @@ mod tests { ); } + /// A version names no more parties than a version event may name the votes of two + /// thirds of. + #[test] + fn a_version_names_at_most_96_parties() { + use super::super::harness::{Party, Spec}; + let parties: Vec<Party> = (1..=PARTIES as u8 + 1) + .map(|n| Party::new(&format!("p{n}"), n)) + .collect(); + let named: Vec<&Party> = parties.iter().collect(); + assert!(Version::read(&Spec::first(&named[1..], &[]).json()).is_ok()); + let why = Version::read(&Spec::first(&named, &[]).json()).unwrap_err(); + assert_eq!(why, "97 parties, more than 96"); + } + #[test] fn a_version_changes_another_by_its_number_hash_and_sinces() { let first = Version::read(&first()).expect("a version"); |
