Skip to content

Commit 9012aef

Browse files
committed
Minor bugs fixed 2
1 parent 41dd201 commit 9012aef

File tree

4 files changed

+32
-55
lines changed

4 files changed

+32
-55
lines changed

watchtower-plugin/src/net/http.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ mod tests {
429429

430430
#[cfg(feature = "accountable")]
431431
let appointment_receipt = get_random_appointment_receipt(tower_sk);
432-
#[cfg(feature = "accountable")]
432+
// #[cfg(feature = "accountable")]
433433
let add_appointment_response =
434-
get_dummy_add_appointment_response(appointment.locator, &appointment_receipt);
435-
#[cfg(not(feature = "accountable"))]
436-
let add_appointment_response = get_dummy_add_appointment_response(appointment.locator);
434+
get_dummy_add_appointment_response(appointment.locator, #[cfg(feature = "accountable")]
435+
&appointment_receipt);
436+
437437

438438
let mut server = mockito::Server::new_async().await;
439439
let api_mock = server
@@ -455,7 +455,7 @@ mod tests {
455455
.await
456456
.unwrap();
457457
#[cfg(not(feature = "accountable"))]
458-
let (response) = add_appointment(
458+
let response = add_appointment(
459459
TowerId(tower_pk),
460460
&NetAddr::new(server.url()),
461461
&None,
@@ -521,17 +521,13 @@ mod tests {
521521
}
522522

523523
#[tokio::test]
524+
#[cfg(feature = "accountable")]
524525
async fn test_send_appointment_misbehaving() {
525526
let (sybil_tower_sk, sibyl_tower_pk) = cryptography::get_random_keypair();
526527
let appointment = generate_random_appointment(None);
527-
528-
#[cfg(feature = "accountable")]
529528
let appointment_receipt = get_random_appointment_receipt(tower_sk);
530-
#[cfg(feature = "accountable")]
531529
let add_appointment_response =
532530
get_dummy_add_appointment_response(appointment.locator, &appointment_receipt);
533-
#[cfg(not(feature = "accountable"))]
534-
let add_appointment_response = get_dummy_add_appointment_response(appointment.locator);
535531

536532
let mut server = mockito::Server::new_async().await;
537533
let api_mock = server
@@ -554,7 +550,6 @@ mod tests {
554550
.unwrap_err();
555551

556552
api_mock.assert_async().await;
557-
#[cfg(feature = "accountable")]
558553
if let AddAppointmentError::SignatureError(proof) = error {
559554
assert_eq!(
560555
MisbehaviorProof::new(

watchtower-plugin/src/retrier.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ use teos_common::UserId as TowerId;
1414

1515
use crate::net::http::{self, AddAppointmentError};
1616
use crate::wt_client::{RevocationData, WTClient};
17-
#[cfg(not(feature = "accountable"))]
1817
use crate::TowerStatus;
1918
#[cfg(feature = "accountable")]
20-
use crate::{MisbehaviorProof, TowerStatus};
19+
use crate::MisbehaviorProof;
2120

2221
const POLLING_TIME: u64 = 1;
2322

@@ -48,7 +47,7 @@ impl RetryError {
4847
fn is_permanent(&self) -> bool {
4948
matches!(
5049
self,
51-
RetryError::Subscription(_, true) | RetryError::Misbehaving(_) | RetryError::Abandoned
50+
RetryError::Subscription(_, true) | RetryError::Abandoned | RetryError::Misbehaving(_)
5251
)
5352
}
5453
}
@@ -520,6 +519,7 @@ impl Retrier {
520519
tower_id,
521520
appointment.locator,
522521
slots,
522+
#[cfg(feature = "accountable")]
523523
&receipt,
524524
);
525525
wt_client.remove_pending_appointment(tower_id, appointment.locator);
@@ -529,7 +529,7 @@ impl Retrier {
529529
Ok(slots) => {
530530
self.pending_appointments.lock().unwrap().remove(&locator);
531531
let mut wt_client = self.wt_client.lock().unwrap();
532-
wt_client.add_accepted_appointment(tower_id, appointment.locator, slots);
532+
wt_client.add_appointment_receipt(tower_id, appointment.locator, slots);
533533
wt_client.remove_pending_appointment(tower_id, appointment.locator);
534534
log::debug!("Response verified and data stored in the database");
535535
}
@@ -652,6 +652,8 @@ mod tests {
652652
}
653653

654654
#[tokio::test]
655+
#[cfg(feature = "accountable")]
656+
// #[cfg(feature = "accountable")]
655657
async fn test_manage_retry_reachable() {
656658
let tmp_path = TempDir::new(&format!("watchtower_{}", get_random_user_id())).unwrap();
657659
let (tx, rx) = unbounded_channel();
@@ -678,19 +680,19 @@ mod tests {
678680
.unwrap()
679681
.add_pending_appointment(tower_id, &appointment);
680682

681-
#[cfg(not(feature = "accountable"))]
683+
682684
// Prepare the mock response
683685
let mut add_appointment_receipt = AppointmentReceipt::new(
684686
cryptography::sign(&appointment.to_vec(), &wt_client.lock().unwrap().user_sk).unwrap(),
685687
42,
686688
);
687-
#[cfg(not(feature = "accountable"))]
689+
688690
add_appointment_receipt.sign(&tower_sk);
689-
#[cfg(feature = "accountable")]
691+
690692
let add_appointment_response =
691693
get_dummy_add_appointment_response(appointment.locator, &add_appointment_receipt);
692694

693-
#[cfg(not(feature = "accountable"))]
695+
694696
let add_appointment_response = get_dummy_add_appointment_response(appointment.locator);
695697
let api_mock = server
696698
.mock("POST", Endpoint::AddAppointment.path().as_str())

watchtower-plugin/src/test_utils.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@ use teos_common::protos as common_msgs;
33
#[cfg(feature = "accountable")]
44
use teos_common::receipts::AppointmentReceipt;
55

6-
#[cfg(feature = "accountable")]
7-
pub fn get_dummy_add_appointment_response(
8-
locator: Locator,
9-
receipt: &AppointmentReceipt,
10-
) -> common_msgs::AddAppointmentResponse {
11-
common_msgs::AddAppointmentResponse {
12-
locator: locator.to_vec(),
13-
start_block: receipt.start_block(),
14-
signature: receipt.signature().unwrap(),
15-
available_slots: 21,
16-
subscription_expiry: 1000,
17-
}
18-
}
196

20-
#[cfg(not(feature = "accountable"))]
21-
pub fn get_dummy_add_appointment_response(locator: Locator) -> common_msgs::AddAppointmentResponse {
7+
// #[cfg(not(feature = "accountable"))]
8+
pub fn get_dummy_add_appointment_response(locator: Locator, #[cfg(feature = "accountable")]receipt: &AppointmentReceipt,) -> common_msgs::AddAppointmentResponse {
229
common_msgs::AddAppointmentResponse {
2310
locator: locator.to_vec(),
11+
#[cfg(feature = "accountable")]
12+
start_block: receipt.start_block(),
13+
#[cfg(not(feature = "accountable"))]
2414
start_block: 0,
15+
#[cfg(feature = "accountable")]
16+
signature: receipt.signature().unwrap(),
17+
#[cfg(not(feature = "accountable"))]
2518
signature: "None".to_string(),
2619
available_slots: 21,
2720
subscription_expiry: 1000,

watchtower-plugin/src/wt_client.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
99
use teos_common::appointment::{Appointment, Locator};
1010
use teos_common::cryptography;
1111
use teos_common::dbm::Error as DBError;
12-
#[cfg(not(feature = "accountable"))]
1312
use teos_common::receipts::RegistrationReceipt;
1413
#[cfg(feature = "accountable")]
15-
use teos_common::receipts::{AppointmentReceipt, RegistrationReceipt};
14+
use teos_common::receipts::AppointmentReceipt;
1615
use teos_common::{TowerId, UserId};
1716

1817
use crate::dbm::DBM;
1918
use crate::net::ProxyInfo;
2019
use crate::retrier::RetrierStatus;
2120
#[cfg(feature = "accountable")]
22-
use crate::{MisbehaviorProof, SubscriptionError, TowerInfo, TowerStatus, TowerSummary};
23-
#[cfg(not(feature = "accountable"))]
21+
use crate::MisbehaviorProof;
2422
use crate::{SubscriptionError, TowerInfo, TowerStatus, TowerSummary};
2523

2624
#[derive(Eq, PartialEq)]
@@ -219,40 +217,29 @@ impl WTClient {
219217
}
220218

221219
/// Adds an appointment receipt to the tower record.
222-
#[cfg(feature = "accountable")]
223220
pub fn add_appointment_receipt(
224221
&mut self,
225222
tower_id: TowerId,
226223
locator: Locator,
227224
available_slots: u32,
225+
#[cfg(feature = "accountable")]
228226
receipt: &AppointmentReceipt,
229227
) {
230228
if let Some(tower) = self.towers.get_mut(&tower_id) {
231229
// DISCUSS: It may be nice to independently compute the slots and compare
232230
tower.available_slots = available_slots;
233-
231+
#[cfg(feature = "accountable")]
234232
self.dbm
235233
.store_appointment_receipt(tower_id, locator, available_slots, receipt)
236234
.unwrap();
237-
} else {
238-
log::error!("Cannot add appointment receipt to tower. Unknown tower_id: {tower_id}");
239-
}
240-
}
241-
#[cfg(not(feature = "accountable"))]
242-
pub fn add_accepted_appointment(
243-
&mut self,
244-
tower_id: TowerId,
245-
locator: Locator,
246-
available_slots: u32,
247-
) {
248-
if let Some(tower) = self.towers.get_mut(&tower_id) {
249-
// DISCUSS: It may be nice to independently compute the slots and compare
250-
tower.available_slots = available_slots;
251-
235+
#[cfg(not(feature = "accountable"))]
252236
self.dbm
253237
.store_accepted_appointments(tower_id, locator, available_slots)
254238
.unwrap();
255239
} else {
240+
#[cfg(feature = "accountable")]
241+
log::error!("Cannot add appointment receipt to tower. Unknown tower_id: {tower_id}");
242+
#[cfg(not(feature = "accountable"))]
256243
log::error!("Cannot add accepted appointment to tower. Unknown tower_id: {tower_id}");
257244
}
258245
}

0 commit comments

Comments
 (0)