Skip to content

Commit 1c6f114

Browse files
committed
update to the migration cli
1 parent b27951a commit 1c6f114

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

synd-migration-cli/src/migration.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ pub struct RollupState {
145145
pub safe_block_hash: Option<B256>,
146146
/// The batch count
147147
pub batch_count: u64,
148+
/// The batch accumulator before applying the latest batch
149+
pub batch_acc_before: B256,
148150
/// The batch accumulator
149151
pub batch_acc: B256,
150152
/// The parent chain block
@@ -153,8 +155,9 @@ pub struct RollupState {
153155
pub delayed_msgs_count: u64,
154156
/// The delayed messages accumulator
155157
pub delayed_msgs_acc: B256,
156-
/// Arb message count
157-
pub batch_message_count: u64,
158+
/// Arb sub-messages count (what is stored in the bridge contract as
159+
/// `sequencerReportedSubMessageCount`
160+
pub batch_submessage_count: u64,
158161
}
159162

160163
/// Migration command - it inspects a given Nitro database, extracts relevant information and sets
@@ -203,14 +206,16 @@ pub async fn get_migration_data(nitro_db_path: &Path) -> Result<(RollupState, Ve
203206
debug!("chain config: {:#?}", chain_config);
204207

205208
println!("\n---------------TRANSLATOR / MCHAIN config ---------------\n");
206-
println!("MIGRATED_BATCH_ACC: {}", rollup_state.batch_acc);
207-
println!("MIGRATED_BATCH_COUNT: {}", rollup_state.batch_count);
208-
println!("MIGRATED_DELAYED_MSGS_ACC: {}", rollup_state.delayed_msgs_acc);
209-
println!("MIGRATED_DELAYED_MSGS_COUNT: {}", rollup_state.delayed_msgs_count);
210-
println!("MIGRATED_APPCHAIN_BLOCK_HASH: {:?}", rollup_state.last_block_hash);
211-
println!("SETTLEMENT_START_BLOCK: {}", rollup_state.parent_chain_block);
212-
println!("GENESIS_CONFIG: '{}'", std::str::from_utf8(&raw_genesis_from_db).unwrap());
213-
println!("\n------------------------------\n\n");
209+
println!("BATCH_ACC_BEFORE={}", rollup_state.batch_acc_before);
210+
println!("BATCH_ACC={}", rollup_state.batch_acc);
211+
println!("BATCH_COUNT={}", rollup_state.batch_count);
212+
println!("DELAYED_MSGS_ACC={}", rollup_state.delayed_msgs_acc);
213+
println!("DELAYED_MSGS_COUNT={}", rollup_state.delayed_msgs_count);
214+
println!("ARB_SUB_MSGS_COUNT={}", rollup_state.batch_submessage_count);
215+
println!("\n");
216+
println!("SETTLEMENT_CHAIN_BLOCK={}", rollup_state.parent_chain_block);
217+
println!("APPCHAIN_BLOCK_HASH={:?}", rollup_state.last_block_hash);
218+
println!("GENESIS_CONFIG='{}'", std::str::from_utf8(&raw_genesis_from_db).unwrap());
214219

215220
println!("\n--------------- NITRO configuration ---------------\n");
216221

@@ -227,8 +232,6 @@ pub async fn get_migration_data(nitro_db_path: &Path) -> Result<(RollupState, Ve
227232

228233
println!("\n------------------------------\n\n");
229234

230-
println!("last batch \"arb msg count\": {}", rollup_state.batch_message_count);
231-
232235
println!(
233236
"last rollup block: {:?} - {:?}",
234237
rollup_state.last_block_number, rollup_state.last_block_hash
@@ -240,7 +243,7 @@ pub async fn get_migration_data(nitro_db_path: &Path) -> Result<(RollupState, Ve
240243

241244
if rollup_state.safe_block_hash.is_some() &&
242245
rollup_state.safe_block_hash.unwrap() == rollup_state.last_block_hash &&
243-
rollup_state.last_block_number == rollup_state.batch_message_count - 1
246+
rollup_state.last_block_number == rollup_state.batch_submessage_count - 1
244247
{
245248
println!("✅✅✅✅✅ Rollup is in safe state to be migrated");
246249
} else {
@@ -342,6 +345,12 @@ fn get_rollup_state(db: &DB, arb_db: &DB) -> Result<RollupState> {
342345
.ok_or_else(|| eyre!("Failed to get batch data"))?;
343346
debug!("batch_data: {:#?}", batch_data);
344347

348+
let batch_before_data = arb_db
349+
.get(make_numbered_key(b"s", batch_count - 2, &[]))?
350+
.map(|bytes| BatchMetadata::decode(&mut &bytes[..]).unwrap())
351+
.ok_or_else(|| eyre!("Failed to get batch data"))?;
352+
debug!("batch_before_dat: {:#?}", batch_before_data);
353+
345354
let delayed_msgs_count = batch_data.delayed_message_count;
346355

347356
// RlpDelayedMessagePrefix is "e" and maps delayed messages sequence_num to
@@ -357,10 +366,11 @@ fn get_rollup_state(db: &DB, arb_db: &DB) -> Result<RollupState> {
357366
safe_block_number,
358367
safe_block_hash,
359368
batch_count,
369+
batch_acc_before: batch_before_data.acc,
360370
batch_acc: batch_data.acc,
361371
parent_chain_block: batch_data.parent_chain_block,
362372
delayed_msgs_count,
363373
delayed_msgs_acc,
364-
batch_message_count: batch_data.message_count,
374+
batch_submessage_count: batch_data.message_count,
365375
})
366376
}

0 commit comments

Comments
 (0)