Skip to content

Commit 69d0762

Browse files
fix: resolve corrupted accounts (#306)
## Description - Resolve corrupted accounts on restart ## Note This change assume that we ensure undelegation are landing <!-- greptile_comment --> ## Greptile Summary Enhanced account corruption handling and ledger replay functionality, focusing on improved restart reliability and account state management. - Added debug logging in `magicblock-accounts-db/src/persist/accounts_persister.rs` to trace storage file loading and corruption detection - Increased account hydration concurrency from 30 to 100 in `magicblock-account-cloner/src/remote_account_cloner_worker.rs` for better performance - Added ownership validation in `magicblock-account-cloner/src/remote_account_cloner_worker.rs` to prevent unnecessary re-cloning of delegated accounts - Implemented scheduled commits clearing in `magicblock-api/src/magic_validator.rs` to avoid duplicate commits during ledger processing - Added slot advancement logic in `magicblock-api/src/magic_validator.rs` to ensure correct transaction ordering after restart <!-- /greptile_comment -->
1 parent 101db25 commit 69d0762

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

magicblock-account-cloner/src/remote_account_cloner_worker.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ where
276276
// TODO(GabrielePicco): Make the concurrency configurable
277277
stream
278278
.map(Ok::<_, AccountClonerError>)
279-
.try_for_each_concurrent(30, |(pubkey, owner)| async move {
279+
.try_for_each_concurrent(100, |(pubkey, owner)| async move {
280280
trace!("Hydrating '{}'", pubkey);
281281
let res = self
282282
.do_clone_and_update_cache(
@@ -613,7 +613,14 @@ where
613613
at_slot: account_chain_snapshot.at_slot,
614614
});
615615
}
616-
if !stage.should_clone_delegated_account(delegation_record) {
616+
if !stage.should_clone_delegated_account(delegation_record)
617+
&& self
618+
.internal_account_provider
619+
.get_account(pubkey)
620+
.is_some_and(|acc| {
621+
acc.owner().eq(&delegation_record.owner)
622+
})
623+
{
617624
// NOTE: the account was already cloned when the initial instance of this
618625
// validator ran. We don't want to clone it again during ledger replay, however
619626
// we want to use it as a delegated + cloned account, thus we respond in the
@@ -625,6 +632,7 @@ where
625632
signature: Signature::new_unique(),
626633
});
627634
}
635+
628636
self.do_clone_delegated_account(
629637
pubkey,
630638
// TODO(GabrielePicco): Avoid cloning

magicblock-accounts-db/src/persist/accounts_persister.rs

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl AccountsPersister {
316316
StorageAccess::Mmap,
317317
) {
318318
Ok((append_vec, num_accounts)) => {
319+
debug!("Loading storage from {:?}", file);
319320
let accounts = AccountsFile::AppendVec(append_vec);
320321
let storage = AccountStorageEntry::new_existing(
321322
slot,

magicblock-api/src/magic_validator.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ use std::{
1010
time::Duration,
1111
};
1212

13+
use crate::{
14+
accounts::create_accounts_run_and_snapshot_dirs,
15+
errors::{ApiError, ApiResult},
16+
external_config::try_convert_accounts_config,
17+
fund_account::{
18+
fund_magic_context, fund_validator_identity, funded_faucet,
19+
},
20+
geyser_transaction_notify_listener::GeyserTransactionNotifyListener,
21+
init_geyser_service::{init_geyser_service, InitGeyserServiceConfig},
22+
ledger::{
23+
self, ledger_parent_dir, read_validator_keypair_from_ledger,
24+
write_validator_keypair_to_ledger,
25+
},
26+
slot::advance_slot_and_update_ledger,
27+
tickers::{
28+
init_commit_accounts_ticker, init_slot_ticker,
29+
init_system_metrics_ticker,
30+
},
31+
};
1332
use conjunto_transwise::RpcProviderConfig;
1433
use log::*;
1534
use magicblock_account_cloner::{
@@ -59,26 +78,6 @@ use solana_sdk::{
5978
use tempfile::TempDir;
6079
use tokio_util::sync::CancellationToken;
6180

62-
use crate::{
63-
accounts::create_accounts_run_and_snapshot_dirs,
64-
errors::{ApiError, ApiResult},
65-
external_config::try_convert_accounts_config,
66-
fund_account::{
67-
fund_magic_context, fund_validator_identity, funded_faucet,
68-
},
69-
geyser_transaction_notify_listener::GeyserTransactionNotifyListener,
70-
init_geyser_service::{init_geyser_service, InitGeyserServiceConfig},
71-
ledger::{
72-
self, ledger_parent_dir, read_validator_keypair_from_ledger,
73-
write_validator_keypair_to_ledger,
74-
},
75-
slot::advance_slot_and_update_ledger,
76-
tickers::{
77-
init_commit_accounts_ticker, init_slot_ticker,
78-
init_system_metrics_ticker,
79-
},
80-
};
81-
8281
// -----------------
8382
// MagicValidatorConfig
8483
// -----------------

0 commit comments

Comments
 (0)