Skip to content

Commit

Permalink
Optimise the getting of address data-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-PH committed Jan 19, 2023
1 parent f87dcbf commit d1d027e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
5 changes: 1 addition & 4 deletions massa-ledger-worker/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ impl LedgerController for FinalLedger {
/// # 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)).flatten(),
false => None,
}
self.sorted_ledger.get_datastore_keys(addr)
}

/// Get the current disk ledger hash
Expand Down
22 changes: 9 additions & 13 deletions massa-ledger-worker/src/ledger_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,20 @@ impl LedgerDB {
let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR);

let mut opt = ReadOptions::default();
opt.set_iterate_upper_bound(helpers::end_prefix(data_prefix!(addr)).unwrap());
opt.set_iterate_range(
data_prefix!(addr).clone()..helpers::end_prefix(data_prefix!(addr)).unwrap(),
);
opt.set_pin_data(true);

let set: BTreeSet<_> = self
let mut iter = self
.db
.iterator_cf_opt(
handle,
opt,
IteratorMode::From(data_prefix!(addr), Direction::Forward),
)
.iterator_cf_opt(handle, opt, IteratorMode::Start)
.flatten()
.map(|(key, _)| key.split_at(ADDRESS_SIZE_BYTES + 1).1.to_vec())
.collect();
.peekable();

if set.is_empty() {
None
} else {
Some(set)
}
iter.peek()?;
Some(iter.collect())
}

/// Get a part of the disk Ledger.
Expand Down

0 comments on commit d1d027e

Please sign in to comment.