Repository: farcaster-project/farcaster-node
Pull request #206 (2021-11-19 23:33:13)

Syncer TaskId
This was more an exercise for myself than actually yielding much benefit. Especially the `SyncerBlockHeight` type is a bit unwieldy. Should I split their implementation into separate commits an PRs?

codecov-commenter: # [Codecov](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#206](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (9cab229) into [main](https://codecov.io/gh/farcaster-project/farcaster-node/commit/b884e8afe03ae8f6774fd45f96dda911c56bae0d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (b884e8a) will **increase** coverage by `0.6%`.
> The diff coverage is `68.9%`.

[![Impacted file tree graph](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206/graphs/tree.svg?width=650&height=150&src=pr&token=ZZ9RnFhgFC&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

```diff
@@           Coverage Diff           @@
##            main    #206     +/-   ##
=======================================
+ Coverage   15.5%   16.1%   +0.6%     
=======================================
  Files         27      27             
  Lines       6071    6150     +79     
=======================================
+ Hits         941     990     +49     
- Misses      5130    5160     +30     
```


| [Impacted Files](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [src/swapd/runtime.rs](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3N3YXBkL3J1bnRpbWUucnM=) | `0.0% <0.0%> (ø)` | |
| [src/syncerd/bitcoin\_syncer.rs](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3N5bmNlcmQvYml0Y29pbl9zeW5jZXIucnM=) | `0.0% <0.0%> (ø)` | |
| [src/syncerd/monero\_syncer.rs](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3N5bmNlcmQvbW9uZXJvX3N5bmNlci5ycw==) | `0.0% <0.0%> (ø)` | |
| [src/syncerd/types.rs](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3N5bmNlcmQvdHlwZXMucnM=) | `38.2% <48.8%> (+1.1%)` | :arrow_up: |
| [src/syncerd/syncer\_state.rs](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3N5bmNlcmQvc3luY2VyX3N0YXRlLnJz) | `92.6% <88.7%> (-0.3%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [b884e8a...9cab229](https://codecov.io/gh/farcaster-project/farcaster-node/pull/206?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).

zkao: i rebased #207 here, and then we have issues with offer, format changed, it seems
h4sh3d: > i rebased #207 on #206 (on a private branch), and then we have issues with offer, format changed, it seems
> 
> alices: daemon:
> 
> ```
> [2021-11-20T15:27:38Z ERROR microservices::esb::controller] ESB request processing error: Farcaster core errors: Consensus error: Incorrect magic bytes
> ```

That’s probably an offer serialized with to_hex instead of to_string, at least the last 5 errors like this one were that for me.
zkao: ack
h4sh3d: `SyncerBlockHeight` is, as you said, not giving benefits. Maybe an implementation that generalized over different concept such as dags, or... I don't know what, but this is not needed now and maybe not even the right place to be generic, so I think you can drop the `SyncerBlockHeight` but keep the other one. (or discard both, I don't have a strong opinion)
TheCharlatan: I removed all the block height typing, just the TaskId remains.
TheCharlatan: Do not merge before #230 

Patch:
diff --git a/src/swapd/runtime.rs b/src/swapd/runtime.rs
index c54f2274..110c3c5f 100644
--- a/src/swapd/runtime.rs
+++ b/src/swapd/runtime.rs
@@ -15,7 +15,7 @@
 
 use crate::syncerd::{
     opts::Coin, Abort, HeightChanged, SweepAddress, SweepAddressAddendum, SweepSuccess,
-    SweepXmrAddress, TaskTarget, WatchHeight, XmrAddressAddendum,
+    SweepXmrAddress, TaskId, TaskTarget, WatchHeight, XmrAddressAddendum,
 };
 use std::{
     any::Any,
@@ -246,15 +246,15 @@ impl TemporalSafety {
 
 struct SyncerTasks {
     counter: u32,
-    watched_txs: HashMap<u32, TxLabel>,
-    watched_addrs: HashMap<u32, TxLabel>,
-    sweeping_addr: Option<u32>,
+    watched_txs: HashMap<TaskId, TxLabel>,
+    watched_addrs: HashMap<TaskId, TxLabel>,
+    sweeping_addr: Option<TaskId>,
 }
 
 impl SyncerTasks {
-    fn new_taskid(&mut self) -> u32 {
+    fn new_taskid(&mut self) -> TaskId {
         self.counter += 1;
-        self.counter
+        TaskId(self.counter)
     }
 }
 
@@ -724,7 +724,7 @@ impl SyncerState {
             .values()
             .any(|&x| x == TxLabel::AccLock)
     }
-    fn handle_tx_confs(&self, id: &u32, confirmations: &Option<u32>) {
+    fn handle_tx_confs(&self, id: &TaskId, confirmations: &Option<u32>) {
         if let Some(txlabel) = self.tasks.watched_txs.get(id) {
             match confirmations {
                 Some(0) => {
diff --git a/src/syncerd/syncer_state.rs b/src/syncerd/syncer_state.rs
index 83f40a11..56f7e2f3 100644
--- a/src/syncerd/syncer_state.rs
+++ b/src/syncerd/syncer_state.rs
@@ -2,7 +2,7 @@ use crate::farcaster_core::{blockchain::Network, consensus::Decodable};
 use crate::rpc::request::SyncerdBridgeEvent;
 use crate::syncerd::opts::Coin;
 use crate::syncerd::runtime::SyncerdTask;
-use crate::syncerd::TaskTarget;
+use crate::syncerd::{TaskId, TaskTarget};
 use crate::Error;
 use crate::ServiceId;
 use microservices::rpc_connection::Request;
@@ -105,9 +105,9 @@ impl SyncerState {
             TaskTarget::TaskId(task_id) => Some(task_id),
         };
 
-        let mut aborted_ids: Vec<u32> = vec![];
+        let mut aborted_ids: Vec<TaskId> = vec![];
         // check addresses tasks
-        let ids: Vec<(InternalId, u32)> = self
+        let ids: Vec<(InternalId, TaskId)> = self
             .addresses
             .iter()
             .filter_map(|(id, address_transaction)| {
@@ -135,7 +135,7 @@ impl SyncerState {
         );
 
         // check transactions tasks
-        let ids: Vec<(InternalId, u32)> = self
+        let ids: Vec<(InternalId, TaskId)> = self
             .transactions
             .iter()
             .filter_map(|(id, watched_transaction)| {
@@ -162,7 +162,7 @@ impl SyncerState {
         );
 
         // check height tasks
-        let ids: Vec<(InternalId, u32)> = self
+        let ids: Vec<(InternalId, TaskId)> = self
             .watch_height
             .iter()
             .filter_map(|(id, watch_height)| {
@@ -189,7 +189,7 @@ impl SyncerState {
         );
 
         // check sweep address tasks
-        let ids: Vec<(InternalId, u32)> = self
+        let ids: Vec<(InternalId, TaskId)> = self
             .sweep_addresses
             .iter()
             .filter_map(|(id, sweep_address)| {
@@ -659,23 +659,26 @@ async fn syncer_state_transaction() {
     let mut state = SyncerState::new(event_tx.clone());
 
     let transaction_task_one = WatchTransaction {
-        id: 0,
+        id: TaskId(0),
         lifetime: 1,
         hash: vec![0],
         confirmation_bound: 4,
     };
     let transaction_task_two = WatchTransaction {
-        id: 0,
+        id: TaskId(0),
         lifetime: 3,
         hash: vec![1],
         confirmation_bound: 4,
     };
-    let height_task = WatchHeight { id: 0, lifetime: 4 };
+    let height_task = WatchHeight {
+        id: TaskId(0),
+        lifetime: 4,
+    };
     let source1 = ServiceId::Syncer(Coin::Bitcoin, Network::Mainnet);
 
     state.watch_transaction(transaction_task_one.clone(), source1.clone());
     state
-        .abort(TaskTarget::TaskId(0), source1.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source1.clone(), true)
         .await;
     assert!(event_rx.try_recv().is_ok());
 
@@ -737,7 +740,7 @@ async fn syncer_state_transaction() {
     let source2 = ServiceId::Syncer(Coin::Monero, Network::Mainnet);
     state.watch_transaction(transaction_task_two.clone(), source2.clone());
     state
-        .abort(TaskTarget::TaskId(0), source2.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source2.clone(), true)
         .await;
     assert_eq!(state.lifetimes.len(), 3);
     assert_eq!(state.transactions.len(), 2);
@@ -769,13 +772,13 @@ async fn syncer_state_addresses() {
         script_pubkey: address.script_pubkey(),
     });
     let address_task = WatchAddress {
-        id: 0,
+        id: TaskId(0),
         lifetime: 1,
         addendum: addendum.clone(),
         include_tx: Boolean::False,
     };
     let address_task_two = WatchAddress {
-        id: 0,
+        id: TaskId(0),
         lifetime: 1,
         addendum: addendum.clone(),
         include_tx: Boolean::False,
@@ -786,7 +789,7 @@ async fn syncer_state_addresses() {
         .watch_address(address_task_two.clone(), source1.clone())
         .unwrap();
     state
-        .abort(TaskTarget::TaskId(0), source1.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source1.clone(), true)
         .await;
     assert_eq!(state.lifetimes.len(), 0);
     assert_eq!(state.tasks_sources.len(), 0);
@@ -884,7 +887,7 @@ async fn syncer_state_addresses() {
         .watch_address(address_task_two.clone(), source2.clone())
         .unwrap();
     state
-        .abort(TaskTarget::TaskId(0), source2.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source2.clone(), true)
         .await;
     assert_eq!(state.lifetimes.len(), 1);
     assert_eq!(state.tasks_sources.len(), 1);
@@ -892,7 +895,10 @@ async fn syncer_state_addresses() {
     assert!(event_rx.try_recv().is_ok());
 
     state.change_height(1, vec![0]).await;
-    let height_task = WatchHeight { id: 0, lifetime: 3 };
+    let height_task = WatchHeight {
+        id: TaskId(0),
+        lifetime: 3,
+    };
     state.watch_height(height_task, source1.clone()).await;
     assert_eq!(state.lifetimes.len(), 2);
     assert_eq!(state.tasks_sources.len(), 2);
@@ -921,7 +927,7 @@ async fn syncer_state_sweep_addresses() {
     ) = tokio::sync::mpsc::channel(120);
     let mut state = SyncerState::new(event_tx.clone());
     let sweep_task = SweepAddress {
-        id: 0,
+        id: TaskId(0),
         lifetime: 11,
         addendum: SweepAddressAddendum::Monero(SweepXmrAddress {
             view_key: monero::PrivateKey::from_str(
@@ -945,7 +951,7 @@ async fn syncer_state_sweep_addresses() {
     assert_eq!(state.tasks_sources.len(), 1);
     assert_eq!(state.sweep_addresses.len(), 1);
     state
-        .abort(TaskTarget::TaskId(0), source1.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source1.clone(), true)
         .await;
     assert_eq!(state.lifetimes.len(), 0);
     assert_eq!(state.tasks_sources.len(), 0);
@@ -971,15 +977,21 @@ async fn syncer_state_height() {
         TokioReceiver<SyncerdBridgeEvent>,
     ) = tokio::sync::mpsc::channel(120);
     let mut state = SyncerState::new(event_tx.clone());
-    let height_task = WatchHeight { id: 0, lifetime: 0 };
-    let another_height_task = WatchHeight { id: 0, lifetime: 3 };
+    let height_task = WatchHeight {
+        id: TaskId(0),
+        lifetime: 0,
+    };
+    let another_height_task = WatchHeight {
+        id: TaskId(0),
+        lifetime: 3,
+    };
     let source1 = ServiceId::Syncer(Coin::Bitcoin, Network::Mainnet);
 
     state
         .watch_height(height_task.clone(), source1.clone())
         .await;
     state
-        .abort(TaskTarget::TaskId(0), source1.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source1.clone(), true)
         .await;
     assert_eq!(state.lifetimes.len(), 0);
     assert_eq!(state.tasks_sources.len(), 0);
@@ -1020,7 +1032,7 @@ async fn syncer_state_height() {
         .watch_height(another_height_task.clone(), source2.clone())
         .await;
     state
-        .abort(TaskTarget::TaskId(0), source2.clone(), true)
+        .abort(TaskTarget::TaskId(TaskId(0)), source2.clone(), true)
         .await;
     assert_eq!(state.lifetimes.len(), 1);
     assert_eq!(state.tasks_sources.len(), 1);
diff --git a/src/syncerd/types.rs b/src/syncerd/types.rs
index 49406b05..170c665a 100644
--- a/src/syncerd/types.rs
+++ b/src/syncerd/types.rs
@@ -1,8 +1,15 @@
 use monero::consensus::Decodable;
 use monero::consensus::Encodable;
 use std::io;
+use std::ops::Add;
 use strict_encoding::{StrictDecode, StrictEncode};
 
+#[derive(
+    Clone, Copy, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Ord, PartialOrd, Hash,
+)]
+#[display(Debug)]
+pub struct TaskId(pub u32);
+
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub enum AddressAddendum {
@@ -67,7 +74,7 @@ impl StrictDecode for XmrAddressAddendum {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct SweepAddress {
-    pub id: u32,
+    pub id: TaskId,
     pub lifetime: u64,
     pub addendum: SweepAddressAddendum,
 }
@@ -137,21 +144,21 @@ pub struct Abort {
 
 #[derive(Clone, Debug, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 pub enum TaskTarget {
-    TaskId(u32),
+    TaskId(TaskId),
     AllTasks,
 }
 
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct WatchHeight {
-    pub id: u32,
+    pub id: TaskId,
     pub lifetime: u64,
 }
 
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct WatchAddress {
-    pub id: u32,
+    pub id: TaskId,
     pub lifetime: u64,
     pub addendum: AddressAddendum,
     pub include_tx: Boolean,
@@ -176,7 +183,7 @@ impl From<Boolean> for bool {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct WatchTransaction {
-    pub id: u32,
+    pub id: TaskId,
     pub lifetime: u64,
     pub hash: Vec<u8>,
     pub confirmation_bound: u32,
@@ -185,7 +192,7 @@ pub struct WatchTransaction {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct BroadcastTransaction {
-    pub id: u32,
+    pub id: TaskId,
     pub tx: Vec<u8>,
 }
 
@@ -205,14 +212,14 @@ pub enum Task {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct TaskAborted {
-    pub id: Vec<u32>,
+    pub id: Vec<TaskId>,
     pub error: Option<String>,
 }
 
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct HeightChanged {
-    pub id: u32,
+    pub id: TaskId,
     pub block: Vec<u8>,
     pub height: u64,
 }
@@ -220,7 +227,7 @@ pub struct HeightChanged {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct AddressTransaction {
-    pub id: u32,
+    pub id: TaskId,
     pub hash: Vec<u8>,
     pub amount: u64,
     pub block: Vec<u8>,
@@ -230,7 +237,7 @@ pub struct AddressTransaction {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct TransactionConfirmations {
-    pub id: u32,
+    pub id: TaskId,
     pub block: Vec<u8>,
     pub confirmations: Option<u32>,
 }
@@ -238,7 +245,7 @@ pub struct TransactionConfirmations {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct TransactionBroadcasted {
-    pub id: u32,
+    pub id: TaskId,
     pub tx: Vec<u8>,
     pub error: Option<String>,
 }
@@ -246,7 +253,7 @@ pub struct TransactionBroadcasted {
 #[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
 #[display(Debug)]
 pub struct SweepSuccess {
-    pub id: u32,
+    pub id: TaskId,
     pub txids: Vec<Vec<u8>>,
 }
 


Test patch:
diff --git a/tests/functional.rs b/tests/functional.rs
index 51fdc2c2..0c9e81b9 100644
--- a/tests/functional.rs
+++ b/tests/functional.rs
@@ -6,12 +6,10 @@ use farcaster_node::syncerd::bitcoin_syncer::BitcoinSyncer;
 use farcaster_node::syncerd::monero_syncer::MoneroSyncer;
 use farcaster_node::syncerd::opts::{Coin, Opts};
 use farcaster_node::syncerd::runtime::SyncerdTask;
-use farcaster_node::syncerd::runtime::Synclet;
-use farcaster_node::syncerd::SweepAddress;
-use farcaster_node::syncerd::SweepAddressAddendum;
-use farcaster_node::syncerd::SweepXmrAddress;
-use farcaster_node::syncerd::TaskTarget;
-use farcaster_node::syncerd::XmrAddressAddendum;
+use farcaster_node::syncerd::{
+    runtime::Synclet, SweepAddress, SweepAddressAddendum, SweepXmrAddress, TaskId, TaskTarget,
+    XmrAddressAddendum,
+};
 use farcaster_node::ServiceId;
 use internet2::transport::MAX_FRAME_SIZE;
 use internet2::Decrypt;
@@ -97,7 +95,7 @@ fn bitcoin_syncer_block_height_test(polling: bool) {
     // Send a WatchHeight task
     let task = SyncerdTask {
         task: Task::WatchHeight(WatchHeight {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 2,
         }),
         source: SOURCE1.clone(),
@@ -123,7 +121,7 @@ fn bitcoin_syncer_block_height_test(polling: bool) {
     // Send another WatchHeight task
     let task = SyncerdTask {
         task: Task::WatchHeight(WatchHeight {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 2,
         }),
         source: SOURCE1.clone(),
@@ -207,7 +205,7 @@ fn bitcoin_syncer_address_test(polling: bool) {
     });
     let watch_address_task_1 = SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 1,
             addendum: addendum_1,
             include_tx: Boolean::True,
@@ -217,7 +215,7 @@ fn bitcoin_syncer_address_test(polling: bool) {
     tx.send(watch_address_task_1).unwrap();
     let watch_address_task_2 = SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 2,
             addendum: addendum_2.clone(),
             include_tx: Boolean::True,
@@ -281,7 +279,7 @@ fn bitcoin_syncer_address_test(polling: bool) {
     // watch for the same address, it should already contain transactions
     let watch_address_task_3 = SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 2,
             addendum: addendum_2,
             include_tx: Boolean::True,
@@ -317,7 +315,7 @@ fn bitcoin_syncer_address_test(polling: bool) {
     for i in 0..5 {
         tx.send(SyncerdTask {
             task: Task::WatchAddress(WatchAddress {
-                id: i,
+                id: TaskId(i),
                 lifetime: blocks + 5,
                 addendum: addendum_4.clone(),
                 include_tx: Boolean::True,
@@ -352,7 +350,7 @@ fn bitcoin_syncer_address_test(polling: bool) {
     });
     tx.send(SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 5,
+            id: TaskId(5),
             lifetime: blocks + 5,
             addendum: addendum_5,
             include_tx: Boolean::False,
@@ -410,7 +408,7 @@ fn bitcoin_syncer_transaction_test(polling: bool) {
 
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid_1.to_vec(),
             confirmation_bound: 2,
@@ -452,7 +450,7 @@ fn bitcoin_syncer_transaction_test(polling: bool) {
 
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: address_txid.to_vec(),
             confirmation_bound: 2,
@@ -488,7 +486,7 @@ fn bitcoin_syncer_transaction_test(polling: bool) {
 
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid_2.to_vec(),
             confirmation_bound: 2,
@@ -498,7 +496,7 @@ fn bitcoin_syncer_transaction_test(polling: bool) {
     .unwrap();
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid_3.to_vec(),
             confirmation_bound: 2,
@@ -553,7 +551,7 @@ fn bitcoin_syncer_transaction_test(polling: bool) {
 
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid.to_vec(),
             confirmation_bound: 2,
@@ -601,7 +599,7 @@ fn bitcoin_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 10,
             hash: vec![0; 32],
             confirmation_bound: 2,
@@ -617,7 +615,7 @@ fn bitcoin_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::Abort(Abort {
-            task_target: TaskTarget::TaskId(0),
+            task_target: TaskTarget::TaskId(TaskId(0)),
             respond: Boolean::True,
         }),
         source: SOURCE1.clone(),
@@ -631,7 +629,7 @@ fn bitcoin_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::Abort(Abort {
-            task_target: TaskTarget::TaskId(0),
+            task_target: TaskTarget::TaskId(TaskId(0)),
             respond: Boolean::True,
         }),
         source: SOURCE1.clone(),
@@ -649,7 +647,7 @@ fn bitcoin_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 10,
             hash: vec![0; 32],
             confirmation_bound: 2,
@@ -664,7 +662,7 @@ fn bitcoin_syncer_abort_test() {
     assert_transaction_confirmations(request, None, vec![0]);
     let task = SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 10,
             hash: vec![0; 32],
             confirmation_bound: 2,
@@ -693,7 +691,7 @@ fn bitcoin_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::Abort(Abort {
-            task_target: TaskTarget::TaskId(0),
+            task_target: TaskTarget::TaskId(TaskId(0)),
             respond: Boolean::True,
         }),
         source: SOURCE1.clone(),
@@ -741,7 +739,7 @@ fn bitcoin_syncer_broadcast_tx_test(polling: bool) {
 
     let task = SyncerdTask {
         task: Task::BroadcastTransaction(BroadcastTransaction {
-            id: 0,
+            id: TaskId(0),
             tx: transaction.hex,
         }),
         source: SOURCE1.clone(),
@@ -784,7 +782,7 @@ fn bitcoin_syncer_broadcast_tx_test(polling: bool) {
         .unwrap();
     let task = SyncerdTask {
         task: Task::BroadcastTransaction(BroadcastTransaction {
-            id: 0,
+            id: TaskId(0),
             tx: signed_tx.hex,
         }),
         source: SOURCE1.clone(),
@@ -894,7 +892,7 @@ async fn monero_syncer_block_height_test() {
     // Send a WatchHeight task
     let task = SyncerdTask {
         task: Task::WatchHeight(WatchHeight {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 2,
         }),
         source: SOURCE1.clone(),
@@ -919,7 +917,7 @@ async fn monero_syncer_block_height_test() {
     // Send another WatchHeight task
     let task = SyncerdTask {
         task: Task::WatchHeight(WatchHeight {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 2,
         }),
         source: SOURCE1.clone(),
@@ -976,7 +974,7 @@ async fn monero_syncer_sweep_test() {
 
     let task = SyncerdTask {
         task: Task::SweepAddress(SweepAddress {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 40,
             addendum: SweepAddressAddendum::Monero(SweepXmrAddress {
                 spend_key,
@@ -994,7 +992,7 @@ async fn monero_syncer_sweep_test() {
     let message = rx_event.recv_multipart(0).unwrap();
     println!("received sweep success message");
     let request = get_request_from_message(message);
-    assert_sweep_success(request, 0);
+    assert_sweep_success(request, TaskId(0));
 }
 
 /*
@@ -1047,7 +1045,7 @@ async fn monero_syncer_address_test() {
     });
     let watch_address_task_1 = SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 1,
             addendum: addendum_1,
             include_tx: Boolean::True,
@@ -1074,7 +1072,7 @@ async fn monero_syncer_address_test() {
     });
     let watch_address_task_2 = SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 1,
             addendum: addendum_2,
             include_tx: Boolean::True,
@@ -1102,7 +1100,7 @@ async fn monero_syncer_address_test() {
     });
     let watch_address_task_3 = SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 1,
             addendum: addendum_3,
             include_tx: Boolean::True,
@@ -1133,7 +1131,7 @@ async fn monero_syncer_address_test() {
     for i in 0..5 {
         tx.send(SyncerdTask {
             task: Task::WatchAddress(WatchAddress {
-                id: i,
+                id: TaskId(i),
                 lifetime: blocks + 5,
                 addendum: addendum_4.clone(),
                 include_tx: Boolean::True,
@@ -1163,7 +1161,7 @@ async fn monero_syncer_address_test() {
 
     tx.send(SyncerdTask {
         task: Task::WatchAddress(WatchAddress {
-            id: 5,
+            id: TaskId(5),
             lifetime: blocks + 5,
             addendum: addendum_5.clone(),
             include_tx: Boolean::True,
@@ -1220,7 +1218,7 @@ async fn monero_syncer_transaction_test() {
 
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid_1.to_vec(),
             confirmation_bound: 2,
@@ -1255,7 +1253,7 @@ async fn monero_syncer_transaction_test() {
     let block_hash = get_block_hash_from_height(&regtest, block_height).await;
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: block_height + 5,
             hash: tx_id2,
             confirmation_bound: 2,
@@ -1281,7 +1279,7 @@ async fn monero_syncer_transaction_test() {
 
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid_2.to_vec(),
             confirmation_bound: 2,
@@ -1291,7 +1289,7 @@ async fn monero_syncer_transaction_test() {
     .unwrap();
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: txid_3.to_vec(),
             confirmation_bound: 2,
@@ -1332,7 +1330,7 @@ async fn monero_syncer_transaction_test() {
         .unwrap();
     tx.send(SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 5,
             hash: hex::decode(transaction.tx_hash.to_string()).unwrap(),
             confirmation_bound: 2,
@@ -1387,7 +1385,7 @@ async fn monero_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 2,
             hash: vec![0; 32],
             confirmation_bound: 2,
@@ -1401,7 +1399,7 @@ async fn monero_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::Abort(Abort {
-            task_target: TaskTarget::TaskId(0),
+            task_target: TaskTarget::TaskId(TaskId(0)),
             respond: Boolean::True,
         }),
         source: SOURCE2.clone(),
@@ -1415,7 +1413,7 @@ async fn monero_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::Abort(Abort {
-            task_target: TaskTarget::TaskId(0),
+            task_target: TaskTarget::TaskId(TaskId(0)),
             respond: Boolean::True,
         }),
         source: SOURCE2.clone(),
@@ -1433,7 +1431,7 @@ async fn monero_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 0,
+            id: TaskId(0),
             lifetime: blocks + 10,
             hash: vec![0; 32],
             confirmation_bound: 2,
@@ -1446,7 +1444,7 @@ async fn monero_syncer_abort_test() {
     assert_transaction_confirmations(request, None, vec![0]);
     let task = SyncerdTask {
         task: Task::WatchTransaction(WatchTransaction {
-            id: 1,
+            id: TaskId(1),
             lifetime: blocks + 10,
             hash: vec![0; 32],
             confirmation_bound: 2,
@@ -1473,7 +1471,7 @@ async fn monero_syncer_abort_test() {
 
     let task = SyncerdTask {
         task: Task::Abort(Abort {
-            task_target: TaskTarget::TaskId(0),
+            task_target: TaskTarget::TaskId(TaskId(0)),
             respond: Boolean::True,
         }),
         source: SOURCE2.clone(),
@@ -1504,7 +1502,10 @@ async fn monero_syncer_broadcast_tx_test() {
     let (tx, rx_event) = create_monero_syncer("broadcast");
 
     let task = SyncerdTask {
-        task: Task::BroadcastTransaction(BroadcastTransaction { id: 0, tx: vec![0] }),
+        task: Task::BroadcastTransaction(BroadcastTransaction {
+            id: TaskId(0),
+            tx: vec![0],
+        }),
         source: SOURCE2.clone(),
     };
     tx.send(task).unwrap();
@@ -1651,7 +1652,7 @@ fn assert_address_transaction(request: Request, expected_amount: u64, expected_t
     }
 }
 
-fn assert_sweep_success(request: Request, id: u32) {
+fn assert_sweep_success(request: Request, id: TaskId) {
     match request {
         Request::SyncerdBridgeEvent(event) => match event.event {
             Event::SweepSuccess(sweep_success) => {