-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ledgerdb migrations verified proofs, batch by number, slot by number (#…
…1649) Co-authored-by: eyusufatik <[email protected]>
- Loading branch information
1 parent
a2adbdf
commit 0da7227
Showing
13 changed files
with
286 additions
and
19 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
crates/batch-prover/src/db_migrations/batch_and_slot_by_number.rs
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,27 @@ | ||
use std::sync::Arc; | ||
|
||
use sov_db::ledger_db::migrations::{LedgerMigration, MigrationName, MigrationVersion}; | ||
use sov_db::ledger_db::LedgerDB; | ||
|
||
/// Table removal migration | ||
/// tables BatchByNumber and SlotByNumber are removed | ||
pub(crate) struct MigrateBatchAndSlotByNumber {} | ||
|
||
impl LedgerMigration for MigrateBatchAndSlotByNumber { | ||
fn identifier(&self) -> (MigrationName, MigrationVersion) { | ||
("MigrateBatchAndSlotByNumber".to_owned(), 1) | ||
} | ||
|
||
fn execute( | ||
&self, | ||
_ledger_db: Arc<LedgerDB>, | ||
tables_to_drop: &mut Vec<String>, | ||
) -> anyhow::Result<()> { | ||
let batch_by_number = "BatchByNumber".to_owned(); | ||
let slot_by_number = "SlotByNumber".to_owned(); | ||
|
||
tables_to_drop.push(batch_by_number); | ||
tables_to_drop.push(slot_by_number); | ||
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
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,40 @@ | ||
use std::sync::Arc; | ||
|
||
use sov_db::ledger_db::migrations::{LedgerMigration, MigrationName, MigrationVersion}; | ||
use sov_db::ledger_db::LedgerDB; | ||
|
||
/// Table name change migration | ||
/// table name "VerifiedProofsBySlotNumber" is now "VerifiedBatchProofsBySlotNumber" | ||
pub(crate) struct MigrateVerifiedProofsBySlotNumber {} | ||
|
||
// Name of the schema was changed from VerifiedProofsBySlotNumber to VerifiedBatchProofsBySlotNumber | ||
impl LedgerMigration for MigrateVerifiedProofsBySlotNumber { | ||
fn identifier(&self) -> (MigrationName, MigrationVersion) { | ||
("MigrateVerifiedProofsBySlotNumber".to_owned(), 1) | ||
} | ||
|
||
fn execute( | ||
&self, | ||
ledger_db: Arc<LedgerDB>, | ||
tables_to_drop: &mut Vec<String>, | ||
) -> anyhow::Result<()> { | ||
let from = "VerifiedProofsBySlotNumber"; | ||
let to = "VerifiedBatchProofsBySlotNumber"; | ||
|
||
let migrate_from_handle = ledger_db.get_cf_handle(from)?; | ||
|
||
let migrate_from_iterator = ledger_db.get_iterator_for_cf(migrate_from_handle, None)?; | ||
|
||
let migrate_to_handle = ledger_db.get_cf_handle(to)?; | ||
|
||
// Insert key value pairs from old table to new table | ||
for key_value_res in migrate_from_iterator { | ||
let (key, value) = key_value_res.unwrap(); | ||
ledger_db.insert_into_cf_raw(migrate_to_handle, &key, &value)?; | ||
} | ||
drop(ledger_db); | ||
|
||
tables_to_drop.push(from.to_string()); | ||
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
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
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
27 changes: 27 additions & 0 deletions
27
crates/fullnode/src/db_migrations/batch_and_slot_by_number.rs
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,27 @@ | ||
use std::sync::Arc; | ||
|
||
use sov_db::ledger_db::migrations::{LedgerMigration, MigrationName, MigrationVersion}; | ||
use sov_db::ledger_db::LedgerDB; | ||
|
||
/// Table removal migration | ||
/// tables BatchByNumber and SlotByNumber are removed | ||
pub(crate) struct MigrateBatchAndSlotByNumber {} | ||
|
||
impl LedgerMigration for MigrateBatchAndSlotByNumber { | ||
fn identifier(&self) -> (MigrationName, MigrationVersion) { | ||
("MigrateBatchAndSlotByNumber".to_owned(), 1) | ||
} | ||
|
||
fn execute( | ||
&self, | ||
_ledger_db: Arc<LedgerDB>, | ||
tables_to_drop: &mut Vec<String>, | ||
) -> anyhow::Result<()> { | ||
let batch_by_number = "BatchByNumber".to_owned(); | ||
let slot_by_number = "SlotByNumber".to_owned(); | ||
|
||
tables_to_drop.push(batch_by_number); | ||
tables_to_drop.push(slot_by_number); | ||
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
27 changes: 27 additions & 0 deletions
27
crates/sequencer/src/db_migrations/batch_and_slot_by_number.rs
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,27 @@ | ||
use std::sync::Arc; | ||
|
||
use sov_db::ledger_db::migrations::{LedgerMigration, MigrationName, MigrationVersion}; | ||
use sov_db::ledger_db::LedgerDB; | ||
|
||
/// Table removal migration | ||
/// tables BatchByNumber and SlotByNumber are removed | ||
pub(crate) struct MigrateBatchAndSlotByNumber {} | ||
|
||
impl LedgerMigration for MigrateBatchAndSlotByNumber { | ||
fn identifier(&self) -> (MigrationName, MigrationVersion) { | ||
("MigrateBatchAndSlotByNumber".to_owned(), 1) | ||
} | ||
|
||
fn execute( | ||
&self, | ||
_ledger_db: Arc<LedgerDB>, | ||
tables_to_drop: &mut Vec<String>, | ||
) -> anyhow::Result<()> { | ||
let batch_by_number = "BatchByNumber".to_owned(); | ||
let slot_by_number = "SlotByNumber".to_owned(); | ||
|
||
tables_to_drop.push(batch_by_number); | ||
tables_to_drop.push(slot_by_number); | ||
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
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,40 @@ | ||
use std::sync::Arc; | ||
|
||
use sov_db::ledger_db::migrations::{LedgerMigration, MigrationName, MigrationVersion}; | ||
use sov_db::ledger_db::LedgerDB; | ||
|
||
/// Table name change migration | ||
/// table name "VerifiedProofsBySlotNumber" is now "VerifiedBatchProofsBySlotNumber" | ||
pub(crate) struct MigrateVerifiedProofsBySlotNumber {} | ||
|
||
// Name of the schema was changed from VerifiedProofsBySlotNumber to VerifiedBatchProofsBySlotNumber | ||
impl LedgerMigration for MigrateVerifiedProofsBySlotNumber { | ||
fn identifier(&self) -> (MigrationName, MigrationVersion) { | ||
("MigrateVerifiedProofsBySlotNumber".to_owned(), 1) | ||
} | ||
|
||
fn execute( | ||
&self, | ||
ledger_db: Arc<LedgerDB>, | ||
tables_to_drop: &mut Vec<String>, | ||
) -> anyhow::Result<()> { | ||
let from = "VerifiedProofsBySlotNumber"; | ||
let to = "VerifiedBatchProofsBySlotNumber"; | ||
|
||
let migrate_from_handle = ledger_db.get_cf_handle(from)?; | ||
|
||
let migrate_from_iterator = ledger_db.get_iterator_for_cf(migrate_from_handle, None)?; | ||
|
||
let migrate_to_handle = ledger_db.get_cf_handle(to)?; | ||
|
||
// Insert key value pairs from old table to new table | ||
for key_value_res in migrate_from_iterator { | ||
let (key, value) = key_value_res.unwrap(); | ||
ledger_db.insert_into_cf_raw(migrate_to_handle, &key, &value)?; | ||
} | ||
drop(ledger_db); | ||
|
||
tables_to_drop.push(from.to_string()); | ||
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
Oops, something went wrong.