Skip to content

Commit

Permalink
use table_hash to uniquely identify the table extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
hackaugusto committed Oct 11, 2024
1 parent 071948a commit 431d086
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
33 changes: 24 additions & 9 deletions lgn-messages/src/types/v1/preprocessing/ext_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,15 @@ impl FinalExtraction {
}

pub fn new_single_table(
table_hash: u64,
table_id: TableId,
table_hash: TableHash,
block_nr: BlockNr,
contract: Address,
compound: Option<TableDimension>,
value_proof_version: MptNodeVersion,
) -> Self {
Self::Single(SingleTableExtraction::new(
table_id,
table_hash,
block_nr,
contract,
Expand All @@ -267,40 +269,51 @@ impl FinalExtraction {
contract: Address,
mapping_table_hash: u64,
simple_table_hash: u64,
mapping_table_value_proof_version: MptNodeVersion,
simple_table_value_proof_version: MptNodeVersion,
table_value_proof_version: MptNodeVersion,
) -> Self {
Self::Merge {
table_id,
mapping: SingleTableExtraction::new(
// use the table_hash as the table_id when the extraction is a sub-table
mapping_table_hash,
mapping_table_hash,
block_nr,
contract,
None,
mapping_table_value_proof_version,
table_value_proof_version.clone(),
),
simple: SingleTableExtraction::new(
// use the table_hash as the table_id when the extraction is a sub-table
simple_table_hash,
simple_table_hash,
block_nr,
contract,
None,
simple_table_value_proof_version,
table_value_proof_version,
),
}
}
}

/// Inputs for a single table proof.
///
/// This can be either a simple valued or a mapping table.
/// # Identifiers
///
/// A [SingleTableExtraction] is either a final or a sub extraction. Final extractions can be
/// either a simple table, a mapping table, or a mapping table with length. A sub extraction is
/// either a simple or a no-length mapping table, which is later used by a merge extraction.
///
/// When this extraction is final, `table_id` must match the table's unique identifier. Sub
/// extractions on the other hand should use the `table_hash`.
///
/// The `table_hash` is used to match identify the value extraction.
#[derive(Clone, Dbg, PartialEq, Deserialize, Serialize)]
pub struct SingleTableExtraction {
pub table_id: TableId,
pub table_hash: TableHash,
pub value_proof_version: MptNodeVersion,
pub block_nr: BlockNr,
pub contract: Address,

/// This is always versioned because we prove values only if they changed.
pub value_proof_version: MptNodeVersion,
pub extraction_type: FinalExtractionType,

#[dbg(placeholder = "...")]
Expand All @@ -319,6 +332,7 @@ pub struct SingleTableExtraction {
impl SingleTableExtraction {
pub fn new(
table_id: TableId,
table_hash: TableHash,
block_nr: BlockNr,
contract: Address,
compound: Option<TableDimension>,
Expand All @@ -331,6 +345,7 @@ impl SingleTableExtraction {

Self {
table_id,
table_hash,
block_nr,
contract,
value_proof_version,
Expand Down
10 changes: 6 additions & 4 deletions lgn-messages/src/types/v1/preprocessing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl WorkerTaskType {
/// `table_hash`.
pub fn ext_final_extraction_simple(
table_id: TableId,
table_hash: TableHash,
block_nr: BlockNr,
contract: Address,
compound: TableDimension,
Expand All @@ -171,6 +172,7 @@ impl WorkerTaskType {
WorkerTaskType::Extraction(ExtractionType::FinalExtraction(Box::new(
FinalExtraction::new_single_table(
table_id,
table_hash,
block_nr,
contract,
Some(compound),
Expand All @@ -181,13 +183,15 @@ impl WorkerTaskType {

pub fn ext_final_extraction_lengthed(
table_id: TableId,
table_hash: TableHash,
block_nr: BlockNr,
contract: Address,
value_proof_version: MptNodeVersion,
) -> WorkerTaskType {
WorkerTaskType::Extraction(ExtractionType::FinalExtraction(Box::new(
FinalExtraction::new_single_table(
table_id,
table_hash,
block_nr,
contract,
None,
Expand All @@ -202,8 +206,7 @@ impl WorkerTaskType {
contract: Address,
mapping_table_hash: u64,
simple_table_hash: u64,
mapping_table_value_proof_version: MptNodeVersion,
simple_table_value_proof_version: MptNodeVersion,
table_value_proof_version: MptNodeVersion,
) -> WorkerTaskType {
WorkerTaskType::Extraction(ExtractionType::FinalExtraction(Box::new(
FinalExtraction::new_merge_table(
Expand All @@ -212,8 +215,7 @@ impl WorkerTaskType {
contract,
mapping_table_hash,
simple_table_hash,
mapping_table_value_proof_version,
simple_table_value_proof_version,
table_value_proof_version,
),
)))
}
Expand Down

0 comments on commit 431d086

Please sign in to comment.