Deitos-Network / deitos-node

GNU General Public License v3.0
1 stars 1 forks source link

Bug: Installment calculation. #18

Closed hbulgarini closed 8 months ago

hbulgarini commented 8 months ago

There is an issue with the installment calculation:

    /// Calculate the cost of an installment. The cost of the installment is the length of the
    /// installment multiplied by the storage cost per block.
    ///
    /// The installment index is the index of the installment in the payment plan. The first
    /// installment has index 0.
    ///
    /// Returns `None` if the installment index is out of bounds.
    fn calculate_installment_cost(&self, installment_index: usize) -> Option<BalanceOf<T>> {
        let installment_length = self.calculate_installment_length(installment_index)?;
        let cost = CurrentPrices::<T>::get()
            .storage_mb_per_block
            .saturating_mul(BalanceOf::<T>::saturated_from(
                installment_length.saturated_into::<u128>(),
            ));

        Some(cost)
    }

That code which is the one that calculates the installment cost is not considering the amount of storage from the agreement, charging only one unit of storage per amount of blocks, when it has to be amount of blocks amount of storage requested storage unit.