diff --git a/README.md b/README.md index 3cf5076..1ebd7e6 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/index.js b/src/index.js index d176aae..996459b 100644 --- a/src/index.js +++ b/src/index.js @@ -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`; @@ -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 {