Try to speed up with new BlockTools

This commit is contained in:
Mariano Sorgente 2020-06-18 16:36:54 +09:00 committed by Gene Hoffman
parent b0356d5810
commit 9c748cfec4
16 changed files with 59 additions and 16 deletions

View File

@ -14,7 +14,8 @@ from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from tests.block_tools import BlockTools
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
@pytest.fixture(scope="module")
@ -27,6 +28,7 @@ class TestBlockStore:
@pytest.mark.asyncio
async def test_block_store(self):
assert sqlite3.threadsafety == 1
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")
blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
db_filename = Path("blockchain_test.db")
@ -107,6 +109,7 @@ class TestBlockStore:
@pytest.mark.asyncio
async def test_deadlock(self):
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, 10, [], 9, b"0")
db_filename = Path("blockchain_test.db")

View File

@ -20,7 +20,10 @@ from src.types.sized_bytes import bytes32
from src.full_node.block_store import BlockStore
from src.full_node.coin_store import CoinStore
from src.consensus.find_fork_point import find_fork_point_in_chain
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
bt = BlockTools()
@pytest.fixture(scope="module")

View File

@ -18,9 +18,12 @@ from src.types.spend_bundle import SpendBundle
from src.util.errors import Err
from src.util.ints import uint64
from tests.block_tools import BlockTools
from tests.setup_nodes import setup_two_nodes, test_constants, bt
from tests.setup_nodes import setup_two_nodes, test_constants
from tests.block_tools import BlockTools
from tests.wallet_tools import WalletTool
bt = BlockTools()
@pytest.fixture(scope="module")
def event_loop():

View File

@ -10,7 +10,10 @@ from src.full_node.coin_store import CoinStore
from src.full_node.block_store import BlockStore
from tests.block_tools import BlockTools
from src.consensus.constants import constants as consensus_constants
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
bt = BlockTools()
@pytest.fixture(scope="module")

View File

@ -24,7 +24,8 @@ from src.util.hash import std_hash
from src.full_node.full_node import FullNode
from src.types.condition_var_pair import ConditionVarPair
from src.types.condition_opcodes import ConditionOpcode
from tests.setup_nodes import setup_two_nodes, test_constants, bt
from tests.setup_nodes import setup_two_nodes, test_constants
from tests.block_tools import BlockTools
from tests.wallet_tools import WalletTool
from src.types.mempool_inclusion_status import MempoolInclusionStatus
from src.types.coin import hash_coin_list
@ -36,6 +37,8 @@ from src.util.merkle_set import (
from src.util.errors import Err, ConsensusError
from tests.time_out_assert import time_out_assert
bt = BlockTools()
async def get_block_path(full_node: FullNode):
blocks_list = [(await full_node.blockchain.get_full_tips())[0]]

View File

@ -12,7 +12,8 @@ from src.full_node.blockchain import Blockchain
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
@pytest.fixture(scope="module")
@ -25,6 +26,7 @@ class TestFullNodeStore:
@pytest.mark.asyncio
async def test_basic_store(self):
assert sqlite3.threadsafety == 1
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")
blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
db_filename = Path("blockchain_test.db")

View File

@ -6,9 +6,12 @@ import pytest
from src.types.peer_info import PeerInfo
from src.protocols import full_node_protocol
from src.util.ints import uint16
from tests.setup_nodes import setup_two_nodes, test_constants, bt
from tests.setup_nodes import setup_two_nodes, test_constants
from tests.block_tools import BlockTools
from tests.time_out_assert import time_out_assert
bt = BlockTools()
def node_height_at_least(node, h):
if (max([h.height for h in node.blockchain.get_current_tips()])) >= h:

View File

@ -21,9 +21,12 @@ from src.util.condition_tools import (
hash_key_pairs_for_conditions_dict,
)
from src.util.ints import uint64
from tests.setup_nodes import setup_two_nodes, test_constants, bt
from tests.setup_nodes import setup_two_nodes, test_constants
from tests.block_tools import BlockTools
from tests.wallet_tools import WalletTool
bt = BlockTools()
@pytest.fixture(scope="module")
def event_loop():

View File

@ -8,7 +8,8 @@ from src.server.connection import NodeType
from src.server.outbound_message import Delivery, Message, OutboundMessage
from src.types.peer_info import PeerInfo
from src.util.ints import uint16
from tests.setup_nodes import setup_two_nodes, test_constants, bt
from tests.setup_nodes import setup_two_nodes, test_constants
from tests.block_tools import BlockTools
from tests.time_out_assert import time_out_assert
@ -34,6 +35,7 @@ class TestNodeLoad:
async def test_unfinished_blocks_load(self, two_nodes):
num_blocks = 2
full_node_1, full_node_2, server_1, server_2 = two_nodes
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10)
for i in range(1, num_blocks - 1):
@ -75,6 +77,7 @@ class TestNodeLoad:
async def test_blocks_load(self, two_nodes):
num_blocks = 50
full_node_1, full_node_2, server_1, server_2 = two_nodes
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10)
await server_2.start_client(PeerInfo("localhost", uint16(server_1._port)), None)

View File

@ -12,7 +12,8 @@ from src.full_node.blockchain import Blockchain
from src.types.full_block import FullBlock
from src.types.sized_bytes import bytes32
from src.util.ints import uint32, uint64
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
@pytest.fixture(scope="module")
@ -25,6 +26,7 @@ class TestStore:
@pytest.mark.asyncio
async def test_basic_store(self):
assert sqlite3.threadsafety == 1
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, 9, [], 9, b"0")
blocks_alt = bt.get_consecutive_blocks(test_constants, 3, [], 9, b"1")
db = await SyncStore.create()

View File

@ -7,7 +7,8 @@ from src.rpc.rpc_server import start_rpc_server
from src.protocols import full_node_protocol
from src.rpc.full_node_rpc_client import FullNodeRpcClient
from src.util.ints import uint16
from tests.setup_nodes import setup_two_nodes, test_constants, bt
from tests.setup_nodes import setup_two_nodes, test_constants
from tests.block_tools import BlockTools
from tests.time_out_assert import time_out_assert
@ -28,6 +29,7 @@ class TestRpc:
num_blocks = 5
test_rpc_port = uint16(21522)
full_node_1, full_node_2, server_1, server_2 = two_nodes
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10)
for i in range(1, num_blocks):

View File

@ -6,7 +6,8 @@ from src.consensus.constants import constants
from src.util.bundle_tools import best_solution_program
from src.util.cost_calculator import calculate_cost_of_program
from src.util.mempool_check_conditions import get_name_puzzle_conditions
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
from tests.wallet_tools import WalletTool
@ -23,6 +24,7 @@ class TestCostCalculation:
receiver = WalletTool()
num_blocks = 2
bt = BlockTools()
blocks = bt.get_consecutive_blocks(
test_constants,
num_blocks,

View File

@ -3,9 +3,10 @@ from typing import List
import pytest
from blspy import ExtendedPrivateKey
from tests.block_tools import BlockTools
from chiabip158 import PyBIP158
from tests.setup_nodes import test_constants, bt, setup_simulators_and_wallets
from tests.setup_nodes import test_constants, setup_simulators_and_wallets
@pytest.fixture(scope="module")
@ -29,6 +30,7 @@ class TestFilter:
num_blocks = 2
ph = await wallet.get_new_puzzlehash()
bt = BlockTools()
blocks = bt.get_consecutive_blocks(
test_constants, num_blocks, [], 10, reward_puzzlehash=ph,
)

View File

@ -3,7 +3,8 @@ import asyncio
import pytest
from src.util.merkle_set import MerkleSet, confirm_included_already_hashed
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
from tests.wallet_tools import WalletTool
@ -19,6 +20,7 @@ class TestMerkleSet:
wallet_tool = WalletTool()
num_blocks = 10
bt = BlockTools()
blocks = bt.get_consecutive_blocks(
test_constants,
num_blocks,

View File

@ -9,7 +9,8 @@ from src.types.full_block import FullBlock
from src.util.streamable import Streamable, streamable
from tests.block_tools import BlockTools
from src.protocols.wallet_protocol import RespondRemovals
from tests.setup_nodes import test_constants, bt
from tests.setup_nodes import test_constants
from tests.block_tools import BlockTools
from src.util import cbor
@ -54,6 +55,7 @@ class TestStreamable(unittest.TestCase):
pass
def test_json(self):
bt = BlockTools()
block = bt.create_genesis_block(test_constants, bytes([0] * 32), b"0")
dict_block = block.to_json_dict()

View File

@ -6,13 +6,14 @@ import pytest
from src.types.peer_info import PeerInfo
from src.protocols import full_node_protocol
from src.util.ints import uint16, uint64
from tests.setup_nodes import setup_two_nodes, setup_node_and_wallet, test_constants, bt
from tests.setup_nodes import setup_two_nodes, setup_node_and_wallet, test_constants
from src.types.spend_bundle import SpendBundle
from src.util.bundle_tools import best_solution_program
from tests.wallet_tools import WalletTool
from src.types.coin import Coin
from src.consensus.coinbase import create_coinbase_coin
from tests.time_out_assert import time_out_assert
from tests.block_tools import BlockTools
def wallet_height_at_least(wallet_node, h):
@ -46,6 +47,7 @@ class TestWalletSync:
@pytest.mark.asyncio
async def test_basic_sync_wallet(self, wallet_node):
num_blocks = 25 # This must be greater than the short_sync in wallet_node
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [])
full_node_1, wallet_node, server_1, server_2 = wallet_node
@ -76,6 +78,7 @@ class TestWalletSync:
@pytest.mark.asyncio
async def test_fast_sync_wallet(self, wallet_node_starting_height):
num_blocks = 25 # This must be greater than the short_sync in wallet_node
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [])
full_node_1, wallet_node, server_1, server_2 = wallet_node_starting_height
@ -94,6 +97,7 @@ class TestWalletSync:
@pytest.mark.asyncio
async def test_short_sync_wallet(self, wallet_node):
num_blocks = 5 # This must be lower than the short_sync in wallet_node
bt = BlockTools()
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10)
full_node_1, wallet_node, server_1, server_2 = wallet_node
@ -117,6 +121,7 @@ class TestWalletSync:
puzzle_hashes = [await wallet_a.get_new_puzzlehash() for _ in range(10)]
puzzle_hashes.append(wallet_b.get_new_puzzlehash())
bt = BlockTools()
blocks = bt.get_consecutive_blocks(
test_constants, 3, [], 10, b"", coinbase_puzzlehash
)