Skip to content

Commit

Permalink
ledger-db restructuring (#3441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-PH authored Feb 1, 2023
1 parent 03776e5 commit fad42ae
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 221 deletions.
9 changes: 6 additions & 3 deletions massa-execution-worker/src/speculative_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,12 @@ impl SpeculativeLedger {
.fetch_active_history_data_entry(addr, key)
{
HistorySearchResult::Present(_entry) => true,
HistorySearchResult::NoInfo => {
self.final_state.read().ledger.has_data_entry(addr, key)
}
HistorySearchResult::NoInfo => self
.final_state
.read()
.ledger
.get_data_entry(addr, key)
.is_some(),
HistorySearchResult::Absent => false,
}
})
Expand Down
10 changes: 0 additions & 10 deletions massa-ledger-exports/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ pub trait LedgerController: Send + Sync + Debug {
/// A copy of the datastore value, or `None` if the ledger entry or datastore entry was not found
fn get_data_entry(&self, addr: &Address, key: &[u8]) -> Option<Vec<u8>>;

/// Checks for the existence of a datastore entry for a given address.
///
/// # Arguments
/// * `addr`: target address
/// * `key`: datastore key
///
/// # Returns
/// true if the datastore entry was found, or false if the ledger entry or datastore entry was not found
fn has_data_entry(&self, addr: &Address, key: &[u8]) -> bool;

/// Get every key of the datastore for a given address.
///
/// # Returns
Expand Down
19 changes: 1 addition & 18 deletions massa-ledger-worker/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,12 @@ impl LedgerController for FinalLedger {
.get_sub_entry(addr, LedgerSubEntry::Datastore(key.to_owned()))
}

/// Checks for the existence of a datastore entry for a given address.
///
/// # Arguments
/// * `addr`: target address
/// * `key`: datastore key
///
/// # Returns
/// true if the datastore entry was found, or false if the ledger entry or datastore entry was not found
fn has_data_entry(&self, addr: &Address, key: &[u8]) -> bool {
self.sorted_ledger
.get_sub_entry(addr, LedgerSubEntry::Datastore(key.to_owned()))
.is_some()
}

/// Get every key of the datastore for a given address.
///
/// # Returns
/// A `BTreeSet` of the datastore keys
fn get_datastore_keys(&self, addr: &Address) -> Option<BTreeSet<Vec<u8>>> {
match self.entry_exists(addr) {
true => Some(self.sorted_ledger.get_datastore_keys(addr)),
false => None,
}
self.sorted_ledger.get_datastore_keys(addr)
}

/// Get the current disk ledger hash
Expand Down
Loading

0 comments on commit fad42ae

Please sign in to comment.