sync & async saving. Bleh
This commit is contained in:
parent
12cb8a0c29
commit
afc063fb97
@ -4,7 +4,7 @@ const config = {
|
|||||||
bcoin_http: 'localhost',
|
bcoin_http: 'localhost',
|
||||||
bcoin: {
|
bcoin: {
|
||||||
network: 'main',
|
network: 'main',
|
||||||
db: 'leveldb',
|
db: 'mem',
|
||||||
prefix: '.',
|
prefix: '.',
|
||||||
checkpoints: true,
|
checkpoints: true,
|
||||||
workers: false,
|
workers: false,
|
||||||
|
|||||||
@ -23,7 +23,7 @@ module.exports = function transactionAPI(router) {
|
|||||||
const txid = req.params.txid || '';
|
const txid = req.params.txid || '';
|
||||||
|
|
||||||
db.txs.getTxById(txid, (err, transaction) => {
|
db.txs.getTxById(txid, (err, transaction) => {
|
||||||
if (err) {
|
if (err || !transaction) {
|
||||||
logger.log('error',
|
logger.log('error',
|
||||||
`/tx/:tid getTxById: ${err.err}`);
|
`/tx/:tid getTxById: ${err.err}`);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
|
|||||||
@ -11,9 +11,13 @@ mongoose.connection.on('error', (err) => {
|
|||||||
|
|
||||||
process.on('SIGINT', gracefulExit).on('SIGTERM', gracefulExit);
|
process.on('SIGINT', gracefulExit).on('SIGTERM', gracefulExit);
|
||||||
|
|
||||||
|
// Catastrophic Fails can still result in data loss
|
||||||
function gracefulExit() {
|
function gracefulExit() {
|
||||||
|
logger.log('debug',
|
||||||
|
'Graceful Shutdown Starting...');
|
||||||
mongoose.connection.close(() => {
|
mongoose.connection.close(() => {
|
||||||
console.log('Mongoose connection with DB disconnected through app termination');
|
logger.log('debug',
|
||||||
|
'Mongoose connection with DB disconnected through app termination');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function auditInputs() {
|
|||||||
getEmptyInputs(
|
getEmptyInputs(
|
||||||
(err, txs) => {
|
(err, txs) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return logger.log('error',
|
return logger.log('warn',
|
||||||
`No Empty Inputs found: ${err.err}`);
|
`No Empty Inputs found: ${err.err}`);
|
||||||
}
|
}
|
||||||
// For each tx with unmarked inputs
|
// For each tx with unmarked inputs
|
||||||
@ -56,7 +56,8 @@ function auditInputs() {
|
|||||||
|
|
||||||
return getTxById(txHash, (error, tx) => {
|
return getTxById(txHash, (error, tx) => {
|
||||||
if (error || !tx) {
|
if (error || !tx) {
|
||||||
return logger.log('error',
|
// Mongo save is async. Bcoin is kinda sync... Does not mean the tx will not be found
|
||||||
|
return logger.log('warn',
|
||||||
`No Tx found: ${txHash} ${error}`);
|
`No Tx found: ${txHash} ${error}`);
|
||||||
}
|
}
|
||||||
return updateInput(inputTx._id, input._id, tx.outputs[outIdx].value, tx.outputs[outIdx].address);
|
return updateInput(inputTx._id, input._id, tx.outputs[outIdx].value, tx.outputs[outIdx].address);
|
||||||
|
|||||||
@ -6,9 +6,10 @@ const config = require('../../config');
|
|||||||
const socket = require('../../lib/api/socket');
|
const socket = require('../../lib/api/socket');
|
||||||
const db = require('../../lib/db');
|
const db = require('../../lib/db');
|
||||||
|
|
||||||
const node = new FullNode(config.bcoin);
|
const node = new FullNode(config.bcoin);
|
||||||
let doneSyncing = false;
|
let doneSyncing = false;
|
||||||
|
|
||||||
|
|
||||||
function start(bestBlockHeight) {
|
function start(bestBlockHeight) {
|
||||||
node.open()
|
node.open()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -20,13 +21,16 @@ function start(bestBlockHeight) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.chain.on('connect', (entry, block) => {
|
node.chain.on('connect', (entry, block) => {
|
||||||
|
// Saved block acts like a journal
|
||||||
BlockParser.parse(entry, block);
|
BlockParser.parse(entry, block);
|
||||||
TxParser.parse(entry, block.txs);
|
TxParser.parse(entry, block.txs);
|
||||||
socket.processBlock(entry, block);
|
socket.processBlock(entry, block);
|
||||||
db.blocks.bestHeight(entry.height);
|
db.blocks.bestHeight(entry.height);
|
||||||
if (entry.height % 20 === 0 || doneSyncing) {
|
|
||||||
db.txs.auditInputs();
|
node.chain.db.getBlockView(block)
|
||||||
}
|
.then((view) => {
|
||||||
|
console.log(view);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
node.chain.on('full', () => {
|
node.chain.on('full', () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user