blockchain_worker startup crash loop on non-following apps
Opened this issue · 0 comments
Summary
Some apps that use blockchain-core without intending to follow the chain (e.g. the Helium miner) will receive a crash notice in blockchain_worker
every 90 seconds after it attempts to start up. This is likely due to the code attempting to perform a delayed "cache pre-warm" on the local ledger, even if there is no local ledger being used.
Expected behavior
If an app has signaled to blockchain_worker
that it is not a chain follower (application:get_env(blockchain, autoload)
returns undefined
or false
), it should not attempt to pre-warm the ledger cache.
Logs
2022-12-13 17:50:21.327 1 [error] emulator@Undefined:Undefined:Undefined Error in process <0.1719.0> on node 'miner@127.0.0.1' with exit value:
{function_clause,[{blockchain,ledger,[undefined],[{file,"blockchain.erl"},{line,556}]},{blockchain_worker,'-init/1-fun-4-',0,[{file,"blockchain_worker.erl"},{line,437}]}]}
Likely source
The likely source of the issue is this section of the blockchain_worker
startup, which spawns a function that eventually attempts to instantiate a ledger, regardless of whether the app is following the chain:
blockchain-core/src/blockchain_worker.erl
Line 435 in f71f7ef
case application:get_env(blockchain, disable_prewarm, false) of
true -> ok;
false ->
spawn(fun() ->
timer:sleep(90000),
Ledger = blockchain:ledger(),
blockchain_region_v1:prewarm_cache(Ledger)
end)
end,