async def create(
        coin_store: CoinStore,
        block_store: BlockStore,
        consensus_constants: ConsensusConstants,
    ):
        """
        Initializes a blockchain with the SubBlockRecords from disk, assuming they have all been
        validated. Uses the genesis block given in override_constants, or as a fallback,
        in the consensus constants config.
        """
        self = Blockchain()
        self.lock = asyncio.Lock()  # External lock handled by full node
        cpu_count = multiprocessing.cpu_count()
        if cpu_count > 61:
            cpu_count = 61  # Windows Server 2016 has an issue https://bugs.python.org/issue26903
        num_workers = max(cpu_count - 2, 1)
        log.info(f"Starting {num_workers} processes for block validation")
        self.pool = ProcessPoolExecutor(max_workers=num_workers)

        self.constants = consensus_constants
        self.coin_store = coin_store
        self.block_store = block_store
        self.constants_json = recurse_jsonify(
            dataclasses.asdict(self.constants))
        self._shut_down = False
        await self._load_chain_from_store()
        return self
 async def create(
     block_store: WalletBlockStore,
     consensus_constants: ConsensusConstants,
     coins_of_interest_received:
     Callable,  # f(removals: List[Coin], additions: List[Coin], height: uint32)
     reorg_rollback: Callable,
 ):
     """
     Initializes a blockchain with the SubBlockRecords from disk, assuming they have all been
     validated. Uses the genesis block given in override_constants, or as a fallback,
     in the consensus constants config.
     """
     self = WalletBlockchain()
     self.lock = asyncio.Lock()  # External lock handled by full node
     cpu_count = multiprocessing.cpu_count()
     if cpu_count > 61:
         cpu_count = 61  # Windows Server 2016 has an issue https://bugs.python.org/issue26903
     num_workers = max(cpu_count - 2, 1)
     self.pool = ProcessPoolExecutor(max_workers=num_workers)
     log.info(f"Started {num_workers} processes for block validation")
     self.constants = consensus_constants
     self.constants_json = recurse_jsonify(
         dataclasses.asdict(self.constants))
     self.block_store = block_store
     self._shut_down = False
     self.coins_of_interest_received = coins_of_interest_received
     self.reorg_rollback = reorg_rollback
     self.log = logging.getLogger(__name__)
     await self._load_chain_from_store()
     return self
Beispiel #3
0
    def __init__(self, coin_store: CoinStore,
                 consensus_constants: ConsensusConstants):
        self.constants: ConsensusConstants = consensus_constants
        self.constants_json = recurse_jsonify(
            dataclasses.asdict(self.constants))

        # Transactions that were unable to enter mempool, used for retry. (they were invalid)
        self.potential_txs: Dict[bytes32, Tuple[SpendBundle, CostResult,
                                                bytes32]] = {}
        # Keep track of seen spend_bundles
        self.seen_bundle_hashes: Dict[bytes32, bytes32] = {}

        self.coin_store = coin_store

        tx_per_sec = self.constants.TX_PER_SEC
        sec_per_block = self.constants.SUB_SLOT_TIME_TARGET // self.constants.SLOT_BLOCKS_TARGET
        block_buffer_count = self.constants.MEMPOOL_BLOCK_BUFFER

        # MEMPOOL_SIZE = 60000
        self.mempool_size = int(tx_per_sec * sec_per_block *
                                block_buffer_count)
        self.potential_cache_size = 300
        self.seen_cache_size = 10000
        self.pool = ProcessPoolExecutor(max_workers=1)

        # The mempool will correspond to a certain peak
        self.peak: Optional[BlockRecord] = None
        self.mempool: Mempool = Mempool.create(self.mempool_size)