Exemplo n.º 1
0
 def cluster_config(self, c):
     self.__cluster_config = c
     # Configure precompiled contracts according to hard fork config
     if c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP is not None:
         for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED:
             configure_special_contract_ts(
                 specials, addr, c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP)
     if c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP is not None:
         configure_system_contract_ts(
             _system_contracts,
             SystemContract.NON_RESERVED_NATIVE_TOKEN,
             c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP,
         )
         for precompiled in (
                 PRECOMPILED_CONTRACT_MINT_MNT,
                 PRECOMPILED_CONTRACT_QUERY_MNT_BALANCE,
         ):
             configure_special_contract_ts(
                 specials,
                 precompiled,
                 c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP,
             )
     if c.QUARKCHAIN.ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP is not None:
         configure_system_contract_ts(
             _system_contracts,
             SystemContract.GENERAL_NATIVE_TOKEN,
             c.QUARKCHAIN.ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP,
         )
Exemplo n.º 2
0
 def cluster_config(self, c):
     self.__cluster_config = c
     # Configure precompiled contracts according to hard fork config
     if c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP is not None:
         for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED:
             configure_special_contract_ts(
                 specials, addr, c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP
             )
Exemplo n.º 3
0
 def cluster_config(self, c):
     self.__cluster_config = c
     # Configure precompiled contracts according to hard fork config
     if c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP is not None:
         for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED:
             configure_special_contract_ts(
                 specials, addr, c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP)
     if c.QUARKCHAIN.ENABLE_MNT_AUCTION_TIMESTAMP is not None:
         configure_system_contract_ts(
             _system_contracts,
             SystemContract.NON_RESERVED_NATIVE_TOKEN,
             c.QUARKCHAIN.ENABLE_MNT_AUCTION_TIMESTAMP,
         )
Exemplo n.º 4
0
    def cluster_config(self, c):
        self.__cluster_config = c
        # Configure precompiled contracts according to hard fork config
        if c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP is not None:
            for addr in PRECOMPILED_CONTRACTS_AFTER_EVM_ENABLED:
                configure_special_contract_ts(
                    specials, addr, c.QUARKCHAIN.ENABLE_EVM_TIMESTAMP)

        # Apply mainnet default ts
        if (c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP is None
                and c.QUARKCHAIN.NETWORK_ID == 1):
            c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP = (
                MAINNET_ENABLE_NON_RESERVED_NATIVE_TOKEN_CONTRACT_TIMESTAMP)
        if c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP is not None:
            configure_system_contract_ts(
                _system_contracts,
                SystemContract.NON_RESERVED_NATIVE_TOKEN,
                c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP,
            )
            for precompiled in (
                    PRECOMPILED_CONTRACT_MINT_MNT,
                    PRECOMPILED_CONTRACT_QUERY_MNT_BALANCE,
            ):
                configure_special_contract_ts(
                    specials,
                    precompiled,
                    c.QUARKCHAIN.ENABLE_NON_RESERVED_NATIVE_TOKEN_TIMESTAMP,
                )

        if (c.QUARKCHAIN.ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP is None
                and c.QUARKCHAIN.NETWORK_ID == 1):
            c.QUARKCHAIN.ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP = (
                MAINNET_ENABLE_GENERAL_NATIVE_TOKEN_CONTRACT_TIMESTAMP)
        if c.QUARKCHAIN.ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP is not None:
            configure_system_contract_ts(
                _system_contracts,
                SystemContract.GENERAL_NATIVE_TOKEN,
                c.QUARKCHAIN.ENABLE_GENERAL_NATIVE_TOKEN_TIMESTAMP,
            )
        if (c.QUARKCHAIN.ENABLE_POSW_STAKING_DECAY_TIMESTAMP is None
                and c.QUARKCHAIN.NETWORK_ID == 1):
            c.QUARKCHAIN.ENABLE_POSW_STAKING_DECAY_TIMESTAMP = (
                MAINNET_ENABLE_POSW_STAKING_DECAY_TIMESTAMP)
        if (c.QUARKCHAIN.ENABLE_EIP155_SIGNER_TIMESTAMP is None
                and c.QUARKCHAIN.NETWORK_ID == 1):
            c.QUARKCHAIN.ENABLE_EIP155_SIGNER_TIMESTAMP = (
                MAINNET_ENABLE_EIP155_SIGNER_TIMESTAMP)
        if c.QUARKCHAIN.BASE_ETH_CHAIN_ID is None and c.QUARKCHAIN.NETWORK_ID == 1:
            c.QUARKCHAIN.BASE_ETH_CHAIN_ID = MAINNET_BASE_ETH_CHAIN_ID
def init_state(env, pre, is_qkc_state, qkc_env=None):
    # Setup env
    db = InMemoryDb()
    state_env = Env(config=konfig)
    state_env.db = db
    state = State(
        env=state_env,
        block_prevhash=decode_hex(remove_0x_head(env["previousHash"])),
        prev_headers=[
            mk_fake_header(i)
            for i in range(
                parse_int_or_hex(env["currentNumber"]) - 1,
                max(-1, parse_int_or_hex(env["currentNumber"]) - 257),
                -1,
            )
        ],
        block_number=parse_int_or_hex(env["currentNumber"]),
        block_coinbase=decode_hex(remove_0x_head(env["currentCoinbase"])),
        block_difficulty=parse_int_or_hex(env["currentDifficulty"]),
        gas_limit=parse_int_or_hex(env["currentGasLimit"]),
        timestamp=parse_int_or_hex(env["currentTimestamp"]),
        qkc_config=qkc_env.quark_chain_config,
        # If testing QuarkChain states, should not use mock account
        use_mock_evm_account=not is_qkc_state,
    )

    if "overrides" in env:
        if "specialContractTimestamp" in env["overrides"]:
            for overrides in env["overrides"]["specialContractTimestamp"]:
                configure_special_contract_ts(
                    specials,
                    bytes.fromhex(overrides["address"]),
                    overrides["timestamp"],
                )

    seen_token_ids = set()
    # Fill up pre
    for address, h in list(pre.items()):
        assert len(address) in (40, 42)
        address = decode_hex(remove_0x_head(address))
        state.set_nonce(address, parse_int_or_hex(h["nonce"]))
        if is_qkc_state and "balances" in h:
            # In QuarkChain state tests, can either specify balance map or single balance
            for token_id, balance in h["balances"].items():
                parsed_token_id = parse_int_or_hex(token_id)
                state.set_token_balance(
                    address, parsed_token_id, parse_int_or_hex(balance)
                )
                seen_token_ids.add(parsed_token_id)
        else:
            state.set_balance(address, parse_int_or_hex(h["balance"]))
        state.set_code(address, decode_hex(remove_0x_head(h["code"])))
        for k, v in h["storage"].items():
            state.set_storage_data(
                address,
                big_endian_to_int(decode_hex(k[2:])),
                big_endian_to_int(decode_hex(v[2:])),
            )

    # Update allowed token IDs
    if seen_token_ids:
        state.qkc_config._allowed_token_ids = seen_token_ids

    state.commit(allow_empties=True)
    return state