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

Remove dummy entries in Blockstore special columns #33511

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2127,14 +2127,29 @@ impl Blockstore {
.put(0, &TransactionStatusIndexMeta::default())?;
self.transaction_status_index_cf
.put(1, &TransactionStatusIndexMeta::default())?;
// This dummy status improves compaction performance
let default_status = TransactionStatusMeta::default().into();
self.transaction_status_cf
.put_protobuf(cf::TransactionStatus::as_index(2), &default_status)?;
self.address_signatures_cf.put(
cf::AddressSignatures::as_index(2),
&AddressSignatureMeta::default(),
)

// If present, delete dummy entries inserted by old software
// https://github.com/solana-labs/solana/blob/bc2b372/ledger/src/blockstore.rs#L2130-L2137
let transaction_status_dummy_key = cf::TransactionStatus::as_index(2);
if self
.transaction_status_cf
.get_protobuf_or_bincode::<StoredTransactionStatusMeta>(transaction_status_dummy_key)?
.is_some()
{
self.transaction_status_cf
.delete(transaction_status_dummy_key)?;
};
let address_signatures_dummy_key = cf::AddressSignatures::as_index(2);
if self
.address_signatures_cf
.get(address_signatures_dummy_key)?
.is_some()
{
self.address_signatures_cf
.delete(address_signatures_dummy_key)?;
};

Ok(())
}

/// Toggles the active primary index between `0` and `1`, and clears the
Expand Down Expand Up @@ -7669,8 +7684,6 @@ pub mod tests {
fn test_get_transaction_status() {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();

// TransactionStatus column opens initialized with one entry at index 2
let transaction_status_cf = &blockstore.transaction_status_cf;

let pre_balances_vec = vec![1, 2, 3];
Expand Down Expand Up @@ -7849,22 +7862,20 @@ pub mod tests {
.get_transaction_status_with_counter(signature7, &[].into())
.unwrap();
assert_eq!(status, None);
assert_eq!(counter, 2);
assert_eq!(counter, 1);

let (status, counter) = blockstore
.get_transaction_status_with_counter(signature7, &[3].into())
.unwrap();
assert_eq!(status, None);
assert_eq!(counter, 2);
assert_eq!(counter, 1);
}

fn do_test_lowest_cleanup_slot_and_special_cfs(simulate_ledger_cleanup_service: bool) {
solana_logger::setup();

let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();

// TransactionStatus column opens initialized with one entry at index 2
let transaction_status_cf = &blockstore.transaction_status_cf;

let pre_balances_vec = vec![1, 2, 3];
Expand Down
13 changes: 3 additions & 10 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,6 @@ pub mod tests {
IteratorDirection::Forward,
))
.unwrap();
let padding_entry = status_entry_iterator.next().unwrap().0;
assert_eq!(padding_entry.0, 2);
assert_eq!(padding_entry.2, 0);
assert!(status_entry_iterator.next().is_none());
let mut address_transactions_iterator = blockstore
.db
Expand All @@ -660,10 +657,8 @@ pub mod tests {
IteratorDirection::Forward,
))
.unwrap();
let padding_entry = address_transactions_iterator.next().unwrap().0;
assert_eq!(padding_entry.0, 2);
assert_eq!(padding_entry.2, 0);
assert!(address_transactions_iterator.next().is_none());

assert_eq!(
transaction_status_index_cf.get(0).unwrap().unwrap(),
TransactionStatusIndexMeta {
Expand Down Expand Up @@ -1095,8 +1090,6 @@ pub mod tests {
frozen: false,
}
);
let entry = status_entry_iterator.next().unwrap().0;
assert_eq!(entry.0, 2); // Buffer entry, no index 1 entries remaining
drop(status_entry_iterator);

// Purge up to but not including index0_max_slot
Expand Down Expand Up @@ -1135,6 +1128,8 @@ pub mod tests {
IteratorDirection::Forward,
))
.unwrap();
assert!(status_entry_iterator.next().is_none());

assert_eq!(
blockstore
.transaction_status_index_cf
Expand All @@ -1157,8 +1152,6 @@ pub mod tests {
frozen: false,
}
);
let entry = status_entry_iterator.next().unwrap().0;
assert_eq!(entry.0, 2); // Buffer entry, no index 0 or index 1 entries remaining
}

#[test]
Expand Down