diff --git a/signer/src/request_decider.rs b/signer/src/request_decider.rs index 5af5cb36e..f320b0200 100644 --- a/signer/src/request_decider.rs +++ b/signer/src/request_decider.rs @@ -124,11 +124,13 @@ where .await? .ok_or(Error::NoChainTip)?; + let signer_public_key = self.signer_public_key(); + let span = tracing::Span::current(); span.record("chain_tip", tracing::field::display(chain_tip)); let deposit_requests = db - .get_pending_deposit_requests(&chain_tip, self.context_window) + .get_pending_deposit_requests(&chain_tip, self.context_window, &signer_public_key) .await?; for deposit_request in deposit_requests { @@ -137,7 +139,7 @@ where } let withdraw_requests = db - .get_pending_withdrawal_requests(&chain_tip, self.context_window) + .get_pending_withdrawal_requests(&chain_tip, self.context_window, &signer_public_key) .await?; for withdraw_request in withdraw_requests { diff --git a/signer/src/storage/in_memory.rs b/signer/src/storage/in_memory.rs index 837f79fa4..1901479ee 100644 --- a/signer/src/storage/in_memory.rs +++ b/signer/src/storage/in_memory.rs @@ -3,8 +3,6 @@ use bitcoin::consensus::Decodable as _; use bitcoin::OutPoint; use blockstack_lib::types::chainstate::StacksBlockId; -use futures::StreamExt as _; -use futures::TryStreamExt as _; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::collections::HashMap; @@ -187,6 +185,96 @@ impl Store { get_utxo(aggregate_key, sbtc_txs) } + + /// Get all deposit requests that are on the blockchain identified by + /// the chain tip within the context window. + pub fn get_deposit_requests( + &self, + chain_tip: &model::BitcoinBlockHash, + context_window: u16, + ) -> Vec { + (0..context_window) + // Find all tracked transaction IDs in the context window + .scan(chain_tip, |block_hash, _| { + let transaction_ids = self + .bitcoin_block_to_transactions + .get(*block_hash) + .cloned() + .unwrap_or_else(Vec::new); + + let block = self.bitcoin_blocks.get(*block_hash)?; + *block_hash = &block.parent_hash; + + Some(transaction_ids) + }) + .flatten() + // Return all deposit requests associated with any of these transaction IDs + .flat_map(|txid| { + self.deposit_requests + .values() + .filter(move |req| req.txid == txid) + .cloned() + }) + .collect() + } + + fn get_stacks_chain_tip( + &self, + bitcoin_chain_tip: &model::BitcoinBlockHash, + ) -> Option { + let bitcoin_chain_tip = self.bitcoin_blocks.get(bitcoin_chain_tip)?; + + std::iter::successors(Some(bitcoin_chain_tip), |block| { + self.bitcoin_blocks.get(&block.parent_hash) + }) + .filter_map(|block| self.bitcoin_anchor_to_stacks_blocks.get(&block.block_hash)) + .flatten() + .filter_map(|stacks_block_hash| self.stacks_blocks.get(stacks_block_hash)) + .max_by_key(|block| (block.block_height, &block.block_hash)) + .cloned() + } + + fn get_withdrawal_requests( + &self, + chain_tip: &model::BitcoinBlockHash, + context_window: u16, + ) -> Vec { + let first_block = self.bitcoin_blocks.get(chain_tip); + + let context_window_end_block = std::iter::successors(first_block, |block| { + self.bitcoin_blocks.get(&block.parent_hash) + }) + .nth(context_window as usize); + + let Some(stacks_chain_tip) = self.get_stacks_chain_tip(chain_tip) else { + return Vec::new(); + }; + + std::iter::successors(Some(&stacks_chain_tip), |stacks_block| { + self.stacks_blocks.get(&stacks_block.parent_hash) + }) + .take_while(|stacks_block| { + !context_window_end_block.as_ref().is_some_and(|block| { + self.bitcoin_blocks + .get(&stacks_block.bitcoin_anchor) + .is_some_and(|anchor| anchor.block_height <= block.block_height) + }) + }) + .flat_map(|stacks_block| { + self.stacks_block_to_withdrawal_requests + .get(&stacks_block.block_hash) + .cloned() + .unwrap_or_default() + .into_iter() + .map(|pk| { + self.withdrawal_requests + .get(&pk) + .expect("missing withdraw request") + .clone() + }) + }) + .collect() + } } impl super::DbRead for SharedStore { @@ -220,52 +308,32 @@ impl super::DbRead for SharedStore { &self, bitcoin_chain_tip: &model::BitcoinBlockHash, ) -> Result, Error> { - let store = self.lock().await; - let Some(bitcoin_chain_tip) = store.bitcoin_blocks.get(bitcoin_chain_tip) else { - return Ok(None); - }; - - Ok(std::iter::successors(Some(bitcoin_chain_tip), |block| { - store.bitcoin_blocks.get(&block.parent_hash) - }) - .filter_map(|block| store.bitcoin_anchor_to_stacks_blocks.get(&block.block_hash)) - .flatten() - .filter_map(|stacks_block_hash| store.stacks_blocks.get(stacks_block_hash)) - .max_by_key(|block| (block.block_height, &block.block_hash)) - .cloned()) + Ok(self.lock().await.get_stacks_chain_tip(bitcoin_chain_tip)) } async fn get_pending_deposit_requests( &self, chain_tip: &model::BitcoinBlockHash, context_window: u16, + signer_public_key: &PublicKey, ) -> Result, Error> { let store = self.lock().await; - Ok((0..context_window) - // Find all tracked transaction IDs in the context window - .scan(chain_tip, |block_hash, _| { - let transaction_ids = store - .bitcoin_block_to_transactions - .get(*block_hash) - .cloned() - .unwrap_or_else(Vec::new); + let deposits_requests = store.get_deposit_requests(chain_tip, context_window); + let voted: HashSet<(model::BitcoinTxId, u32)> = store + .signer_to_deposit_request + .get(signer_public_key) + .cloned() + .unwrap_or(Vec::new()) + .into_iter() + .collect(); - let block = store.bitcoin_blocks.get(*block_hash)?; - *block_hash = &block.parent_hash; + let result = deposits_requests + .into_iter() + .filter(|x| !voted.contains(&(x.txid, x.output_index))) + .collect(); - Some(transaction_ids) - }) - .flatten() - // Return all deposit requests associated with any of these transaction IDs - .flat_map(|txid| { - store - .deposit_requests - .values() - .filter(move |req| req.txid == txid) - .cloned() - }) - .collect()) + Ok(result) } async fn get_pending_accepted_deposit_requests( @@ -274,12 +342,10 @@ impl super::DbRead for SharedStore { context_window: u16, threshold: u16, ) -> Result, Error> { - let pending_deposit_requests = self - .get_pending_deposit_requests(chain_tip, context_window) - .await?; + let store = self.lock().await; + let deposit_requests = store.get_deposit_requests(chain_tip, context_window); let threshold = threshold as usize; - let store = self.lock().await; // Add one to the acceptable unlock height because the chain tip is at height one less // than the height of the next block, which is the block for which we are assessing @@ -299,7 +365,7 @@ impl super::DbRead for SharedStore { .take(context_window as usize) .collect::>(); - Ok(pending_deposit_requests + Ok(deposit_requests .into_iter() .filter(|deposit_request| { store @@ -433,57 +499,29 @@ impl super::DbRead for SharedStore { &self, chain_tip: &model::BitcoinBlockHash, context_window: u16, + signer_public_key: &PublicKey, ) -> Result, Error> { - let Some(bitcoin_chain_tip) = self.get_bitcoin_block(chain_tip).await? else { - return Ok(Vec::new()); - }; + let store = self.lock().await; + let withdrawal_requests = store.get_withdrawal_requests(chain_tip, context_window); - let context_window_end_block = - futures::stream::try_unfold(bitcoin_chain_tip.block_hash, |block_hash| async move { - self.get_bitcoin_block(&block_hash) - .await - .map(|opt| opt.map(|block| (block.clone(), block.parent_hash))) + // These are the withdrawal requests that this signer has voted on. + let voted: HashSet<(u64, model::StacksBlockHash)> = store + .withdrawal_request_to_signers + .iter() + .filter_map(|(pk, decisions)| { + decisions + .iter() + .find(|decision| &decision.signer_pub_key == signer_public_key) + .map(|_| *pk) }) - .skip(context_window as usize) - .boxed() - .try_next() - .await?; - - let Some(stacks_chain_tip) = self.get_stacks_chain_tip(chain_tip).await? else { - return Ok(Vec::new()); - }; + .collect(); - let store = self.lock().await; + let result = withdrawal_requests + .into_iter() + .filter(|x| !voted.contains(&(x.request_id, x.block_hash))) + .collect(); - Ok( - std::iter::successors(Some(&stacks_chain_tip), |stacks_block| { - store.stacks_blocks.get(&stacks_block.parent_hash) - }) - .take_while(|stacks_block| { - !context_window_end_block.as_ref().is_some_and(|block| { - store - .bitcoin_blocks - .get(&stacks_block.bitcoin_anchor) - .is_some_and(|anchor| anchor.block_height <= block.block_height) - }) - }) - .flat_map(|stacks_block| { - store - .stacks_block_to_withdrawal_requests - .get(&stacks_block.block_hash) - .cloned() - .unwrap_or_default() - .into_iter() - .map(|pk| { - store - .withdrawal_requests - .get(&pk) - .expect("missing withdraw request") - .clone() - }) - }) - .collect(), - ) + Ok(result) } async fn get_pending_accepted_withdrawal_requests( @@ -492,14 +530,11 @@ impl super::DbRead for SharedStore { context_window: u16, threshold: u16, ) -> Result, Error> { - let pending_withdraw_requests = self - .get_pending_withdrawal_requests(chain_tip, context_window) - .await?; let store = self.lock().await; - + let withdraw_requests = store.get_withdrawal_requests(chain_tip, context_window); let threshold = threshold as usize; - Ok(pending_withdraw_requests + Ok(withdraw_requests .into_iter() .filter(|withdraw_request| { store diff --git a/signer/src/storage/mod.rs b/signer/src/storage/mod.rs index eaa766292..6ce1e2e39 100644 --- a/signer/src/storage/mod.rs +++ b/signer/src/storage/mod.rs @@ -54,10 +54,15 @@ pub trait DbRead { ) -> impl Future, Error>> + Send; /// Get pending deposit requests + /// + /// These are deposit requests that have been added to our database but + /// where the current signer has not made a decision on whether they + /// will sign for the deposit and sweep in the funds. fn get_pending_deposit_requests( &self, chain_tip: &model::BitcoinBlockHash, context_window: u16, + signer_public_key: &PublicKey, ) -> impl Future, Error>> + Send; /// Get pending deposit requests that have been accepted by at least @@ -142,10 +147,15 @@ pub trait DbRead { ) -> impl Future, Error>> + Send; /// Get pending withdrawal requests + /// + /// These are withdrawal requests that have been added to our database + /// but where the current signer has not made a decision on whether + /// they will sweep out the withdrawal funds and sweep transaction. fn get_pending_withdrawal_requests( &self, chain_tip: &model::BitcoinBlockHash, context_window: u16, + signer_public_key: &PublicKey, ) -> impl Future, Error>> + Send; /// Get pending withdrawal requests that have been accepted by at least diff --git a/signer/src/storage/postgres.rs b/signer/src/storage/postgres.rs index 1a837c806..a1efecc1a 100644 --- a/signer/src/storage/postgres.rs +++ b/signer/src/storage/postgres.rs @@ -776,6 +776,7 @@ impl super::DbRead for PgStore { &self, chain_tip: &model::BitcoinBlockHash, context_window: u16, + signer_public_key: &PublicKey, ) -> Result, Error> { sqlx::query_as::<_, model::DepositRequest>( r#" @@ -812,12 +813,17 @@ impl super::DbRead for PgStore { , deposit_requests.signers_public_key , deposit_requests.sender_script_pub_keys FROM transactions_in_window transactions - JOIN sbtc_signer.deposit_requests deposit_requests ON - deposit_requests.txid = transactions.txid + JOIN sbtc_signer.deposit_requests AS deposit_requests USING (txid) + LEFT JOIN sbtc_signer.deposit_signers AS ds + ON ds.txid = deposit_requests.txid + AND ds.output_index = deposit_requests.output_index + AND ds.signer_pub_key = $3 + WHERE ds.txid IS NULL "#, ) .bind(chain_tip) .bind(i32::from(context_window)) + .bind(signer_public_key) .fetch_all(&self.0) .await .map_err(Error::SqlxQuery) @@ -1186,6 +1192,7 @@ impl super::DbRead for PgStore { &self, chain_tip: &model::BitcoinBlockHash, context_window: u16, + signer_public_key: &PublicKey, ) -> Result, Error> { let Some(stacks_chain_tip) = self.get_stacks_chain_tip(chain_tip).await? else { return Ok(Vec::new()); @@ -1239,12 +1246,18 @@ impl super::DbRead for PgStore { , wr.max_fee , wr.sender_address FROM sbtc_signer.withdrawal_requests wr - JOIN stacks_context_window sc ON wr.block_hash = sc.block_hash + JOIN stacks_context_window sc USING (block_hash) + LEFT JOIN sbtc_signer.withdrawal_signers AS ws + ON ws.request_id = wr.request_id + AND ws.block_hash = wr.block_hash + AND ws.signer_pub_key = $4 + WHERE ws.request_id IS NULL "#, ) .bind(chain_tip) .bind(stacks_chain_tip.block_hash) .bind(i32::from(context_window)) + .bind(signer_public_key) .fetch_all(&self.0) .await .map_err(Error::SqlxQuery) diff --git a/signer/src/testing/storage.rs b/signer/src/testing/storage.rs index 87c45a424..87a83baca 100644 --- a/signer/src/testing/storage.rs +++ b/signer/src/testing/storage.rs @@ -8,6 +8,7 @@ use crate::storage::postgres::PgStore; use crate::storage::DbRead; pub mod model; +pub mod postgres; /// The postgres connection string to the test database. pub const DATABASE_URL: &str = "postgres://postgres:postgres@localhost:5432/signer"; diff --git a/signer/src/testing/storage/postgres.rs b/signer/src/testing/storage/postgres.rs new file mode 100644 index 000000000..88d77cb5f --- /dev/null +++ b/signer/src/testing/storage/postgres.rs @@ -0,0 +1,40 @@ +//! A module with helper query functions. +//! + +use crate::error::Error; +use crate::storage::model; +use crate::storage::postgres::PgStore; + +impl PgStore { + /// Get all deposit requests that have been confirmed within the + /// context window. + pub async fn get_deposit_requests( + &self, + chain_tip: &model::BitcoinBlockHash, + context_window: u16, + ) -> Result, Error> { + sqlx::query_as::<_, model::DepositRequest>( + r#" + SELECT + dr.txid + , dr.output_index + , dr.spend_script + , dr.reclaim_script + , dr.recipient + , dr.amount + , dr.max_fee + , dr.lock_time + , dr.signers_public_key + , dr.sender_script_pub_keys + FROM sbtc_signer.bitcoin_blockchain_of($1, $2) + JOIN sbtc_signer.bitcoin_transactions USING (block_hash) + JOIN sbtc_signer.deposit_requests AS dr USING (txid) + "#, + ) + .bind(chain_tip) + .bind(i32::from(context_window)) + .fetch_all(self.pool()) + .await + .map_err(Error::SqlxQuery) + } +} diff --git a/signer/tests/integration/block_observer.rs b/signer/tests/integration/block_observer.rs index 02e57af7f..d2b417435 100644 --- a/signer/tests/integration/block_observer.rs +++ b/signer/tests/integration/block_observer.rs @@ -211,7 +211,7 @@ async fn load_latest_deposit_requests_persists_requests_from_past(blocks_ago: u6 let chain_tip_info = rpc.get_chain_tips().unwrap().pop().unwrap(); let deposit_requests = db - .get_pending_deposit_requests(&chain_tip_info.hash.into(), 100) + .get_deposit_requests(&chain_tip_info.hash.into(), 100) .await .unwrap(); @@ -246,10 +246,7 @@ async fn load_latest_deposit_requests_persists_requests_from_past(blocks_ago: u6 .await .unwrap() .is_some()); - let deposit_requests = db - .get_pending_deposit_requests(&chain_tip, 100) - .await - .unwrap(); + let deposit_requests = db.get_deposit_requests(&chain_tip, 100).await.unwrap(); assert_eq!(deposit_requests.len(), 2); let req_outpoints: HashSet = diff --git a/signer/tests/integration/emily.rs b/signer/tests/integration/emily.rs index cc82f0988..f106d748b 100644 --- a/signer/tests/integration/emily.rs +++ b/signer/tests/integration/emily.rs @@ -34,6 +34,7 @@ use signer::emily_client::EmilyClient; use signer::emily_client::EmilyInteract; use signer::error::Error; use signer::keys; +use signer::keys::PublicKey; use signer::keys::SignerScriptPubKey as _; use signer::network; use signer::stacks::api::TenureBlocks; @@ -446,9 +447,11 @@ async fn deposit_flow() { let tx_coordinator_handle = tokio::spawn(async move { tx_coordinator.run().await }); // There shouldn't be any request yet + let signer_public_key = PublicKey::from_private_key(&context.config().signer.private_key); + let chain_tip = bitcoin_chain_tip.block_hash; assert!(context .get_storage() - .get_pending_deposit_requests(&bitcoin_chain_tip.block_hash, context_window as u16) + .get_pending_deposit_requests(&chain_tip, context_window as u16, &signer_public_key) .await .unwrap() .is_empty()); @@ -477,9 +480,10 @@ async fn deposit_flow() { deposit_block_hash.into() ); // and that now we have the deposit request + let deposit_block = deposit_block_hash.into(); assert!(!context .get_storage() - .get_pending_deposit_requests(&deposit_block_hash.into(), context_window as u16) + .get_pending_deposit_requests(&deposit_block, context_window as u16, &signer_public_key) .await .unwrap() .is_empty()); diff --git a/signer/tests/integration/postgres.rs b/signer/tests/integration/postgres.rs index c92ab19a1..d4678ee62 100644 --- a/signer/tests/integration/postgres.rs +++ b/signer/tests/integration/postgres.rs @@ -66,7 +66,11 @@ use signer::DEPOSIT_LOCKTIME_BLOCK_BUFFER; use test_case::test_case; use test_log::test; +use crate::setup::backfill_bitcoin_blocks; +use crate::setup::DepositAmounts; +use crate::setup::TestSignerSet; use crate::setup::TestSweepSetup; +use crate::setup::TestSweepSetup2; use crate::DATABASE_NUM; #[cfg_attr(not(feature = "integration-tests"), ignore)] @@ -355,22 +359,133 @@ async fn should_return_the_same_pending_deposit_requests_as_in_memory_store() { chain_tip ); - let mut pending_deposit_requests = in_memory_store - .get_pending_deposit_requests(&chain_tip, context_window) + for signer_public_key in signer_set.iter() { + let mut pending_deposit_requests = in_memory_store + .get_pending_deposit_requests(&chain_tip, context_window, signer_public_key) + .await + .expect("failed to get pending deposit requests"); + + pending_deposit_requests.sort(); + assert!(!pending_deposit_requests.is_empty()); + + let mut pg_pending_deposit_requests = pg_store + .get_pending_deposit_requests(&chain_tip, context_window, signer_public_key) + .await + .expect("failed to get pending deposit requests"); + + pg_pending_deposit_requests.sort(); + + assert_eq!(pending_deposit_requests, pg_pending_deposit_requests); + } + + signer::testing::storage::drop_db(pg_store).await; +} + +/// Test that [`DbRead::get_pending_deposit_requests`] returns deposit +/// requests that do not have a vote on them yet. +#[cfg_attr(not(feature = "integration-tests"), ignore)] +#[tokio::test] +async fn get_pending_deposit_requests_only_pending() { + let db_num = testing::storage::DATABASE_NUM.fetch_add(1, Ordering::SeqCst); + let db = testing::storage::new_test_database(db_num, true).await; + + let (rpc, faucet) = sbtc::testing::regtest::initialize_blockchain(); + + let mut rng = rand::rngs::StdRng::seed_from_u64(43); + + let amounts = DepositAmounts { amount: 123456, max_fee: 12345 }; + let signers = TestSignerSet::new(&mut rng); + let setup = TestSweepSetup2::new_setup(signers, faucet, &[amounts]); + + backfill_bitcoin_blocks(&db, rpc, &setup.deposit_block_hash).await; + let chain_tip = db.get_bitcoin_canonical_chain_tip().await.unwrap().unwrap(); + + // There aren't any deposit requests in the database. + let signer_public_key = setup.signers.signer_keys()[0]; + let pending_requests = db + .get_pending_deposit_requests(&chain_tip, 1000, &signer_public_key) .await - .expect("failed to get pending deposit requests"); + .unwrap(); - pending_deposit_requests.sort(); + assert!(pending_requests.is_empty()); - let mut pg_pending_deposit_requests = pg_store - .get_pending_deposit_requests(&chain_tip, context_window) + // Now let's store a deposit request with no votes. + // `get_pending_deposit_requests` should return it now. + setup.store_deposit_txs(&db).await; + setup.store_deposit_request(&db).await; + + let pending_requests = db + .get_pending_deposit_requests(&chain_tip, 1000, &signer_public_key) .await - .expect("failed to get pending deposit requests"); + .unwrap(); - pg_pending_deposit_requests.sort(); + assert_eq!(pending_requests.len(), 1); - assert_eq!(pending_deposit_requests, pg_pending_deposit_requests); - signer::testing::storage::drop_db(pg_store).await; + // Okay now lets suppose we have a decision on it. + // `get_pending_deposit_requests` should not return it now. + setup.store_deposit_decisions(&db).await; + + let pending_requests = db + .get_pending_deposit_requests(&chain_tip, 1000, &signer_public_key) + .await + .unwrap(); + + assert!(pending_requests.is_empty()); + + signer::testing::storage::drop_db(db).await; +} + +/// Test that [`DbRead::get_pending_withdrawal_requests`] returns +/// withdrawal requests that do not have a vote on them yet. +#[cfg_attr(not(feature = "integration-tests"), ignore)] +#[tokio::test] +async fn get_pending_withdrawal_requests_only_pending() { + let db_num = testing::storage::DATABASE_NUM.fetch_add(1, Ordering::SeqCst); + let db = testing::storage::new_test_database(db_num, true).await; + + let (rpc, faucet) = sbtc::testing::regtest::initialize_blockchain(); + + let mut rng = rand::rngs::StdRng::seed_from_u64(43); + + let amounts = DepositAmounts { amount: 123456, max_fee: 12345 }; + let signers = TestSignerSet::new(&mut rng); + let setup = TestSweepSetup2::new_setup(signers, faucet, &[amounts]); + + backfill_bitcoin_blocks(&db, rpc, &setup.deposit_block_hash).await; + let chain_tip = db.get_bitcoin_canonical_chain_tip().await.unwrap().unwrap(); + + // There aren't any withdrawal requests in the database. + let signer_public_key = setup.signers.signer_keys()[0]; + let pending_requests = db + .get_pending_withdrawal_requests(&chain_tip, 1000, &signer_public_key) + .await + .unwrap(); + + assert!(pending_requests.is_empty()); + + // Now let's store a withdrawal request with no votes. + // `get_pending_withdrawal_requests` should return it now. + setup.store_withdrawal_request(&db).await; + + let pending_requests = db + .get_pending_withdrawal_requests(&chain_tip, 1000, &signer_public_key) + .await + .unwrap(); + + assert_eq!(pending_requests.len(), 1); + + // Okay now lets suppose we have a decision on it. + // `get_pending_withdrawal_requests` should not return it now. + setup.store_withdrawal_decisions(&db).await; + + let pending_requests = db + .get_pending_withdrawal_requests(&chain_tip, 1000, &signer_public_key) + .await + .unwrap(); + + assert!(pending_requests.is_empty()); + + signer::testing::storage::drop_db(db).await; } /// This ensures that the postgres store and the in memory stores returns equivalent results @@ -428,23 +543,26 @@ async fn should_return_the_same_pending_withdraw_requests_as_in_memory_store() { .expect("no chain tip"), ); - let mut pending_withdraw_requests = in_memory_store - .get_pending_withdrawal_requests(&chain_tip, context_window) - .await - .expect("failed to get pending deposit requests"); + for signer_public_key in signer_set.iter() { + let mut pending_withdraw_requests = in_memory_store + .get_pending_withdrawal_requests(&chain_tip, context_window, signer_public_key) + .await + .expect("failed to get pending deposit requests"); - pending_withdraw_requests.sort(); + pending_withdraw_requests.sort(); - assert!(!pending_withdraw_requests.is_empty()); + assert!(!pending_withdraw_requests.is_empty()); - let mut pg_pending_withdraw_requests = pg_store - .get_pending_withdrawal_requests(&chain_tip, context_window) - .await - .expect("failed to get pending deposit requests"); + let mut pg_pending_withdraw_requests = pg_store + .get_pending_withdrawal_requests(&chain_tip, context_window, signer_public_key) + .await + .expect("failed to get pending deposit requests"); - pg_pending_withdraw_requests.sort(); + pg_pending_withdraw_requests.sort(); + + assert_eq!(pending_withdraw_requests, pg_pending_withdraw_requests); + } - assert_eq!(pending_withdraw_requests, pg_pending_withdraw_requests); signer::testing::storage::drop_db(pg_store).await; } diff --git a/signer/tests/integration/request_decider.rs b/signer/tests/integration/request_decider.rs index c61305dea..218a17d12 100644 --- a/signer/tests/integration/request_decider.rs +++ b/signer/tests/integration/request_decider.rs @@ -161,8 +161,9 @@ async fn handle_pending_deposit_request_address_script_pub_key() { // need a row in the dkg_shares table. setup.store_dkg_shares(&db).await; + let signer_public_key = setup.aggregated_signer.keypair.public_key().into(); let mut requests = db - .get_pending_deposit_requests(&chain_tip, 100) + .get_pending_deposit_requests(&chain_tip, 100, &signer_public_key) .await .unwrap(); // There should only be the one deposit request that we just fetched. @@ -246,8 +247,9 @@ async fn handle_pending_deposit_request_not_in_signing_set() { // signing set. setup.store_dkg_shares(&db).await; + let signer_public_key = setup.aggregated_signer.keypair.public_key().into(); let mut requests = db - .get_pending_deposit_requests(&chain_tip, 100) + .get_pending_deposit_requests(&chain_tip, 100, &signer_public_key) .await .unwrap(); // There should only be the one deposit request that we just fetched.