Skip to content

Commit cf96214

Browse files
authored
Storage initialization is idempotent (#4543)
## Motivation Currently, initializing a storage is a one-time only operation meaning that if we try to do it again it will return an error. ## Proposal Storage initialization is an idempotent operation – we only write blobs under specific keys. Do not return an error, instead return early with `Ok(())`, if storage is already initialized. ## Test Plan CI ## Release Plan - These changes follow the usual release cycle. - These changes should be backported to the latest `testnet` branch, then - be released in a new SDK ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent c5eecef commit cf96214

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

linera-client/src/config.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ 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>),
3533
#[error("no admin chain configured")]
3634
NoAdminChain,
3735
}
@@ -169,15 +167,16 @@ impl GenesisConfig {
169167
.await
170168
.map_err(linera_chain::ChainError::from)?
171169
{
172-
return Err(Error::StorageIsAlreadyInitialized(Box::new(description)));
170+
tracing::debug!(?description, "storage already initialized");
171+
return Ok(());
173172
}
174173
let network_description = self.network_description();
175174
storage
176-
.write_blob(&self.committee_blob())
175+
.write_network_description(&network_description)
177176
.await
178177
.map_err(linera_chain::ChainError::from)?;
179178
storage
180-
.write_network_description(&network_description)
179+
.write_blob(&self.committee_blob())
181180
.await
182181
.map_err(linera_chain::ChainError::from)?;
183182
for description in &self.chains {

0 commit comments

Comments
 (0)