Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logger.debug(error.stack)
this.transactionPool.purgeBlock(block)
// Only fork when the block generator is an active delegate
if (error.message !== "inactive generator") {
this.dispatch('FORK');
}
return callback()
}
try {
// broadcast only current block
const blocktime = config.getConstants(block.data.height).blocktime
if (slots.getSlotNumber() * blocktime <= block.data.timestamp) {
this.p2p.broadcastBlock(block)
}
} catch (error) {
logger.warn(
`Can't properly broadcast block ${block.data.height.toLocaleString()}`,
)
logger.debug(error.stack)
}
return callback()
}
async startForging() {
const slot = slots.getSlotNumber()
while (slots.getSlotNumber() === slot) {
await delay(100)
}
return this.__monitor(null)
}
getPBFTForgingStatus() {
const height = this.getNetworkHeight()
const slot = slots.getSlotNumber()
let allowedToForge = 0
let syncedPeers = 0
for (const peer of this.getPeers()) {
if (peer.state) {
if (peer.state.currentSlot === slot) {
syncedPeers++
if (peer.state.forgingAllowed && peer.state.height >= height) {
allowedToForge++
}
}
}
}
public getPBFTForgingStatus(): number {
const height = this.getNetworkHeight();
const slot = slots.getSlotNumber();
let allowedToForge = 0;
let syncedPeers = 0;
for (const peer of this.getPeers()) {
if (peer.state) {
if (peer.state.currentSlot === slot) {
syncedPeers++;
if (peer.state.forgingAllowed && peer.state.height >= height) {
allowedToForge++;
}
}
}
}
export = (monitor, lastBlock) => {
const createStateObject = (quorum, minimumNetworkReach, coldStart, overHeightBlockHeader) => ({
quorum,
nodeHeight: lastBlock.data.height,
lastBlockId: lastBlock.data.id,
overHeightBlockHeader,
minimumNetworkReach,
coldStart,
});
const peers = monitor.getPeers();
const minimumNetworkReach = localConfig.get("minimumNetworkReach", 20);
const currentSlot = slots.getSlotNumber();
let quorum = 0;
let noQuorum = 0;
let overHeightQuorum = 0;
let overHeightBlockHeader = null;
if (monitor.__isColdStartActive()) {
return createStateObject(0, true, true, overHeightBlockHeader);
}
if (process.env.ARK_ENV === "test") {
return createStateObject(1, true, false, overHeightBlockHeader);
}
if (peers.length < minimumNetworkReach) {
return createStateObject(0, false, false, overHeightBlockHeader);
queueBlock(block) {
logger.info(
`Received new block at height ${block.height.toLocaleString()} with ${pluralize(
'transaction',
block.numberOfTransactions,
true,
)} from ${block.ip}`,
)
const currentSlot = slots.getSlotNumber();
const blockSlot = slots.getSlotNumber(block.timestamp);
if (blockSlot > currentSlot) {
logger.info(`Block disregarded because the block takes a future slot.`)
return;
}
if (
this.state.started &&
this.state.blockchain.value === 'idle' &&
!this.state.forked
) {
this.dispatch('NEWBLOCK')
this.processQueue.push(block)
this.state.lastDownloadedBlock = new Block(block)
} else {
__isChained(previousBlock, nextBlock) {
const followsPrevious =
nextBlock.data.previousBlock === previousBlock.data.id
const isPlusOne = nextBlock.data.height === previousBlock.data.height + 1
const previousSlot = slots.getSlotNumber(previousBlock.data.timestamp);
const nextSlot = slots.getSlotNumber(nextBlock.data.timestamp);
const isAfterLastSlot = previousSlot < nextSlot;
return followsPrevious && isPlusOne && isAfterLastSlot
}