Пример #1
0
LOGFILE = '/tmp/lightchain-shell.log'
LOGLEVEL = logging.INFO

parser = argparse.ArgumentParser()
parser.add_argument('-db', type=str, required=True)
parser.add_argument('-debug', action='store_true')
args = parser.parse_args()

print("Logging to", LOGFILE)
if args.debug:
    LOGLEVEL = logging.DEBUG
logging.basicConfig(level=LOGLEVEL, filename=LOGFILE)

DemoLightChain = LightChain.configure(
    name='Demo LightChain',
    vm_configuration=MAINNET_VM_CONFIGURATION,
    network_id=ROPSTEN_NETWORK_ID,
)

chaindb = ChainDB(LevelDB(args.db))
peer_pool = PeerPool(LESPeer, chaindb, ROPSTEN_NETWORK_ID,
                     ecies.generate_privkey())
try:
    chaindb.get_canonical_head()
except CanonicalHeadNotFound:
    # We're starting with a fresh DB.
    chain = DemoLightChain.from_genesis_header(chaindb, ROPSTEN_GENESIS_HEADER,
                                               peer_pool)
else:
    # We're reusing an existing db.
    chain = DemoLightChain(chaindb, peer_pool)
Пример #2
0
    def __init__(self, *args, **kwargs):
        pass

    def subscribe(self, subscriber):
        pass

    async def run(self):
        pass

    async def stop(self):
        pass


LightChainForTests = LightChain.configure(
    'LightChainForTests',
    vm_configuration=MAINNET_VM_CONFIGURATION,
    network_id=MAINNET_NETWORK_ID,
)


def assert_canonical_chains_are_equal(chaindb1, chaindb2, block_number=None):
    """Assert that the canonical chains in both DBs are identical up to block_number."""
    if block_number is None:
        block_number = chaindb1.get_canonical_head().block_number
        assert block_number == chaindb2.get_canonical_head().block_number
    for i in range(0, block_number + 1):
        assert chaindb1.get_canonical_block_header_by_number(i) == (
            chaindb2.get_canonical_block_header_by_number(i))


@pytest.fixture
Пример #3
0
    def __init__(self, *args, **kwargs):
        pass

    def subscribe(self, subscriber):
        pass

    async def run(self):
        pass

    async def stop(self):
        pass


LightChainForTests = LightChain.configure(
    'LightChainForTests',
    vm_configuration=MAINNET_VM_CONFIGURATION,
    network_id=MAINNET_NETWORK_ID,
)


def assert_canonical_chains_are_equal(chaindb1, chaindb2, block_number=None):
    """Assert that the canonical chains in both DBs are identical up to block_number."""
    if block_number is None:
        block_number = chaindb1.get_canonical_head().block_number
        assert block_number == chaindb2.get_canonical_head().block_number
    for i in range(0, block_number + 1):
        assert chaindb1.get_canonical_block_header_by_number(i) == (
            chaindb2.get_canonical_block_header_by_number(i))


@pytest.fixture
)

from evm.chains.ropsten import ROPSTEN_NETWORK_ID, ROPSTEN_GENESIS_HEADER
from evm.chains.mainnet import MAINNET_VM_CONFIGURATION
from evm.db.backends.memory import MemoryDB
from evm.vm.forks.frontier import FrontierBlock

from p2p import ecies
from p2p.lightchain import LightChain
from p2p.peer import LESPeer

from integration_test_helpers import FakeAsyncChainDB, LocalGethPeerPool

IntegrationTestLightChain = LightChain.configure(
    name='IntegrationTest LightChain',
    vm_configuration=MAINNET_VM_CONFIGURATION,
    network_id=ROPSTEN_NETWORK_ID,
    max_consecutive_timeouts=1,
)


@pytest.mark.asyncio
async def test_lightchain_integration(request, event_loop):
    """Test LightChain against a local geth instance.

    This test assumes a geth/ropsten instance is listening on 127.0.0.1:30303 and serving light
    clients. In order to achieve that, simply run it with the following command line:

        $ geth -nodekeyhex 45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8 \
               -testnet -lightserv 90
    """
    # TODO: Implement a pytest fixture that runs geth as above, so that we don't need to run it
Пример #5
0
from evm.chains.mainnet import (
    MAINNET_NETWORK_ID,
    MAINNET_VM_CONFIGURATION,
)

from p2p.lightchain import LightChain

from typing import Type

MainnetLightChain: Type[LightChain] = LightChain.configure(
    __name__='MainnetLightChain',
    vm_configuration=MAINNET_VM_CONFIGURATION,
    network_id=MAINNET_NETWORK_ID,
)
Пример #6
0
from evm.chains.ropsten import (
    ROPSTEN_NETWORK_ID,
    ROPSTEN_VM_CONFIGURATION,
)

from p2p.lightchain import LightChain

from typing import Type

RopstenLightChain: Type[LightChain] = LightChain.configure(
    __name__='RopstenLightChain',
    vm_configuration=ROPSTEN_VM_CONFIGURATION,
    network_id=ROPSTEN_NETWORK_ID,
)
Пример #7
0
from evm.chains.mainnet import MAINNET_VM_CONFIGURATION
from evm.chains.ropsten import ROPSTEN_NETWORK_ID

from p2p.lightchain import LightChain

from typing import Type

RopstenLightChain: Type[LightChain] = LightChain.configure(
    __name__='RopstenLightChain',
    vm_configuration=
    MAINNET_VM_CONFIGURATION,  # TODO: use real ropsten configuration
    network_id=ROPSTEN_NETWORK_ID,
)
Пример #8
0
                        format='%(levelname)s: %(message)s')
    logging.getLogger("p2p.lightchain").setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('-db', type=str, required=True)
    parser.add_argument('-mainnet', action="store_true")
    args = parser.parse_args()

    GENESIS_HEADER = ROPSTEN_GENESIS_HEADER
    NETWORK_ID = ROPSTEN_NETWORK_ID
    if args.mainnet:
        GENESIS_HEADER = MAINNET_GENESIS_HEADER
        NETWORK_ID = MAINNET_NETWORK_ID
    DemoLightChain = LightChain.configure(
        'RPCDemoLightChain',
        vm_configuration=MAINNET_VM_CONFIGURATION,
        network_id=NETWORK_ID,
        privkey=ecies.generate_privkey(),
    )

    chaindb = ChainDB(LevelDB(args.db))
    try:
        chaindb.get_canonical_head()
    except CanonicalHeadNotFound:
        # We're starting with a fresh DB.
        chain = DemoLightChain.from_genesis_header(chaindb, GENESIS_HEADER)
    else:
        # We're reusing an existing db.
        chain = DemoLightChain(chaindb)

    app = App(chain)
    web.run_app(app, port=8080)
Пример #9
0
    logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
    logging.getLogger("p2p.lightchain").setLevel(logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('-db', type=str, required=True)
    parser.add_argument('-mainnet', action="store_true")
    args = parser.parse_args()

    GENESIS_HEADER = ROPSTEN_GENESIS_HEADER
    NETWORK_ID = ROPSTEN_NETWORK_ID
    if args.mainnet:
        GENESIS_HEADER = MAINNET_GENESIS_HEADER
        NETWORK_ID = MAINNET_NETWORK_ID
    DemoLightChain = LightChain.configure(
        'RPCDemoLightChain',
        vm_configuration=MAINNET_VM_CONFIGURATION,
        network_id=NETWORK_ID,
        privkey=ecies.generate_privkey(),
    )

    chaindb = ChainDB(LevelDB(args.db))
    try:
        chaindb.get_canonical_head()
    except CanonicalHeadNotFound:
        # We're starting with a fresh DB.
        chain = DemoLightChain.from_genesis_header(chaindb, GENESIS_HEADER)
    else:
        # We're reusing an existing db.
        chain = DemoLightChain(chaindb)

    app = App(chain)
    web.run_app(app, port=8080)
from evm.chains.ropsten import ROPSTEN_NETWORK_ID, ROPSTEN_GENESIS_HEADER
from evm.chains.mainnet import MAINNET_VM_CONFIGURATION
from evm.db.backends.memory import MemoryDB
from evm.vm.forks.frontier import FrontierBlock

from p2p import ecies
from p2p.lightchain import LightChain
from p2p.peer import LESPeer

from integration_test_helpers import FakeAsyncChainDB, LocalGethPeerPool


IntegrationTestLightChain = LightChain.configure(
    name='IntegrationTest LightChain',
    vm_configuration=MAINNET_VM_CONFIGURATION,
    network_id=ROPSTEN_NETWORK_ID,
    max_consecutive_timeouts=1,
)


@pytest.mark.asyncio
async def test_lightchain_integration(request, event_loop):
    """Test LightChain against a local geth instance.

    This test assumes a geth/ropsten instance is listening on 127.0.0.1:30303 and serving light
    clients. In order to achieve that, simply run it with the following command line:

        $ geth -nodekeyhex 45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8 \
               -testnet -lightserv 90
    """
    # TODO: Implement a pytest fixture that runs geth as above, so that we don't need to run it