mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-05 21:14:32 -04:00
Make Monero and Bitcoin wallet use a generalized sync interval
We define the sync interval as 1/10th of the blocktime. For the special case of our tests, we however check at max once per second. The tests have a super fast blocktime. As such we shouldn't hammer the nodes with a request every 100ms.
This commit is contained in:
parent
09c41f89c4
commit
ce78075932
3 changed files with 43 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::bitcoin::{CancelTimelock, PunishTimelock};
|
||||
use std::cmp::max;
|
||||
use std::time::Duration;
|
||||
use time::NumericalStdDurationShort;
|
||||
|
||||
|
@ -15,6 +16,16 @@ pub struct Config {
|
|||
pub monero_network: monero::Network,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn bitcoin_sync_interval(&self) -> Duration {
|
||||
sync_interval(self.bitcoin_avg_block_time)
|
||||
}
|
||||
|
||||
pub fn monero_sync_interval(&self) -> Duration {
|
||||
sync_interval(self.monero_avg_block_time)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GetConfig {
|
||||
fn get_config() -> Config;
|
||||
}
|
||||
|
@ -75,3 +86,26 @@ impl GetConfig for Regtest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_interval(avg_block_time: Duration) -> Duration {
|
||||
max(avg_block_time / 10, Duration::from_secs(1))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn check_interval_is_one_second_if_avg_blocktime_is_one_second() {
|
||||
let interval = sync_interval(Duration::from_secs(1));
|
||||
|
||||
assert_eq!(interval, Duration::from_secs(1))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_interval_is_tenth_of_avg_blocktime() {
|
||||
let interval = sync_interval(Duration::from_secs(100));
|
||||
|
||||
assert_eq!(interval, Duration::from_secs(10))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue