Skip to content

Commit 24ba390

Browse files
committed
refactor: small code refactor based on PR comment
1 parent e406ab8 commit 24ba390

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

substrate-node/pallets/pallet-smart-contract/src/billing.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,24 @@ impl<T: Config> Pallet<T> {
395395
// Ensure associated node contracts have no reserved balance.
396396
// If none, proceed to move the contract to the 'deleted' state.
397397
// Otherwise, wait.
398-
let can_be_deleted = match contract.contract_type {
398+
match contract.contract_type {
399399
types::ContractData::RentContract(_) => {
400400
let active_node_contracts = ActiveNodeContracts::<T>::get(contract.get_node_id());
401-
!active_node_contracts.iter().any(|id| {
401+
let rent_has_node_contracts_with_reserve =
402+
active_node_contracts.iter().any(|id| {
402403
ContractPaymentState::<T>::get(id).map_or(false, |s| s.has_reserve())
403-
})
404+
});
405+
406+
if rent_has_node_contracts_with_reserve {
407+
log::debug!(
408+
"Grace period on rented node expired, but one or more associated node contracts hold user funds. \
409+
Rent contract deletion will be delayed until funds are distributed to beneficiaries."
410+
);
411+
return Ok(().into());
412+
}
404413
}
405-
_ => true,
414+
_ => (),
406415
};
407-
if !can_be_deleted {
408-
log::debug!(
409-
"Grace period expired, but one or more associated node contracts have held user funds. \
410-
Rent contract deletion will be delayed until funds are distributed to beneficiaries."
411-
);
412-
return Ok(().into());
413-
}
414416

415417
log::info!("Contract {:?} state changed to deleted at block {:?} due to an expired grace period.", contract.contract_id, current_block);
416418
Self::deposit_event(Event::ContractGracePeriodElapsed {

substrate-node/pallets/pallet-smart-contract/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
cost, mock::{RuntimeEvent as MockEvent, *}, test_utils::*, types::{self, RentContract}, Error,
2+
cost, mock::{RuntimeEvent as MockEvent, *}, test_utils::*, types, Error,
33
Event as SmartContractEvent,
44
};
55
use frame_support::{

0 commit comments

Comments
 (0)