-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zebra-scan): Connect with zebrad (#7989)
* connect zebrad with zebra-scan * remove unwrap * use tokio::sleep * fix the task handler * Don't panic on an empty state --------- Co-authored-by: teor <teor@riseup.net>
- Loading branch information
1 parent
681ae68
commit 0f24c31
Showing
7 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! The scan task. | ||
use std::time::Duration; | ||
|
||
use color_eyre::{eyre::eyre, Report}; | ||
use tower::{buffer::Buffer, util::BoxService, Service, ServiceExt}; | ||
use tracing::info; | ||
|
||
use crate::storage::Storage; | ||
|
||
type State = Buffer< | ||
BoxService<zebra_state::Request, zebra_state::Response, zebra_state::BoxError>, | ||
zebra_state::Request, | ||
>; | ||
|
||
/// Wait a few seconds at startup so tip height is always `Some`. | ||
const INITIAL_WAIT: Duration = Duration::from_secs(10); | ||
|
||
/// The amount of time between checking and starting new scans. | ||
const CHECK_INTERVAL: Duration = Duration::from_secs(10); | ||
|
||
/// Start the scan task given state and storage. | ||
/// | ||
/// - This function is dummy at the moment. It just makes sure we can read the storage and the state. | ||
/// - Modificatiuons here might have an impact in the `scan_task_starts` test. | ||
/// - Real scanning code functionality will be added in the future here. | ||
pub async fn start(mut state: State, storage: Storage) -> Result<(), Report> { | ||
// We want to make sure the state has a tip height available before we start scanning. | ||
tokio::time::sleep(INITIAL_WAIT).await; | ||
|
||
loop { | ||
// Make sure we can query the state | ||
let request = state | ||
.ready() | ||
.await | ||
.map_err(|e| eyre!(e))? | ||
.call(zebra_state::Request::Tip) | ||
.await | ||
.map_err(|e| eyre!(e)); | ||
|
||
let tip = match request? { | ||
zebra_state::Response::Tip(tip) => tip, | ||
_ => unreachable!("unmatched response to a state::Tip request"), | ||
}; | ||
|
||
// Read keys from the storage | ||
let available_keys = storage.get_sapling_keys(); | ||
|
||
for key in available_keys { | ||
info!( | ||
"Scanning the blockchain for key {} from block 1 to {:?}", | ||
key.0, tip, | ||
); | ||
} | ||
|
||
tokio::time::sleep(CHECK_INTERVAL).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,9 @@ impl Storage { | |
self.sapling_keys.clone() | ||
} | ||
} | ||
|
||
impl Default for Storage { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters