<commit_before>var async = require('async'),
  bignum = require('bignum'),
  Account = require('../account.js');

/**
 * process the transaction in a block and pays the miners
 * @param {Block} block the block we are processing
 * @param {Buffer} root the state root which to start from
 * @param {Boolean} [gen=false] whether to generate
 * @param {Function} cb the callback which is given an error string
 */
module.exports = function (block, root, gen, cb) {

  if (arguments.length === 3) {
    cb = gen;
    gen = false;
  }

  var trie = this.trie,
    self = this,

    minerReward = bignum('1500000000000000000'),
    uncleReward = bignum('1406250000000000000'),
    nephewReward = bignum('46875000000000000'),

    //?
    r = bignum(0),
    account;

  this.block = block;

  trie.checkpoint();
  if (root) trie.root = root;

  /**
   * Processes all of the transaction in the block
   * @method processTransaction
   * @param {Function} cb the callback is given error if there are any
   */
  function processTransactions(cb) {
    //the totally amount of gas used processing this block
    var gasUsed = bignum(0),
      results,
      i = 0;

    async.eachSeries(block.transactionReceipts, function (tr, cb2) {
      async.series([
        //run the tx through the VM
        function (cb3) {
          self.runTx(tr.transaction, block, function (err, r) {
            results = r;
            cb3(err);
          });
        },
        //update the miner's account
        function (cb3) {
          gasUsed = gasUsed.add(results.gasUsed);

          //is the miner also the sender?
          if (block.header.coinbase.toString('hex') === tr.transaction.getSenderAddress().toString('hex')) {
            account = results.fromAccount;
          }

          //is the miner also the receiver?
          if (block.header.coinbase.toString('hex') === tr.transaction.to.toString('hex')) {
            account = results.toAccount;
          }

          //add the amount spent on gas to the mine's account
          account.balance = bignum
            .fromBuffer(account.balance)
            .add(results.amountSpent);

          //save the miner's account
          trie.put(block.header.coinbase, account.serialize(), function (err) {
            if (gen) {
              block.transactionReceipts[i].state = trie.root;
              i++;
            } else {
              if (tr.state.toString('hex') !== trie.root.toString('hex')) {
                err = 'state hash doesn\'t match the state hash from the transaction receipt';
              } else if (!bignum.fromBuffer(tr.gasUsed).eq(gasUsed)) {
                err = 'gas used does not match amount from the transaction receipt';
              }
            }

            cb3(err);

          });
        }
      ], cb2);

    }, cb);
  }

  //get the miners account
  function getMinerAccount(cb) {<commit_msg>added bloom checking in runblock<commit_after>var async = require('async'),
  bignum = require('bignum'),
  Bloom = require('../bloom.js'),
  Account = require('../account.js');

/**
 * process the transaction in a block and pays the miners
 * @param {Block} block the block we are processing
 * @param {Buffer} root the state root which to start from
 * @param {Boolean} [gen=false] whether to generate
 * @param {Function} cb the callback which is given an error string
 */
module.exports = function (block, root, gen, cb) {

  if (arguments.length === 3) {
    cb = gen;
    gen = false;
  }

  var trie = this.trie,
    self = this,
    bloom = new Bloom(),

    minerReward = bignum('1500000000000000000'),
    uncleReward = bignum('1406250000000000000'),
    nephewReward = bignum('46875000000000000'),

    //?
    r = bignum(0),
    account;

  this.block = block;

  trie.checkpoint();
  if (root) trie.root = root;

  /**
   * Processes all of the transaction in the block
   * @method processTransaction
   * @param {Function} cb the callback is given error if there are any
   */
  function processTransactions(cb) {
    //the totally amount of gas used processing this block
    var gasUsed = bignum(0),
      results,
      i = 0;

      bloom.add(block.header.coinbase);

    async.eachSeries(block.transactionReceipts, function (tr, cb2) {
      async.series([
        //run the tx through the VM
        function (cb3) {
          self.runTx(tr.transaction, block, function (err, r) {
            results = r;
            cb3(err);
          });
        },
        //update the miner's account
        function (cb3) {
          gasUsed = gasUsed.add(results.gasUsed);

          //is the miner also the sender?
          if (block.header.coinbase.toString('hex') === tr.transaction.getSenderAddress().toString('hex')) {
            account = results.fromAccount;
          }

          //is the miner also the receiver?
          if (block.header.coinbase.toString('hex') === tr.transaction.to.toString('hex')) {
            account = results.toAccount;
          }

          //add the amount spent on gas to the mine's account
          account.balance = bignum
            .fromBuffer(account.balance)
            .add(results.amountSpent);

          //or the blooms together
          if(results.bloom){
            bloom = (bignum.fromBuffer(bloom).or(bignum.fromBuffer(results.bloom))).toBuffer();
          }

          //save the miner's account
          trie.put(block.header.coinbase, account.serialize(), function (err) {
            if (gen) {
              block.header.bloom = bloom;
              block.transactionReceipts[i].state = trie.root;
              i++;
            } else {
              if(bloom.toString('hex') !== block.header.bloom.toString('hex')){
                err = 'invalid bloom bitvector';
              } else if (tr.state.toString('hex') !== trie.root.toString('hex')) {
                err = 'state hash doesn\'t match the state hash from the transaction receipt';
              } else if (!bignum.fromBuffer(tr.gasUsed).eq(gasUsed)) {
                err = 'gas used does not match amount from the transaction receipt';
              }
            }

            cb3(err);

          });
        }
      ], cb2);

    }, cb);
  }

  //get the miners account
  function getMinerAccount(cb) {
{'fraction_non_alphanumeric': 0.122674791533034, 'fraction_numerical': 0.02084669660038486, 'mean_word_length': 2.0906838453914767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '3053810', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1776, 'n_words': 510}