<commit_before>"use strict";

const co        = require('co');
const constants = require('../constants');
const rules     = require('../rules');
const parsers   = require('../streams/parsers');

module.exports = (server) => new PermanentProver(server);

function PermanentProver(server) {

  const logger = require('../logger')('permprover');
  const that = this;

  let onBlockCallback = null,
      blockchainChangedResolver = null,
      powPromise = null,
      promiseOfWaitingBetween2BlocksOfOurs = null,
      lastComputedBlock = null;

  // Promises triggering the prooving lopp
  let resolveContinuePromise = null;
  let continuePromise = new Promise((resolve) => resolveContinuePromise = resolve);

  this.isPoWWaiting = () => !powPromise;

  this.allowedToStart = () => resolveContinuePromise(true);

  this.loops = 0;

  /******************
   * Main proof loop
   *****************/
  co(function*() {
    while (yield continuePromise) {
      try {
        const waitingRaces = [];

        // By default, we do not make a new proof
        let doProof = false;

        try {
          const selfPubkey = server.keyPair.publicKey;
          const dal = server.dal;
          const conf = server.conf;
          if (!conf.participate) {
            throw 'This node is configured for not participating to compute blocks, but this message is showing up. Weird.';
          }
          if (!selfPubkey) {
            throw 'No self pubkey found.';
          }
          let block, current;
          const isMember = yield dal.isMember(selfPubkey);
          if (!isMember) {
            throw 'Local node is not a member. Waiting to be a member before computing a block.';
          }
          current = yield dal.getCurrentBlockOrNull();
          if (!current) {
            throw 'Waiting for a root block before computing new blocks';
          }
          const version = current ? current.version : 3;
          const trial = yield rules.HELPERS.getTrialLevel(version, selfPubkey, conf, dal);
          if (trial > (current.powMin + 2)) {
            logger.warn('Trial = ', trial);
            throw 'Too high difficulty: waiting for other members to write next block';
          }
          const lastIssuedByUs = current.issuer == selfPubkey;
          if (lastIssuedByUs && !promiseOfWaitingBetween2BlocksOfOurs) {
            promiseOfWaitingBetween2BlocksOfOurs = new Promise((resolve) => setTimeout(resolve, conf.powDelay));
            logger.warn('Waiting ' + conf.powDelay + 'ms before starting to compute next block...');
          } else {
            // We have waited enough
            promiseOfWaitingBetween2BlocksOfOurs = null;
            // But under some conditions, we can make one
            doProof = true;
          }
        } catch (e) {
          logger.warn(e);
        }
<commit_msg>Fix: little typo in "Trial" message<commit_after>"use strict";

const co        = require('co');
const constants = require('../constants');
const rules     = require('../rules');
const parsers   = require('../streams/parsers');

module.exports = (server) => new PermanentProver(server);

function PermanentProver(server) {

  const logger = require('../logger')('permprover');
  const that = this;

  let onBlockCallback = null,
      blockchainChangedResolver = null,
      powPromise = null,
      promiseOfWaitingBetween2BlocksOfOurs = null,
      lastComputedBlock = null;

  // Promises triggering the prooving lopp
  let resolveContinuePromise = null;
  let continuePromise = new Promise((resolve) => resolveContinuePromise = resolve);

  this.isPoWWaiting = () => !powPromise;

  this.allowedToStart = () => resolveContinuePromise(true);

  this.loops = 0;

  /******************
   * Main proof loop
   *****************/
  co(function*() {
    while (yield continuePromise) {
      try {
        const waitingRaces = [];

        // By default, we do not make a new proof
        let doProof = false;

        try {
          const selfPubkey = server.keyPair.publicKey;
          const dal = server.dal;
          const conf = server.conf;
          if (!conf.participate) {
            throw 'This node is configured for not participating to compute blocks, but this message is showing up. Weird.';
          }
          if (!selfPubkey) {
            throw 'No self pubkey found.';
          }
          let block, current;
          const isMember = yield dal.isMember(selfPubkey);
          if (!isMember) {
            throw 'Local node is not a member. Waiting to be a member before computing a block.';
          }
          current = yield dal.getCurrentBlockOrNull();
          if (!current) {
            throw 'Waiting for a root block before computing new blocks';
          }
          const version = current ? current.version : 3;
          const trial = yield rules.HELPERS.getTrialLevel(version, selfPubkey, conf, dal);
          if (trial > (current.powMin + 2)) {
            logger.warn('Trial = %s', trial);
            throw 'Too high difficulty: waiting for other members to write next block';
          }
          const lastIssuedByUs = current.issuer == selfPubkey;
          if (lastIssuedByUs && !promiseOfWaitingBetween2BlocksOfOurs) {
            promiseOfWaitingBetween2BlocksOfOurs = new Promise((resolve) => setTimeout(resolve, conf.powDelay));
            logger.warn('Waiting ' + conf.powDelay + 'ms before starting to compute next block...');
          } else {
            // We have waited enough
            promiseOfWaitingBetween2BlocksOfOurs = null;
            // But under some conditions, we can make one
            doProof = true;
          }
        } catch (e) {
          logger.warn(e);
        }

{'fraction_non_alphanumeric': 0.11349262122276879, 'fraction_numerical': 0.002459592410400562, 'mean_word_length': 2.27183908045977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597991', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1505, 'n_words': 460}