From e714f9de68bda31749a1f52cd7bdcb4e0b293312 Mon Sep 17 00:00:00 2001 From: John Adler Date: Tue, 16 Feb 2021 18:05:51 -0500 Subject: [PATCH] Define non-integer type (#124) * 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. --- specs/consensus.md | 5 +++-- specs/data_structures.md | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/specs/consensus.md b/specs/consensus.md index a450ab1..c26ffff 100644 --- a/specs/consensus.md +++ b/specs/consensus.md @@ -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` +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: @@ -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 diff --git a/specs/data_structures.md b/specs/data_structures.md index a0c4491..9778644 100644 --- a/specs/data_structures.md +++ b/specs/data_structures.md @@ -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