@@ -52,6 +52,23 @@ fn build_signature_request(
5252 } )
5353}
5454
55+ // Awaits on the future for specified grace duration, and calls on_slow
56+ // if grace period expires.
57+ async fn await_with_slow_hook < F : Future > (
58+ grace : Duration ,
59+ fut : F ,
60+ on_slow : impl FnOnce ( ) ,
61+ ) -> F :: Output {
62+ tokio:: pin!( fut) ;
63+ match timeout ( grace, & mut fut) . await {
64+ Ok ( output) => output,
65+ Err ( _) => {
66+ on_slow ( ) ;
67+ fut. await
68+ }
69+ }
70+ }
71+
5572impl VerifyForeignTxProvider {
5673 pub ( crate ) async fn make_verify_foreign_tx_leader (
5774 & self ,
@@ -90,22 +107,20 @@ impl VerifyForeignTxProvider {
90107 // alive condition and be a subset of the chain's supporters. Since
91108 // presignature generation is not chain-aware, a compatible one may
92109 // not exist yet, count and log when the take has to wait.
93- let take = keyshare
94- . presignature_store
95- . take_owned_matching ( chain_supporters. iter ( ) . copied ( ) . collect ( ) ) ;
96- tokio:: pin!( take) ;
97- let ( presignature_id, presignature) =
98- match timeout ( PRESIGNATURE_TAKE_GRACE_PERIOD , & mut take) . await {
99- Ok ( taken) => taken,
100- Err ( _) => {
101- metrics:: MPC_NUM_VERIFY_FOREIGN_TX_PRESIGNATURE_WAITS . inc ( ) ;
102- tracing:: warn!(
103- ?requested_chain,
104- "no chain-compatible presignature available, waiting"
105- ) ;
106- take. await
107- }
108- } ;
110+ let ( presignature_id, presignature) = await_with_slow_hook (
111+ PRESIGNATURE_TAKE_GRACE_PERIOD ,
112+ keyshare
113+ . presignature_store
114+ . take_owned_matching ( chain_supporters. iter ( ) . copied ( ) . collect ( ) ) ,
115+ || {
116+ metrics:: MPC_NUM_VERIFY_FOREIGN_TX_PRESIGNATURE_WAITS . inc ( ) ;
117+ tracing:: warn!(
118+ ?requested_chain,
119+ "no chain-compatible presignatures available, waiting"
120+ )
121+ } ,
122+ )
123+ . await ;
109124 let participants = presignature. participants . clone ( ) ;
110125 let channel = self . ecdsa_signature_provider . new_channel_for_task (
111126 VerifyForeignTxTaskId :: VerifyForeignTx {
0 commit comments