Skip to content

Commit

Permalink
dev: change to use option instead of 0 nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
0xqd committed Jul 8, 2024
1 parent 819070a commit 83f4d0b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/rbuilder/src/backtest/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ impl HistoricalDataFetcher {
async move {
let mut all_nonces_failed = true;
for nonce in nonces {
let mut res_onchain_nonce = 0_u64;
let mut res_onchain_nonce: Option<u64> = None;
if let Ok(nonce_cache) = nonce_cache.read() {
if let Some(onchain_nonce) = nonce_cache.get(&nonce.address) {
res_onchain_nonce = *onchain_nonce
res_onchain_nonce = Some(*onchain_nonce);
}
}
if res_onchain_nonce == 0 {
if res_onchain_nonce.is_none() {
let address = nonce.address;
let onchain_nonce = self
.eth_provider
Expand All @@ -198,15 +198,18 @@ impl HistoricalDataFetcher {
if let Ok(mut nonce_cache) = nonce_cache.write() {
nonce_cache.insert(nonce.address, onchain_nonce);
}
res_onchain_nonce = onchain_nonce;
res_onchain_nonce = Some(onchain_nonce);
}

if res_onchain_nonce > nonce.nonce && !nonce.optional {
let low_nonce = res_onchain_nonce.map_or(true, |onchain_nonce| {
onchain_nonce > nonce.nonce && !nonce.optional
});
if low_nonce {
trace!(
"Order nonce too low, order: {:?}, nonce: {}, onchain tx count: {}",
id,
nonce.nonce,
res_onchain_nonce,
res_onchain_nonce.unwrap_or_default(),
);
return Ok(());
} else {
Expand Down

0 comments on commit 83f4d0b

Please sign in to comment.