-
Notifications
You must be signed in to change notification settings - Fork 211
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
[Merged by Bors] - vm, blocks: integrate rewards from updated economics #3559
Conversation
@@ -41,7 +41,7 @@ func (v *Vault) Available(lid core.LayerID) uint64 { | |||
} | |||
incremental := new(big.Int).SetUint64(v.TotalAmount - v.InitialUnlockAmount) | |||
incremental.Mul(incremental, new(big.Int).SetUint64(uint64(lid.Difference(v.VestingStart)))) | |||
incremental.Div(incremental, new(big.Int).SetUint64(uint64(v.VestingEnd.Difference(v.VestingStart)))) | |||
incremental.Quo(incremental, new(big.Int).SetUint64(uint64(v.VestingEnd.Difference(v.VestingStart)))) |
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.
this is for consistency with rewards, Div and Quo works the same for uint64
bors try |
tryBuild succeeded: |
// set the block ID when received | ||
b.Initialize() | ||
|
||
if err := vm.ValidateRewards(b.Rewards); err != nil { |
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.
why do it here instead of after the de-duplication check?
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.
because syntactic validation is cheap. i can move it afterwards, doesn't matter much to me
Quo(subsidyReward, relative.Denom()) | ||
if !subsidyReward.IsUint64() { | ||
return fmt.Errorf("%w: subsidy reward %v for %v overflows uint64", | ||
core.ErrInternal, subsidyReward, blockReward.Coinbase) |
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.
looks like you can factor out an utility method to do the division and check uint64
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.
it is looks cleaner without such method
v.logger.With().Debug("rewards for layer", | ||
lctx.Layer, | ||
log.Uint32("after genesis", layersAfterEffectiveGenesis), | ||
log.Uint64("subsidy estimated", subsidy), |
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.
why the term "estimated" here and for total?
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.
actual amount computed from how much was transfered
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 don't understand - "estimated" here means "before rounding"? or something else?
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.
before rounding
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.
- can also close blocks: invalidate block without rewards (or leave everything as it is) #3251
- i think we should burn the subsidy if there are empty layers
they are already burned |
bors merge |
closes: spacemeshos/pm#151 closes: #3408 closes: #3251 this change enforces next rules for block syntactic validity: - every block must have at least one reward (empty layers are an obvious exception) - to make block more compact there should be at most one reward per coinbase (smeshers are not recorded in rewards) - this is already like that in the code that generates block, i am adding a validation for it - weight is recorded as fractional int using two uint64 (num/denom), if any of those is 0 - block is syntactically invalid total rewards is a sum of fees and subsidy (subsidy is computed using github.com/spacemeshos/economics). total rewards are splited between coinbases recorded in the block. each coinbase share is a relative to the total weight recorded in the block. share is computed using big.Rat from stdlib on integer values. absolute value is computed by multiplying total reward by big.Rat numerator and divides by denominator using big.Int from stdlib (no floating operations).
Pull request successfully merged into develop. Build succeeded: |
@dshulyak sorry i missed that. where does that happen? |
what do you mean? rewards that are not transferred are burned. so in case of empty layer - rewards are always burned |
but we don't call vm.Apply() on types.EmptyBlockID |
burning doesn't modify any state |
oh ok. its in the math (num layers since genesis). i get it now. thanks |
closes: spacemeshos/pm#151
closes: #3408
closes: #3251
this change enforces next rules for block syntactic validity:
total rewards is a sum of fees and subsidy (subsidy is computed using github.com/spacemeshos/economics). total rewards are splited between coinbases recorded in the block. each coinbase share is a relative to the total weight recorded in the block. share is computed using big.Rat from stdlib on integer values.
absolute value is computed by multiplying total reward by big.Rat numerator and divides by denominator using big.Int from stdlib (no floating operations).