Skip to content

Commit cf884da

Browse files
authored
Track delegation status (#452)
Add persistence for the delegation status of accounts in accountsdb. This is achieved via setting delegation flag explicitly after account has been "dumped" to the database. closes #442 <!-- greptile_comment --> ## Greptile Summary Implements account delegation status persistence in AccountsDB with comprehensive database architecture changes. - Refactored LMDB database implementation in `magicblock-accounts-db/src/index.rs` to use new Table abstraction for better encapsulation and performance - Added explicit delegation status tracking in `magicblock-account-dumper/src/account_dumper_bank.rs` for both delegated and undelegated accounts - Removed standalone indices (`standalone.rs`) in favor of consolidated main environment structure - Updated account index handling in `magicblock-accounts-db/src/index/tests.rs` to return empty iterators instead of NotFound errors - Added 'dev' branch to CI workflows for enhanced testing coverage <!-- /greptile_comment -->
1 parent 1ce6943 commit cf884da

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ serde = "1.0.217"
142142
serde_derive = "1.0"
143143
serde_json = "1.0"
144144
sha3 = "0.10.8"
145-
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "5b50fad" }
145+
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "176540a" }
146146
solana-accounts-db = { version = "2.2" }
147147
solana-account-decoder = { version = "2.2" }
148148
solana-address-lookup-table-program = { version = "2.2" }
@@ -203,6 +203,6 @@ vergen = "8.3.1"
203203
# some solana dependencies have solana-storage-proto as dependency
204204
# we need to patch them with our version, because they use protobuf-src v1.1.0
205205
# and we use protobuf-src v2.1.1. Otherwise compilation fails
206-
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "5b50fad" }
206+
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "176540a" }
207207
solana-storage-proto = { path = "./storage-proto" }
208208
solana-svm = { git = "https://github.com/magicblock-labs/magicblock-svm.git" }

magicblock-account-dumper/src/account_dumper_bank.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ impl AccountDumper for AccountDumperBank {
9191
None,
9292
self.bank.last_blockhash(),
9393
);
94-
self.execute_transaction(transaction)
94+
let result = self.execute_transaction(transaction)?;
95+
if let Some(mut acc) = self.bank.get_account(pubkey) {
96+
acc.set_delegated(false);
97+
self.bank.store_account(*pubkey, acc);
98+
}
99+
Ok(result)
95100
}
96101

97102
fn dump_delegated_account(
@@ -111,7 +116,12 @@ impl AccountDumper for AccountDumperBank {
111116
overrides,
112117
self.bank.last_blockhash(),
113118
);
114-
self.execute_transaction(transaction)
119+
let result = self.execute_transaction(transaction)?;
120+
if let Some(mut acc) = self.bank.get_account(pubkey) {
121+
acc.set_delegated(true);
122+
self.bank.store_account(*pubkey, acc);
123+
}
124+
Ok(result)
115125
}
116126

117127
fn dump_program_accounts(

magicblock-accounts-db/src/index.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ impl AccountsDbIndex {
399399
*self = Self::new(DEFAULT_SIZE, dbpath)?;
400400
Ok(())
401401
}
402+
403+
/// Returns the number of deallocations in the database
404+
#[cfg(test)]
405+
pub(crate) fn get_delloactions_count(&self) -> usize {
406+
let Ok(txn) = self.env.begin_ro_txn() else {
407+
warn!("failed to start transaction for stats retrieval");
408+
return 0;
409+
};
410+
self.deallocations.entries(&txn)
411+
}
402412
}
403413

404414
pub(crate) mod iterator;

magicblock-accounts-db/src/index/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ fn test_remove_account() {
133133
matches!(offset, Err(AccountsDbError::NotFound)),
134134
"removed account offset is still present in index"
135135
);
136+
assert_eq!(
137+
tenv.get_delloactions_count(),
138+
1,
139+
"the number of deallocations should have increased after account removal"
140+
);
136141
}
137142

138143
#[test]
@@ -239,23 +244,44 @@ fn test_recycle_allocation_after_realloc() {
239244
tenv.reallocate_account(&pubkey, &mut txn, &index_value)
240245
.expect("failed to reallocate account");
241246
txn.commit().expect("failed to commit transaction");
247+
assert_eq!(
248+
tenv.get_delloactions_count(),
249+
1,
250+
"the number of deallocations should have increased after account realloc"
251+
);
252+
242253
let result = tenv.try_recycle_allocation(new_allocation.blocks);
243254
assert_eq!(
244255
result.expect("failed to recycle allocation"),
245256
allocation.into()
246257
);
258+
assert_eq!(
259+
tenv.get_delloactions_count(),
260+
0,
261+
"the number of deallocations should have decresed after recycling"
262+
);
247263
let result = tenv.try_recycle_allocation(new_allocation.blocks);
248264
assert!(
249265
matches!(result, Err(AccountsDbError::NotFound)),
250266
"deallocations index should have run out of existing allocations"
251267
);
252268
tenv.remove_account(&pubkey)
253269
.expect("failed to remove account");
270+
assert_eq!(
271+
tenv.get_delloactions_count(),
272+
1,
273+
"the number of deallocations should have increased after account removal"
274+
);
254275
let result = tenv.try_recycle_allocation(new_allocation.blocks);
255276
assert_eq!(
256277
result.expect("failed to recycle allocation after account removal"),
257278
new_allocation.into()
258279
);
280+
assert_eq!(
281+
tenv.get_delloactions_count(),
282+
0,
283+
"the number of deallocations should have decresed after recycling"
284+
);
259285
}
260286

261287
#[test]

test-integration/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ program-schedulecommit-security = { path = "programs/schedulecommit-security" }
5151
rayon = "1.10.0"
5252
schedulecommit-client = { path = "schedulecommit/client" }
5353
serde = "1.0.217"
54-
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "5b50fad" }
54+
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "176540a" }
5555
solana-program = "2.2"
5656
solana-program-test = "2.2"
5757
solana-pubkey = { version = "2.2" }
@@ -73,4 +73,4 @@ tokio = "1.0"
7373
# and we use protobuf-src v2.1.1. Otherwise compilation fails
7474
solana-storage-proto = { path = "../storage-proto" }
7575
# same reason as above
76-
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "5b50fad" }
76+
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "176540a" }

0 commit comments

Comments
 (0)