dcrdex icon indicating copy to clipboard operation
dcrdex copied to clipboard

markets should self-suspend when a chain is out of sync

Open buck54321 opened this issue 1 year ago • 7 comments

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
}

buck54321 avatar Sep 08 '23 17:09 buck54321

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?

peterzen avatar Sep 18 '23 00:09 peterzen

Could use the timestamp of the latest block. Would be dumb but good enough in my opinion. Would vary between chains.

JoeGruffins avatar Sep 22 '23 05:09 JoeGruffins

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

peterzen avatar Oct 10 '23 23:10 peterzen

I honestly don't understand the need for anything beyond the first line.

if timeSinceLastBlock > hardMaxBlockInterval
  suspendMarket

buck54321 avatar Oct 11 '23 03:10 buck54321

What's the hardMaxBlockInterval value for DCR and BTC?

peterzen avatar Oct 11 '23 07:10 peterzen

What's the hardMaxBlockInterval value for DCR and BTC?

Maybe an hour?

buck54321 avatar Oct 11 '23 15:10 buck54321

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.

buck54321 avatar Nov 07 '23 21:11 buck54321