Document how fees are calculated

parent 117b642f
Pipeline #30096863 passed with stages
in 18 minutes and 19 seconds
......@@ -191,7 +191,7 @@ Vote transactions can be performed by validators to vote for fee sizes and proto
Account transaction create accounts or extend their validity.
Every transaction except a vote transaction deducts a fee from the account from which it is performed. Fees are calculated from validators’ votes. They are put into long fee deposit (fees per block) and short fee deposit (fees per tx and per byte).
Every transaction except a vote transaction deducts fees from the account from which it is performed. They are put into long fee deposit (fees per block) and short fee deposit (fees per tx and per byte). Applicable fee amounts are calculated as medians of weighted validators’ votes, with higher middle values chosen if sum of weights is even.
At the end of every epoch, short fee deposit and part of long fee deposit are divided between validators proportionally to their voting power. If the epoch lasted longer than expected, a ratio proportional to the relative delay is put into long fee deposit instead of being granted to validators. If a validator doesn’t have an account or has at least 1⁄3 absencies in the passing epoch, its reward is destroyed.
......
......@@ -115,5 +115,7 @@ voted_choices(#data{validators=Validators}) ->
Validators),
SortedChoicesVPs = maps:map(fun (_, ChoiceVPs) -> lists:sort(ChoiceVPs) end, ChoicesVPs),
maps:map(
fun (_, ChoiceVPs) -> quantiles:'weighted-quantile'(0.5, ChoiceVPs, VoteSum) end,
%% The quantile function should return higher middle value if sum of weights is even, but
%% to be even more sure we make the first argument a little higher than 0.5.
fun (_, ChoiceVPs) -> quantiles:'weighted-quantile'(0.500001, ChoiceVPs, VoteSum) end,
SortedChoicesVPs).
......@@ -21,7 +21,8 @@
((_ (list (tuple val _)) _)
val)
((degree (cons (tuple val weight) tail) weight-sum)
;; TODO: Test that > is used here, not >=.
(if (> (/ weight weight-sum) degree)
val
(weighted-quantile (/ (- degree (/ weight weight-sum)) (/ (- weight-sum weight) weight-sum)) tail (- weight-sum weight)))))
(weighted-quantile (/ (- degree (/ weight weight-sum)) (/ (- weight-sum weight) weight-sum))
tail
(- weight-sum weight)))))
......@@ -14,7 +14,7 @@
-include_lib("include/ercoin_test.hrl").
prop_fees_are_sometimes_non_negative() ->
prop_fees_are_sometimes_positive() ->
fails(
?FORALL(
{Data, Tx},
......
......@@ -14,6 +14,7 @@
;; Triq’s autoexport parse transform doesn’t work here, as parse transforms don’t work in LFE, so we just export everything.
(export all))
(include-lib "eunit/include/eunit.hrl")
(include-lib "triq/include/triq.hrl")
(defun weight-sum (l)
......@@ -25,6 +26,9 @@
(([] acc)
acc))
(defun border_case_test ()
(assertEqual 2 (quantiles:weighted-quantile 0.5 (list #(1 1) #(2 1)) 2)))
(defun weight ()
(pos_integer))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment