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

Commit

Permalink
Add support for HIP15
Browse files Browse the repository at this point in the history
  • Loading branch information
vihu committed Oct 22, 2020
1 parent 575338f commit 079d3e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
-define(poc_witnesses_percent, poc_witnesses_percent).
-define(poc_challengers_percent, poc_challengers_percent).
-define(dc_percent, dc_percent).
-define(witness_redundancy, witness_redundancy).

%%%
%%% bundle txn vars
Expand Down
28 changes: 26 additions & 2 deletions src/transactions/v1/blockchain_txn_rewards_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ get_reward_vars(Start, End, Ledger) ->
{ok, R4} -> R4;
_ -> 1
end,

WitnessRedundancy = case blockchain:config(?witness_redundancy, Ledger) of
{ok, WR} -> WR;
_ -> 1
end,

EpochReward = calculate_epoch_reward(Start, End, Ledger),
#{
monthly_reward => MonthlyReward,
Expand All @@ -300,6 +306,7 @@ get_reward_vars(Start, End, Ledger) ->
poc_challengees_percent => PocChallengeesPercent,
poc_challengers_percent => PocChallengersPercent,
poc_witnesses_percent => PocWitnessesPercent,
witness_redundancy => WitnessRedundancy,
consensus_percent => ConsensusPercent,
consensus_members => ConsensusMembers,
dc_percent => DCPercent,
Expand Down Expand Up @@ -578,7 +585,7 @@ poc_challengees_rewards_(Version, [Elem|Path], StaticPath, Txn, Chain, Ledger, _
Ledger :: blockchain_ledger_v1:ledger(),
WitnessRewards :: map()) -> #{{gateway, libp2p_crypto:pubkey_bin()} => non_neg_integer()}.
poc_witnesses_rewards(Transactions,
#{poc_version := POCVersion},
#{poc_version := POCVersion, witness_redundancy := WitnessRedundancy},
Chain,
Ledger,
WitnessRewards) ->
Expand All @@ -604,11 +611,28 @@ poc_witnesses_rewards(Transactions,
[] ->
Acc1;
ValidWitnesses ->
ToAdd = case WitnessRedundancy of
1 ->
%% continue with the old thing
1;
N ->
L = length(ValidWitnesses),
case L =< N of
true ->
%% Consider ideal redundant coverage when number of valid_witnesses is less than
%% or equal to configured witness_redundancy
1;
false ->
%% Proportional reward_unit as there are more valid_witnesses than necessary
blockchain_utils:normalize_float(N/L)
end
end,

lists:foldl(
fun(WitnessRecord, Map) ->
Witness = blockchain_poc_witness_v1:gateway(WitnessRecord),
I = maps:get(Witness, Map, 0),
maps:put(Witness, I+1, Map)
maps:put(Witness, I+ToAdd, Map)
end,
Acc1,
ValidWitnesses
Expand Down
2 changes: 2 additions & 0 deletions src/transactions/v1/blockchain_txn_vars_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ validate_var(?poc_challengers_percent, Value) ->
validate_float(Value, "poc_challengers_percent", 0.0, 1.0);
validate_var(?dc_percent, Value) ->
validate_float(Value, "dc_percent", 0.0, 1.0);
validate_var(?witness_redundancy, Value) ->
validate_int(Value, "witness_redundancy", 2, 100, false);
validate_var(?reward_version, Value) ->
case Value of
N when is_integer(N), N >= 1, N =< 5 ->
Expand Down

0 comments on commit 079d3e6

Please sign in to comment.