Skip to content

Commit

Permalink
Added a parent iterator by object_id or (objectid,version) (#166)
Browse files Browse the repository at this point in the history
Co-authored-by: George Danezis <george@danez.is>
  • Loading branch information
gdanezis and George Danezis authored Jan 13, 2022
1 parent 48ad627 commit a65b129
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
12 changes: 12 additions & 0 deletions fastpay_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,16 @@ impl AuthorityState {
) -> Result<Vec<Option<Object>>, FastPayError> {
self._database.get_objects(_objects)
}

/// Returns all parents (object_ref and transaction digests) that match an object_id, at
/// any object version, or optionally at a specific version.
pub async fn get_parent_iterator(
&self,
object_id: ObjectID,
seq: Option<SequenceNumber>,
) -> Result<Vec<(ObjectRef, TransactionDigest)>, FastPayError> {
{
self._database.get_parent_iterator(object_id, seq)
}
}
}
26 changes: 26 additions & 0 deletions fastpay_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,32 @@ impl AuthorityStore {
.map_err(|_| FastPayError::StorageError)
}

/// Returns all parents (object_ref and transaction digests) that match an object_id, at
/// any object version, or optionally at a specific version.
pub fn get_parent_iterator(
&self,
object_id: ObjectID,
seq: Option<SequenceNumber>,
) -> Result<Vec<(ObjectRef, TransactionDigest)>, FastPayError> {
let seq_inner = seq.unwrap_or_else(|| SequenceNumber::from(0));
let obj_dig_inner = ObjectDigest::new([0; 32]);

Ok(self
.parent_sync
.iter()
// The object id [0; 16] is the smallest possible
.skip_to(&(object_id, seq_inner, obj_dig_inner))
.map_err(|_| FastPayError::StorageError)?
.take_while(|((id, iseq, _digest), _txd)| {
let mut flag = id == &object_id;
if seq.is_some() {
flag &= seq_inner == *iseq;
}
flag
})
.collect())
}

// Methods to mutate the store

/// Insert an object
Expand Down
11 changes: 10 additions & 1 deletion fastpay_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ async fn test_handle_confirmation_order_ok() {
.unwrap();
authority_state.read_certificate(&refx).await.unwrap()
},
Some(certified_transfer_order)
Some(certified_transfer_order.clone())
);

// Check locks are set and archived correctly
Expand All @@ -780,6 +780,15 @@ async fn test_handle_confirmation_order_ok() {
.await
.expect("Exists")
.is_none());

// Check that all the parents are returned.
assert!(
authority_state.get_parent_iterator(object_id, None).await
== Ok(vec![(
(object_id, 1.into(), new_account.digest()),
certified_transfer_order.order.digest()
)])
);
}

#[tokio::test]
Expand Down

1 comment on commit a65b129

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bench results

�[0m�[0m�[1m�[32m Finished�[0m release [optimized + debuginfo] target(s) in 2.84s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
[2022-01-13T16:50:15Z INFO bench] Starting benchmark: OrdersAndCerts
[2022-01-13T16:50:15Z INFO bench] Preparing accounts.
[2022-01-13T16:50:21Z INFO bench] Preparing transactions.
[2022-01-13T16:50:33Z INFO fastpay::network] Listening to Tcp traffic on 127.0.0.1:9555
[2022-01-13T16:50:34Z INFO bench] Set max_in_flight to 500
[2022-01-13T16:50:34Z INFO bench] Sending requests.
[2022-01-13T16:50:34Z INFO fastpay::network] Sending Tcp requests to 127.0.0.1:9555
[2022-01-13T16:50:36Z INFO fastpay::network] 127.0.0.1:9555 has processed 5000 packets
[2022-01-13T16:50:37Z INFO fastpay::network] In flight 500 Remaining 35000
[2022-01-13T16:50:37Z INFO fastpay::network] 127.0.0.1:9555 has processed 10000 packets
[2022-01-13T16:50:39Z INFO fastpay::network] 127.0.0.1:9555 has processed 15000 packets
[2022-01-13T16:50:40Z INFO fastpay::network] In flight 500 Remaining 30000
[2022-01-13T16:50:41Z INFO fastpay::network] 127.0.0.1:9555 has processed 20000 packets
[2022-01-13T16:50:42Z INFO fastpay::network] 127.0.0.1:9555 has processed 25000 packets
[2022-01-13T16:50:43Z INFO fastpay::network] In flight 500 Remaining 25000
[2022-01-13T16:50:43Z INFO fastpay::network] 127.0.0.1:9555 has processed 30000 packets
[2022-01-13T16:50:44Z INFO fastpay::network] 127.0.0.1:9555 has processed 35000 packets
[2022-01-13T16:50:45Z INFO fastpay::network] In flight 500 Remaining 20000
[2022-01-13T16:50:45Z INFO fastpay::network] 127.0.0.1:9555 has processed 40000 packets
[2022-01-13T16:50:46Z INFO fastpay::network] 127.0.0.1:9555 has processed 45000 packets
[2022-01-13T16:50:47Z INFO fastpay::network] In flight 500 Remaining 15000
[2022-01-13T16:50:47Z INFO fastpay::network] 127.0.0.1:9555 has processed 50000 packets
[2022-01-13T16:50:48Z INFO fastpay::network] 127.0.0.1:9555 has processed 55000 packets
[2022-01-13T16:50:50Z INFO fastpay::network] In flight 500 Remaining 10000
[2022-01-13T16:50:50Z INFO fastpay::network] 127.0.0.1:9555 has processed 60000 packets
[2022-01-13T16:50:51Z INFO fastpay::network] 127.0.0.1:9555 has processed 65000 packets
[2022-01-13T16:50:52Z INFO fastpay::network] In flight 500 Remaining 5000
[2022-01-13T16:50:52Z INFO fastpay::network] 127.0.0.1:9555 has processed 70000 packets
[2022-01-13T16:50:53Z INFO fastpay::network] 127.0.0.1:9555 has processed 75000 packets
[2022-01-13T16:50:54Z INFO fastpay::network] Done sending Tcp requests to 127.0.0.1:9555
[2022-01-13T16:50:54Z INFO fastpay::network] 127.0.0.1:9555 has processed 80000 packets
[2022-01-13T16:50:54Z INFO bench] Received 80000 responses.
[2022-01-13T16:50:54Z WARN bench] Completed benchmark for OrdersAndCerts
Total time: 20545890us, items: 40000, tx/sec: 1946.861391743069

Please sign in to comment.