-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
use std::sync::OnceLock; | ||
|
||
use sov_db::ledger_db::migrations::LedgerMigration; | ||
|
||
mod pruned_height; | ||
|
||
pub(crate) fn migrations() -> &'static Vec<Box<dyn LedgerMigration + Send + Sync + 'static>> { | ||
static MIGRATIONS: OnceLock<Vec<Box<dyn LedgerMigration + Send + Sync + 'static>>> = | ||
OnceLock::new(); | ||
MIGRATIONS.get_or_init(|| vec![Box::new(pruned_height::MigratePrunedL2Height {})]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::sync::Arc; | ||
|
||
use sov_db::ledger_db::migrations::{LedgerMigration, MigrationName, MigrationVersion}; | ||
use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; | ||
|
||
pub(super) struct MigratePrunedL2Height {} | ||
|
||
impl LedgerMigration for MigratePrunedL2Height { | ||
fn identifier(&self) -> (MigrationName, MigrationVersion) { | ||
("MigratePrunedL2Height".to_owned(), 1) | ||
} | ||
|
||
fn execute(&self, ledger_db: Arc<LedgerDB>) -> anyhow::Result<()> { | ||
let Some(mut last_pruned_height) = ledger_db.get_last_pruned_l2_height()? else { | ||
// No need to do any migration | ||
return Ok(()); | ||
}; | ||
|
||
// Example | ||
last_pruned_height += 10; | ||
ledger_db.set_last_pruned_l2_height(last_pruned_height)?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters