Skip to content

Commit

Permalink
Merge pull request MystenLabs#288 from huitseeker/upgrade_typed_store
Browse files Browse the repository at this point in the history
fix: Remove a bunch of clones in batch DB operations
  • Loading branch information
huitseeker authored Jan 28, 2022
2 parents f6a3a6b + 870a212 commit 3ee46b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fastpay_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ move-package = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102
move-vm-runtime = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102bbfc1fb33b57ba6125d2" }


typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "2e829074f40c9ef852ecd6808b80d083174c778b" }
typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "232c44e88e69eb54fe80dab247adcd1b643aeb8c" }

[dev-dependencies]
fdlimit = "0.2.1"
Expand Down
17 changes: 6 additions & 11 deletions fastpay_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl AuthorityStore {
&self.order_lock,
mutable_input_objects
.iter()
.map(|obj_ref| (*obj_ref, Some(tx_digest))),
.map(|obj_ref| (obj_ref, Some(tx_digest))),
)?
.insert_batch(
&self.signed_orders,
Expand Down Expand Up @@ -261,30 +261,28 @@ impl AuthorityStore {
certificate: CertifiedOrder,
signed_effects: SignedOrderEffects,
) -> Result<OrderInfoResponse, FastPayError> {
// TODO: There is a lot of cloning used -- eliminate it.

// Extract the new state from the execution
let (objects, active_inputs, written, deleted) = temporary_store.into_inner();
let mut write_batch = self.order_lock.batch();

// Archive the old lock.
write_batch = write_batch.delete_batch(&self.order_lock, active_inputs.iter().cloned())?;
write_batch = write_batch.delete_batch(&self.order_lock, active_inputs.iter())?;

// Store the certificate indexed by transaction digest
let transaction_digest: TransactionDigest = certificate.order.digest();
write_batch = write_batch.insert_batch(
&self.certificates,
std::iter::once((transaction_digest, certificate.clone())),
std::iter::once((transaction_digest, &certificate)),
)?;

// Store the signed effects of the order
write_batch = write_batch.insert_batch(
&self.signed_effects,
std::iter::once((transaction_digest, signed_effects.clone())),
std::iter::once((transaction_digest, &signed_effects)),
)?;

// Delete objects
write_batch = write_batch.delete_batch(&self.objects, deleted.clone().into_iter())?;
write_batch = write_batch.delete_batch(&self.objects, deleted.iter())?;

// Make an iterator over all objects that are either deleted or have changed owner,
// along with their old owner. This is used to update the owner index.
Expand Down Expand Up @@ -335,10 +333,7 @@ impl AuthorityStore {
)?;

// Insert each output object into the stores
write_batch = write_batch.insert_batch(
&self.objects,
written.into_iter().map(|(id, new_object)| (id, new_object)),
)?;
write_batch = write_batch.insert_batch(&self.objects, written.iter())?;

// Update the indexes of the objects written

Expand Down
2 changes: 1 addition & 1 deletion fastx_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde_bytes = "0.11.5"
serde_with = "1.11.0"
static_assertions = "0.3.4"

typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "2e829074f40c9ef852ecd6808b80d083174c778b" }
typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "232c44e88e69eb54fe80dab247adcd1b643aeb8c" }

move-binary-format = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102bbfc1fb33b57ba6125d2" }
move-core-types = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102bbfc1fb33b57ba6125d2", features=["address20"] }

0 comments on commit 3ee46b8

Please sign in to comment.