Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Define non-integer type (#124)
Browse files Browse the repository at this point in the history
* Use rational number representation for Decimal type.

* Add check for commission rate bounds.

* Fix reference to commissionRate field for proposer.

* Compute commission reward using rational rate.
  • Loading branch information
adlerjohn authored Feb 16, 2021
1 parent 04fc593 commit e714f9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions specs/consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ The following checks must be `true`:
1. `tx.fee.tipRateMax` >= `block.header.feeHeader.tipRate`.
1. `totalCost(0, bytesPaid)` <= `state.accounts[sender].balance`.
1. `tx.nonce` == `state.accounts[sender].nonce + 1`.
1. `tx.commissionRate` <!--TODO check some bounds here-->
1. `tx.commissionRate.denominator > 0`.
1. `tx.commissionRate.numerator <= tx.commissionRate.denominator`.
1. `state.accounts[sender].status` == `AccountStatus.None`.

Apply the following to the state:
Expand Down Expand Up @@ -729,7 +730,7 @@ proposer.latestEntry += compute_new_entry(proposer.pendingRewards, proposer.voti
proposer.pendingRewards = 0

blockReward = state.activeValidatorSet.proposerBlockReward
commissionReward = proposer.commission * blockReward
commissionReward = proposer.commissionRate.numerator * blockReward // proposer.commissionRate.denominator
proposer.commissionRewards += commissionReward
proposer.pendingRewards += blockReward - commissionReward

Expand Down
7 changes: 6 additions & 1 deletion specs/data_structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,12 @@ For explanation on entries, see the [reward distribution rationale document](../

### Decimal

TODO define a format for numbers in the range `[0,1]`
| name | type | description |
| ------------- | ------ | --------------------- |
| `numerator` | uint64 | Rational numerator. |
| `denominator` | uint64 | Rational denominator. |

Represents a (potentially) non-integer number.

## Consensus Parameters

Expand Down

0 comments on commit e714f9d

Please sign in to comment.