@@ -77,46 +77,34 @@ impl AwsPair {
77
77
self . pubkey
78
78
}
79
79
80
- /// Try to sign `message` using our remote signer. Accept a `delay` so that
81
- /// this can be called repeatedly with a backoff
82
- async fn try_sign_remote (
83
- & self ,
84
- message : & [ u8 ] ,
85
- delay : Duration ,
86
- ) -> Result < AwsSignature , AwsSignerError > {
87
- sleep ( delay) . await ;
88
- // Sign and map between our remote and local 65-byte ECDSA sigs
89
- self . signer
90
- . sign_message ( message)
91
- . await
92
- . map ( Into :: < AwsSignature > :: into)
93
- }
94
-
95
80
/// Try to sign `message` `max_retries` times with an exponential backoff between attempts.
96
81
/// If we hit `max_retries` `panic` since we're unable to return an error here.
97
82
fn sign_remote ( & self , message : & [ u8 ] ) -> AwsSignature {
98
- let mut times_attempted = 0 ;
99
- let mut delay = Duration :: from_millis ( 0 ) ;
100
83
tokio:: runtime:: Builder :: new_current_thread ( )
101
84
. enable_all ( )
102
85
. build ( )
103
86
. expect ( "unable to create tokio::runtime (this should never happen)" )
104
87
. block_on ( async {
105
- loop {
106
- match self . try_sign_remote ( message , delay ) . await {
107
- Ok ( signature ) => return signature ,
108
- Err ( error) => {
109
- times_attempted += 1 ;
110
- delay = Duration :: from_millis ( self . min_retry_ms . pow ( times_attempted ) ) ;
111
- if times_attempted == self . max_retries {
112
- panic ! (
113
- "giving up after attempting to sign message {} times: {:?}" ,
114
- times_attempted , error ,
115
- )
116
- }
117
- }
118
- }
88
+ let mut error = None ;
89
+ for i in 0 .. self . max_retries {
90
+ sleep ( Duration :: from_millis ( self . min_retry_ms . pow ( i ) ) ) . await ;
91
+ error = Some (
92
+ match self
93
+ . signer
94
+ . sign_message ( message )
95
+ . await
96
+ . map ( Into :: < AwsSignature > :: into )
97
+ {
98
+ Ok ( signature ) => return signature ,
99
+ Err ( error ) => error ,
100
+ } ,
101
+ ) ;
119
102
}
103
+ panic ! (
104
+ "giving up after attempting to sign message {} times: {:?}" ,
105
+ self . max_retries,
106
+ error. unwrap( ) ,
107
+ ) ;
120
108
} )
121
109
}
122
110
}
0 commit comments