def test_set_execution_results():
    """Test set_execution_results(state, collation)
    """
    collation = Collation(CollationHeader(coinbase=tester.a2))
    state = State()
    state_transition.set_execution_results(state, collation)
    assert collation.header.receipts_root == mk_receipt_sha(state.receipts)
    assert collation.header.tx_list_root == mk_transaction_sha(
        collation.transactions)
    assert collation.header.post_state_root == state.trie.root_hash
Пример #2
0
def verify_execution_results(state, collation):
    """Verify the results by Merkle Proof
    (refer to ethereum.common.verify_execution_results)
    """
    state.commit()

    validate_transaction_tree(collation)

    if collation.header.post_state_root != state.trie.root_hash:
        raise ValueError('State root mismatch: header %s computed %s' %
                         (encode_hex(collation.header.post_state_root),
                          encode_hex(state.trie.root_hash)))
    if collation.header.receipts_root != mk_receipt_sha(state.receipts):
        raise ValueError(
            'Receipt root mismatch: header %s computed %s, computed %d, %d receipts'
            % (encode_hex(collation.header.receipts_root),
               encode_hex(mk_receipt_sha(
                   state.receipts)), state.gas_used, len(state.receipts)))

    return True
Пример #3
0
def set_execution_results(state, collation):
    """Set state root, receipt root, etc
    (ethereum.pow.common.set_execution_results)
    """
    collation.header.receipts_root = mk_receipt_sha(state.receipts)
    collation.header.tx_list_root = mk_transaction_sha(collation.transactions)

    # Notice: commit state before assigning
    state.commit()
    collation.header.post_state_root = state.trie.root_hash

    # TODO: Don't handle in basic sharding currently
    # block.header.gas_used = state.gas_used
    # block.header.bloom = state.bloom

    log.info('Collation pre-sealed, %d gas used' % state.gas_used)
Пример #4
0
    def mine_blocks(self, num_blocks=1, coinbase=None):
        if not coinbase:
            coinbase = self.get_accounts()[0]

        from ethereum.common import mk_receipt_sha

        for _ in range(num_blocks):
            receipts = self.evm.head_state.receipts
            block = self.evm.mine(coinbase=coinbase)
            if block is None:
                # earlier versions of pyethereum21 didn't return the block.
                block = _get_block_by_number(self.evm, self.evm.block.number - 1)

            receipts_root = mk_receipt_sha(receipts)
            self.evm.chain.db.put(receipts_root, rlp.encode(receipts))

            yield block.hash