Skip to content

Commit 2dd0845

Browse files
committed
fix: remove unused enums, impl
1 parent b74126a commit 2dd0845

File tree

5 files changed

+19
-35
lines changed

5 files changed

+19
-35
lines changed

validator_worker/src/core/events.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) fn merge_aggrs(
3535
let new_accounting = Accounting {
3636
last_event_aggregate,
3737
balances_before_fees,
38-
balances
38+
balances,
3939
};
4040

4141
Ok(new_accounting)
@@ -115,9 +115,8 @@ mod test {
115115
balances: BalancesMap::default(),
116116
};
117117

118-
let new_accounting =
119-
merge_aggrs(&acc, &[gen_ev_aggr(5, &IDS["publisher"])], &channel)
120-
.expect("Something went wrong");
118+
let new_accounting = merge_aggrs(&acc, &[gen_ev_aggr(5, &IDS["publisher"])], &channel)
119+
.expect("Something went wrong");
121120

122121
assert_eq!(
123122
new_accounting.balances_before_fees[&IDS["publisher"]],
@@ -165,9 +164,8 @@ mod test {
165164
balances: BalancesMap::default(),
166165
};
167166

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

172170
assert_eq!(
173171
new_accounting.balances_before_fees[&IDS["publisher"]],

validator_worker/src/follower.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ impl fmt::Display for InvalidNewState {
3636

3737
#[derive(Debug)]
3838
pub enum ApproveStateResult<AE: AdapterErrorKind> {
39-
Sent(Vec<PropagationResult<AE>>),
40-
/// Conditions for handling the new state haven't been met
41-
NotSent,
39+
/// If None, Conditions for handling the new state haven't been met
40+
Sent(Option<Vec<PropagationResult<AE>>>),
4241
RejectedState {
4342
reason: InvalidNewState,
44-
reject_state_propagation: Vec<PropagationResult<AE>>,
43+
state_root: String,
44+
propagation: Vec<PropagationResult<AE>>,
4545
},
4646
}
4747

@@ -85,7 +85,7 @@ pub async fn tick<A: Adapter + 'static>(
8585
let approve_state_result = if let (Some(new_state), false) = (new_msg, latest_is_responded_to) {
8686
on_new_state(&iface, &balances, &new_state).await?
8787
} else {
88-
ApproveStateResult::NotSent
88+
ApproveStateResult::Sent(None)
8989
};
9090

9191
Ok(TickStatus {
@@ -147,15 +147,15 @@ async fn on_new_state<'a, A: Adapter + 'static>(
147147
})])
148148
.await;
149149

150-
Ok(ApproveStateResult::Sent(propagation_result))
150+
Ok(ApproveStateResult::Sent(Some(propagation_result)))
151151
}
152152

153153
async fn on_error<'a, A: Adapter + 'static>(
154154
iface: &'a SentryApi<A>,
155155
new_state: &'a NewState,
156156
status: InvalidNewState,
157157
) -> ApproveStateResult<A::AdapterError> {
158-
let reject_state_propagation = iface
158+
let propagation = iface
159159
.propagate(&[&MessageTypes::RejectState(RejectState {
160160
reason: status.to_string(),
161161
state_root: new_state.state_root.clone(),
@@ -168,6 +168,7 @@ async fn on_error<'a, A: Adapter + 'static>(
168168

169169
ApproveStateResult::RejectedState {
170170
reason: status,
171-
reject_state_propagation,
171+
state_root: new_state.state_root.clone(),
172+
propagation,
172173
}
173174
}

validator_worker/src/heartbeat.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ use chrono::{Duration, Utc};
55

66
use adapter::get_signable_state_root;
77
use byteorder::{BigEndian, ByteOrder};
8-
use primitives::adapter::{Adapter, AdapterErrorKind};
8+
use primitives::adapter::Adapter;
99
use primitives::merkle_tree::MerkleTree;
1010
use primitives::validator::{Heartbeat, MessageTypes};
1111
use primitives::{BalancesMap, BigNum, Channel};
1212

1313
use crate::sentry_interface::{PropagationResult, SentryApi};
1414

15-
#[derive(Debug)]
16-
pub enum HeartbeatStatus<AE: AdapterErrorKind> {
17-
Sent(Vec<PropagationResult<AE>>),
18-
NotSent,
19-
}
15+
pub type HeartbeatStatus<A> = Option<Vec<PropagationResult<A>>>;
2016

2117
async fn send_heartbeat<A: Adapter + 'static>(
2218
iface: &SentryApi<A>,
@@ -59,9 +55,9 @@ pub async fn heartbeat<A: Adapter + 'static>(
5955
});
6056

6157
if should_send {
62-
Ok(HeartbeatStatus::Sent(send_heartbeat(&iface).await?))
58+
Ok(Some(send_heartbeat(&iface).await?))
6359
} else {
64-
Ok(HeartbeatStatus::NotSent)
60+
Ok(None)
6561
}
6662
}
6763

validator_worker/src/leader.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ use crate::heartbeat::{heartbeat, HeartbeatStatus};
77
use crate::sentry_interface::{PropagationResult, SentryApi};
88
use crate::{get_state_root_hash, producer};
99

10-
#[derive(Debug)]
11-
pub enum NewStateResult<AE: AdapterErrorKind> {
12-
Sent(Vec<PropagationResult<AE>>),
13-
/// Conditions for sending the new state haven't been met
14-
NotSent,
15-
}
16-
1710
#[derive(Debug)]
1811
pub struct TickStatus<AE: AdapterErrorKind> {
1912
pub heartbeat: HeartbeatStatus<AE>,
@@ -27,10 +20,7 @@ pub async fn tick<A: Adapter + 'static>(
2720
) -> Result<TickStatus<A::AdapterError>, Box<dyn Error>> {
2821
let producer_tick = producer::tick(&iface).await?;
2922
let (balances, new_state) = match &producer_tick {
30-
producer::TickStatus::Sent {
31-
new_accounting,
32-
..
33-
} => {
23+
producer::TickStatus::Sent { new_accounting, .. } => {
3424
let new_state = on_new_accounting(&iface, new_accounting).await?;
3525
(&new_accounting.balances, Some(new_state))
3626
}

validator_worker/src/producer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::sentry_interface::{PropagationResult, SentryApi};
1313
pub enum TickStatus<AE: AdapterErrorKind> {
1414
Sent {
1515
channel: ChannelId,
16-
// balances: BalancesMap,
1716
new_accounting: Accounting,
1817
accounting_propagation: Vec<PropagationResult<AE>>,
1918
event_counts: usize,

0 commit comments

Comments
 (0)