Skip to content

Commit e0efa24

Browse files
author
Alan Christie
committed
fix: Now correctly uses the 'peak' storage costs for 'today'
1 parent 4cf12a9 commit e0efa24

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/coins.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ def main(c_args: argparse.Namespace) -> None:
7979
pprint(pc_rv.msg)
8080

8181
# Accumulate all the storage costs
82-
# (excluding the current which will be interpreted as the "burn rate")
82+
# (the current record wil be used to set the future the "burn rate")
8383
num_storage_charges: int = 0
8484
burn_rate: Decimal = Decimal()
8585
total_storage_coins: Decimal = Decimal()
8686
if "items" in pc_rv.msg["storage_charges"]:
8787
for item in pc_rv.msg["storage_charges"]["items"]:
88+
total_storage_coins += Decimal(item["coins"])
8889
if "current_bytes" in item["additional_data"]:
8990
burn_rate = Decimal(item["burn_rate"])
9091
else:
91-
total_storage_coins += Decimal(item["coins"])
9292
num_storage_charges += 1
9393

9494
# Accumulate all the processing costs
@@ -142,7 +142,14 @@ def main(c_args: argparse.Namespace) -> None:
142142
"Coins (Adjusted)": f"{ac.fc} + {ac.aac} = {ac.coins}",
143143
}
144144

145-
burn_rate_contribution: Decimal = burn_rate * remaining_days
145+
# We've accumulated today's storage costs (based on the current 'peak'),
146+
# so we can only predict further storage costs if there's more than
147+
# 1 day left until the billing day. And that 'burn rate' is based on today's
148+
# 'current' storage, not its 'peak'.
149+
burn_rate_contribution: Decimal = Decimal()
150+
burn_rate_days: int = max(remaining_days - 1, 0)
151+
if burn_rate_days > 0:
152+
burn_rate_contribution = burn_rate * burn_rate_days
146153
additional_coins: Decimal = total_uncommitted_processing_coins + burn_rate_contribution
147154
predicted_total_coins: Decimal = total_coins
148155
zero: Decimal = Decimal()
@@ -158,7 +165,7 @@ def main(c_args: argparse.Namespace) -> None:
158165

159166
invoice["Prediction"] = {
160167
"Coins (Burn Rate)": str(burn_rate),
161-
"Coins (Expected Burn Rate Contribution)": f"{remaining_days} x {burn_rate} = {burn_rate_contribution}",
168+
"Coins (Expected Burn Rate Contribution)": f"{burn_rate_days} x {burn_rate} = {burn_rate_contribution}",
162169
"Coins (Additional Spend)": f"{total_uncommitted_processing_coins} + {burn_rate_contribution} = {additional_coins}",
163170
"Coins (Total Raw)": f"{total_coins} + {additional_coins} = {predicted_total_coins}",
164171
"Coins (Penalty Free)": str(p_ac.fc),

0 commit comments

Comments
 (0)