blockchain-core
blockchain-core copied to clipboard
blockchain_worker startup crash loop on non-following apps
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 '[email protected]' 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:
https://github.com/helium/blockchain-core/blob/f71f7efc391633913287f685408ae1e9f8709adf/src/blockchain_worker.erl#L435
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,