Skip to content

Commit 508b339

Browse files
committed
add: exhausted property to validator messages
1 parent 102e3e7 commit 508b339

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

primitives/src/validator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ pub struct ApproveState {
165165
pub state_root: String,
166166
pub signature: String,
167167
pub is_healthy: bool,
168+
#[serde(default)]
169+
pub exhausted: bool,
168170
}
169171

170172
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
@@ -173,6 +175,8 @@ pub struct NewState {
173175
pub state_root: String,
174176
pub signature: String,
175177
pub balances: BalancesMap,
178+
#[serde(default)]
179+
pub exhausted: bool,
176180
}
177181

178182
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]

validator_worker/src/follower.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33

44
use primitives::adapter::{Adapter, AdapterErrorKind};
55
use primitives::validator::{ApproveState, MessageTypes, NewState, RejectState};
6-
use primitives::BalancesMap;
6+
use primitives::{BalancesMap, BigNum};
77

88
use crate::core::follower_rules::{get_health, is_valid_transition};
99
use crate::heartbeat::{heartbeat, HeartbeatStatus};
@@ -140,12 +140,14 @@ async fn on_new_state<'a, A: Adapter + 'static>(
140140
let signature = iface.adapter.sign(&new_state.state_root)?;
141141
let health_threshold = u64::from(iface.config.health_threshold_promilles);
142142
let is_healthy = health >= health_threshold;
143+
let exhausted = proposed_balances.clone().values().sum::<BigNum>() == iface.channel.deposit_amount;
143144

144145
let propagation_result = iface
145146
.propagate(&[&MessageTypes::ApproveState(ApproveState {
146147
state_root: proposed_state_root,
147148
signature,
148149
is_healthy,
150+
exhausted,
149151
})])
150152
.await;
151153

validator_worker/src/leader.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use primitives::adapter::{Adapter, AdapterErrorKind};
44
use primitives::{
55
validator::{Accounting, MessageTypes, NewState},
66
BalancesMap,
7+
BigNum,
78
};
89

910
use crate::heartbeat::{heartbeat, HeartbeatStatus};
@@ -48,13 +49,16 @@ async fn on_new_accounting<A: Adapter + 'static>(
4849

4950
let signature = iface.adapter.sign(&state_root)?;
5051

52+
let exhausted = new_accounting.balances.clone().values().sum::<BigNum>() == iface.channel.deposit_amount;
53+
5154
let propagation_results = iface
5255
.propagate(&[&MessageTypes::NewState(NewState {
5356
state_root,
5457
signature,
5558
balances: new_accounting.balances.clone(),
59+
exhausted
5660
})])
5761
.await;
5862

5963
Ok(propagation_results)
60-
}
64+
}

0 commit comments

Comments
 (0)