Cache the block's events within TemporalSerai

Event retrieval was prior:
- Retrieve all events in the block, which may be hundreds of KB
- Filter to just a few

Since it's frequent to want multiple sets of events, each filtered in their own
way, this caused the retrieval to happen multiple times. Now, it only will
happen once.

Also has the scoped clients take a reference, not an owned TemporalSerai.
This commit is contained in:
Luke Parker
2023-12-08 08:41:14 -05:00
parent 397fca748f
commit 7122e0faf4
12 changed files with 357 additions and 51 deletions

View File

@@ -54,6 +54,7 @@ serai_test!(
let block = provide_batch(&serai, batch.clone()).await;
let instruction = {
let serai = serai.as_of(block);
let batches = serai.in_instructions().batch_events().await.unwrap();
assert_eq!(
@@ -82,19 +83,20 @@ serai_test!(
OsRng.fill_bytes(&mut rand_bytes);
let data = Data::new(rand_bytes).unwrap();
let instruction = OutInstructionWithBalance {
OutInstructionWithBalance {
balance,
instruction: OutInstruction { address: external_address, data: Some(data) },
};
}
};
let serai = serai.into_inner();
let block = publish_tx(
serai,
&serai,
&serai.sign(&pair, SeraiCoins::burn_with_instruction(instruction.clone()), 0, 0),
)
.await;
let serai = serai.as_of(block).coins();
let serai = serai.as_of(block);
let serai = serai.coins();
let events = serai.burn_with_instruction_events().await.unwrap();
assert_eq!(events, vec![CoinsEvent::BurnWithInstruction { from: address, instruction }]);
assert_eq!(serai.coin_supply(coin).await.unwrap(), Amount(0));

View File

@@ -48,7 +48,8 @@ serai_test!(
);
{
let vs_serai = serai.as_of_latest_finalized_block().await.unwrap().validator_sets();
let vs_serai = serai.as_of_latest_finalized_block().await.unwrap();
let vs_serai = vs_serai.validator_sets();
let participants = vs_serai.participants(set.network).await
.unwrap()
.unwrap()
@@ -64,7 +65,8 @@ serai_test!(
// While the set_keys function should handle this, it's beneficial to
// independently test it
let serai = serai.as_of(block).validator_sets();
let serai = serai.as_of(block);
let serai = serai.validator_sets();
assert_eq!(
serai.key_gen_events().await.unwrap(),
vec![ValidatorSetsEvent::KeyGen { set, key_pair: key_pair.clone() }]