From c5eb9d624f919ed24df67292cf83bac7407de116 Mon Sep 17 00:00:00 2001 From: timorleph Date: Mon, 9 Dec 2024 11:21:39 +0100 Subject: [PATCH 1/5] Add ABFT performance scorer --- .../src/abft/current/performance/mod.rs | 1 + .../src/abft/current/performance/scorer.rs | 155 ++++++++++++++++++ .../src/abft/current/performance/service.rs | 27 ++- finality-aleph/src/abft/traits.rs | 7 + finality-aleph/src/party/manager/mod.rs | 2 +- 5 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 finality-aleph/src/abft/current/performance/scorer.rs diff --git a/finality-aleph/src/abft/current/performance/mod.rs b/finality-aleph/src/abft/current/performance/mod.rs index cb05b0369d..5cc4e4175e 100644 --- a/finality-aleph/src/abft/current/performance/mod.rs +++ b/finality-aleph/src/abft/current/performance/mod.rs @@ -1,5 +1,6 @@ use crate::{data_io::AlephData, Hasher}; +mod scorer; mod service; pub use service::Service; diff --git a/finality-aleph/src/abft/current/performance/scorer.rs b/finality-aleph/src/abft/current/performance/scorer.rs new file mode 100644 index 0000000000..46ef5b8815 --- /dev/null +++ b/finality-aleph/src/abft/current/performance/scorer.rs @@ -0,0 +1,155 @@ +use current_aleph_bft::{NodeCount, NodeMap, Round}; + +use crate::{abft::current::performance::Batch, UnverifiedHeader}; + +pub type Score = Vec; + +/// Scoring ABFT performance based on returned ordered unit batches. +pub struct Scorer { + newest_unit_by: NodeMap, +} + +impl Scorer { + /// Create a new scorer for the provided node count. + pub fn new(node_count: NodeCount) -> Self { + Scorer { + newest_unit_by: NodeMap::with_size(node_count), + } + } + + /// Add a batch of ordered units and return a score consisting of numbers of rounds a specific + /// node is behind. + pub fn process_batch(&mut self, batch: Batch) -> Score { + let max_round = batch.last().expect("batches always contain a head").round; + for unit in batch { + // Units are always added in order, so any unit created by an honest node + // here has a round greater than any that was included earlier. + // This is not necessarily true for forkers, but punishing them is fine. + self.newest_unit_by.insert(unit.creator, unit.round) + } + self.newest_unit_by + .size() + .into_iterator() + .map(|node_id| { + self.newest_unit_by + .get(node_id) + // All other units have lower round than head, so the saturating_sub is just + // subtraction. + .map(|unit_round| max_round.saturating_sub(*unit_round)) + // If we don't have a unit it's the same as having a unit of round -1. + .unwrap_or(max_round + 1) + }) + .collect() + } +} + +#[cfg(test)] +mod tests { + use std::iter; + + use current_aleph_bft::{NodeCount, OrderedUnit, Round}; + + use super::Scorer; + use crate::{block::mock::MockHeader, data_io::AlephData, Hasher}; + + const NODE_COUNT: NodeCount = NodeCount(7); + + fn units_up_to(max_round: Round) -> Vec, Hasher>>> { + let mut result = Vec::new(); + for round in 0..=max_round { + let mut round_units = Vec::new(); + for creator in NODE_COUNT.into_iterator() { + round_units.push(OrderedUnit { + data: None, + // We ignore the parents, so just putting nothing here. + parents: Vec::new(), + hash: Hasher::random_hash(), + creator, + round, + }); + } + result.push(round_units); + } + result + } + + #[test] + fn processes_initial_batch() { + let mut scorer = Scorer::new(NODE_COUNT); + let unit = units_up_to(0) + .pop() + .expect("there is a round") + .pop() + .expect("there is a unit"); + assert_eq!(scorer.process_batch(vec![unit]), vec![1, 1, 1, 1, 1, 1, 0]); + } + + #[test] + fn processes_perfect_performance_batch() { + let mut scorer = Scorer::new(NODE_COUNT); + let mut all_units = units_up_to(1); + let mut round_one_units = all_units.pop().expect("just created"); + let mut round_zero_units = all_units.pop().expect("just created"); + let first_head = round_zero_units.pop().expect("there is a unit"); + assert_eq!( + scorer.process_batch(vec![first_head]), + vec![1, 1, 1, 1, 1, 1, 0] + ); + let second_head = round_one_units.pop().expect("there is a unit"); + round_zero_units.push(second_head); + assert_eq!( + scorer.process_batch(round_zero_units), + vec![1, 1, 1, 1, 1, 1, 0] + ); + } + + #[test] + fn processes_lacking_creator_batch() { + let mut scorer = Scorer::new(NODE_COUNT); + let mut all_units = units_up_to(1); + let mut round_one_units = all_units.pop().expect("just created"); + round_one_units.pop(); + let mut round_zero_units = all_units.pop().expect("just created"); + round_zero_units.pop(); + let first_head = round_zero_units.pop().expect("there is a unit"); + assert_eq!( + scorer.process_batch(vec![first_head]), + vec![1, 1, 1, 1, 1, 0, 1] + ); + let second_head = round_one_units.pop().expect("there is a unit"); + round_zero_units.push(second_head); + assert_eq!( + scorer.process_batch(round_zero_units), + vec![1, 1, 1, 1, 1, 0, 2] + ); + } + + #[test] + fn processes_lagging_creator_batch() { + let mut scorer = Scorer::new(NODE_COUNT); + let mut all_units = units_up_to(2); + let mut round_two_units = all_units.pop().expect("just created"); + round_two_units.pop(); + let mut round_one_units = all_units.pop().expect("just created"); + round_one_units.pop(); + let mut round_zero_units = all_units.pop().expect("just created"); + let lagged_unit = round_zero_units.pop().expect("just created"); + let first_head = round_zero_units.pop().expect("there is a unit"); + assert_eq!( + scorer.process_batch(vec![first_head]), + vec![1, 1, 1, 1, 1, 0, 1] + ); + let second_head = round_one_units.pop().expect("there is a unit"); + round_zero_units.push(second_head); + assert_eq!( + scorer.process_batch(round_zero_units), + vec![1, 1, 1, 1, 1, 0, 2] + ); + let third_head = round_two_units.pop().expect("there is a unit"); + let third_batch = iter::once(lagged_unit) + .chain(round_one_units) + .chain(iter::once(third_head)) + .collect(); + assert_eq!(scorer.process_batch(third_batch), vec![1, 1, 1, 1, 1, 0, 2]); + } +} diff --git a/finality-aleph/src/abft/current/performance/service.rs b/finality-aleph/src/abft/current/performance/service.rs index 8a55c7e63e..88928f8da2 100644 --- a/finality-aleph/src/abft/current/performance/service.rs +++ b/finality-aleph/src/abft/current/performance/service.rs @@ -1,11 +1,15 @@ +use current_aleph_bft::NodeCount; use futures::{ channel::{mpsc, oneshot}, StreamExt, }; -use log::{debug, warn}; +use log::{debug, error, warn}; use crate::{ - abft::{current::performance::Batch, LOG_TARGET}, + abft::{ + current::performance::{scorer::Scorer, Batch}, + LOG_TARGET, + }, data_io::AlephData, party::manager::Runnable, Hasher, UnverifiedHeader, @@ -59,6 +63,7 @@ where UH: UnverifiedHeader, { batches_from_abft: mpsc::UnboundedReceiver>, + scorer: Scorer, } impl Service @@ -68,6 +73,7 @@ where /// Create a new service, together with a unit finalization handler that should be passed to /// ABFT. It will wrap the provided finalization handler and call it in the background. pub fn new( + n_members: usize, finalization_handler: FH, ) -> ( Self, @@ -78,7 +84,10 @@ where { let (batches_for_us, batches_from_abft) = mpsc::unbounded(); ( - Service { batches_from_abft }, + Service { + batches_from_abft, + scorer: Scorer::new(NodeCount(n_members)), + }, FinalizationWrapper::new(finalization_handler, batches_for_us), ) } @@ -92,8 +101,16 @@ where async fn run(mut self, mut exit: oneshot::Receiver<()>) { loop { tokio::select! { - _maybe_batch = self.batches_from_abft.next() => { - // TODO(A0-4575): actually compute the score form batches etc + maybe_batch = self.batches_from_abft.next() => { + let score = match maybe_batch { + Some(batch) => self.scorer.process_batch(batch), + None => { + error!(target: LOG_TARGET, "Batches' channel closed, ABFT performance scoring terminating."); + break; + }, + }; + debug!(target: LOG_TARGET, "Received ABFT score: {:?}.", score); + // TODO(A0-4339): sometimes submit these scores to the chain. } _ = &mut exit => { debug!(target: LOG_TARGET, "ABFT performance scoring task received exit signal. Terminating."); diff --git a/finality-aleph/src/abft/traits.rs b/finality-aleph/src/abft/traits.rs index 8f65f4a4ee..098584b8e5 100644 --- a/finality-aleph/src/abft/traits.rs +++ b/finality-aleph/src/abft/traits.rs @@ -50,6 +50,13 @@ impl Wrapper { inner: ::hash(s), } } + + #[cfg(test)] + pub fn random_hash() -> OrdForHash { + use rand::distributions::{Alphanumeric, DistString}; + let string = Alphanumeric.sample_string(&mut rand::thread_rng(), 137); + Self::hash(string.as_ref()) + } } impl current_aleph_bft::Hasher for Wrapper { diff --git a/finality-aleph/src/party/manager/mod.rs b/finality-aleph/src/party/manager/mod.rs index 8f98a20e88..82fdb4fcae 100644 --- a/finality-aleph/src/party/manager/mod.rs +++ b/finality-aleph/src/party/manager/mod.rs @@ -275,7 +275,7 @@ where session_boundaries.clone(), ); let (abft_performance, abft_batch_handler) = - CurrentPerformanceService::new(ordered_data_interpreter); + CurrentPerformanceService::new(n_members, ordered_data_interpreter); let consensus_config = current_create_aleph_config(n_members, node_id, session_id, self.unit_creation_delay); let data_network = data_network.map(); From 06353438d357ae97fa505fee3e0d58833103b9fd Mon Sep 17 00:00:00 2001 From: timorleph Date: Mon, 9 Dec 2024 13:05:57 +0100 Subject: [PATCH 2/5] Connect to primitives --- finality-aleph/src/abft/current/performance/scorer.rs | 6 ++---- primitives/src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/finality-aleph/src/abft/current/performance/scorer.rs b/finality-aleph/src/abft/current/performance/scorer.rs index 46ef5b8815..06fec5b0bf 100644 --- a/finality-aleph/src/abft/current/performance/scorer.rs +++ b/finality-aleph/src/abft/current/performance/scorer.rs @@ -1,8 +1,6 @@ use current_aleph_bft::{NodeCount, NodeMap, Round}; -use crate::{abft::current::performance::Batch, UnverifiedHeader}; - -pub type Score = Vec; +use crate::{abft::current::performance::Batch, aleph_primitives::RawScore, UnverifiedHeader}; /// Scoring ABFT performance based on returned ordered unit batches. pub struct Scorer { @@ -19,7 +17,7 @@ impl Scorer { /// Add a batch of ordered units and return a score consisting of numbers of rounds a specific /// node is behind. - pub fn process_batch(&mut self, batch: Batch) -> Score { + pub fn process_batch(&mut self, batch: Batch) -> RawScore { let max_round = batch.last().expect("batches always contain a head").round; for unit in batch { // Units are always added in order, so any unit created by an honest node diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index f0759a4d37..eff8d20e9e 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -416,11 +416,13 @@ pub mod staking { pub type ScoreNonce = u32; +pub type RawScore = Vec; + #[derive(PartialEq, Decode, Encode, TypeInfo, Debug, Clone)] pub struct Score { pub session_id: SessionIndex, pub nonce: ScoreNonce, - pub points: Vec, + pub points: RawScore, } pub mod crypto { From 0a4ed1513bea60afe31e14b65c70a35ff0390cef Mon Sep 17 00:00:00 2001 From: timorleph Date: Mon, 9 Dec 2024 13:11:00 +0100 Subject: [PATCH 3/5] Minor comment improvement --- finality-aleph/src/abft/current/performance/scorer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/finality-aleph/src/abft/current/performance/scorer.rs b/finality-aleph/src/abft/current/performance/scorer.rs index 06fec5b0bf..8aa6bc9af1 100644 --- a/finality-aleph/src/abft/current/performance/scorer.rs +++ b/finality-aleph/src/abft/current/performance/scorer.rs @@ -34,7 +34,7 @@ impl Scorer { // All other units have lower round than head, so the saturating_sub is just // subtraction. .map(|unit_round| max_round.saturating_sub(*unit_round)) - // If we don't have a unit it's the same as having a unit of round -1. + // If we don't have a unit it's the same as having a unit of round equal to -1. .unwrap_or(max_round + 1) }) .collect() From 1ebae4ddf5e95f492ed74541889182f92817393b Mon Sep 17 00:00:00 2001 From: timorleph Date: Mon, 9 Dec 2024 15:01:57 +0100 Subject: [PATCH 4/5] Update the client file --- aleph-client/src/aleph_zero.rs | 156 ++++++++++++++++----------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/aleph-client/src/aleph_zero.rs b/aleph-client/src/aleph_zero.rs index 0e17416899..0896be163a 100644 --- a/aleph-client/src/aleph_zero.rs +++ b/aleph-client/src/aleph_zero.rs @@ -1223,10 +1223,10 @@ pub mod api { "submit_abft_score", types::SubmitAbftScore { score, signature }, [ - 140u8, 93u8, 130u8, 205u8, 26u8, 91u8, 15u8, 42u8, 114u8, 53u8, 228u8, - 197u8, 231u8, 224u8, 63u8, 33u8, 244u8, 230u8, 47u8, 139u8, 127u8, - 145u8, 125u8, 127u8, 28u8, 177u8, 132u8, 104u8, 99u8, 65u8, 170u8, - 49u8, + 2u8, 222u8, 25u8, 52u8, 171u8, 188u8, 243u8, 151u8, 79u8, 219u8, 153u8, + 246u8, 149u8, 159u8, 214u8, 78u8, 247u8, 43u8, 107u8, 218u8, 223u8, + 42u8, 58u8, 172u8, 75u8, 223u8, 149u8, 178u8, 201u8, 140u8, 63u8, + 108u8, ], ) } @@ -2180,9 +2180,9 @@ pub mod api { .hash(); runtime_metadata_hash == [ - 189u8, 1u8, 127u8, 19u8, 36u8, 11u8, 205u8, 128u8, 195u8, 127u8, 6u8, 242u8, 133u8, - 40u8, 178u8, 27u8, 175u8, 202u8, 182u8, 173u8, 177u8, 211u8, 114u8, 209u8, 204u8, - 250u8, 176u8, 221u8, 20u8, 78u8, 100u8, 101u8, + 100u8, 173u8, 14u8, 49u8, 85u8, 234u8, 174u8, 22u8, 137u8, 99u8, 161u8, 103u8, + 73u8, 89u8, 78u8, 227u8, 43u8, 154u8, 150u8, 230u8, 196u8, 58u8, 237u8, 181u8, + 68u8, 115u8, 44u8, 137u8, 6u8, 58u8, 165u8, 87u8, ] } pub mod system { @@ -3582,10 +3582,9 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 216u8, 135u8, 112u8, 25u8, 28u8, 96u8, 254u8, 189u8, 10u8, 68u8, 63u8, - 70u8, 129u8, 143u8, 24u8, 224u8, 139u8, 138u8, 101u8, 9u8, 195u8, - 254u8, 122u8, 234u8, 111u8, 149u8, 196u8, 215u8, 158u8, 234u8, 249u8, - 91u8, + 43u8, 245u8, 152u8, 130u8, 251u8, 206u8, 49u8, 1u8, 2u8, 9u8, 234u8, + 102u8, 148u8, 181u8, 182u8, 56u8, 116u8, 119u8, 164u8, 187u8, 161u8, + 245u8, 127u8, 137u8, 47u8, 1u8, 60u8, 77u8, 76u8, 229u8, 221u8, 34u8, ], ) } @@ -3630,9 +3629,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 129u8, 97u8, 124u8, 53u8, 208u8, 77u8, 131u8, 116u8, 124u8, 70u8, - 107u8, 152u8, 57u8, 6u8, 26u8, 80u8, 242u8, 228u8, 193u8, 197u8, 141u8, - 32u8, 217u8, 156u8, 58u8, 188u8, 78u8, 49u8, 122u8, 109u8, 108u8, 90u8, + 190u8, 254u8, 174u8, 127u8, 71u8, 58u8, 206u8, 226u8, 48u8, 67u8, + 212u8, 121u8, 139u8, 234u8, 40u8, 251u8, 204u8, 54u8, 124u8, 5u8, 65u8, + 132u8, 86u8, 60u8, 241u8, 203u8, 56u8, 119u8, 214u8, 16u8, 176u8, + 226u8, ], ) } @@ -3673,9 +3673,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 199u8, 113u8, 220u8, 8u8, 68u8, 3u8, 155u8, 6u8, 219u8, 61u8, 163u8, - 6u8, 128u8, 221u8, 78u8, 133u8, 109u8, 21u8, 164u8, 8u8, 96u8, 58u8, - 44u8, 222u8, 244u8, 223u8, 136u8, 5u8, 153u8, 242u8, 8u8, 227u8, + 163u8, 67u8, 54u8, 229u8, 52u8, 84u8, 82u8, 7u8, 96u8, 44u8, 107u8, + 254u8, 130u8, 171u8, 196u8, 192u8, 229u8, 111u8, 191u8, 152u8, 133u8, + 195u8, 214u8, 192u8, 97u8, 151u8, 2u8, 159u8, 213u8, 27u8, 141u8, + 211u8, ], ) } @@ -3702,10 +3703,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 211u8, 226u8, 125u8, 86u8, 58u8, 192u8, 171u8, 141u8, 35u8, 105u8, - 193u8, 21u8, 210u8, 186u8, 30u8, 168u8, 205u8, 206u8, 105u8, 168u8, - 15u8, 120u8, 49u8, 156u8, 145u8, 172u8, 215u8, 28u8, 117u8, 137u8, - 130u8, 172u8, + 170u8, 139u8, 66u8, 165u8, 182u8, 194u8, 225u8, 114u8, 82u8, 44u8, + 83u8, 83u8, 83u8, 41u8, 198u8, 11u8, 202u8, 160u8, 147u8, 83u8, 249u8, + 187u8, 17u8, 91u8, 191u8, 213u8, 251u8, 211u8, 143u8, 107u8, 198u8, + 28u8, ], ) } @@ -9558,9 +9559,9 @@ pub mod api { "unsigned_submit_abft_score", types::UnsignedSubmitAbftScore { score, signature }, [ - 149u8, 135u8, 162u8, 2u8, 161u8, 78u8, 158u8, 8u8, 139u8, 206u8, 234u8, - 227u8, 54u8, 92u8, 55u8, 189u8, 24u8, 9u8, 192u8, 155u8, 73u8, 105u8, - 254u8, 100u8, 95u8, 146u8, 152u8, 55u8, 71u8, 121u8, 56u8, 14u8, + 5u8, 88u8, 75u8, 237u8, 209u8, 39u8, 22u8, 221u8, 92u8, 99u8, 67u8, + 64u8, 192u8, 47u8, 124u8, 110u8, 2u8, 59u8, 243u8, 32u8, 98u8, 101u8, + 14u8, 180u8, 38u8, 193u8, 119u8, 96u8, 123u8, 94u8, 115u8, 62u8, ], ) } @@ -9879,10 +9880,9 @@ pub mod api { _0.borrow(), )], [ - 61u8, 84u8, 105u8, 208u8, 230u8, 198u8, 161u8, 36u8, 58u8, 245u8, - 209u8, 88u8, 181u8, 129u8, 209u8, 232u8, 104u8, 24u8, 251u8, 228u8, - 160u8, 196u8, 47u8, 202u8, 243u8, 83u8, 96u8, 225u8, 8u8, 125u8, 201u8, - 168u8, + 150u8, 237u8, 116u8, 146u8, 6u8, 142u8, 58u8, 219u8, 81u8, 187u8, + 158u8, 62u8, 144u8, 52u8, 6u8, 130u8, 220u8, 70u8, 210u8, 64u8, 130u8, + 40u8, 76u8, 134u8, 32u8, 253u8, 9u8, 135u8, 75u8, 122u8, 153u8, 130u8, ], ) } @@ -9900,10 +9900,9 @@ pub mod api { "AbftScores", Vec::new(), [ - 61u8, 84u8, 105u8, 208u8, 230u8, 198u8, 161u8, 36u8, 58u8, 245u8, - 209u8, 88u8, 181u8, 129u8, 209u8, 232u8, 104u8, 24u8, 251u8, 228u8, - 160u8, 196u8, 47u8, 202u8, 243u8, 83u8, 96u8, 225u8, 8u8, 125u8, 201u8, - 168u8, + 150u8, 237u8, 116u8, 146u8, 6u8, 142u8, 58u8, 219u8, 81u8, 187u8, + 158u8, 62u8, 144u8, 52u8, 6u8, 130u8, 220u8, 70u8, 210u8, 64u8, 130u8, + 40u8, 76u8, 134u8, 32u8, 253u8, 9u8, 135u8, 75u8, 122u8, 153u8, 130u8, ], ) } @@ -11884,9 +11883,10 @@ pub mod api { "batch", types::Batch { calls }, [ - 167u8, 199u8, 32u8, 167u8, 173u8, 231u8, 211u8, 147u8, 35u8, 151u8, - 170u8, 32u8, 16u8, 33u8, 73u8, 77u8, 75u8, 56u8, 145u8, 231u8, 106u8, - 112u8, 148u8, 37u8, 121u8, 239u8, 3u8, 137u8, 235u8, 46u8, 45u8, 105u8, + 172u8, 250u8, 125u8, 240u8, 123u8, 232u8, 174u8, 243u8, 24u8, 206u8, + 122u8, 23u8, 124u8, 167u8, 221u8, 224u8, 143u8, 188u8, 93u8, 139u8, + 173u8, 45u8, 65u8, 83u8, 138u8, 103u8, 118u8, 238u8, 73u8, 110u8, + 174u8, 232u8, ], ) } @@ -11904,10 +11904,9 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 73u8, 208u8, 17u8, 101u8, 70u8, 127u8, 192u8, 105u8, 34u8, 136u8, - 105u8, 253u8, 107u8, 82u8, 175u8, 250u8, 76u8, 173u8, 247u8, 45u8, - 20u8, 56u8, 167u8, 127u8, 149u8, 44u8, 120u8, 26u8, 62u8, 87u8, 198u8, - 170u8, + 204u8, 255u8, 184u8, 213u8, 189u8, 9u8, 51u8, 237u8, 35u8, 217u8, + 248u8, 70u8, 12u8, 51u8, 46u8, 142u8, 36u8, 104u8, 229u8, 8u8, 157u8, + 118u8, 100u8, 7u8, 243u8, 69u8, 2u8, 192u8, 15u8, 128u8, 139u8, 194u8, ], ) } @@ -11921,10 +11920,9 @@ pub mod api { "batch_all", types::BatchAll { calls }, [ - 5u8, 193u8, 47u8, 75u8, 176u8, 124u8, 248u8, 182u8, 179u8, 167u8, - 210u8, 200u8, 92u8, 61u8, 161u8, 196u8, 50u8, 143u8, 252u8, 94u8, 82u8, - 188u8, 188u8, 164u8, 151u8, 65u8, 121u8, 227u8, 89u8, 77u8, 119u8, - 220u8, + 120u8, 203u8, 110u8, 9u8, 204u8, 246u8, 70u8, 22u8, 59u8, 236u8, 153u8, + 95u8, 12u8, 114u8, 117u8, 50u8, 252u8, 227u8, 126u8, 7u8, 198u8, 165u8, + 88u8, 47u8, 176u8, 168u8, 232u8, 29u8, 159u8, 240u8, 58u8, 221u8, ], ) } @@ -11942,10 +11940,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 254u8, 180u8, 101u8, 177u8, 115u8, 167u8, 61u8, 33u8, 231u8, 195u8, - 85u8, 164u8, 250u8, 175u8, 166u8, 63u8, 12u8, 237u8, 100u8, 147u8, - 72u8, 210u8, 110u8, 157u8, 187u8, 70u8, 141u8, 132u8, 252u8, 45u8, - 135u8, 213u8, + 104u8, 219u8, 54u8, 41u8, 26u8, 93u8, 150u8, 110u8, 108u8, 224u8, + 109u8, 92u8, 220u8, 104u8, 2u8, 25u8, 138u8, 157u8, 175u8, 191u8, + 187u8, 36u8, 58u8, 193u8, 24u8, 87u8, 158u8, 72u8, 14u8, 206u8, 10u8, + 161u8, ], ) } @@ -11959,9 +11957,10 @@ pub mod api { "force_batch", types::ForceBatch { calls }, [ - 254u8, 0u8, 228u8, 197u8, 56u8, 90u8, 56u8, 106u8, 14u8, 122u8, 228u8, - 149u8, 13u8, 64u8, 104u8, 114u8, 140u8, 251u8, 27u8, 239u8, 6u8, 241u8, - 124u8, 157u8, 164u8, 148u8, 127u8, 75u8, 3u8, 205u8, 182u8, 90u8, + 223u8, 124u8, 166u8, 175u8, 134u8, 86u8, 10u8, 228u8, 61u8, 132u8, + 18u8, 155u8, 199u8, 27u8, 239u8, 211u8, 135u8, 214u8, 138u8, 42u8, + 145u8, 9u8, 206u8, 140u8, 73u8, 152u8, 87u8, 189u8, 16u8, 90u8, 157u8, + 248u8, ], ) } @@ -11979,9 +11978,9 @@ pub mod api { weight, }, [ - 253u8, 2u8, 221u8, 250u8, 223u8, 123u8, 175u8, 166u8, 70u8, 21u8, 38u8, - 9u8, 82u8, 89u8, 170u8, 1u8, 247u8, 239u8, 227u8, 237u8, 21u8, 250u8, - 14u8, 104u8, 142u8, 240u8, 231u8, 91u8, 111u8, 162u8, 219u8, 106u8, + 59u8, 8u8, 37u8, 49u8, 165u8, 213u8, 44u8, 92u8, 221u8, 67u8, 247u8, + 33u8, 223u8, 56u8, 83u8, 236u8, 202u8, 28u8, 90u8, 191u8, 184u8, 153u8, + 29u8, 23u8, 50u8, 76u8, 15u8, 223u8, 240u8, 242u8, 112u8, 70u8, ], ) } @@ -12271,9 +12270,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 76u8, 120u8, 75u8, 99u8, 8u8, 58u8, 75u8, 70u8, 35u8, 51u8, 196u8, - 250u8, 220u8, 200u8, 108u8, 243u8, 177u8, 70u8, 221u8, 143u8, 98u8, - 192u8, 7u8, 198u8, 92u8, 9u8, 34u8, 111u8, 107u8, 250u8, 16u8, 201u8, + 43u8, 100u8, 54u8, 254u8, 229u8, 253u8, 158u8, 88u8, 179u8, 129u8, + 214u8, 122u8, 154u8, 46u8, 202u8, 82u8, 252u8, 194u8, 154u8, 77u8, 2u8, + 56u8, 110u8, 123u8, 88u8, 60u8, 158u8, 140u8, 111u8, 83u8, 100u8, + 113u8, ], ) } @@ -12301,9 +12301,9 @@ pub mod api { max_weight, }, [ - 187u8, 105u8, 129u8, 75u8, 77u8, 227u8, 172u8, 6u8, 150u8, 105u8, - 222u8, 34u8, 99u8, 14u8, 136u8, 54u8, 168u8, 73u8, 203u8, 65u8, 75u8, - 159u8, 81u8, 184u8, 30u8, 52u8, 232u8, 10u8, 1u8, 184u8, 242u8, 51u8, + 226u8, 83u8, 63u8, 163u8, 4u8, 136u8, 208u8, 22u8, 246u8, 150u8, 107u8, + 21u8, 111u8, 17u8, 141u8, 196u8, 118u8, 72u8, 31u8, 74u8, 148u8, 225u8, + 142u8, 60u8, 164u8, 162u8, 18u8, 179u8, 77u8, 248u8, 125u8, 30u8, ], ) } @@ -12716,10 +12716,9 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 196u8, 155u8, 161u8, 8u8, 124u8, 41u8, 123u8, 119u8, 153u8, 212u8, - 106u8, 212u8, 87u8, 141u8, 120u8, 39u8, 106u8, 105u8, 67u8, 242u8, - 50u8, 29u8, 35u8, 179u8, 209u8, 150u8, 177u8, 233u8, 99u8, 23u8, 167u8, - 243u8, + 143u8, 70u8, 1u8, 78u8, 162u8, 172u8, 3u8, 89u8, 189u8, 100u8, 205u8, + 134u8, 76u8, 202u8, 116u8, 173u8, 5u8, 13u8, 232u8, 78u8, 89u8, 55u8, + 13u8, 123u8, 58u8, 38u8, 146u8, 129u8, 31u8, 33u8, 68u8, 169u8, ], ) } @@ -12737,10 +12736,10 @@ pub mod api { weight, }, [ - 245u8, 117u8, 70u8, 152u8, 64u8, 216u8, 73u8, 166u8, 126u8, 167u8, - 247u8, 15u8, 102u8, 35u8, 255u8, 180u8, 41u8, 193u8, 181u8, 95u8, - 114u8, 240u8, 124u8, 87u8, 148u8, 79u8, 108u8, 160u8, 208u8, 80u8, - 140u8, 47u8, + 77u8, 162u8, 95u8, 229u8, 250u8, 136u8, 96u8, 120u8, 222u8, 167u8, + 157u8, 192u8, 104u8, 119u8, 42u8, 253u8, 227u8, 91u8, 20u8, 243u8, + 171u8, 105u8, 196u8, 147u8, 139u8, 158u8, 219u8, 24u8, 6u8, 5u8, 184u8, + 240u8, ], ) } @@ -12780,9 +12779,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 0u8, 125u8, 64u8, 32u8, 109u8, 35u8, 27u8, 146u8, 105u8, 178u8, 140u8, - 15u8, 175u8, 240u8, 145u8, 184u8, 226u8, 56u8, 123u8, 155u8, 78u8, - 127u8, 127u8, 153u8, 125u8, 96u8, 245u8, 33u8, 98u8, 141u8, 11u8, 41u8, + 180u8, 244u8, 105u8, 203u8, 46u8, 196u8, 11u8, 218u8, 210u8, 82u8, + 175u8, 51u8, 221u8, 247u8, 236u8, 254u8, 58u8, 14u8, 160u8, 233u8, + 86u8, 54u8, 69u8, 196u8, 21u8, 43u8, 102u8, 222u8, 155u8, 39u8, 44u8, + 72u8, ], ) } @@ -19090,9 +19090,9 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 206u8, 64u8, 21u8, 122u8, 18u8, 20u8, 116u8, 15u8, 191u8, 125u8, 72u8, - 140u8, 119u8, 10u8, 93u8, 222u8, 79u8, 7u8, 132u8, 26u8, 202u8, 176u8, - 83u8, 51u8, 226u8, 223u8, 164u8, 192u8, 42u8, 152u8, 124u8, 135u8, + 63u8, 164u8, 16u8, 54u8, 165u8, 3u8, 208u8, 240u8, 83u8, 132u8, 162u8, + 93u8, 197u8, 251u8, 88u8, 1u8, 89u8, 66u8, 151u8, 216u8, 222u8, 99u8, + 75u8, 111u8, 153u8, 185u8, 118u8, 237u8, 211u8, 98u8, 187u8, 223u8, ], ) } @@ -19304,10 +19304,10 @@ pub mod api { call: ::std::boxed::Box::new(call), }, [ - 202u8, 188u8, 166u8, 130u8, 234u8, 235u8, 200u8, 156u8, 5u8, 215u8, - 139u8, 126u8, 198u8, 252u8, 176u8, 150u8, 169u8, 118u8, 243u8, 33u8, - 105u8, 220u8, 199u8, 65u8, 20u8, 117u8, 124u8, 157u8, 250u8, 109u8, - 124u8, 87u8, + 102u8, 244u8, 173u8, 88u8, 194u8, 183u8, 18u8, 13u8, 225u8, 195u8, + 159u8, 178u8, 172u8, 184u8, 135u8, 162u8, 168u8, 163u8, 241u8, 249u8, + 182u8, 137u8, 161u8, 62u8, 153u8, 29u8, 180u8, 89u8, 130u8, 74u8, 2u8, + 108u8, ], ) } @@ -27505,7 +27505,7 @@ pub mod api { pub struct Score { pub session_id: ::core::primitive::u32, pub nonce: ::core::primitive::u32, - pub points: ::std::vec::Vec<::core::primitive::u32>, + pub points: ::std::vec::Vec<::core::primitive::u16>, } #[derive( :: subxt :: ext :: codec :: Decode, From c94bdf72f6f3383e8a0e33828e9386fadf9d90b8 Mon Sep 17 00:00:00 2001 From: timorleph Date: Mon, 9 Dec 2024 15:58:21 +0100 Subject: [PATCH 5/5] Readability improvements from review --- finality-aleph/src/abft/current/performance/scorer.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/finality-aleph/src/abft/current/performance/scorer.rs b/finality-aleph/src/abft/current/performance/scorer.rs index 8aa6bc9af1..edde034014 100644 --- a/finality-aleph/src/abft/current/performance/scorer.rs +++ b/finality-aleph/src/abft/current/performance/scorer.rs @@ -25,9 +25,8 @@ impl Scorer { // This is not necessarily true for forkers, but punishing them is fine. self.newest_unit_by.insert(unit.creator, unit.round) } - self.newest_unit_by - .size() - .into_iterator() + let all_nodes = self.newest_unit_by.size().into_iterator(); + all_nodes .map(|node_id| { self.newest_unit_by .get(node_id) @@ -35,7 +34,7 @@ impl Scorer { // subtraction. .map(|unit_round| max_round.saturating_sub(*unit_round)) // If we don't have a unit it's the same as having a unit of round equal to -1. - .unwrap_or(max_round + 1) + .unwrap_or(max_round.saturating_add(1)) }) .collect() }