fix(esplora): reuse returned height instead of zipping
This commit is contained in:
parent
6f824cf325
commit
63fa710319
@ -85,20 +85,20 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
|
|||||||
local_tip: CheckPoint,
|
local_tip: CheckPoint,
|
||||||
request_heights: impl IntoIterator<IntoIter = impl Iterator<Item = u32> + Send> + Send,
|
request_heights: impl IntoIterator<IntoIter = impl Iterator<Item = u32> + Send> + Send,
|
||||||
) -> Result<local_chain::Update, Error> {
|
) -> Result<local_chain::Update, Error> {
|
||||||
let new_tip_height = self.get_height().await?;
|
|
||||||
|
|
||||||
// Atomically fetch latest blocks from Esplora. This way, we avoid creating an update with
|
// Atomically fetch latest blocks from Esplora. This way, we avoid creating an update with
|
||||||
// an inconsistent set of blocks (assuming that a reorg depth cannot be greater than the
|
// an inconsistent set of blocks (assuming that a reorg depth cannot be greater than the
|
||||||
// latest blocks fetched).
|
// latest blocks fetched).
|
||||||
let mut fetched_blocks = {
|
let mut fetched_blocks = self
|
||||||
let heights = (0..=new_tip_height).rev();
|
.get_blocks(None)
|
||||||
let hashes = self
|
|
||||||
.get_blocks(Some(new_tip_height))
|
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|b| b.id);
|
.map(|b| (b.time.height, b.id))
|
||||||
heights.zip(hashes).collect::<BTreeMap<u32, BlockHash>>()
|
.collect::<BTreeMap<u32, BlockHash>>();
|
||||||
};
|
let new_tip_height = fetched_blocks
|
||||||
|
.keys()
|
||||||
|
.last()
|
||||||
|
.copied()
|
||||||
|
.expect("must have atleast one block");
|
||||||
|
|
||||||
// fetch blocks of heights that the caller is interested in, reusing latest blocks that are
|
// fetch blocks of heights that the caller is interested in, reusing latest blocks that are
|
||||||
// already fetched.
|
// already fetched.
|
||||||
|
@ -78,19 +78,19 @@ impl EsploraExt for esplora_client::BlockingClient {
|
|||||||
local_tip: CheckPoint,
|
local_tip: CheckPoint,
|
||||||
request_heights: impl IntoIterator<Item = u32>,
|
request_heights: impl IntoIterator<Item = u32>,
|
||||||
) -> Result<local_chain::Update, Error> {
|
) -> Result<local_chain::Update, Error> {
|
||||||
let new_tip_height = self.get_height()?;
|
|
||||||
|
|
||||||
// Atomically fetch latest blocks from Esplora. This way, we avoid creating an update with
|
// Atomically fetch latest blocks from Esplora. This way, we avoid creating an update with
|
||||||
// an inconsistent set of blocks (assuming that a reorg depth cannot be greater than the
|
// an inconsistent set of blocks (assuming that a reorg depth cannot be greater than the
|
||||||
// latest blocks fetched).
|
// latest blocks fetched).
|
||||||
let mut fetched_blocks = {
|
let mut fetched_blocks = self
|
||||||
let heights = (0..=new_tip_height).rev();
|
.get_blocks(None)?
|
||||||
let hashes = self
|
|
||||||
.get_blocks(Some(new_tip_height))?
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|b| b.id);
|
.map(|b| (b.time.height, b.id))
|
||||||
heights.zip(hashes).collect::<BTreeMap<u32, BlockHash>>()
|
.collect::<BTreeMap<u32, BlockHash>>();
|
||||||
};
|
let new_tip_height = fetched_blocks
|
||||||
|
.keys()
|
||||||
|
.last()
|
||||||
|
.copied()
|
||||||
|
.expect("must atleast have one block");
|
||||||
|
|
||||||
// fetch blocks of heights that the caller is interested in, reusing latest blocks that are
|
// fetch blocks of heights that the caller is interested in, reusing latest blocks that are
|
||||||
// already fetched.
|
// already fetched.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user