Skip to content

Commit 7eb40cf

Browse files
authored
Merge pull request #317 from AdExNetwork/hotfix-315-dont-allow-empty-accounting
Hotfix #315 Do not allow empty Accounting, skip them instead
2 parents e8dd5c0 + fb185be commit 7eb40cf

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

adview-manager/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
154154
}
155155

156156
fn is_video(ad_unit: &AdUnit) -> bool {
157-
ad_unit.media_mime.split('/').nth(0) == Some("video")
157+
ad_unit.media_mime.split('/').next() == Some("video")
158158
}
159159

160160
fn calculate_target_score(a: &[TargetingTag], b: &[TargetingTag]) -> TargetingScore {

primitives/src/balances_map.rs

+8
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 {

primitives/src/big_num.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::convert::TryFrom;
2-
use std::error::Error;
32
use std::iter::Sum;
43
use std::ops::{Add, AddAssign, Div, Mul, Sub};
54
use std::str::FromStr;
@@ -195,7 +194,7 @@ impl TryFrom<&str> for BigNum {
195194

196195
fn try_from(num: &str) -> Result<Self, Self::Error> {
197196
let big_uint = BigUint::from_str(&num)
198-
.map_err(|err| super::DomainError::InvalidArgument(err.description().to_string()))?;
197+
.map_err(|err| super::DomainError::InvalidArgument(err.to_string()))?;
199198

200199
Ok(Self(big_uint))
201200
}

primitives/src/config.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use lazy_static::lazy_static;
44
use serde::{Deserialize, Serialize};
55
use serde_hex::{SerHex, StrictPfx};
66
use std::fs;
7-
use toml;
87

98
lazy_static! {
109
static ref DEVELOPMENT_CONFIG: Config =

validator_worker/src/producer.rs

+15-5
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)