Skip to content

Commit b74126a

Browse files
committed
fix: remove balancesmpa, newstateresult
1 parent bd4ba8c commit b74126a

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

adapter/src/ethereum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ mod test {
536536
.expect("Valid ValidatorId"),
537537
payload: Payload {
538538
id: "awesomeValidator".to_string(),
539-
era: 100000,
539+
era: 100_000,
540540
address: "0x2bDeAFAE53940669DaA6F519373f686c1f3d3393".to_string(),
541541
identity: None,
542542
},

validator_worker/src/core/events.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) fn merge_aggrs(
1010
accounting: &Accounting,
1111
aggregates: &[EventAggregate],
1212
channel: &Channel,
13-
) -> Result<(BalancesMap, Accounting), DomainError> {
13+
) -> Result<Accounting, DomainError> {
1414
let deposit = channel.deposit_amount.clone();
1515

1616
let last_event_aggregate = [accounting.last_event_aggregate]
@@ -35,10 +35,10 @@ pub(crate) fn merge_aggrs(
3535
let new_accounting = Accounting {
3636
last_event_aggregate,
3737
balances_before_fees,
38-
balances: balances.clone(),
38+
balances
3939
};
4040

41-
Ok((balances, new_accounting))
41+
Ok(new_accounting)
4242
}
4343

4444
fn merge_payouts_into_balances<'a, T: Iterator<Item = &'a AggregateEvents>>(
@@ -115,11 +115,10 @@ mod test {
115115
balances: BalancesMap::default(),
116116
};
117117

118-
let (balances, new_accounting) =
118+
let new_accounting =
119119
merge_aggrs(&acc, &[gen_ev_aggr(5, &IDS["publisher"])], &channel)
120120
.expect("Something went wrong");
121121

122-
assert_eq!(balances, new_accounting.balances, "balances is the same");
123122
assert_eq!(
124123
new_accounting.balances_before_fees[&IDS["publisher"]],
125124
150.into(),
@@ -166,11 +165,10 @@ mod test {
166165
balances: BalancesMap::default(),
167166
};
168167

169-
let (balances, new_accounting) =
168+
let new_accounting =
170169
merge_aggrs(&acc, &[gen_ev_aggr(1_001, &IDS["publisher"])], &channel)
171170
.expect("Something went wrong");
172171

173-
assert_eq!(balances, new_accounting.balances, "balances is the same");
174172
assert_eq!(
175173
new_accounting.balances_before_fees[&IDS["publisher"]],
176174
9_800.into(),

validator_worker/src/follower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub async fn tick<A: Adapter + 'static>(
7979

8080
let producer_tick = producer::tick(&iface).await?;
8181
let balances = match &producer_tick {
82-
producer::TickStatus::Sent { balances, .. } => balances,
82+
producer::TickStatus::Sent { new_accounting, .. } => &new_accounting.balances,
8383
producer::TickStatus::NoNewEventAggr(balances) => balances,
8484
};
8585
let approve_state_result = if let (Some(new_state), false) = (new_msg, latest_is_responded_to) {

validator_worker/src/leader.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::error::Error;
22

33
use primitives::adapter::{Adapter, AdapterErrorKind};
44
use primitives::validator::{Accounting, MessageTypes, NewState};
5-
use primitives::BalancesMap;
65

76
use crate::heartbeat::{heartbeat, HeartbeatStatus};
87
use crate::sentry_interface::{PropagationResult, SentryApi};
@@ -19,7 +18,7 @@ pub enum NewStateResult<AE: AdapterErrorKind> {
1918
pub struct TickStatus<AE: AdapterErrorKind> {
2019
pub heartbeat: HeartbeatStatus<AE>,
2120
/// If None, then the conditions for handling a new state haven't been met
22-
pub new_state: NewStateResult<AE>,
21+
pub new_state: Option<Vec<PropagationResult<AE>>>,
2322
pub producer_tick: producer::TickStatus<AE>,
2423
}
2524

@@ -29,14 +28,13 @@ pub async fn tick<A: Adapter + 'static>(
2928
let producer_tick = producer::tick(&iface).await?;
3029
let (balances, new_state) = match &producer_tick {
3130
producer::TickStatus::Sent {
32-
balances,
3331
new_accounting,
3432
..
3533
} => {
36-
let new_state = on_new_accounting(&iface, (balances, new_accounting)).await?;
37-
(balances, new_state)
34+
let new_state = on_new_accounting(&iface, new_accounting).await?;
35+
(&new_accounting.balances, Some(new_state))
3836
}
39-
producer::TickStatus::NoNewEventAggr(balances) => (balances, NewStateResult::NotSent),
37+
producer::TickStatus::NoNewEventAggr(balances) => (balances, None),
4038
};
4139

4240
Ok(TickStatus {
@@ -48,9 +46,9 @@ pub async fn tick<A: Adapter + 'static>(
4846

4947
async fn on_new_accounting<A: Adapter + 'static>(
5048
iface: &SentryApi<A>,
51-
(balances, new_accounting): (&BalancesMap, &Accounting),
52-
) -> Result<NewStateResult<A::AdapterError>, Box<dyn Error>> {
53-
let state_root_raw = get_state_root_hash(&iface, &balances)?;
49+
new_accounting: &Accounting,
50+
) -> Result<Vec<PropagationResult<A::AdapterError>>, Box<dyn Error>> {
51+
let state_root_raw = get_state_root_hash(&iface, &new_accounting.balances)?;
5452
let state_root = hex::encode(state_root_raw);
5553

5654
let signature = iface.adapter.sign(&state_root)?;
@@ -63,5 +61,5 @@ async fn on_new_accounting<A: Adapter + 'static>(
6361
})])
6462
.await;
6563

66-
Ok(NewStateResult::Sent(propagation_results))
64+
Ok(propagation_results)
6765
}

validator_worker/src/producer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::sentry_interface::{PropagationResult, SentryApi};
1313
pub enum TickStatus<AE: AdapterErrorKind> {
1414
Sent {
1515
channel: ChannelId,
16-
balances: BalancesMap,
16+
// balances: BalancesMap,
1717
new_accounting: Accounting,
1818
accounting_propagation: Vec<PropagationResult<AE>>,
1919
event_counts: usize,
@@ -40,14 +40,13 @@ pub async fn tick<A: Adapter + 'static>(
4040
.await?;
4141

4242
if !aggrs.events.is_empty() {
43-
let (balances, new_accounting) = merge_aggrs(&accounting, &aggrs.events, &iface.channel)?;
43+
let new_accounting = merge_aggrs(&accounting, &aggrs.events, &iface.channel)?;
4444

4545
let message_types = MessageTypes::Accounting(new_accounting.clone());
4646

4747
Ok(TickStatus::Sent {
4848
channel: iface.channel.id,
4949
accounting_propagation: iface.propagate(&[&message_types]).await,
50-
balances,
5150
new_accounting,
5251
event_counts: aggrs.events.len(),
5352
})

0 commit comments

Comments
 (0)