Skip to content

Commit

Permalink
add power target is switched to Down condition
Browse files Browse the repository at this point in the history
  • Loading branch information
renauter committed Jan 22, 2024
1 parent 0c101ef commit f08b934
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions substrate-node/pallets/pallet-tfgrid/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<T: Config> Pallet<T> {

let mut node_power = NodePower::<T>::get(node_id);

// if the power state is different from what is set, change it and emit event
// If the power state is different from what is set, change it and emit event
if node_power.state != power_state {
node_power.state = power_state.clone();
NodePower::<T>::insert(node_id, node_power);
Expand Down Expand Up @@ -368,27 +368,24 @@ impl<T: Config> Pallet<T> {
Error::<T>::UnauthorizedToChangePowerTarget
);

// Make sure there are no active contracts on node
// When power target is switched to Down, make sure there are no active contracts on node
ensure!(
T::NodeActiveContracts::node_has_no_active_contracts(node_id),
power_target == Power::Down
&& T::NodeActiveContracts::node_has_no_active_contracts(node_id),
Error::<T>::NodeHasActiveContracts
);

Self::_change_power_target_on_node(node.id, node.farm_id, power_target);

Ok(().into())
}

fn _change_power_target_on_node(node_id: u32, farm_id: u32, power_target: Power) {
let mut node_power = NodePower::<T>::get(node_id);
node_power.target = power_target.clone();
NodePower::<T>::insert(node_id, &node_power);

Self::deposit_event(Event::PowerTargetChanged {
farm_id,
farm_id: node.farm_id,
node_id,
power_target,
});

Ok(().into())
}

fn get_resources(
Expand Down

0 comments on commit f08b934

Please sign in to comment.