Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only request transactions when building ordinal index #851

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Updater {
Some(progress_bar)
};

let rx = Self::fetch_blocks_from(index, self.height)?;
let rx = Self::fetch_blocks_from(index, self.height, self.index_ordinals)?;

let mut uncommitted = 0;
loop {
Expand Down Expand Up @@ -135,7 +135,11 @@ impl Updater {
Ok(())
}

fn fetch_blocks_from(index: &Index, mut height: u64) -> Result<mpsc::Receiver<Block>> {
fn fetch_blocks_from(
index: &Index,
mut height: u64,
index_ordinals: bool,
) -> Result<mpsc::Receiver<Block>> {
let (tx, rx) = mpsc::sync_channel(32);

let height_limit = index.height_limit;
Expand All @@ -150,7 +154,7 @@ impl Updater {
}
}

match Self::get_block_with_retries(&client, height) {
match Self::get_block_with_retries(&client, height, index_ordinals) {
Ok(Some(block)) => {
if let Err(err) = tx.send(block) {
log::info!("Block receiver disconnected: {err}");
Expand All @@ -169,14 +173,30 @@ impl Updater {
Ok(rx)
}

pub(crate) fn get_block_with_retries(client: &Client, height: u64) -> Result<Option<Block>> {
pub(crate) fn get_block_with_retries(
client: &Client,
height: u64,
transactions: bool,
) -> Result<Option<Block>> {
let mut errors = 0;
loop {
match client
.get_block_hash(height)
.into_option()
.and_then(|option| option.map(|hash| Ok(client.get_block(&hash)?)).transpose())
{
.and_then(|option| {
option
.map(|hash| {
if transactions {
Ok(client.get_block(&hash)?)
} else {
Ok(Block {
header: client.get_block_header(&hash)?,
txdata: Vec::new(),
})
}
})
.transpose()
}) {
Err(err) => {
if cfg!(test) {
return Err(err);
Expand Down