Skip to content

Commit 53be90e

Browse files
better error handling + sql update (#376)
* better error handling + sql update * do not stop parsing a btc block if encountering a parse error, we may have a parse error partially down the block but we shouldn't halt parsing the rest of the txs for that * sql update; delete invalid pop basis upon re-org * revert
1 parent 5d1bf8f commit 53be90e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

database/bfgd/postgres/postgres.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
const (
23-
bfgdVersion = 15
23+
bfgdVersion = 16
2424

2525
logLevel = "INFO"
2626
verbose = false

database/bfgd/scripts/0016.sql

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Copyright (c) 2025 Hemi Labs, Inc.
2+
-- Use of this source code is governed by the MIT License,
3+
-- which can be found in the LICENSE file.
4+
5+
BEGIN;
6+
7+
UPDATE version SET version = 16;
8+
9+
ALTER TABLE pop_basis DROP CONSTRAINT pop_basis_btc_block_hash_fkey;
10+
11+
-- upon a re-org, set all references to deleted btc block to NULL, then delete those rows via a trigger
12+
13+
ALTER TABLE pop_basis ADD CONSTRAINT pop_basis_btc_block_hash_fkey FOREIGN KEY (btc_block_hash) REFERENCES btc_blocks (hash) ON UPDATE SET NULL;
14+
15+
CREATE FUNCTION clean_pop_basis() RETURNS TRIGGER AS $clean_pop_basis$
16+
BEGIN
17+
DELETE FROM pop_basis WHERE btc_block_hash IS NULL;
18+
RETURN NULL;
19+
END;
20+
$clean_pop_basis$ LANGUAGE plpgsql;
21+
22+
CREATE TRIGGER btc_blocks_clean AFTER INSERT OR UPDATE OR DELETE
23+
ON btc_blocks EXECUTE FUNCTION clean_pop_basis();
24+
25+
COMMIT;

service/bfg/bfg.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ func (s *Server) processBitcoinBlock(ctx context.Context, height uint64) error {
678678

679679
publicKeyUncompressed, err := pop.ParsePublicKeyFromSignatureScript(mtx.TxIn[0].SignatureScript)
680680
if err != nil {
681-
return fmt.Errorf("could not parse signature script: %w", err)
681+
log.Errorf("could not parse signature script: %w", err)
682+
continue
682683
}
683684

684685
popTxIdFull := []byte{}

0 commit comments

Comments
 (0)