feat: Refactor TransitionId tables, BlockBodyIndices table. (#2039)

This commit is contained in:
rakita
2023-04-05 13:10:18 +02:00
committed by GitHub
parent 9a011b4900
commit 633d84ded0
31 changed files with 476 additions and 367 deletions

View File

@@ -164,7 +164,7 @@ impl Command {
HeaderTD,
HeaderNumbers,
Headers,
BlockBodies,
BlockBodyIndices,
BlockOmmers,
BlockWithdrawals,
TransactionBlock,
@@ -174,8 +174,6 @@ impl Command {
PlainStorageState,
PlainAccountState,
Bytecodes,
BlockTransitionIndex,
TxTransitionIndex,
AccountHistory,
StorageHistory,
AccountChangeSet,

View File

@@ -52,7 +52,7 @@ fn import_tables_with_range<DB: Database>(
tx.import_table_with_range::<tables::Headers, _>(&db_tool.db.tx()?, Some(from), to)
})??;
output_db.update(|tx| {
tx.import_table_with_range::<tables::BlockBodies, _>(&db_tool.db.tx()?, Some(from), to)
tx.import_table_with_range::<tables::BlockBodyIndices, _>(&db_tool.db.tx()?, Some(from), to)
})??;
output_db.update(|tx| {
tx.import_table_with_range::<tables::BlockOmmers, _>(&db_tool.db.tx()?, Some(from), to)
@@ -60,15 +60,15 @@ fn import_tables_with_range<DB: Database>(
// Find range of transactions that need to be copied over
let (from_tx, to_tx) = db_tool.db.view(|read_tx| {
let mut read_cursor = read_tx.cursor_read::<tables::BlockBodies>()?;
let mut read_cursor = read_tx.cursor_read::<tables::BlockBodyIndices>()?;
let (_, from_block) =
read_cursor.seek(from)?.ok_or(eyre::eyre!("BlockBody {from} does not exist."))?;
let (_, to_block) =
read_cursor.seek(to)?.ok_or(eyre::eyre!("BlockBody {to} does not exist."))?;
Ok::<(u64, u64), eyre::ErrReport>((
from_block.start_tx_id,
to_block.start_tx_id + to_block.tx_count,
from_block.first_tx_num,
to_block.first_tx_num + to_block.tx_count,
))
})??;

View File

@@ -21,10 +21,14 @@ pub(crate) async fn dump_hashing_account_stage<DB: Database>(
// Import relevant AccountChangeSets
let tx = db_tool.db.tx()?;
let from_transition_rev =
tx.get::<tables::BlockTransitionIndex>(from)?.expect("there should be at least one.");
let to_transition_rev =
tx.get::<tables::BlockTransitionIndex>(to)?.expect("there should be at least one.");
let from_transition_rev = tx
.get::<tables::BlockBodyIndices>(from)?
.expect("there should be at least one.")
.transition_at_block();
let to_transition_rev = tx
.get::<tables::BlockBodyIndices>(to)?
.expect("there should be at least one.")
.transition_after_block();
output_db.update(|tx| {
tx.import_table_with_range::<tables::AccountChangeSet, _>(
&db_tool.db.tx()?,

View File

@@ -28,10 +28,14 @@ pub(crate) async fn dump_merkle_stage<DB: Database>(
})??;
let tx = db_tool.db.tx()?;
let from_transition_rev =
tx.get::<tables::BlockTransitionIndex>(from)?.expect("there should be at least one.");
let to_transition_rev =
tx.get::<tables::BlockTransitionIndex>(to)?.expect("there should be at least one.");
let from_transition_rev = tx
.get::<tables::BlockBodyIndices>(from)?
.expect("there should be at least one.")
.transition_at_block();
let to_transition_rev = tx
.get::<tables::BlockBodyIndices>(to)?
.expect("there should be at least one.")
.transition_after_block();
output_db.update(|tx| {
tx.import_table_with_range::<tables::AccountChangeSet, _>(

View File

@@ -108,8 +108,8 @@ impl Command {
}
}
/// Sets up the database and initial state on `BlockTransitionIndex`. Also returns the tip block
/// number.
/// Sets up the database and initial state on [`tables::BlockBodyIndices`]. Also returns the tip
/// block number.
pub(crate) fn setup<DB: Database>(
from: u64,
to: u64,
@@ -123,17 +123,15 @@ pub(crate) fn setup<DB: Database>(
let output_db = init_db(output_db)?;
output_db.update(|tx| {
tx.import_table_with_range::<tables::BlockTransitionIndex, _>(
tx.import_table_with_range::<tables::BlockBodyIndices, _>(
&db_tool.db.tx()?,
Some(from - 1),
to + 1,
)
})??;
let (tip_block_number, _) = db_tool
.db
.view(|tx| tx.cursor_read::<tables::BlockTransitionIndex>()?.last())??
.expect("some");
let (tip_block_number, _) =
db_tool.db.view(|tx| tx.cursor_read::<tables::BlockBodyIndices>()?.last())??.expect("some");
Ok((output_db, tip_block_number))
}

View File

@@ -60,11 +60,9 @@ pub(crate) fn generate_vectors(mut tables: Vec<String>) -> Result<()> {
(HeaderTD, PER_TABLE, TABLE),
(HeaderNumbers, PER_TABLE, TABLE),
(Headers, PER_TABLE, TABLE),
(BlockBodies, PER_TABLE, TABLE),
(BlockBodyIndices, PER_TABLE, TABLE),
(BlockOmmers, 100, TABLE),
(TxHashNumber, PER_TABLE, TABLE),
(BlockTransitionIndex, PER_TABLE, TABLE),
(TxTransitionIndex, PER_TABLE, TABLE),
(Transactions, 100, TABLE),
(PlainStorageState, PER_TABLE, DUPSORT),
(PlainAccountState, PER_TABLE, TABLE)