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

validate file size and hash after downloading #1283

Open
wants to merge 75 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
68c7267
filter bad netids from sync targets
evanmcc Mar 18, 2022
c129cec
add as923_1b region
mikev May 18, 2022
7e075df
comment FAIL tests
mikev May 18, 2022
0dddfe6
comment FAIL tests
mikev May 18, 2022
0e0423d
Update hex value for as923_1b and add H3 comment
mikev May 19, 2022
d037059
Fix ledger context leaks in poc_receipts_v1 and rewards_v2
xandkar May 27, 2022
dbdedb8
all eunit tests running green
jeffgrunewald Jun 2, 2022
7ba1d43
fixing simple suite ct
jeffgrunewald Jun 2, 2022
5407343
validate size and hash after download
joecaswell Mar 16, 2022
78782fe
explicitly match validate result to ensure error is thrown
joecaswell Mar 16, 2022
0e4e07d
remove unnecessary match
joecaswell Apr 13, 2022
636f199
missing ;
joecaswell Apr 14, 2022
897bbde
try to streamline poc v6 targeting
evanmcc Jun 3, 2022
a71d8db
Merge branch 'master' of https://github.com/helium/blockchain-core in…
mikev Jun 4, 2022
2ff00a5
pull in follower proto
jeffgrunewald Jun 6, 2022
f29d257
Merge pull request #1382 from helium/jg/follower_service
madninja Jun 6, 2022
320c4ee
Un-export gateways_for_zone as it should not be used
Vagabond Jun 6, 2022
22324be
Pass through force_network_id Erlang env var
jadeallenx Jun 7, 2022
8637bd7
Merge pull request #1380 from helium/jg/make_build_green_again
madninja Jun 7, 2022
c21c536
Don't invalidate h3->region lookups on var nonce change
Vagabond Jun 7, 2022
4d97f37
Merge pull request #1384 from helium/jma/always-set-network-id
jadeallenx Jun 7, 2022
7e1e9b9
Merge pull request #1287 from helium/pevm/filter-network-id
jadeallenx Jun 7, 2022
152670e
Merge pull request #1385 from helium/adt/better-h3-lookup-caching
evanmcc Jun 7, 2022
3235533
Merge pull request #1381 from helium/pevm/select-from-actives
evanmcc Jun 8, 2022
850006b
use the proper binary convert function
evanmcc Jun 8, 2022
6d79b84
Merge pull request #1386 from helium/pevm/proper_convert
evanmcc Jun 8, 2022
05a8c51
fix response format
andymck Jun 8, 2022
15d729f
Merge pull request #1387 from helium/andymck/fix-targeting-response
madninja Jun 8, 2022
df9b1cf
resolve merge from master
mikev Jun 8, 2022
4933807
remove FIXME ifdef
mikev Jun 8, 2022
d1cbe7f
Merge pull request #1355 from helium/mv/as923_1b
vihu Jun 8, 2022
47d0240
upgrade libp2p for removal of old ledger handling code
jeffgrunewald Jun 9, 2022
0ca1ea8
Merge pull request #1390 from helium/jg/bump_libp2p
evanmcc Jun 9, 2022
097ca8c
Revert "Don't invalidate h3->region lookups on var nonce change"
evanmcc Jun 17, 2022
8e1f348
Fix unclosed rocks iterators
xandkar Jun 20, 2022
bf185b2
Don't warn on normal iterator error
xandkar Jun 20, 2022
5d9aeb2
Log any rocksdb:iterator_close errors
xandkar Jun 21, 2022
773b0de
automatically prewarm region cache on startup and var txn
evanmcc Jun 21, 2022
7bce1af
Handle no hexes on a new network
jadeallenx Jun 21, 2022
2d73abf
Merge pull request #1399 from helium/pevm/revert-var-cache
evanmcc Jun 21, 2022
79cc96d
Add cache cli
PaulVMo Jun 19, 2022
bcf4048
Merge pull request #1400 from helium/jma/poc-v5-crash-fix
jadeallenx Jun 22, 2022
3c53fd0
Ledger lookup happens in spawn
jadeallenx Jun 23, 2022
7edfbe1
Merge pull request #1402 from helium/jma/blockchain-ledger-undefined
madninja Jun 23, 2022
84deb8f
h3dex remove gateway bugfix
PaulVMo Jun 23, 2022
95cc9ac
Add function to convert B58 keypair to seed words
jadeallenx Jun 23, 2022
6834b37
sc handler optimisations
andymck Jun 20, 2022
ee9ae87
eliminate use of state chain and ledger
andymck Jun 20, 2022
1610f86
add read concurrency to cache table
andymck Jun 24, 2022
5a00a4b
Merge pull request #1396 from helium/andymck/optimise-core-sc-server-…
evanmcc Jun 24, 2022
a28ab79
Add support for new ledger entries
vihu May 17, 2022
add3323
Add support for multi token payments
vihu May 20, 2022
33db88d
Add support for ledger entry migration
vihu May 24, 2022
6185bbf
Add support for aux ledger
vihu Jun 9, 2022
10bb3d6
Add support for subnetwork transactions
vihu Jun 4, 2022
fbf06c7
Merge pull request #1354 from helium/rg/hip-xx-experiments
vihu Jun 24, 2022
a3fb4b7
dialyzer fix for different ledger fetch path
evanmcc Jun 24, 2022
1495a66
Merge pull request #1401 from PaulVMo/add-cache-cli
evanmcc Jun 24, 2022
a394008
Merge pull request #1404 from helium/jma/b58-key-decode
evanmcc Jun 24, 2022
e46ddc3
Merge pull request #1403 from PaulVMo/h3dex-remove-gateway-fix
evanmcc Jun 24, 2022
15d7ca6
remove stale comments
evanmcc Jun 24, 2022
3631a65
Merge pull request #1405 from helium/pevm/dialzzz
evanmcc Jun 24, 2022
e706b4e
handling txn fees in balance clearing
jeffgrunewald Jun 21, 2022
b9a56e8
Switch from error to warning log level on iterator close exceptions
xandkar Jun 27, 2022
0db34f8
upgrade libp2p
evanmcc Jun 27, 2022
5e16e12
Fix region cache prewarm and fix blockchain_payment_v2_SUITE tests
Vagabond Jun 27, 2022
82daeed
Add option to disable iterator_close exception logging
xandkar Jun 27, 2022
5b8ac4c
Merge pull request #1406 from helium/pevm/bump-p2p
Vagabond Jun 27, 2022
d68c15a
Merge pull request #1398 from helium/jg/fix_balance_clearing
Vagabond Jun 27, 2022
6617e4a
Merge pull request #1372 from helium/sk/fix-ledger-context-leaks
Vagabond Jun 27, 2022
2418468
Merge pull request #1397 from helium/sk/close-iterators
Vagabond Jun 27, 2022
14bff32
Move headers to include dir
vihu Jun 29, 2022
b318da9
Merge pull request #1408 from helium/rg/move-hrl-to-include
vihu Jun 29, 2022
e0f5e78
validate size and hash after download
joecaswell Mar 16, 2022
d1c72dc
rebase on master and squash commits
joecaswell Jun 30, 2022
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
1 change: 1 addition & 0 deletions eqc/stake_txns_eqc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ initial_state() ->
init_chain_env() ->
%% these should be idempotent
_ = application:ensure_all_started(lager),
_ = application:ensure_all_started(telemetry),
_ = blockchain_lock:start_link(),
application:set_env(blockchain, test_mode, true),

Expand Down
15 changes: 15 additions & 0 deletions include/blockchain_rocks.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-define(ROCKSDB_ITERATOR_CLOSE(IteratorHandle),
%% Wrapping in fun to avoid scope leakage:
(fun() ->
try
rocksdb:iterator_close(IteratorHandle)
catch ErrorClass:ErrorReason ->
case application:get_env(blockchain, log_rocksdb_iterator_close_errors, true) of
true ->
lager:warning("rocksdb:iterator_close error: ~p:~p", [ErrorClass, ErrorReason]);
false ->
ok
end
end
end)()
).
File renamed without changes.
17 changes: 16 additions & 1 deletion include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
%% max number of hexes to GC in the h3dex per block: integer
-define(h3dex_gc_width, h3dex_gc_width).

%% determines whether or not to use the fix for a bug in removing gateways from h3dex : boolean
-define(h3dex_remove_gw_fix, h3dex_remove_gw_fix).

%% the version number of poc targeting in use: integer
%% if not set, code paths with default to 3 ( blockchain_poc_target_v3 )
-define(poc_targeting_version, poc_targeting_version).
Expand Down Expand Up @@ -581,7 +584,7 @@
%% regulatory_region related variables

%% This is a comma separated string like so:
%% <<"region_as923_1,region_as923_2,region_as923_3,region_as923_4,region_au915,region_cn470,region_eu433,region_eu868,region_in865,region_kr920,region_ru864,region_us915">>
%% <<"region_as923_1,region_as923_1b,region_as923_2,region_as923_3,region_as923_4,region_au915,region_cn470,region_eu433,region_eu868,region_in865,region_kr920,region_ru864,region_us915">>
-define(regulatory_regions, regulatory_regions).

%% Each of the former regions is associated with a dynamic var of the same name which is is a serialized form of an h3_region set determined at h3_res: 7
Expand Down Expand Up @@ -614,3 +617,15 @@

%% Block size limit variable (in bytes). Set to 25 * 1024 * 1024.
-define(block_size_limit, block_size_limit).

%% ------------------------------------------------------------------
%% Token version (aka support multiple tokens). Set to 2 (pos_integer).
-define(token_version, token_version).
%% Ledger entry migration variable
%% Will be used to hook and switch the old style ledger entries
%% to new style ledger entries. Set to 2 (pos_integer).
-define(ledger_entry_version, ledger_entry_version).
%% Var to switch off legacy security_exchange txn. Boolean.
-define(deprecate_security_exchange_v1, deprecate_security_exchange_v1).
%% How many reward server keys to allow
-define(allowed_num_reward_server_keys, allowed_num_reward_server_keys).
4 changes: 2 additions & 2 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.18.0">>},0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"425610c233af0dd9688c1695668d208174695562"}},
{ref,"d1694d5ddb3801f70461921a33407b04d9df66f3"}},
0},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2},
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},1},
Expand All @@ -92,7 +92,7 @@
{<<"lager">>,{pkg,<<"lager">>,<<"3.9.2">>},0},
{<<"libp2p">>,
{git,"https://github.com/helium/erlang-libp2p.git",
{ref,"95fd37f967e6d83b9fd7796ef7d060abff47a018"}},
{ref,"070fea4a05e8a9d7e5cd0af1c9c4c4f7a507aaa7"}},
0},
{<<"libp2p_crypto">>,
{git,"https://github.com/helium/libp2p-crypto.git",
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/ledger
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/peer
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/repair
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/trace
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
5 changes: 4 additions & 1 deletion scripts/extensions/txn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ if [ -t 0 ] ; then
export CLIQUE_COLUMNS
fi

export RELX_RPC_TIMEOUT=${RELX_RPC_TIMEOUT:-900}
# extend relx default timeout (60s) if it has not already been overwritten
if [ $RELX_RPC_TIMEOUT -eq 60 ] ; then
export RELX_RPC_TIMEOUT=900
fi

j=1
l=$#
Expand Down
4 changes: 2 additions & 2 deletions src/blockchain.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
h3,
erl_angry_purple_tiger,
erlang_stats,
telemetry,
e2qc,
vincenty,
helium_proto,
Expand All @@ -29,8 +30,7 @@
jsx,
erbloom,
grpc_client,
hackney,
telemetry
hackney
]},
{env,[]},
{modules, []},
Expand Down
38 changes: 27 additions & 11 deletions src/blockchain.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
]).

-include("blockchain.hrl").
-include("blockchain_rocks.hrl").
-include("blockchain_vars.hrl").

-ifdef(TEST).
Expand Down Expand Up @@ -892,12 +893,18 @@ find_first_height_after(MinHeight0, #blockchain{db=DB, heights=HeightsCF}) ->
MinHeight = max(0, MinHeight0),
{ok, Iter} = rocksdb:iterator(DB, HeightsCF, []),
rocksdb:iterator_move(Iter, {seek, <<(MinHeight):64/integer-unsigned-big>>}),
case rocksdb:iterator_move(Iter, next) of
{ok, <<Height:64/integer-unsigned-big>>, Hash} ->
{ok, Height, Hash};
{error, _} ->
{error, not_found}
end.
Result =
case rocksdb:iterator_move(Iter, next) of
{ok, <<Height:64/integer-unsigned-big>>, Hash} ->
{ok, Height, Hash};
{error, invalid_iterator} ->
{error, not_found};
{error, Reason} ->
lager:error("Unexpected iterator error: ~p", [Reason]),
{error, not_found}
end,
?ROCKSDB_ITERATOR_CLOSE(Iter),
Result.

find_first_block_after(MinHeight, Blockchain) ->
case find_first_height_after(MinHeight, Blockchain) of
Expand Down Expand Up @@ -2082,10 +2089,17 @@ rocksdb_gc(BytesToDrop, #blockchain{db=DB, heights=HeightsCF}=Blockchain) ->
CutoffHeight = max(2, Height - application:get_env(blockchain, blocks_to_protect_from_gc, 10000)),
%% start at 2 here so we don't GC the genesis block
{ok, Itr} = rocksdb:iterator(DB, HeightsCF, [{iterate_lower_bound, <<2:64/integer-unsigned-big>>}, {iterate_upper_bound, <<CutoffHeight:64/integer-unsigned-big>>}]),
do_rocksdb_gc(BytesToDrop, Itr, Blockchain, rocksdb:iterator_move(Itr, first)).
ok = do_rocksdb_gc(BytesToDrop, Itr, Blockchain, rocksdb:iterator_move(Itr, first)),
?ROCKSDB_ITERATOR_CLOSE(Itr),
ok.

do_rocksdb_gc(_Bytes, _Itr, _Blockchain, {error, _}) ->
ok;
do_rocksdb_gc(_, _, _, {error, Reason}) ->
case Reason of
invalid_iterator ->
ok;
_ ->
lager:error("Unexpected iterator error: ~p", [Reason])
end;
do_rocksdb_gc(Bytes, _Itr, _Blockchain, _Res) when Bytes < 1 ->
ok;
do_rocksdb_gc(Bytes, Itr, #blockchain{dir=Dir, db=DB, heights=HeightsCF, blocks=BlocksCF, snapshots=SnapshotsCF}=Blockchain, {ok, <<IntHeight:64/integer-unsigned-big>>=Height, Hash}) ->
Expand Down Expand Up @@ -3010,7 +3024,7 @@ check_plausible_blocks(#blockchain{db=DB}=Chain, GossipedHash) ->
get_plausible_blocks(#blockchain{db=DB, plausible_blocks=CF}) ->
{ok, Itr} = rocksdb:iterator(DB, CF, []),
Res = get_plausible_blocks(Itr, rocksdb:iterator_move(Itr, first), []),
catch rocksdb:iterator_close(Itr),
?ROCKSDB_ITERATOR_CLOSE(Itr),
Res.

get_plausible_blocks(_Itr, {error, _}, Acc) ->
Expand Down Expand Up @@ -3292,6 +3306,7 @@ get_block_test_() ->
end
}.

-ifdef(FIXME).
block_info_upgrade_test() ->
%% boilerplate to get a chain
#{secret := Priv, public := Pub} = libp2p_crypto:generate_keys(ecc_compact),
Expand Down Expand Up @@ -3324,11 +3339,12 @@ block_info_upgrade_test() ->
ExpV2BlockInfo = #block_info_v2{height = 1,
time = 1,
hash = <<"blockhash">>,
pocs = [],
pocs = #{},
hbbft_round = 1,
election_info = {1, 0},
penalties = {<<>>, []}},
V2BlockInfo = upgrade_block_info(V1BlockInfo, Block, Chain),
?assertMatch(ExpV2BlockInfo, V2BlockInfo).
-endif.

-endif.
5 changes: 4 additions & 1 deletion src/blockchain_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ start_link(Args) ->
init(Args) ->
application:ensure_all_started(ranch),
application:ensure_all_started(lager),
application:ensure_all_started(telemetry),
application:ensure_all_started(clique),
application:ensure_all_started(throttle),
%% start http client and ssl here
Expand Down Expand Up @@ -94,6 +95,7 @@ init(Args) ->
[{signed_metadata_fun, MetadataFun},
{notify_peer_gossip_limit, application:get_env(blockchain, gossip_width, 100)},
{notify_time, application:get_env(blockchain, peerbook_update_interval, timer:minutes(5))},
{force_network_id, application:get_env(blockchain, force_network_id, undefined)},
{allow_rfc1918, application:get_env(blockchain, peerbook_allow_rfc1918, false)}
]},
{libp2p_group_gossip,
Expand All @@ -112,7 +114,8 @@ init(Args) ->
BWorkerOpts = [
{port, proplists:get_value(port, Args, 0)},
{base_dir, BaseDir},
{update_dir, proplists:get_value(update_dir, Args, undefined)}
{update_dir, proplists:get_value(update_dir, Args, undefined)},
{ets_cache, blockchain_worker:make_ets_table()}
],

BEventOpts = [],
Expand Down
16 changes: 16 additions & 0 deletions src/blockchain_token_v1.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%%%-------------------------------------------------------------------
%% @doc
%% == Blockchain Token V1 ==
%% @end
%%%-------------------------------------------------------------------
-module(blockchain_token_v1).

-type type() :: hnt | hst | mobile | iot.
-type types() :: [type()].

-export_type([type/0, types/0]).
-export([supported_tokens/0]).

-spec supported_tokens() -> types().
supported_tokens() ->
[hnt, hst, mobile, iot].
Loading