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

delete 'shallow' fh eth blks on rpc+ingestor start #4790

Merged
merged 8 commits into from
Aug 7, 2023

This file was deleted.

This file was deleted.

10 changes: 8 additions & 2 deletions store/postgres/src/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,15 @@ impl BlockStore {
continue;
};
}
match store.chain_head_block(&&store.chain).unwrap_or(None) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

if let Some(head) = store.chain_head_block(&&store.chain)?

Some(head) => {
let lower_bound = head - ENV_VARS.reorg_threshold;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for overflow. Also I'd give some slack here so we don't have to worry about off by one, race conditions or whatever, maybe use 2 * ENV_VARS.reorg_threshold.


info!(&self.logger, "Cleaning shallow blocks on non-firehose chain"; "network" => &store.chain);
store.cleanup_shallow_blocks()?
info!(&self.logger, "Cleaning shallow blocks on non-firehose chain"; "network" => &store.chain, "lower_bound" => lower_bound);
store.cleanup_shallow_blocks(lower_bound)?
}
None => {}
}
}
Ok(())
}
Expand Down
15 changes: 9 additions & 6 deletions store/postgres/src/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ mod data {
data jsonb not null
);
create index blocks_number ON {nsp}.blocks using btree(number);
create index blocks_expr_idx ON {nsp}.blocks USING BTREE ((data->'block'->'data')) where data->'block'->'data' = 'null'::jsonb;

create table {nsp}.call_cache (
id bytea not null primary key,
Expand Down Expand Up @@ -419,14 +418,18 @@ mod data {
Ok(())
}

pub(super) fn cleanup_shallow_blocks(&self, conn: &PgConnection) -> Result<(), StoreError> {
pub(super) fn cleanup_shallow_blocks(
&self,
conn: &PgConnection,
lowest_block: i32,
) -> Result<(), StoreError> {
let table_name = match &self {
Storage::Shared => ETHEREUM_BLOCKS_TABLE_NAME,
Storage::Private(Schema { blocks, .. }) => &blocks.qname,
};
conn.batch_execute(&format!(
"delete from {} WHERE data->'block'->'data' = 'null'::jsonb;",
table_name
"delete from {} WHERE number >= {} AND data->'block'->'data' = 'null'::jsonb;",
table_name, lowest_block,
))?;
Ok(())
}
Expand Down Expand Up @@ -1566,9 +1569,9 @@ impl ChainStore {
.delete_blocks_by_hash(&conn, &self.chain, block_hashes)
}

pub fn cleanup_shallow_blocks(&self) -> Result<(), StoreError> {
pub fn cleanup_shallow_blocks(&self, lowest_block: i32) -> Result<(), StoreError> {
let conn = self.get_conn()?;
self.storage.cleanup_shallow_blocks(&conn)?;
self.storage.cleanup_shallow_blocks(&conn, lowest_block)?;
Ok(())
}

Expand Down