Skip to content

Commit 08eee0f

Browse files
committed
producer::tick - check for empty Accounting
1 parent e8dd5c0 commit 08eee0f

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

primitives/src/balances_map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ impl BalancesMap {
3939
pub fn insert(&mut self, key: ValidatorId, value: BigNum) -> Option<BigNum> {
4040
self.0.insert(key, value)
4141
}
42+
43+
pub fn len(&self) -> usize {
44+
self.0.len()
45+
}
46+
47+
pub fn is_empty(&self) -> bool {
48+
self.0.is_empty()
49+
}
4250
}
4351

4452
impl FromIterator<(ValidatorId, BigNum)> for BalancesMap {

validator_worker/src/producer.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,30 @@ pub async fn tick<A: Adapter + 'static>(iface: &SentryApi<A>) -> Result {
2828
.get_event_aggregates(accounting.last_event_aggregate)
2929
.await?;
3030

31-
if !aggrs.events.is_empty() {
31+
if aggrs.events.is_empty() {
32+
return Ok((accounting.balances, None));
33+
}
34+
35+
let (balances, new_accounting) = merge_aggrs(&accounting, &aggrs.events, &iface.channel)?;
36+
37+
if new_accounting.balances.is_empty() {
3238
info!(
3339
iface.logger,
34-
"channel {}: processing {} event aggregates",
40+
"channel {}: empty Accounting balances, skipping propagation", iface.channel.id
41+
);
42+
43+
Ok((balances, None))
44+
} else {
45+
info!(
46+
iface.logger,
47+
"channel {}: processed {} event aggregates",
3548
iface.channel.id,
3649
aggrs.events.len()
3750
);
38-
let (balances, new_accounting) = merge_aggrs(&accounting, &aggrs.events, &iface.channel)?;
3951

4052
let message_types = MessageTypes::Accounting(new_accounting.clone());
4153
iface.propagate(&[&message_types]).await;
4254

4355
Ok((balances, Some(new_accounting)))
44-
} else {
45-
Ok((accounting.balances.clone(), None))
4656
}
4757
}

0 commit comments

Comments
 (0)