Skip to content

Commit

Permalink
revert to avoid deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
dknopik committed Jan 28, 2025
1 parent 3d5647d commit 63543df
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions anchor/database/src/validator_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ impl NetworkDatabase {
owner: Address,
fee_recipient: Address,
) -> Result<(), DatabaseError> {
// Make sure the cluster exists by getting the in memory entry
if let Some(mut cluster) = self.state().clusters().get_by(&owner) {
// Update the database
let conn = self.connection()?;
conn.prepare_cached(SQL[&SqlStatement::UpdateFeeRecipient])?
.execute(params![
fee_recipient.to_string(), // New fee recipient address for entire cluster
owner.to_string() // Owner of the cluster
])?;
// Update the database
let conn = self.connection()?;
conn.prepare_cached(SQL[&SqlStatement::UpdateFeeRecipient])?
.execute(params![
fee_recipient.to_string(), // New fee recipient address for entire cluster
owner.to_string() // Owner of the cluster
])?;

// Update in memory
cluster.fee_recipient = fee_recipient;
self.modify_state(|state| {
self.modify_state(|state| {
if let Some(mut cluster) = state.multi_state.clusters.get_by(&owner) {
// Update in memory
cluster.fee_recipient = fee_recipient;
state
.multi_state
.clusters
.update(&cluster.cluster_id.clone(), cluster);
});
}
}
});
Ok(())
}

Expand All @@ -38,25 +37,28 @@ impl NetworkDatabase {
validator_pubkey: &PublicKey,
graffiti: Graffiti,
) -> Result<(), DatabaseError> {
// Make sure this validator exists by getting the in memory entry
if let Some(mut validator) = self.state().metadata().get_by(validator_pubkey) {
// Update the database
let conn = self.connection()?;
conn.prepare_cached(SQL[&SqlStatement::SetGraffiti])?
.execute(params![
graffiti.0.as_slice(), // New graffiti
validator_pubkey.to_string() // The public key of the validator
])?;
// Update the database
let conn = self.connection()?;
conn.prepare_cached(SQL[&SqlStatement::SetGraffiti])?
.execute(params![
graffiti.0.as_slice(), // New graffiti
validator_pubkey.to_string() // The public key of the validator
])?;

// Update in memory
validator.graffiti = graffiti;
self.modify_state(|state| {
self.modify_state(|state| {
if let Some(mut validator) = state
.multi_state
.validator_metadata
.get_by(validator_pubkey)
{
// Update in memory
validator.graffiti = graffiti;
state
.multi_state
.validator_metadata
.update(validator_pubkey, validator);
});
}
}
});
Ok(())
}
}

0 comments on commit 63543df

Please sign in to comment.