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

Add support for rewards-v3 #1423

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,5 @@
-define(allowed_num_reward_server_keys, allowed_num_reward_server_keys).
%% limit per-block payout of l2 tokens
-define(subnetwork_reward_per_block_limit, subnetwork_reward_per_block_limit).
%% Single treasury key to fund the remaining rewards (1 - securities_percent - consensus_percent)
-define(treasury_pubkey_bin, treasury_pubkey_bin).
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{erlang_stats, ".*", {git, "https://github.com/helium/erlang-stats.git", {branch, "master"}}},
{e2qc, ".*", {git, "https://github.com/helium/e2qc", {branch, "master"}}},
{vincenty, ".*", {git, "https://github.com/helium/vincenty", {branch, "master"}}},
{helium_proto, {git, "https://github.com/helium/proto.git", {branch, "master"}}},
{helium_proto, {git, "https://github.com/helium/proto.git", {branch, "rg/rewards-v3"}}},
{lorawan, {git, "https://github.com/helium/erlang-lorawan.git", {branch, "master"}}},
{merkerl, ".*", {git, "https://github.com/helium/merkerl.git", {branch, "master"}}},
{xxhash, {git, "https://github.com/pierreis/erlang-xxhash", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.18.1">>},0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"3de41dd9ebe9a67b170d08ab70eecea201e6aa92"}},
{ref,"daa0afb1a4e791d5f61753fea468f895e1eecb83"}},
0},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2},
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},1},
Expand Down
11 changes: 8 additions & 3 deletions src/transactions/blockchain_txn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
{blockchain_txn_add_subnetwork_v1, 38},
{blockchain_txn_update_subnetwork_v1, 39},
{blockchain_txn_subnetwork_rewards_v1, 40},
{blockchain_txn_token_redeem_v1, 41}
{blockchain_txn_token_redeem_v1, 41},
{blockchain_txn_rewards_v3, 42}
]).

block_delay() ->
Expand Down Expand Up @@ -266,7 +267,9 @@ wrap_txn(#blockchain_txn_update_subnetwork_v1_pb{}=Txn) ->
wrap_txn(#blockchain_txn_subnetwork_rewards_v1_pb{}=Txn) ->
#blockchain_txn_pb{txn={subnetwork_rewards, Txn}};
wrap_txn(#blockchain_txn_token_redeem_v1_pb{}=Txn) ->
#blockchain_txn_pb{txn={token_redeem, Txn}}.
#blockchain_txn_pb{txn={token_redeem, Txn}};
wrap_txn(#blockchain_txn_rewards_v3_pb{}=Txn) ->
#blockchain_txn_pb{txn={rewards_v3, Txn}}.

-spec unwrap_txn(#blockchain_txn_pb{}) -> blockchain_txn:txn().
unwrap_txn(#blockchain_txn_pb{txn={bundle, #blockchain_txn_bundle_v1_pb{transactions=Txns} = Bundle}}) ->
Expand Down Expand Up @@ -733,7 +736,9 @@ type(#blockchain_txn_update_subnetwork_v1_pb{}) ->
type(#blockchain_txn_subnetwork_rewards_v1_pb{}) ->
blockchain_txn_subnetwork_rewards_v1;
type(#blockchain_txn_token_redeem_v1_pb{}) ->
blockchain_txn_token_redeem_v1.
blockchain_txn_token_redeem_v1;
type(#blockchain_txn_rewards_v3_pb{}) ->
blockchain_txn_rewards_v3.

-spec validate_fields([{{atom(), iodata() | undefined},
{binary, pos_integer()} |
Expand Down
9 changes: 8 additions & 1 deletion src/transactions/v1/blockchain_txn_vars_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ validate_var(?poc_reward_decay_rate, Value) ->
validate_float(Value, "poc_reward_decay_rate", 0.0, 1.0);
validate_var(?reward_version, Value) ->
case Value of
N when is_integer(N), N >= 1, N =< 6 ->
N when is_integer(N), N >= 1, N =< 7 ->
ok;
_ ->
throw({error, {invalid_reward_version, Value}})
Expand Down Expand Up @@ -1263,6 +1263,13 @@ validate_var(?allowed_num_reward_server_keys, Value) ->
validate_var(?subnetwork_reward_per_block_limit, Value) ->
validate_int(Value, "subnetwork_reward_per_block_limit", 0, 10000000000000, false);

validate_var(?treasury_pubkey_bin, Value) ->
RoundTripValue = libp2p_crypto:b58_to_bin(libp2p_crypto:bin_to_b58(Value)),
case is_binary(Value) andalso RoundTripValue == Value of
true -> ok;
false -> throw({error, {invalid_treasury_pubkey_bin, Value}})
end;

%% general txn vars

validate_var(?txn_field_validation_version, Value) ->
Expand Down
Loading