diff --git a/database/bfgd/scripts/0009.sql b/database/bfgd/scripts/0009.sql index e083ffddc..f63dbfdd0 100644 --- a/database/bfgd/scripts/0009.sql +++ b/database/bfgd/scripts/0009.sql @@ -31,7 +31,6 @@ CREATE MATERIALIZED VIEW btc_blocks_can AS WITH RECURSIVE bb AS ( WHERE -- find the parent block via header -> parent hash ( substr(bb.header, 5, 32) = btc_blocks.hash - AND bb.height > btc_blocks.height ) ), __highest AS ( diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml index 5a8b8a9b7..e55f9b00a 100644 --- a/e2e/docker-compose.yml +++ b/e2e/docker-compose.yml @@ -97,7 +97,7 @@ services: BFG_POSTGRES_URI: "postgres://postgres@bfgd-postgres:5432/bfg?sslmode=disable" BFG_BTC_START_HEIGHT: "1" BFG_EXBTC_ADDRESS: "electrumx:50001" - BFG_LOG_LEVEL: "INFO" + BFG_LOG_LEVEL: "TRACE" BFG_PUBLIC_ADDRESS: ":8383" BFG_PRIVATE_ADDRESS: ":8080" diff --git a/service/bfg/bfg.go b/service/bfg/bfg.go index b6194c67a..bd4fa6623 100644 --- a/service/bfg/bfg.go +++ b/service/bfg/bfg.go @@ -185,13 +185,24 @@ func (s *Server) invalidBlockChecker(ctx context.Context) { } log.Infof("received %d heights with no children, will re-check", len(heights)) + + // if all blocks have children, wait until next btc block to re-check + if len(heights) == 0 { + continue + } + + // otherwise, reprocess blocks with missing children and re-check + for _, height := range heights { log.Infof("reprocessing block at height %d", height) if err := s.processBitcoinBlock(ctx, height); err != nil { log.Errorf("error processing bitcoin block: %s", err) } } - s.queueCheckForInvalidBlocks() + + go func() { + s.queueCheckForInvalidBlocks() + }() } } }