How to use the @arkecosystem/crypto.slots.getSlotNumber function in @arkecosystem/crypto

To help you get started, we’ve selected a few @arkecosystem/crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ArkEcosystem / core / packages / core-blockchain / lib / blockchain.js View on Github external
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()
  }
github ArkEcosystem / core / packages / core-forger / lib / manager.js View on Github external
async startForging() {
    const slot = slots.getSlotNumber()

    while (slots.getSlotNumber() === slot) {
      await delay(100)
    }

    return this.__monitor(null)
  }
github ArkEcosystem / core / packages / core-p2p / lib / monitor.js View on Github external
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++
          }
        }
      }
    }
github ArkEcosystem / core / packages / core-p2p / src / monitor.ts View on Github external
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++;
                    }
                }
            }
        }
github ArkEcosystem / core / packages / core-p2p / src / utils / network-state.ts View on Github external
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);
github ArkEcosystem / core / packages / core-blockchain / lib / blockchain.js View on Github external
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 {
github ArkEcosystem / core / packages / core-blockchain / lib / blockchain.js View on Github external
__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
  }