@@ -265,12 +265,14 @@ impl<T: Config> Pallet<T> {
265265 Error :: <T >:: DuplicateColdkey
266266 ) ;
267267
268- // If the destinations keys are empty or have size 1 then we will add the new coldkey to the list
269- if destination_coldkeys. is_empty ( ) || destination_coldkeys. len ( ) == 1_usize {
268+ // If the destinations keys are empty or have less than the maximum allowed, we will add the new coldkey to the list
269+ const MAX_COLDKEY_DESTINATIONS : usize = 10 ;
270+
271+ if destination_coldkeys. len ( ) < MAX_COLDKEY_DESTINATIONS {
270272 destination_coldkeys. push ( new_coldkey. clone ( ) ) ;
271273 ColdkeySwapDestinations :: < T > :: insert ( old_coldkey. clone ( ) , destination_coldkeys. clone ( ) ) ;
272274 } else {
273- return Err ( Error :: < T > :: ColdkeyIsInArbitration . into ( ) ) ;
275+ return Err ( Error :: < T > :: MaxColdkeyDestinationsReached . into ( ) ) ;
274276 }
275277
276278 // It is the first time we have seen this key
@@ -318,43 +320,36 @@ impl<T: Config> Pallet<T> {
318320 pub fn swap_coldkeys_this_block ( weight_limit : & Weight ) -> Result < Weight , & ' static str > {
319321 let mut weight_used = frame_support:: weights:: Weight :: from_parts ( 0 , 0 ) ;
320322
321- // Get the block number
322323 let current_block: u64 = Self :: get_current_block_as_u64 ( ) ;
323324 log:: debug!( "Swapping coldkeys for block: {:?}" , current_block) ;
324325
325- // Get the coldkeys to swap here and then remove them.
326326 let source_coldkeys: Vec < T :: AccountId > = ColdkeysToSwapAtBlock :: < T > :: get ( current_block) ;
327327 ColdkeysToSwapAtBlock :: < T > :: remove ( current_block) ;
328328 weight_used = weight_used. saturating_add ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
329329
330- // Iterate over all keys in swap and call perform_swap_coldkey for each
331330 let mut keys_swapped = 0u64 ;
332331 for coldkey_i in source_coldkeys. iter ( ) {
333- // Terminate early if we've exhausted the weight limit
334- //
335- // We care only about ref_time and not proof_size because we are a solochain.
336- if weight_used. ref_time ( ) > weight_limit. ref_time ( ) {
337- log:: warn!( "Could not finish swapping all coldkeys this block due to weight limit, breaking after swapping {} keys." , keys_swapped) ;
338- break ;
339- }
332+ // TODO: need a sane way to terminate early without locking users in.
333+ // we should update the swap time
334+ // if weight_used.ref_time() > weight_limit.ref_time() {
335+ // log::warn!("Could not finish swapping all coldkeys this block due to weight limit, breaking after swapping {} keys.", keys_swapped);
336+ // break;
337+ // }
340338
341- // Get the wallets to swap to for this coldkey.
342339 let destinations_coldkeys: Vec < T :: AccountId > =
343340 ColdkeySwapDestinations :: < T > :: get ( coldkey_i) ;
344- ColdkeySwapDestinations :: < T > :: remove ( & coldkey_i) ;
345- weight_used = weight_used. saturating_add ( T :: DbWeight :: get ( ) . reads_writes ( 1 , 1 ) ) ;
341+ weight_used = weight_used. saturating_add ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
346342
347- // If the wallets to swap is > 1 we bump the arbitration period.
348343 if destinations_coldkeys. len ( ) > 1 {
349- // Set the arbitration period to u64::MAX until we have a senate vote
344+ // Do not remove ColdkeySwapDestinations if there are multiple destinations
350345 ColdkeyArbitrationBlock :: < T > :: insert ( coldkey_i. clone ( ) , u64:: MAX ) ;
351-
352346 Self :: deposit_event ( Event :: ArbitrationPeriodExtended {
353347 coldkey : coldkey_i. clone ( ) ,
354348 } ) ;
355349 } else if let Some ( new_coldkey) = destinations_coldkeys. first ( ) {
356- // ONLY 1 wallet: Get the wallet to swap to.
357- // Perform the swap.
350+ // Only remove ColdkeySwapDestinations if there's a single destination
351+ ColdkeySwapDestinations :: < T > :: remove ( & coldkey_i) ;
352+ weight_used = weight_used. saturating_add ( T :: DbWeight :: get ( ) . writes ( 1 ) ) ;
358353 Self :: perform_swap_coldkey ( coldkey_i, new_coldkey) . map ( |weight| {
359354 weight_used = weight_used. saturating_add ( weight) ;
360355 keys_swapped = keys_swapped. saturating_add ( 1 ) ;
0 commit comments