This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from ArweaveTeam/v0.4.0
v0.4.0
- Loading branch information
Showing
15 changed files
with
268 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ cache | |
snapshot | ||
.snapshot | ||
.import | ||
*.temp | ||
|
||
**/*.log | ||
**/.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Rescan Guide | ||
|
||
While syncing, sometimes transactions may not be returned by Arweave Nodes. You can recover these transactions by running a rescan. | ||
If you received an error while retrieving a transaction while running a node. You can recover it by running. | ||
|
||
```bash | ||
yarn rescan:cache | ||
``` | ||
|
||
## Rescanning Snapshots | ||
|
||
If you are recovering from an imported snapshot. It should list missing transactions in the Snapshot under `snapshot/.rescan`. | ||
|
||
You can recover snapshot transactions by running. | ||
|
||
```bash | ||
yarn rescan:snapshot | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@arweave/gateway", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"main": "dist/src/Gateway.js", | ||
"repository": "[email protected]:ArweaveTeam/gateway.git", | ||
"author": "Arweave <[email protected]>", | ||
|
@@ -13,6 +13,9 @@ | |
"dev:restart": "npm run migrate:down && npm run migrate:latest && npm run dev:start", | ||
"dev:snapshot": "npm run dev:build && node dist/src/Snapshot.js", | ||
"dev:import": "npm run dev:build && node dist/src/Import.js", | ||
"rescan:cache": "npm run dev:build && node dist/src/Rescan.cache.js", | ||
"rescan:snapshot": "npm run dev:build && node dist/src/Rescan.snapshot.js", | ||
"rescan:temp": "npm run dev:build && node dist/src/Rescan.temp.js", | ||
"migrate:down": "knex migrate:down", | ||
"migrate:up": "knex migrate:up", | ||
"migrate:latest": "knex migrate:latest", | ||
|
@@ -29,6 +32,7 @@ | |
"body-parser": "^1.19.0", | ||
"colors": "^1.4.0", | ||
"dotenv": "^8.2.0", | ||
"event-stream": "^4.0.1", | ||
"express": "^4.17.1", | ||
"graphql": "^15.5.0", | ||
"graphql-fields": "^2.0.3", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {startRescan} from './database/rescan.database'; | ||
|
||
(async () => await startRescan('cache/.rescan'))(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {startRescan} from './database/rescan.database'; | ||
|
||
(async () => await startRescan('snapshot/.rescan'))(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {startRescan} from './database/rescan.database'; | ||
|
||
(async () => await startRescan('.rescan.temp'))(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import ProgressBar from 'progress'; | ||
import {existsSync, createReadStream, createWriteStream, readFileSync, writeFileSync, unlinkSync} from 'fs'; | ||
import {split, mapSync} from 'event-stream'; | ||
import {config} from 'dotenv'; | ||
import {log} from '../utility/log.utility'; | ||
import {mkdir} from '../utility/file.utility'; | ||
import {importTransactions, importTags} from '../database/import.database'; | ||
import {storeTransaction, processAns, streams} from '../database/sync.database'; | ||
|
||
config(); | ||
mkdir('snapshot'); | ||
mkdir('cache'); | ||
|
||
export interface TxStream { | ||
tx: string; | ||
height: string; | ||
type: string; | ||
} | ||
|
||
export const rescan = createWriteStream('.rescan.temp'); | ||
export let bar: ProgressBar; | ||
|
||
export async function startRescan(path: string = 'cache/.rescan') { | ||
log.info('[rescan] starting rescan'); | ||
|
||
if (existsSync(path)) { | ||
log.info('[rescan] found existing rescan file. Indexing missing transactions.'); | ||
await streamTransactions(path); | ||
} | ||
} | ||
|
||
export async function streamTransactions(path: string) { | ||
const txs: Array<TxStream> = []; | ||
|
||
createReadStream(path) | ||
.pipe(split()) | ||
.pipe(mapSync((line: string) => { | ||
const [tx, height, type] = line.split(','); | ||
txs.push({tx, height, type}); | ||
})) | ||
.on('end', async () => { | ||
txs.pop(); | ||
|
||
for (let i = 0; i < txs.length; i++) { | ||
const {tx, height, type} = txs[i]; | ||
await restoreTransaction(tx, height, type); | ||
} | ||
|
||
const rescan = readFileSync('.rescan.temp'); | ||
writeFileSync(path, rescan); | ||
unlinkSync('.resync.temp'); | ||
|
||
log.info('[rescan] complete, unindexed transaction stored in .rescan'); | ||
|
||
process.exit(); | ||
}); | ||
} | ||
|
||
export async function restoreTransaction(tx: string, height: string, type: string) { | ||
try { | ||
if (type === 'normal') { | ||
await storeTransaction(tx, Number(height)); | ||
} | ||
|
||
if (type === 'ans') { | ||
await processAns(tx, Number(height)); | ||
} | ||
|
||
await importTransactions(`${process.cwd()}/cache/transaction.csv`); | ||
await importTags(`${process.cwd()}/cache/tags.csv`); | ||
|
||
streams.transaction.cache = createWriteStream('cache/transaction.csv'); | ||
streams.tags.cache = createWriteStream('cache/tags.csv'); | ||
|
||
log.info(`[rescan] successfully added missing tx ${tx} at height ${height}`); | ||
} catch (error) { | ||
log.info(`[rescan] failed ${tx} at ${height}, added to the .rescan.temp file. It was not added to the database`); | ||
rescan.write(`${tx},${height}\n`); | ||
} | ||
} |
Oops, something went wrong.