Skip to content

Commit

Permalink
Complete the deployment map updates
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Apr 15, 2023
1 parent 25eb2ef commit e48716b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion synthesizer/src/block/transaction/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<N: Network> FromBytes for Transaction<N> {
let fee = Fee::read_le(&mut reader)?;

// Initialize the transaction.
let transaction = Self::from_deployment(deployment, owner, fee).map_err(|e| error(e.to_string()))?;
let transaction = Self::from_deployment(owner, deployment, fee).map_err(|e| error(e.to_string()))?;
// Return the ID and the transaction.
(id, transaction)
}
Expand Down
2 changes: 1 addition & 1 deletion synthesizer/src/process/stack/inclusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ mod tests {
let deployment_transaction = crate::vm::test_helpers::sample_deployment_transaction(rng);

match deployment_transaction {
Transaction::Deploy(_, _, fee, _) => {
Transaction::Deploy(_, _, _, fee) => {
assert!(Inclusion::verify_fee(&fee).is_ok());
}
_ => panic!("Expected a deployment transaction"),
Expand Down
24 changes: 11 additions & 13 deletions synthesizer/src/store/transaction/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
type EditionMap: for<'a> Map<'a, ProgramID<N>, u16>;
/// The mapping of `(program ID, edition)` to `transaction ID`.
type ReverseIDMap: for<'a> Map<'a, (ProgramID<N>, u16), N::TransactionID>;
/// The mapping of `(program ID, edition)` to `Owner`.
type OwnerMap: for<'a> Map<'a, (ProgramID<N>, u16), Owner<N>>;
/// The mapping of `(program ID, edition)` to `program`.
type ProgramMap: for<'a> Map<'a, (ProgramID<N>, u16), Program<N>>;
/// The mapping of `(program ID, function name, edition)` to `verifying key`.
Expand All @@ -56,8 +58,6 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
type FeeMap: for<'a> Map<'a, N::TransactionID, (N::TransitionID, N::StateRoot, Option<Proof<N>>)>;
/// The mapping of `fee transition ID` to `transaction ID`.
type ReverseFeeMap: for<'a> Map<'a, N::TransitionID, N::TransactionID>;
/// The mapping of `(program ID, revision)` to `Owner`.
type OwnerMap: for<'a> Map<'a, (ProgramID<N>, u16), Owner<N>>;

/// The transition storage.
type TransitionStorage: TransitionStorage<N>;
Expand Down Expand Up @@ -96,12 +96,12 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
self.id_map().start_atomic();
self.edition_map().start_atomic();
self.reverse_id_map().start_atomic();
self.owner_map().start_atomic();
self.program_map().start_atomic();
self.verifying_key_map().start_atomic();
self.certificate_map().start_atomic();
self.fee_map().start_atomic();
self.reverse_fee_map().start_atomic();
self.owner_map().start_atomic();
self.transition_store().start_atomic();
}

Expand All @@ -110,12 +110,12 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
self.id_map().is_atomic_in_progress()
|| self.edition_map().is_atomic_in_progress()
|| self.reverse_id_map().is_atomic_in_progress()
|| self.owner_map().is_atomic_in_progress()
|| self.program_map().is_atomic_in_progress()
|| self.verifying_key_map().is_atomic_in_progress()
|| self.certificate_map().is_atomic_in_progress()
|| self.fee_map().is_atomic_in_progress()
|| self.reverse_fee_map().is_atomic_in_progress()
|| self.owner_map().is_atomic_in_progress()
|| self.transition_store().is_atomic_in_progress()
}

Expand All @@ -124,12 +124,12 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
self.id_map().abort_atomic();
self.edition_map().abort_atomic();
self.reverse_id_map().abort_atomic();
self.owner_map().abort_atomic();
self.program_map().abort_atomic();
self.verifying_key_map().abort_atomic();
self.certificate_map().abort_atomic();
self.fee_map().abort_atomic();
self.reverse_fee_map().abort_atomic();
self.owner_map().abort_atomic();
self.transition_store().abort_atomic();
}

Expand All @@ -138,20 +138,20 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
self.id_map().finish_atomic()?;
self.edition_map().finish_atomic()?;
self.reverse_id_map().finish_atomic()?;
self.owner_map().finish_atomic()?;
self.program_map().finish_atomic()?;
self.verifying_key_map().finish_atomic()?;
self.certificate_map().finish_atomic()?;
self.fee_map().finish_atomic()?;
self.reverse_fee_map().finish_atomic()?;
self.owner_map().finish_atomic()?;
self.transition_store().finish_atomic()
}

/// Stores the given `deployment transaction` pair into storage.
fn insert(&self, transaction: &Transaction<N>) -> Result<()> {
// Ensure the transaction is a deployment.
let (transaction_id, owner, deployment, fee) = match transaction {
Transaction::Deploy(transaction_id, deployment, fee, owner) => (transaction_id, deployment, fee, owner),
Transaction::Deploy(transaction_id, owner, deployment, fee) => (transaction_id, owner, deployment, fee),
Transaction::Execute(..) => {
bail!("Attempted to insert non-deployment transaction into deployment storage.")
}
Expand All @@ -177,6 +177,8 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {

// Store the reverse program ID.
self.reverse_id_map().insert((program_id, edition), *transaction_id)?;
// Store the owner.
self.owner_map().insert((program_id, edition), *owner)?;
// Store the program.
self.program_map().insert((program_id, edition), program.clone())?;

Expand All @@ -195,9 +197,6 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
)?;
self.reverse_fee_map().insert(*fee.transition_id(), *transaction_id)?;

// Store the owner.
self.owner_map().insert((program_id, edition), *owner)?;

// Store the fee transition.
self.transition_store().insert(fee)?;

Expand Down Expand Up @@ -238,6 +237,8 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {

// Remove the reverse program ID.
self.reverse_id_map().remove(&(program_id, edition))?;
// Remove the owner.
self.owner_map().remove(&(program_id, edition))?;
// Remove the program.
self.program_map().remove(&(program_id, edition))?;

Expand All @@ -253,9 +254,6 @@ pub trait DeploymentStorage<N: Network>: Clone + Send + Sync {
self.fee_map().remove(transaction_id)?;
self.reverse_fee_map().remove(&transition_id)?;

// Remove the owner.
self.owner_map().remove(&(program_id, edition))?;

// Remove the fee transition.
self.transition_store().remove(&transition_id)?;

Expand Down

0 comments on commit e48716b

Please sign in to comment.