Skip to content

Commit 817bb66

Browse files
committed
Merge branch 'improvements' into add-exhausted-property
2 parents d35f7ec + 96bfa9a commit 817bb66

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

hooks/post_checkout

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# Docker hub does a recursive clone, then checks the branch out,
3+
# so when a PR adds a submodule (or updates it), it fails.
4+
git submodule update --init

primitives/src/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ pub struct Channel {
9999
pub targeting_rules: Rules,
100100
pub spec: ChannelSpec,
101101
#[serde(default)]
102-
pub exhausted: Vec<bool>
102+
pub exhausted: Vec<bool>,
103103
}
104104

105105
pub fn channel_exhausted(channel: &Channel) -> bool {
106-
channel.exhausted.len() == 2 && channel.exhausted.iter().all(|&x| x == true)
106+
channel.exhausted.len() == 2 && channel.exhausted.iter().all(|&x| x)
107107
}
108108

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

sentry/src/db/channel.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,22 @@ pub async fn update_exhausted_channel(
101101
channel: &Channel,
102102
index: i32,
103103
) -> Result<bool, RunError<bb8_postgres::tokio_postgres::Error>> {
104-
pool
105-
.run(move | connection| {
106-
async move {
107-
match connection.prepare("UPDATE channels SET exhausted[$1] = true WHERE id = $2").await {
108-
Ok(stmt) => match connection.execute(&stmt, &[&index, &channel.id]).await {
109-
Ok(row) => {
110-
let updated = row == 1;
111-
Ok((updated, connection))
112-
},
113-
Err(e) => Err((e, connection)),
114-
},
115-
Err(e) => Err((e, connection)),
104+
pool.run(move |connection| async move {
105+
match connection
106+
.prepare("UPDATE channels SET exhausted[$1] = true WHERE id = $2")
107+
.await
108+
{
109+
Ok(stmt) => match connection.execute(&stmt, &[&index, &channel.id]).await {
110+
Ok(row) => {
111+
let updated = row == 1;
112+
Ok((updated, connection))
116113
}
117-
}
118-
})
119-
.await
120-
114+
Err(e) => Err((e, connection)),
115+
},
116+
Err(e) => Err((e, connection)),
117+
}
118+
})
119+
.await
121120
}
122121

123122
mod list_channels {

sentry/src/routes/channel.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::db::event_aggregate::{latest_approve_state, latest_heartbeats, latest_new_state};
2-
use crate::db::{get_channel_by_id, insert_channel, insert_validator_messages, list_channels, update_exhausted_channel};
2+
use crate::db::{
3+
get_channel_by_id, insert_channel, insert_validator_messages, list_channels,
4+
update_exhausted_channel,
5+
};
36
use crate::{success_response, Application, Auth, ResponseError, RouteParams, Session};
47
use bb8::RunError;
58
use bb8_postgres::tokio_postgres::error;
@@ -244,7 +247,6 @@ pub async fn create_validator_messages<A: Adapter + 'static>(
244247
_ => false,
245248
});
246249

247-
248250
match channel.spec.validators.find(&session.uid) {
249251
None => Err(ResponseError::Unauthorized),
250252
_ => {
@@ -255,11 +257,7 @@ pub async fn create_validator_messages<A: Adapter + 'static>(
255257

256258
if channel_is_exhausted {
257259
if let Some(validator_index) = channel.spec.validators.find_index(&session.uid) {
258-
update_exhausted_channel(
259-
&app.pool,
260-
&channel,
261-
validator_index
262-
).await?;
260+
update_exhausted_channel(&app.pool, &channel, validator_index).await?;
263261
}
264262
}
265263

validator_worker/src/leader.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::error::Error;
33
use primitives::adapter::{Adapter, AdapterErrorKind};
44
use primitives::{
55
validator::{Accounting, MessageTypes, NewState},
6-
BalancesMap,
7-
BigNum,
6+
BalancesMap, BigNum,
87
};
98

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

5049
let signature = iface.adapter.sign(&state_root)?;
5150

52-
let exhausted = new_accounting.balances.values().sum::<BigNum>() == iface.channel.deposit_amount;
51+
let exhausted =
52+
new_accounting.balances.values().sum::<BigNum>() == iface.channel.deposit_amount;
5353

5454
let propagation_results = iface
5555
.propagate(&[&MessageTypes::NewState(NewState {
5656
state_root,
5757
signature,
5858
balances: new_accounting.balances.clone(),
59-
exhausted
59+
exhausted,
6060
})])
6161
.await;
6262

6363
Ok(propagation_results)
64-
}
64+
}

0 commit comments

Comments
 (0)