-
Notifications
You must be signed in to change notification settings - Fork 183
feat(solana-indexer) PR 9: cover the ingester to decoder pipeline end to end #4677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: solana-indexer/PR8-persist
Are you sure you want to change the base?
Changes from 5 commits
5a0fbec
0e2e3c4
4b11c86
bada91c
8cbca56
851e670
cae8b2b
9328f4f
19f7e8f
0cf46a6
8e3ec7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| use { | ||
| super::{Decoder, ResolvedOrder, build_account_keys, decode_settlement, relevant_instructions}, | ||
| crate::{ | ||
| persistence::Persistence, | ||
| indexer::ingester::Ingester, | ||
| persistence::{Call, Persistence}, | ||
| types::{ | ||
| Signature, | ||
| channel::StreamUpdate, | ||
|
|
@@ -14,20 +15,25 @@ use { | |
| InnerInstruction, | ||
| InnerInstructions, | ||
| Message, | ||
| SubscribeUpdate, | ||
| SubscribeUpdateTransaction, | ||
| SubscribeUpdateTransactionInfo, | ||
| Transaction, | ||
| TransactionError, | ||
| TransactionStatusMeta, | ||
| UpdateOneof, | ||
| }, | ||
| }, | ||
| }, | ||
| bytes::Bytes, | ||
| futures::stream, | ||
| settlement_interface::{ | ||
| Pubkey as InterfacePubkey, | ||
| SettlementInstruction, | ||
| data::intent::{EncodedOrderIntent, OrderIntent, OrderKind}, | ||
| }, | ||
| solana_sdk::pubkey::Pubkey, | ||
| std::sync::{Arc, atomic::AtomicU64}, | ||
| tokio::sync::mpsc::Sender, | ||
| }; | ||
|
|
||
|
|
@@ -249,10 +255,21 @@ fn signature(n: u8) -> Signature { | |
|
|
||
| fn test_decoder(settlement: Pubkey, solflow: Pubkey) -> (Decoder, Sender<StreamUpdate>) { | ||
| let (sender, rx) = tokio::sync::mpsc::channel(16); | ||
| let decoder = Decoder::new(Persistence {}, rx, settlement, solflow); | ||
| let decoder = Decoder::new(Persistence::default(), rx, settlement, solflow); | ||
| (decoder, sender) | ||
| } | ||
|
|
||
| /// Wrap a transaction fixture in the proto envelope the ingester reads. | ||
| fn tx_update(slot: u64, info: SubscribeUpdateTransactionInfo) -> SubscribeUpdate { | ||
| SubscribeUpdate { | ||
| update_oneof: Some(UpdateOneof::Transaction(SubscribeUpdateTransaction { | ||
| slot, | ||
| transaction: Some(info), | ||
| })), | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| /// A transaction carrying one settlement instruction, so draining it also | ||
| /// routes into `decode_settlement`. | ||
| fn stream_tx(slot: Slot, signature: Signature, settlement: Pubkey) -> StreamUpdate { | ||
|
|
@@ -554,3 +571,45 @@ fn begin_and_finalize_settle_decode_to_settlement_finalized() { | |
| }] | ||
| ); | ||
| } | ||
|
|
||
| /// Both components as one pipeline: a proto `SubscribeUpdate` carrying a | ||
| /// `CreateOrder` goes into the ingester and comes out of the decoder as a | ||
| /// persisted event. This is the only test spanning the channel, so it pins that | ||
| /// what the ingester forwards is what the decoder can consume, and that the | ||
| /// watermark riding along is the slot before the transaction's own (slot 42 | ||
| /// persists at 41). | ||
| #[tokio::test] | ||
| async fn ingester_to_decoder_persists_decoded_events() { | ||
| let (settlement, solflow) = (pubkey(1), pubkey(2)); | ||
| let (mut info, expected_uid, created_by) = create_order_tx(); | ||
| // The ingester drops transactions without a well-formed signature. | ||
| info.signature = signature(9).as_ref().to_vec(); | ||
|
|
||
| let (sender, receiver) = tokio::sync::mpsc::channel(16); | ||
| let persistence = Persistence::default(); | ||
| let mut ingester = Ingester::new( | ||
| stream::iter(vec![Ok(tx_update(42, info))]), | ||
| sender, | ||
| Arc::new(AtomicU64::new(0)), | ||
| ); | ||
| let mut decoder = Decoder::new(persistence.clone(), receiver, settlement, solflow); | ||
|
|
||
| // Drive the ingester to the canned stream's end, which it reports as an | ||
| // error. `clean_stream_end_returns_stream_ended` pins which one. | ||
| ingester.run().await.unwrap_err(); | ||
| // Dropping the ingester closes the channel so the decoder's drain returns. | ||
| drop(ingester); | ||
| assert!(decoder.run().await.is_ok()); | ||
|
|
||
| assert_eq!( | ||
| persistence.calls(), | ||
| vec![Call::PersistEvents { | ||
| events: vec![DecodedEvent::Settlement(SettlementEvent::OrderCreated { | ||
| order_uid: expected_uid, | ||
| owner: Pubkey::new_from_array([0x11; 32]), | ||
| created_by, | ||
| })], | ||
| watermark: Slot(41), | ||
| }] | ||
| ); | ||
| } | ||
|
Comment on lines
+672
to
+695
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional (coverage): this new harness records three Since the seam now makes both observable for free, consider a second pipeline case (e.g. a reverted tx → |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: An array is sufficient as it also implements
IntoIter.