dcrdex
dcrdex copied to clipboard
markets should self-suspend when a chain is out of sync
Chains sync is currently monitored only at market startup as a check before epoch processing begins. If a chain goes out of sync later though, the market will still match orders.
Also, the (Backend).Synced
implementations would not detect an out-of-sync chain.
btc implementation
func (btc *Backend) Synced() (bool, error) {
chainInfo, err := btc.node.GetBlockChainInfo()
if err != nil {
return false, fmt.Errorf("GetBlockChainInfo error: %w", err)
}
return !chainInfo.InitialBlockDownload && chainInfo.Headers-chainInfo.Blocks <= 1, nil
}
What would be a reliable way to detect out-of-sync chains? Is there a better method than calling a well-known chain explorer service to obtain the chain tip?
Could use the timestamp of the latest block. Would be dumb but good enough in my opinion. Would vary between chains.
Would this logic be safe and robust enough?
In the asset config there would be 3 values, e.g. softMaxBlockInterval
, tolerance
, hardMaxBlockInterval
if timeSinceLastBlock > hardMaxBlockInterval
suspendMarket
else if timeSinceLastBlock > softMaxBlockInterval
++counter
resetTimer
if counter > tolerance
suspendMarket
if lastBlockInterval <= softMaxBlockInterval
counter = 0
if counter == tolerance
suspendMarket
I honestly don't understand the need for anything beyond the first line.
if timeSinceLastBlock > hardMaxBlockInterval
suspendMarket
What's the hardMaxBlockInterval
value for DCR and BTC?
What's the
hardMaxBlockInterval
value for DCR and BTC?
Maybe an hour?
https://github.com/buck54321/dcrdex/compare/97741ba...buck54321:dcrdex:improved-chains-synced is a template for this work. Just needs a once over and some testing. Anyone should feel free to pick it up.