Skip to content

Commit a6a38c7

Browse files
authored
feat: implement ephemeral accounts (#915)
1 parent 03c690d commit a6a38c7

File tree

31 files changed

+1848
-102
lines changed

31 files changed

+1848
-102
lines changed

.github/packages/npm-package/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@magicblock-labs/ephemeral-validator",
3-
"version": "0.6.2",
3+
"version": "0.7.0",
44
"description": "MagicBlock Ephemeral Validator",
55
"homepage": "https://github.com/magicblock-labs/magicblock-validator#readme",
66
"bugs": {
@@ -30,10 +30,10 @@
3030
"typescript": "^4.9.4"
3131
},
3232
"optionalDependencies": {
33-
"@magicblock-labs/ephemeral-validator-darwin-arm64": "0.6.2",
34-
"@magicblock-labs/ephemeral-validator-darwin-x64": "0.6.2",
35-
"@magicblock-labs/ephemeral-validator-linux-arm64": "0.6.2",
36-
"@magicblock-labs/ephemeral-validator-linux-x64": "0.6.2",
33+
"@magicblock-labs/ephemeral-validator-darwin-arm64": "0.7.0",
34+
"@magicblock-labs/ephemeral-validator-darwin-x64": "0.7.0",
35+
"@magicblock-labs/ephemeral-validator-linux-arm64": "0.7.0",
36+
"@magicblock-labs/ephemeral-validator-linux-x64": "0.7.0",
3737
"@magicblock-labs/vrf-oracle-linux-x64": "0.2.3",
3838
"@magicblock-labs/vrf-oracle-linux-arm64": "0.2.3",
3939
"@magicblock-labs/vrf-oracle-darwin-x64": "0.2.3",

.github/packages/npm-package/package.json.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@magicblock-labs/${node_pkg}",
33
"description": "Ephemeral Validator (${node_pkg})",
4-
"version": "0.6.2",
4+
"version": "0.7.0",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/magicblock-labs/magicblock-validator.git"

Cargo.lock

Lines changed: 27 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ resolver = "2"
3838

3939
[workspace.package]
4040
# Solana Version (2.2.x)
41-
version = "0.6.2"
41+
version = "0.7.0"
4242
authors = ["MagicBlock Maintainers <maintainers@magicblock.xyz>"]
4343
repository = "https://github.com/magicblock-labs/ephemeral-validator"
4444
homepage = "https://www.magicblock.xyz"
@@ -138,7 +138,7 @@ serde_json = "1.0"
138138
serde_with = "3.16"
139139
serial_test = "3.2"
140140
sha3 = "0.10.8"
141-
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "2246929" }
141+
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "6eae52b" }
142142
solana-account-decoder = { version = "2.2" }
143143
solana-account-decoder-client-types = { version = "2.2" }
144144
solana-account-info = { version = "2.2" }
@@ -217,7 +217,7 @@ spl-token-2022 = "7.0"
217217

218218
[workspace.dependencies.solana-svm]
219219
git = "https://github.com/magicblock-labs/magicblock-svm.git"
220-
rev = "3e9456ec4"
220+
rev = "bdbaac86"
221221
features = ["dev-context-only-utils"]
222222

223223
[workspace.dependencies.rocksdb]
@@ -229,9 +229,9 @@ version = "0.22.0"
229229
# some solana dependencies have solana-storage-proto as dependency
230230
# we need to patch them with our version, because they use protobuf-src v1.1.0
231231
# and we use protobuf-src v2.1.1. Otherwise compilation fails
232-
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "2246929" }
232+
solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "6eae52b" }
233233
solana-storage-proto = { path = "./storage-proto" }
234-
solana-svm = { git = "https://github.com/magicblock-labs/magicblock-svm.git", rev = "3e9456ec4" }
234+
solana-svm = { git = "https://github.com/magicblock-labs/magicblock-svm.git", rev = "bdbaac86" }
235235
# Fork is used to enable `disable_manual_compaction` usage
236236
# Fork is based on commit d4e9e16 of rocksdb (parent commit of 0.23.0 release)
237237
# without patching update isn't possible due to conflict with solana deps

magicblock-accounts-db/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub type AccountsDbResult<T> = Result<T, AccountsDbError>;
2020

2121
/// A global lock used to suspend all write operations during critical
2222
/// sections (like snapshots).
23-
pub type GlobalWriteLock = Arc<RwLock<()>>;
23+
pub type GlobalSyncLock = Arc<RwLock<()>>;
2424

2525
pub const ACCOUNTSDB_DIR: &str = "accountsdb";
2626

@@ -41,7 +41,7 @@ pub struct AccountsDb {
4141
/// Global lock ensures atomic snapshots by pausing writes.
4242
/// Note: Reads are generally wait-free/lock-free via mmap,
4343
/// unless they require index cursor stability.
44-
write_lock: GlobalWriteLock,
44+
write_lock: GlobalSyncLock,
4545
/// Configured interval (in slots) for creating snapshots.
4646
snapshot_frequency: u64,
4747
}
@@ -86,7 +86,7 @@ impl AccountsDb {
8686
storage,
8787
index,
8888
snapshot_manager,
89-
write_lock: GlobalWriteLock::default(),
89+
write_lock: GlobalSyncLock::default(),
9090
snapshot_frequency: config.snapshot_frequency,
9191
};
9292

@@ -169,6 +169,11 @@ impl AccountsDb {
169169
}
170170
};
171171
}
172+
// The ephemeral account has been closed, remove it from DB
173+
if account.ephemeral() && account.owner() == &Pubkey::default() {
174+
self.index.remove(pubkey, txn!())?;
175+
return Ok(());
176+
}
172177
match account {
173178
AccountSharedData::Borrowed(acc) => {
174179
if acc.owner_changed() {
@@ -366,7 +371,7 @@ impl AccountsDb {
366371
self.index.flush();
367372
}
368373

369-
pub fn write_lock(&self) -> GlobalWriteLock {
374+
pub fn write_lock(&self) -> GlobalSyncLock {
370375
self.write_lock.clone()
371376
}
372377
}

magicblock-api/src/fund_account.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use magicblock_program::MagicContext;
66
use solana_account::{AccountSharedData, WritableAccount};
77
use solana_keypair::Keypair;
88
use solana_pubkey::Pubkey;
9+
use solana_rent::Rent;
910
use solana_signer::Signer;
1011

1112
use crate::{
@@ -82,3 +83,15 @@ pub(crate) fn fund_magic_context(accountsdb: &AccountsDb) {
8283
let _ = accountsdb
8384
.insert_account(&magic_program::MAGIC_CONTEXT_PUBKEY, &magic_context);
8485
}
86+
87+
pub(crate) fn fund_ephemeral_vault(accountsdb: &AccountsDb) {
88+
let lamports = Rent::default().minimum_balance(0);
89+
fund_account(accountsdb, &magic_program::EPHEMERAL_VAULT_PUBKEY, lamports);
90+
let mut vault = accountsdb
91+
.get_account(&magic_program::EPHEMERAL_VAULT_PUBKEY)
92+
.expect("vault should have been created");
93+
vault.set_ephemeral(true);
94+
vault.set_owner(magic_program::ID);
95+
let _ = accountsdb
96+
.insert_account(&magic_program::EPHEMERAL_VAULT_PUBKEY, &vault);
97+
}

0 commit comments

Comments
 (0)