-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create new pallet-minting for on chain minting #493
Conversation
/// SU: hru / 1200 + sru * 0.8 / 200 | ||
pub fn cloud_units_permill(&self) -> (u64, u64) { | ||
// Calculate CU first. Mru and sru are in bytes, but are expressed in GB in the formula. | ||
// Rather than dividing first, we multiply cru first, then take the MIN, and finally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe get more detailed comment here because not easy to understand precision trick
// Rather than converting mru and sru to GB (by dividing first), we multiply cru first instead (to put the values at same scale), then take the MIN, and finally divide the returning values at the end of function
let mut cu_reward = 0; | ||
let mut su_reward = 0; | ||
|
||
let uptime_percentage = (period.uptime * 1_000 / period_length) as u128; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if uptime <= period_length
is always guarantied
we should return some error if not the case
su_reward = su * farming_policy.su as u64; | ||
} else { | ||
let minimal_uptime_met = | ||
period.uptime < (period_length * farming_policy.minimal_uptime as u64) / 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uptime (in sec)
periode_length (in sec)
minimal_uptime is in permil, that's why we divide by 1000?
I saw some minimal_uptime expressed in percent in other part of code (chain_spec.rs)
Not sure it is consistent
// Caculate actual payout for the period uptime | ||
base_payout = base_payout * uptime_percentage / 1_000; | ||
// Inflate base payout for more precision | ||
base_payout = base_payout * 100_000_000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why a precision trick is required here
I don t see where it is divided back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
payouts in musd are converted to units TFT (1e7 decimals precision)
node.certification, | ||
tfchain_support::types::NodeCertification::Certified | ||
) { | ||
base_payout = base_payout * 5 / 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment that certified nodes receive +25% reward to explain calculation
|
||
log::info!("connection price: {}", connection_price); | ||
// Calculate the amount of TFT rewarded | ||
let total_tft_reward = base_payout / connection_price as u128; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each time we have a formula it would be good to specified the units
to avoid confusion
Example here
total_tft_reward (TFT)
base_payout (mUSD)
connection_price (mUSD/TFT)
log::debug!("nru reward: {}", nru_reward); | ||
|
||
// Public IP rewards are per public ip per hour for a period | ||
let ipu_reward = period.ipu * farming_policy.ipv4 as u128 / 3600; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong:
farming_policy.ipv4
is the reward for an IP for 1h
so if you divide by 3600 you get the reward for an IP for 1sec
Right?
Shouldn t we multiply by period_length
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IP units are reported in seconds, so we divide by 3600 (1 hour) to get the value per hour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node_report.counters.ipu += (ipu as u64 * window) as u128; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see so we have
ipu_reward (mUSD) = period.ipu (sec) * farming_policy.ipv4 (mUSD/hour) / 3600 (sec/hour);
I would add this comment for understanding code
// ipu reward (mUSD) = ipu uptime (sec) * ipv4 price (mUSD/hour) / 3600 (sec/hour);
su_reward = su * farming_policy.su as u64; | ||
} else { | ||
let minimal_uptime_met = | ||
period.uptime < (period_length * farming_policy.minimal_uptime as u64) / 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also uptime_percentage
could be reused here with something like:
uptime_percentage < farming_policy.minimal_uptime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uptime percentage is expressed as a percentage, in the minimal uptime met check we calculate how much uptime the farmer actually needs, It's different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's different because you compare time instead of percent
But it is mathematically the same
if you start with:
period.uptime < (period_length * minimal_uptime) / 1000
you multiply by 1000 each side
period.uptime *1000 < period_length * minimal_uptime
you divide each side by period_length
period.uptime *1000 / period_length < minimal_uptime
which is the equivalent to
uptime_percentage < minimal_uptime
3f19cca
to
e3868e9
Compare
Closing because it's not planned anymore |
related to: