Skip to content
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
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resolver = "2"

[workspace.package]
# Solana Version (2.2.x)
version = "0.5.1"
version = "0.5.2"
authors = ["MagicBlock Maintainers <[email protected]>"]
repository = "https://github.com/magicblock-labs/ephemeral-validator"
homepage = "https://www.magicblock.xyz"
Expand Down Expand Up @@ -135,7 +135,7 @@ serde_json = "1.0"
serde_with = "3.16"
serial_test = "3.2"
sha3 = "0.10.8"
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "57158728" }
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "2246929" }
solana-account-decoder = { version = "2.2" }
solana-account-decoder-client-types = { version = "2.2" }
solana-account-info = { version = "2.2" }
Expand Down Expand Up @@ -224,7 +224,7 @@ features = ["lz4"]
# some solana dependencies have solana-storage-proto as dependency
# we need to patch them with our version, because they use protobuf-src v1.1.0
# and we use protobuf-src v2.1.1. Otherwise compilation fails
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "57158728" }
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "2246929" }
solana-storage-proto = { path = "./storage-proto" }
solana-svm = { git = "https://github.com/magicblock-labs/magicblock-svm.git", rev = "3e9456ec4" }
# Fork is used to enable `disable_manual_compaction` usage
Expand Down
4 changes: 2 additions & 2 deletions magicblock-accounts-db/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ impl From<lmdb::Error> for AccountsDbError {
#[macro_export]
macro_rules! log_err {
($msg: expr) => {
|err| ::log::warn!("{} error: {err}", $msg)
|err| ::log::error!("{} error: {err}", $msg)
};
($msg: expr, $($ctx:expr),* $(,)?) => {
|err| ::log::warn!("{} error: {err}", format!($msg, $($ctx),*))
|err| ::log::error!("{} error: {err}", format!($msg, $($ctx),*))
};
}
40 changes: 19 additions & 21 deletions magicblock-accounts-db/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ impl AccountsDbIndex {
pubkey: &Pubkey,
owner: &Pubkey,
allocation: Allocation,
txn: &mut RwTransaction,
) -> AccountsDbResult<Option<ExistingAllocation>> {
let Allocation { offset, blocks, .. } = allocation;

let mut txn = self.env.begin_rw_txn()?;
let mut dealloc = None;

// merge offset and block count into one single u64 and cast it to [u8; 8]
Expand All @@ -181,23 +181,21 @@ impl AccountsDbIndex {

// optimisitically try to insert account to index, assuming that it doesn't exist
let inserted =
self.accounts
.put_if_not_exists(&mut txn, pubkey, index_value)?;
self.accounts.put_if_not_exists(txn, pubkey, index_value)?;
// if the account does exist, then it already occupies space in main storage
if !inserted {
// in which case we just move the account to a new allocation
// adjusting all of the offsets and cleaning up the older ones
let previous =
self.reallocate_account(pubkey, &mut txn, &index_value)?;
self.reallocate_account(pubkey, txn, &index_value)?;
dealloc.replace(previous);
};

// track the account via programs' index as well
self.programs.put(&mut txn, owner, offset_and_pubkey)?;
self.programs.put(txn, owner, offset_and_pubkey)?;
// track the reverse relation between account and its owner
self.owners.put(&mut txn, pubkey, owner)?;
self.owners.put(txn, pubkey, owner)?;

txn.commit()?;
Ok(dealloc)
}

Expand Down Expand Up @@ -267,9 +265,9 @@ impl AccountsDbIndex {
&self,
pubkey: &Pubkey,
owner: &Pubkey,
txn: &mut RwTransaction,
) -> AccountsDbResult<()> {
let txn = self.env.begin_ro_txn()?;
let old_owner = match self.owners.get(&txn, pubkey)? {
let old_owner = match self.owners.get(txn, pubkey)? {
// if current owner matches with that stored in index, then we are all set
Some(val) if owner.as_ref() == val => {
return Ok(());
Expand All @@ -278,23 +276,21 @@ impl AccountsDbIndex {
// if they don't match, then we have to remove old entries and create new ones
Some(val) => Pubkey::try_from(val).ok(),
};
let allocation = self.get_allocation(&txn, pubkey)?;
let mut txn = self.env.begin_rw_txn()?;
let allocation = self.get_allocation(txn, pubkey)?;
// cleanup `programs` and `owners` index
self.remove_programs_index_entry(
pubkey,
old_owner,
&mut txn,
txn,
allocation.offset,
)?;
// track new owner of the account via programs' index
let offset_and_pubkey =
bytes!(#pack, allocation.offset, Offset, *pubkey, Pubkey);
self.programs.put(&mut txn, owner, offset_and_pubkey)?;
self.programs.put(txn, owner, offset_and_pubkey)?;
// track the reverse relation between account and its owner
self.owners.put(&mut txn, pubkey, owner)?;

txn.commit().map_err(Into::into)
self.owners.put(txn, pubkey, owner)?;
Ok(())
}

fn remove_programs_index_entry(
Expand Down Expand Up @@ -379,9 +375,9 @@ impl AccountsDbIndex {
pub(crate) fn try_recycle_allocation(
&self,
space: Blocks,
txn: &mut RwTransaction,
) -> AccountsDbResult<ExistingAllocation> {
let mut txn = self.env.begin_rw_txn()?;
let mut cursor = self.deallocations.cursor_rw(&mut txn)?;
let mut cursor = self.deallocations.cursor_rw(txn)?;
// this is a neat lmdb trick where we can search for entry with matching
// or greater key since we are interested in any allocation of at least
// `blocks` size or greater, this works perfectly well for this case
Expand All @@ -402,9 +398,6 @@ impl AccountsDbIndex {
cursor.put(&remainder.to_le_bytes(), &index_value, WEMPTY)?;
}

drop(cursor);
txn.commit()?;

Ok(ExistingAllocation { offset, blocks })
}

Expand Down Expand Up @@ -438,6 +431,11 @@ impl AccountsDbIndex {
};
self.deallocations.entries(&txn)
}

/// Initiate RW Transaction
pub(crate) fn rwtxn(&self) -> lmdb::Result<RwTransaction<'_>> {
self.env.begin_rw_txn()
}
}

pub(crate) mod iterator;
Expand Down
Loading