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
2 changes: 2 additions & 0 deletions magicblock-account-cloner/src/account_cloner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub enum AccountClonerUnclonableReason {
DoesNotHaveDelegatedEscrowAccount,
DoesNotAllowEscrowedPda,
DoesNotAllowFeepayerWithEscrowedPda,
/// The account does not exist on-chain (RPC returned empty/system default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify that the RPC returns this? I thought it returns some user error if the account is not found or None see here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DoesNotExist,
/// If an account is delegated to our validator then we should use the latest
/// state in our own bank since that is more up to date than the on-chain state.
DelegatedAccountsNotClonedWhileHydrating,
Expand Down
31 changes: 25 additions & 6 deletions magicblock-account-cloner/src/remote_account_cloner_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use solana_sdk::{
clock::Slot,
pubkey::Pubkey,
signature::Signature,
system_program,
sysvar::clock,
};
use tokio::time::sleep;
Expand Down Expand Up @@ -442,12 +443,21 @@ where
stage: ValidatorStage,
) -> AccountClonerResult<AccountClonerOutput> {
let updated_clone_output = self.do_clone(pubkey, stage).await?;
self.last_clone_output
.write()
.expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned")
.insert(*pubkey, updated_clone_output.clone());
if let Ok(map) = self.last_clone_output.read() {
metrics::set_cached_clone_outputs_count(map.len());
// Do not cache non-existent accounts
let should_cache = match &updated_clone_output {
AccountClonerOutput::Unclonable { reason, .. } => {
!matches!(reason, AccountClonerUnclonableReason::DoesNotExist)
}
AccountClonerOutput::Cloned { .. } => true,
};
if should_cache {
self.last_clone_output
.write()
.expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned")
.insert(*pubkey, updated_clone_output.clone());
if let Ok(map) = self.last_clone_output.read() {
metrics::set_cached_clone_outputs_count(map.len());
}
}
Ok(updated_clone_output)
}
Expand Down Expand Up @@ -669,6 +679,15 @@ where
// If the account is present on-chain, but not delegated, it's just readonly data
// We need to differenciate between programs and other accounts
AccountChainState::Undelegated { account, .. } => {
// Skip cloning if the account does not exist on-chain (empty system account)
if account.lamports == 0 && account.owner == system_program::ID
{
return Ok(AccountClonerOutput::Unclonable {
pubkey: *pubkey,
reason: AccountClonerUnclonableReason::DoesNotExist,
at_slot: u64::MAX,
});
}
// If it's an executable, we may have some special fetching to do
if account.executable {
if let Some(allowed_program_ids) = &self.allowed_program_ids
Expand Down
Loading