diff --git a/src/core/round.js b/src/core/round.js index e279dbb..152db6f 100644 --- a/src/core/round.js +++ b/src/core/round.js @@ -84,21 +84,30 @@ Round.prototype.flush = function (round, cb) { } Round.prototype.directionSwap = function (direction, lastBlock, cb) { - if (direction == 'backward') { - private.feesByRound = {}; - private.rewardsByRound = {}; - private.delegatesByRound = {}; - self.flush(self.calc(lastBlock.height), cb); - } else { - private.unFeesByRound = {}; - private.unRewardsByRound = {}; - private.unDelegatesByRound = {}; - self.flush(self.calc(lastBlock.height), cb); - } + cb() + // if (direction == 'backward') { + // private.feesByRound = {}; + // private.rewardsByRound = {}; + // private.delegatesByRound = {}; + // self.flush(self.calc(lastBlock.height), cb); + // } else { + // private.unFeesByRound = {}; + // private.unRewardsByRound = {}; + // private.unDelegatesByRound = {}; + // self.flush(self.calc(lastBlock.height), cb); + // } } Round.prototype.backwardTick = function (block, previousBlock, cb) { function done(err) { + if (err) { + library.logger.error("Round backward tick failed: " + err); + } else { + library.logger.debug("Round backward tick completed", { + block: block, + previousBlock: previousBlock + }); + } cb && cb(err); } @@ -116,14 +125,23 @@ Round.prototype.backwardTick = function (block, previousBlock, cb) { var prevRound = self.calc(previousBlock.height); - private.unFeesByRound[round] = (private.unFeesByRound[round] || 0); - private.unFeesByRound[round] += block.totalFee; + // private.unFeesByRound[round] = (private.unFeesByRound[round] || 0); + // private.unFeesByRound[round] += block.totalFee; - private.unRewardsByRound[round] = (private.unRewardsByRound[round] || []); - private.unRewardsByRound[round].push(block.reward); + // private.unRewardsByRound[round] = (private.unRewardsByRound[round] || []); + // private.unRewardsByRound[round].push(block.reward); - private.unDelegatesByRound[round] = private.unDelegatesByRound[round] || []; - private.unDelegatesByRound[round].push(block.generatorPublicKey); + // private.unDelegatesByRound[round] = private.unDelegatesByRound[round] || []; + // private.unDelegatesByRound[round].push(block.generatorPublicKey); + + private.feesByRound[round] = (private.feesByRound[round] || 0); + private.feesByRound[round] -= block.totalFee; + + private.rewardsByRound[round] = (private.rewardsByRound[round] || []); + private.rewardsByRound[round].pop() + + private.delegatesByRound[round] = private.delegatesByRound[round] || []; + private.delegatesByRound[round].pop() if (prevRound === round && previousBlock.height !== 1) { return done(); @@ -132,6 +150,14 @@ Round.prototype.backwardTick = function (block, previousBlock, cb) { if (private.unDelegatesByRound[round].length !== slots.delegates && previousBlock.height !== 1) { return done(); } + library.logger.warn('Unexpected roll back cross round', { + round: round, + prevRound: prevRound, + block: block, + previousBlock: previousBlock + }); + process.exit(1); + // FIXME process the cross round rollback var outsiders = []; async.series([ function (cb) { diff --git a/src/utils/dblite-helper.js b/src/utils/dblite-helper.js index 8f3ef99..9d23b49 100644 --- a/src/utils/dblite-helper.js +++ b/src/utils/dblite-helper.js @@ -61,11 +61,16 @@ module.exports.connect = function (connectString, cb) { "CREATE UNIQUE INDEX IF NOT EXISTS peers_unique ON peers(ip, port)", "CREATE UNIQUE INDEX IF NOT EXISTS peers_dapp_unique ON peers_dapp(peerId, dappId)", "CREATE INDEX IF NOT EXISTS blocks_generator_public_key ON blocks(generatorPublicKey)", - "CREATE INDEX IF NOT EXISTS blocks_reward ON blocks(reward)", - "CREATE INDEX IF NOT EXISTS blocks_totalFee ON blocks(totalFee)", - "CREATE INDEX IF NOT EXISTS blocks_totalAmount ON blocks(totalAmount)", - "CREATE INDEX IF NOT EXISTS blocks_numberOfTransactions ON blocks(numberOfTransactions)", - "CREATE INDEX IF NOT EXISTS blocks_timestamp ON blocks(timestamp)", + // "CREATE INDEX IF NOT EXISTS blocks_reward ON blocks(reward)", + // "CREATE INDEX IF NOT EXISTS blocks_totalFee ON blocks(totalFee)", + // "CREATE INDEX IF NOT EXISTS blocks_totalAmount ON blocks(totalAmount)", + // "CREATE INDEX IF NOT EXISTS blocks_numberOfTransactions ON blocks(numberOfTransactions)", + // "CREATE INDEX IF NOT EXISTS blocks_timestamp ON blocks(timestamp)", + "drop index if exists blocks_reward", + "drop index if exists blocks_totalFee", + "drop index if exists blocks_totalAmount", + "drop index if exists blocks_numberOfTransactions", + "drop index if exists blocks_timestamp", "CREATE INDEX IF NOT EXISTS trs_block_id ON trs(blockId)", "CREATE INDEX IF NOT EXISTS trs_sender_id ON trs(senderId)", "CREATE INDEX IF NOT EXISTS trs_recipient_id ON trs(recipientId)",