Example #1
0
 def add_receipt_to_header(self, old_header: BlockHeader,
                           receipt: Receipt) -> BlockHeader:
     # Skip merkelizing the account data and persisting it to disk on every transaction.
     # Starting in Byzantium, this is no longer necessary, because the state root isn't
     # in the receipt anymore.
     return old_header.copy(
         bloom=int(BloomFilter(old_header.bloom) | receipt.bloom),
         gas_used=receipt.gas_used,
     )
Example #2
0
    async def preview_transactions(self,
                                   header: BlockHeader,
                                   transactions: Tuple[BaseTransaction, ...],
                                   parent_state_root: Hash32,
                                   lagging: bool = True) -> None:

        self.run_task(
            self._preview_address_load(header, parent_state_root,
                                       transactions))

        # This is a hack, so that preview executions can load ancestor block-hashes
        self._db[header.hash] = rlp.encode(header)

        # Always broadcast, to start previewing transactions that are further ahead in the block
        old_state_header = header.copy(state_root=parent_state_root)
        self._event_bus.broadcast_nowait(
            DoStatelessBlockPreview(old_state_header, transactions))
Example #3
0
    def set_block_transactions(self,
                               base_block: BaseBlock,
                               new_header: BlockHeader,
                               transactions: Tuple[BaseTransaction, ...],
                               receipts: Tuple[Receipt, ...]) -> BaseBlock:

        tx_root_hash, tx_kv_nodes = make_trie_root_and_nodes(transactions)
        self.chaindb.persist_trie_data_dict(tx_kv_nodes)

        receipt_root_hash, receipt_kv_nodes = make_trie_root_and_nodes(receipts)
        self.chaindb.persist_trie_data_dict(receipt_kv_nodes)

        return base_block.copy(
            transactions=transactions,
            header=new_header.copy(
                transaction_root=tx_root_hash,
                receipt_root=receipt_root_hash,
            ),
        )
Example #4
0
    def apply_transaction(
        self, header: BlockHeader, transaction: BaseTransaction
    ) -> Tuple[BlockHeader, Receipt, BaseComputation]:
        """
        Apply the transaction to the current block. This is a wrapper around
        :func:`~eth.vm.state.State.apply_transaction` with some extra orchestration logic.

        :param header: header of the block before application
        :param transaction: to apply
        """
        self.validate_transaction_against_header(header, transaction)
        state_root, computation = self.state.apply_transaction(transaction)
        receipt = self.make_receipt(header, transaction, computation,
                                    self.state)
        self.validate_receipt(receipt)

        new_header = header.copy(
            bloom=int(BloomFilter(header.bloom) | receipt.bloom),
            gas_used=receipt.gas_used,
            state_root=state_root,
        )

        return new_header, receipt, computation
Example #5
0
    async def preview_transactions(self,
                                   header: BlockHeader,
                                   transactions: Tuple[BaseTransaction, ...],
                                   parent_state_root: Hash32,
                                   lagging: bool = True) -> None:

        if not self.manager.is_running:
            # If the service is shutting down, we can ignore preview requests
            return

        self.manager.run_task(self._preview_address_load, header,
                              parent_state_root, transactions)

        # This is a hack, so that preview executions can load ancestor block-hashes
        self._db[header.hash] = rlp.encode(header)

        # Always broadcast, to start previewing transactions that are further ahead in the block
        old_state_header = header.copy(state_root=parent_state_root)
        self._event_bus.broadcast_nowait(
            DoStatelessBlockPreview(old_state_header, transactions),
            FIRE_AND_FORGET_BROADCASTING)

        self._backfiller.set_root_hash(parent_state_root)
Example #6
0
 def add_receipt_to_header(self, old_header: BlockHeader, receipt: Receipt) -> BlockHeader:
     return old_header.copy(
         bloom=int(BloomFilter(old_header.bloom) | receipt.bloom),
         gas_used=receipt.gas_used,
         state_root=self.state.make_state_root(),
     )