Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bootstrap retry #3576

Merged
merged 6 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions massa-async-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ impl AsyncPool {
}
}

/// Resets the pool to its initial state
///
/// USED ONLY FOR BOOTSTRAP
pub fn reset(&mut self) {
self.messages.clear();
self.hash = Hash::from_bytes(ASYNC_POOL_HASH_INITIAL_BYTES);
}

/// Applies pre-compiled `AsyncPoolChanges` to the pool without checking for overflows.
/// This function is used when applying pre-compiled `AsyncPoolChanges` to an `AsyncPool`.
///
Expand Down
2 changes: 2 additions & 0 deletions massa-bootstrap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ async fn stream_final_state_and_consensus(
last_ops_step: StreamingStep::Started,
last_consensus_step: StreamingStep::Started,
};
let mut write_final_state = global_bootstrap_state.final_state.write();
write_final_state.reset();
return Err(BootstrapError::GeneralError(String::from("Slot too old")));
}
BootstrapServerMessage::BootstrapError { error } => {
Expand Down
9 changes: 9 additions & 0 deletions massa-executed-ops/src/executed_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ impl ExecutedOps {
}
}

/// Reset the executed operations
///
/// USED FOR BOOTSTRAP ONLY
pub fn reset(&mut self) {
self.sorted_ops.clear();
self.ops.clear();
self.hash = Hash::from_bytes(EXECUTED_OPS_HASH_INITIAL_BYTES);
}

/// Returns the number of executed operations
pub fn len(&self) -> usize {
self.ops.len()
Expand Down
14 changes: 14 additions & 0 deletions massa-final-state/src/final_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ impl FinalState {
})
}

/// Reset the final state to the initial state.
///
/// USED ONLY FOR BOOTSTRAP
pub fn reset(&mut self) {
self.slot = Slot::new(0, self.config.thread_count.saturating_sub(1));
self.ledger.reset();
self.async_pool.reset();
self.pos_state.reset();
self.executed_ops.reset();
self.changes_history.clear();
// reset the final state hash
self.final_state_hash = Hash::from_bytes(FINAL_STATE_HASH_INITIAL_BYTES);
}

/// Compute the current state hash.
///
/// Used when finalizing a slot.
Expand Down
5 changes: 5 additions & 0 deletions massa-ledger-exports/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ pub trait LedgerController: Send + Sync + Debug {
/// Return: Last key inserted
fn set_ledger_part(&self, data: Vec<u8>) -> Result<StreamingStep<Vec<u8>>, ModelsError>;

/// Reset the ledger
///
/// USED FOR BOOTSTRAP ONLY
fn reset(&mut self);

/// Get every address and their corresponding balance.
///
/// IMPORTANT: This should only be used for debug and test purposes.
Expand Down
7 changes: 7 additions & 0 deletions massa-ledger-worker/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ impl LedgerController for FinalLedger {
self.sorted_ledger.set_ledger_part(data.as_bytes())
}

/// Reset the disk ledger.
///
/// USED FOR BOOTSTRAP ONLY
fn reset(&mut self) {
self.sorted_ledger.reset();
}

/// Get every address and their corresponding balance.
///
/// IMPORTANT: This should only be used for debug and test purposes.
Expand Down
17 changes: 17 additions & 0 deletions massa-ledger-worker/src/ledger_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,23 @@ impl LedgerDB {
))
}
}

pub fn reset(&mut self) {
self.db
.drop_cf(LEDGER_CF)
.expect("Error dropping ledger cf");
self.db
.drop_cf(METADATA_CF)
.expect("Error dropping metadata cf");
let mut db_opts = Options::default();
db_opts.set_error_if_exists(true);
self.db
.create_cf(LEDGER_CF, &db_opts)
.expect("Error creating ledger cf");
self.db
.create_cf(METADATA_CF, &db_opts)
.expect("Error creating metadata cf");
}
}

// Private helpers
Expand Down
8 changes: 8 additions & 0 deletions massa-pos-exports/src/pos_final_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ impl PoSFinalState {
})
}

/// Reset the state of the PoS final state
///
/// USED ONLY FOR BOOTSTRAP
pub fn reset(&mut self) {
self.cycle_history.clear();
self.deferred_credits = DeferredCredits::default();
}

/// Create the initial cycle based off the initial rolls.
///
/// This should be called only if bootstrap did not happen.
Expand Down