@@ -288,8 +288,16 @@ impl<D: Db> Service<D> {
288288 async fn get_mailbox ( & self , id : & str ) -> Result < Response < Body > , HandlerError > {
289289 trace ! ( "get_mailbox" ) ;
290290 let id = ShortId :: from_str ( id) ?;
291- let timeout_response = Response :: builder ( ) . status ( StatusCode :: ACCEPTED ) . body ( empty ( ) ) ?;
292- handle_peek ( self . db . wait_for_v2_payload ( & id) . await , timeout_response)
291+ let empty_response = Response :: builder ( ) . status ( StatusCode :: ACCEPTED ) . body ( empty ( ) ) ?;
292+ match self . db . peek_v2_payload ( & id) . await {
293+ Ok ( Some ( payload) ) => Ok ( Response :: new ( full ( ( * payload) . clone ( ) ) ) ) ,
294+ Ok ( None ) => Ok ( empty_response) ,
295+ Err ( DbError :: Operational ( err) ) => {
296+ error ! ( "Storage error: {err}" ) ;
297+ Err ( HandlerError :: InternalServerError ( anyhow:: Error :: msg ( "Internal server error" ) ) )
298+ }
299+ Err ( _) => Ok ( empty_response) ,
300+ }
293301 }
294302
295303 /// Screen a V1 PSBT body against the address blocklist.
@@ -878,6 +886,25 @@ mod tests {
878886 }
879887 }
880888
889+ #[ tokio:: test( start_paused = true ) ]
890+ async fn get_mailbox_returns_immediately_when_empty ( ) {
891+ let svc = test_service ( None ) . await ;
892+ let id = valid_short_id_path ( ) ;
893+ let start = tokio:: time:: Instant :: now ( ) ;
894+ let res = svc. get_mailbox ( & id) . await . expect ( "get_mailbox" ) ;
895+ assert_eq ! ( res. status( ) , StatusCode :: ACCEPTED ) ;
896+ assert_eq ! ( start. elapsed( ) , Duration :: ZERO , "GET must not block" ) ;
897+ }
898+
899+ #[ tokio:: test]
900+ async fn get_mailbox_returns_payload_when_present ( ) {
901+ let svc = test_service ( None ) . await ;
902+ let id = valid_short_id_path ( ) ;
903+ svc. post_mailbox ( & id, Body :: from ( b"hi" . to_vec ( ) ) ) . await . expect ( "post" ) ;
904+ let res = svc. get_mailbox ( & id) . await . expect ( "get_mailbox" ) ;
905+ assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
906+ }
907+
881908 #[ tokio:: test]
882909 async fn post_mailbox_records_short_id_cardinality ( ) {
883910 use opentelemetry_sdk:: metrics:: {
0 commit comments