hemilabs / heminetwork

The hemi network core daemons.
MIT License
73 stars 49 forks source link

cache bitcoin height from process btc block #236

Closed ClaytonNorthey92 closed 3 months ago

ClaytonNorthey92 commented 3 months ago

Summary As of now, each time pop miner wants to mine they call bfgapi.BitcoinInfoRequest to get the height. Bitcoin height doesn't change that often (not enough to be reaching out to the client in every single request at least).

We have another goroutine that gets the height on a 5 second timer; piggy-back off of this to set a server-value of the btc height from the last success in this goroutine. This way, clients (i.e. pop miners) don't make a call to electrumx when getting bitcoin info.

Changes use the result of another go routine's btcClient.Height to set a cached height value.

this would be at most 5 seconds out-of-sync with electrumx