-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod prune; | ||
mod rollback; | ||
|
||
pub(crate) use prune::*; | ||
pub(crate) use rollback::*; |
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,3 @@ | ||
pub(crate) async fn rollback(_num_block: u32) -> anyhow::Result<()> { | ||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod pruning; | ||
pub mod rollback; | ||
|
||
#[cfg(test)] | ||
mod tests; |
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,12 @@ | ||
pub mod service; | ||
|
||
pub struct Rollback {} | ||
|
||
impl Rollback { | ||
/// Rollback the provided number of blocks | ||
pub fn execute(&self, _num_blocks: u32) -> anyhow::Result<()> { | ||
// Do something | ||
|
||
Ok(()) | ||
} | ||
} |
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,35 @@ | ||
use tokio::select; | ||
use tokio::sync::mpsc::Receiver; | ||
use tokio_util::sync::CancellationToken; | ||
use tracing::{error, info}; | ||
|
||
use super::Rollback; | ||
|
||
pub struct RollbackService { | ||
rollback: Rollback, | ||
receiver: Receiver<u32>, | ||
} | ||
|
||
impl RollbackService { | ||
pub fn new(rollback: Rollback, receiver: Receiver<u32>) -> Self { | ||
Self { rollback, receiver } | ||
} | ||
|
||
/// Run service to rollback when instructed to | ||
pub async fn run(mut self, cancellation_token: CancellationToken) { | ||
loop { | ||
select! { | ||
biased; | ||
_ = cancellation_token.cancelled() => { | ||
return; | ||
}, | ||
Some(num_blocks) = self.receiver.recv() => { | ||
info!("Received signal to rollback {num_blocks} blocks"); | ||
if let Err(e) = self.rollback.execute(num_blocks) { | ||
error!("Could not rollback blocks: {:?}", e); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |