Skip to content

Commit

Permalink
added 'REINDEX_IF_REORG' environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdoman committed Nov 21, 2024
1 parent 7fa2043 commit c529f9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project uses the following environment variables:
| ----------------------------- | ------------------------------------| -----------------------------------------------|
|PORT | Specifies the port number on which the server listens for incoming HTTP requests | 3000   |
|START_HEIGHT | Specifies the block height at which indexing begins | 870525   |
|REINDEX_IF_REORG | Specifies the number of blocks to reindex when a reorg is detected | 6 |
|BITCOIN_NODE | Specifies the URL of the attached Bitcoin node | http://localhost:8332 |
|DATA_DIR | Specifies the directory where the indexed data will be persisted | ./data |

Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dotenv/config';

const PORT = process.env.PORT || 3000;
const START_HEIGHT = process.env.START_HEIGHT || 870525;
const REINDEX_IF_REORG = process.env.REINDEX_IF_REORG || 6;
const BITCOIN_NODE = process.env.BITCOIN_NODE || 'http://localhost:8332';
const DATA_PATH = process.env.DATA_DIR || './data';
const BASE_URL = `${BITCOIN_NODE}/rest`;
Expand Down Expand Up @@ -107,7 +108,7 @@ async function fetchBlocks() {
console.log(`Indexed block ${blockHash} at height:`, nextHeight);

if (db.data.lastBlockHash && previousBlockhash !== db.data.lastBlockHash) {
db.data.lastHeight -= 6;
db.data.lastHeight -= REINDEX_IF_REORG;
db.data.lastBlockHash = '';
console.log("Reorg detected, re-indexing last 6 blocks...");
} else {
Expand Down

0 comments on commit c529f9b

Please sign in to comment.