@@ -82,6 +82,12 @@ impl ShieldKeys {
8282 }
8383}
8484
85+ impl Default for ShieldKeys {
86+ fn default ( ) -> Self {
87+ Self :: new ( )
88+ }
89+ }
90+
8591/// Shared context state.
8692#[ freeze_struct( "62af7d26cf7c1271" ) ]
8793#[ derive( Clone ) ]
@@ -94,7 +100,10 @@ pub struct ShieldContext {
94100pub fn derive_aead_key ( ss : & [ u8 ] ) -> [ u8 ; 32 ] {
95101 let mut key = [ 0u8 ; 32 ] ;
96102 let n = ss. len ( ) . min ( 32 ) ;
97- key[ ..n] . copy_from_slice ( & ss[ ..n] ) ;
103+
104+ if let ( Some ( dst) , Some ( src) ) = ( key. get_mut ( ..n) , ss. get ( ..n) ) {
105+ dst. copy_from_slice ( src) ;
106+ }
98107 key
99108}
100109
@@ -123,8 +132,8 @@ const AURA_KEY_TYPE: KeyTypeId = KeyTypeId(*b"aura");
123132/// - at ~announce_at_ms announce the next key bytes on chain,
124133pub fn spawn_author_tasks < B , C , Pool > (
125134 task_spawner : & sc_service:: SpawnTaskHandle ,
126- client : std :: sync :: Arc < C > ,
127- pool : std :: sync :: Arc < Pool > ,
135+ client : Arc < C > ,
136+ pool : Arc < Pool > ,
128137 keystore : sp_keystore:: KeystorePtr ,
129138 timing : TimeParams ,
130139) -> ShieldContext
@@ -135,13 +144,13 @@ where
135144 B :: Extrinsic : From < sp_runtime:: OpaqueExtrinsic > ,
136145{
137146 let ctx = ShieldContext {
138- keys : std :: sync :: Arc :: new ( std :: sync :: Mutex :: new ( ShieldKeys :: new ( ) ) ) ,
147+ keys : Arc :: new ( Mutex :: new ( ShieldKeys :: new ( ) ) ) ,
139148 timing : timing. clone ( ) ,
140149 } ;
141150
142151 let aura_keys: Vec < sp_core:: sr25519:: Public > = keystore. sr25519_public_keys ( AURA_KEY_TYPE ) ;
143152
144- let local_aura_pub = match aura_keys. get ( 0 ) . cloned ( ) {
153+ let local_aura_pub = match aura_keys. first ( ) . copied ( ) {
145154 Some ( k) => k,
146155 None => {
147156 log:: warn!(
@@ -173,20 +182,15 @@ where
173182 if announce_at_ms > slot_ms {
174183 log:: warn!(
175184 target: "mev-shield" ,
176- "spawn_author_tasks: announce_at_ms ({}) > slot_ms ({}); clamping to slot_ms" ,
177- announce_at_ms,
178- slot_ms,
185+ "spawn_author_tasks: announce_at_ms ({announce_at_ms}) > slot_ms ({slot_ms}); clamping to slot_ms" ,
179186 ) ;
180187 announce_at_ms = slot_ms;
181188 }
182189 let tail_ms = slot_ms. saturating_sub ( announce_at_ms) ;
183190
184191 log:: debug!(
185192 target: "mev-shield" ,
186- "author timing: slot_ms={} announce_at_ms={} (effective) tail_ms={}" ,
187- slot_ms,
188- announce_at_ms,
189- tail_ms
193+ "author timing: slot_ms={slot_ms} announce_at_ms={announce_at_ms} (effective) tail_ms={tail_ms}" ,
190194 ) ;
191195
192196 let mut import_stream = client_clone. import_notification_stream ( ) ;
@@ -204,17 +208,15 @@ where
204208 Err ( e) => {
205209 log:: debug!(
206210 target: "mev-shield" ,
207- "spawn_author_tasks: failed to lock ShieldKeys (poisoned?): {:?}" ,
208- e
211+ "spawn_author_tasks: failed to lock ShieldKeys (poisoned?): {e:?}" ,
209212 ) ;
210213 continue ;
211214 }
212215 } ;
213216
214217 log:: debug!(
215218 target: "mev-shield" ,
216- "Slot start (local author): (pk sizes: curr={}B, next={}B)" ,
217- curr_pk_len, next_pk_len
219+ "Slot start (local author): (pk sizes: curr={curr_pk_len}B, next={next_pk_len}B)" ,
218220 ) ;
219221
220222 // Wait until the announce window in this slot.
@@ -228,8 +230,7 @@ where
228230 Err ( e) => {
229231 log:: debug!(
230232 target: "mev-shield" ,
231- "spawn_author_tasks: failed to lock ShieldKeys for next_pk: {:?}" ,
232- e
233+ "spawn_author_tasks: failed to lock ShieldKeys for next_pk: {e:?}" ,
233234 ) ;
234235 continue ;
235236 }
@@ -240,7 +241,7 @@ where
240241 client_clone. clone ( ) ,
241242 pool_clone. clone ( ) ,
242243 keystore_clone. clone ( ) ,
243- local_aura_pub. clone ( ) ,
244+ local_aura_pub,
244245 next_pk. clone ( ) ,
245246 local_nonce,
246247 )
@@ -257,7 +258,7 @@ where
257258 client_clone. clone ( ) ,
258259 pool_clone. clone ( ) ,
259260 keystore_clone. clone ( ) ,
260- local_aura_pub. clone ( ) ,
261+ local_aura_pub,
261262 next_pk,
262263 local_nonce. saturating_add ( 1 ) ,
263264 )
@@ -297,22 +298,21 @@ where
297298 Err ( e) => {
298299 log:: debug!(
299300 target: "mev-shield" ,
300- "spawn_author_tasks: failed to lock ShieldKeys for roll_for_next_slot: {:?}" ,
301- e
301+ "spawn_author_tasks: failed to lock ShieldKeys for roll_for_next_slot: {e:?}" ,
302302 ) ;
303303 }
304304 }
305305 }
306- }
306+ } ,
307307 ) ;
308308
309309 ctx
310310}
311311
312312/// Build & submit the signed `announce_next_key` extrinsic OFF-CHAIN
313313pub async fn submit_announce_extrinsic < B , C , Pool > (
314- client : std :: sync :: Arc < C > ,
315- pool : std :: sync :: Arc < Pool > ,
314+ client : Arc < C > ,
315+ pool : Arc < Pool > ,
316316 keystore : sp_keystore:: KeystorePtr ,
317317 aura_pub : sp_core:: sr25519:: Public ,
318318 next_public_key : Vec < u8 > ,
@@ -350,10 +350,9 @@ where
350350 let src_start = bytes. len ( ) . saturating_sub ( n) ;
351351 let dst_start = 32usize . saturating_sub ( n) ;
352352
353- if let ( Some ( dst) , Some ( src) ) = (
354- out. get_mut ( dst_start..32 ) ,
355- bytes. get ( src_start..src_start + n) ,
356- ) {
353+ let src_slice = bytes. get ( src_start..) . and_then ( |s| s. get ( ..n) ) ;
354+
355+ if let ( Some ( dst) , Some ( src) ) = ( out. get_mut ( dst_start..32 ) , src_slice) {
357356 dst. copy_from_slice ( src) ;
358357 H256 ( out)
359358 } else {
@@ -411,8 +410,7 @@ where
411410 ) ;
412411
413412 // Build the exact signable payload.
414- let payload: SignedPayload =
415- SignedPayload :: from_raw ( call. clone ( ) , extra. clone ( ) , implicit. clone ( ) ) ;
413+ let payload: SignedPayload = SignedPayload :: from_raw ( call. clone ( ) , extra. clone ( ) , implicit) ;
416414
417415 let raw_payload = payload. encode ( ) ;
418416
@@ -432,6 +430,7 @@ where
432430
433431 let xt_bytes = uxt. encode ( ) ;
434432 let xt_hash = sp_core:: hashing:: blake2_256 ( & xt_bytes) ;
433+ let xt_hash_hex = hex:: encode ( xt_hash) ;
435434
436435 let opaque: sp_runtime:: OpaqueExtrinsic = uxt. into ( ) ;
437436 let xt: <B as sp_runtime:: traits:: Block >:: Extrinsic = opaque. into ( ) ;
@@ -441,9 +440,7 @@ where
441440
442441 log:: debug!(
443442 target: "mev-shield" ,
444- "announce_next_key submitted: xt=0x{}, nonce={}" ,
445- hex:: encode( xt_hash) ,
446- nonce
443+ "announce_next_key submitted: xt=0x{xt_hash_hex}, nonce={nonce}" ,
447444 ) ;
448445
449446 Ok ( ( ) )
0 commit comments