Skip to content

Commit ccf84f3

Browse files
authored
Return error if we try to initialize storage with new genesis (#4547)
## Motivation #4543 started treating storage initialization as idempotent but it is still useful to detect if we try to initialize it for a network that has a different Genesis config. ## Proposal Return (and log) an error if the new genesis config is different from the one our storage is initialized with. ## Test Plan CI ## Release Plan - These changes should be backported to the latest `testnet` branch, then - be released in a new SDK, ## Links #4543 - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent cf96214 commit ccf84f3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

linera-client/src/config.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub enum Error {
3030
Chain(#[from] linera_chain::ChainError),
3131
#[error("persistence error: {0}")]
3232
Persistence(Box<dyn std::error::Error + Send + Sync>),
33+
#[error("storage is already initialized: {0:?}")]
34+
StorageIsAlreadyInitialized(Box<NetworkDescription>),
3335
#[error("no admin chain configured")]
3436
NoAdminChain,
3537
}
@@ -167,16 +169,25 @@ impl GenesisConfig {
167169
.await
168170
.map_err(linera_chain::ChainError::from)?
169171
{
172+
if description != self.network_description() {
173+
// We can't initialize storage with a different network description.
174+
tracing::error!(
175+
current_network=?description,
176+
new_network=?self.network_description(),
177+
"storage already initialized"
178+
);
179+
return Err(Error::StorageIsAlreadyInitialized(Box::new(description)));
180+
}
170181
tracing::debug!(?description, "storage already initialized");
171182
return Ok(());
172183
}
173184
let network_description = self.network_description();
174185
storage
175-
.write_network_description(&network_description)
186+
.write_blob(&self.committee_blob())
176187
.await
177188
.map_err(linera_chain::ChainError::from)?;
178189
storage
179-
.write_blob(&self.committee_blob())
190+
.write_network_description(&network_description)
180191
.await
181192
.map_err(linera_chain::ChainError::from)?;
182193
for description in &self.chains {

0 commit comments

Comments
 (0)