Skip to content

Commit

Permalink
revert get_and_scan_range
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2 committed Sep 17, 2024
1 parent 1c5ed75 commit 123f749
Showing 1 changed file with 30 additions and 46 deletions.
76 changes: 30 additions & 46 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,6 @@ where
Ok(())
}

async fn fetch_blocks(
&mut self,
start: u32,
end: u32,
) -> Result<Streaming<CompactBlock>, Error> {
let range = service::BlockRange {
start: Some(service::BlockId {
height: start.into(),
..Default::default()
}),
end: Some(service::BlockId {
height: end.into(),
..Default::default()
}),
};

Ok(self.client.get_block_range(range).await?.into_inner())
}

/// Download and process all blocks in the given range
async fn fetch_and_scan_range(&mut self, start: u32, end: u32) -> Result<(), Error> {
// get the chainstate prior to the range
Expand All @@ -290,34 +271,37 @@ where
self.db.get_orchard_nullifiers(NullifierQuery::Unspent)?,
);

let mut chunked_block_stream = self
.fetch_blocks(start, end)
let range = service::BlockRange {
start: Some(service::BlockId {
height: start.into(),
..Default::default()
}),
end: Some(service::BlockId {
height: (end - 1).into(),
..Default::default()
}),
};

tracing::info!("Scanning block range: {:?} to {:?}", start, end);

let scanned_blocks = self
.client
.get_block_range(range)
.await?
.try_chunks(BATCH_SIZE as usize);

while let Ok(Some(blocks)) = chunked_block_stream.try_next().await {
tracing::info!(
"Scanning block range: {:?} to {:?}",
blocks.first().unwrap().height,
blocks.last().unwrap().height
);

self.db.put_blocks(
&chainstate,
blocks
.into_iter()
.map(|compact_block| {
scan_block(
&self.network,
compact_block,
&scanning_keys,
&nullifiers,
None,
)
})
.collect::<Result<Vec<_>, _>>()?,
)?;
}
.into_inner()
.map(|compact_block| {
scan_block(
&self.network,
compact_block.unwrap(),
&scanning_keys,
&nullifiers,
None,
)
})
.try_collect()
.await?;

self.db.put_blocks(&chainstate, scanned_blocks)?;

Ok(())
}
Expand Down

0 comments on commit 123f749

Please sign in to comment.