Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2123 from carver/berlin-support
Browse files Browse the repository at this point in the history
Berlin support
  • Loading branch information
carver committed Mar 24, 2021
2 parents df32e13 + 1dfcaed commit ee15a20
Show file tree
Hide file tree
Showing 49 changed files with 568 additions and 199 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ jobs:
environment:
TOXENV: py37-docs

py37-rpc-state-berlin:
<<: *common
docker:
- image: circleci/python:3.7
environment:
TOXENV: py37-rpc-state-berlin
py37-rpc-state-byzantium:
<<: *common
docker:
Expand Down Expand Up @@ -324,6 +330,7 @@ workflows:
- py37-rpc-state-quadratic
- py37-rpc-state-zero_knowledge

- py37-rpc-state-berlin
- py37-rpc-state-byzantium
- py37-rpc-state-constantinople
- py37-rpc-state-frontier
Expand Down
2 changes: 1 addition & 1 deletion fixtures
2 changes: 2 additions & 0 deletions newsfragments/2126.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add support for Berlin, using latest py-evm:
https://py-evm.readthedocs.io/en/latest/release_notes.html#py-evm-0-4-0-alpha-2-2021-03-22
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
addopts= --showlocals --durations 50
addopts= --showlocals --durations 50 -r fEX
python_paths= .
xfail_strict=true
log_format = %(levelname)8s %(asctime)s %(filename)20s %(message)s
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
from setuptools import setup, find_packages

PYEVM_DEPENDENCY = "py-evm==0.3.0a20"
PYEVM_DEPENDENCY = "py-evm==0.4.0a3"


deps = {
Expand Down
28 changes: 15 additions & 13 deletions tests/components/tx_pool/test_default_transaction_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
@pytest.mark.parametrize(
(
'initial_block_number',
'expected_initial_tx_class',
'expected_outdated_tx_class',
'expected_future_tx_class',
'expected_initial_tx_builder',
'expected_outdated_tx_builder',
'expected_future_tx_builder',
),
[
(1, FrontierTransaction, None, SpuriousDragonTransaction,),
Expand All @@ -34,10 +34,12 @@
(None, SpuriousDragonTransaction, HomesteadTransaction, SpuriousDragonTransaction,),
],
)
def test_tx_class_resolution(initial_block_number,
expected_initial_tx_class,
expected_outdated_tx_class,
expected_future_tx_class):
def test_tx_builder_resolution(
initial_block_number,
expected_initial_tx_builder,
expected_outdated_tx_builder,
expected_future_tx_builder):

chain = api.build(
MiningChain,
api.frontier_at(0),
Expand All @@ -47,17 +49,17 @@ def test_tx_class_resolution(initial_block_number,
api.genesis
)
validator = DefaultTransactionValidator(chain, initial_block_number)
assert validator.get_appropriate_tx_class() == expected_initial_tx_class
assert validator.get_appropriate_tx_builder() == expected_initial_tx_builder

if expected_outdated_tx_class is not None:
assert validator.is_outdated_tx_class(expected_outdated_tx_class)
if expected_outdated_tx_builder is not None:
assert validator.is_outdated_tx_builder(expected_outdated_tx_builder)

# The `get_appropriate_tx_class` method has a cache decorator applied
# The `get_appropriate_tx_builder` method has a cache decorator applied
# To test it properly, we need to clear the cache
validator.get_appropriate_tx_class.cache_clear()
validator.get_appropriate_tx_builder.cache_clear()

# Check that the validator uses the correct tx class when we have reached the tip of the chain
for _ in range(10):
chain.mine_block()

assert validator.get_appropriate_tx_class() == expected_future_tx_class
assert validator.get_appropriate_tx_builder() == expected_future_tx_builder
12 changes: 7 additions & 5 deletions tests/core/p2p-proto/test_block_bodies_request_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

from eth.db.trie import make_trie_root_and_nodes
from eth.rlp.headers import BlockHeader
from eth.rlp.transactions import BaseTransactionFields

from trinity.rlp.block_body import BlockBody
from trinity.protocol.eth.validators import GetBlockBodiesValidator
from trinity.tools.factories.transactions import LegacyTransactionFactory


def mk_uncle(block_number):
Expand All @@ -33,16 +33,18 @@ def mk_uncle(block_number):


def mk_transaction():
return BaseTransactionFields(
return LegacyTransactionFactory(
nonce=0,
gas=21000,
gas_price=1,
to=os.urandom(20),
value=random.randint(0, 100),
data=b'',
v=27,
r=big_endian_to_int(os.urandom(32)),
s=big_endian_to_int(os.urandom(32)),
vrs=(
27,
big_endian_to_int(os.urandom(32)),
big_endian_to_int(os.urandom(32)),
),
)


Expand Down
11 changes: 7 additions & 4 deletions tests/core/p2p-proto/test_eth_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
BlockBodyFactory,
BlockHashFactory,
BlockHeaderFactory,
ReceiptFactory,
SerializedTransactionFactory,
UninterpretedReceiptFactory,
UninterpretedTransactionFactory,
)
from trinity.tools.factories.common import (
BlockHeadersQueryFactory,
Expand All @@ -43,7 +43,7 @@
(StatusV63, StatusV63PayloadFactory()),
(Status, StatusPayloadFactory()),
(NewBlockHashes, tuple(NewBlockHashFactory.create_batch(2))),
(Transactions, tuple(SerializedTransactionFactory.create_batch(2))),
(Transactions, tuple(UninterpretedTransactionFactory.create_batch(2))),
(GetBlockHeadersV65, BlockHeadersQueryFactory()),
(GetBlockHeadersV65, BlockHeadersQueryFactory(block_number_or_hash=BlockHashFactory())),
(BlockHeadersV65, tuple(BlockHeaderFactory.create_batch(2))),
Expand All @@ -55,7 +55,10 @@
(GetReceiptsV65, tuple(BlockHashFactory.create_batch(2))),
(
ReceiptsV65,
(tuple(ReceiptFactory.create_batch(2)), tuple(ReceiptFactory.create_batch(3)))
(
tuple(UninterpretedReceiptFactory.create_batch(2)),
tuple(UninterpretedReceiptFactory.create_batch(3)),
)
),
),
)
Expand Down
30 changes: 23 additions & 7 deletions tests/core/p2p-proto/test_forkid.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@

def test_extract_fork_blocks():
fork_blocks = extract_fork_blocks(MAINNET_VM_CONFIGURATION)
assert fork_blocks == (1150000, 1920000, 2463000, 2675000, 4370000, 7280000, 9069000, 9200000)
assert fork_blocks == (
1150000,
1920000,
2463000,
2675000,
4370000,
7280000,
9069000,
9200000,
12244000,
)


@pytest.mark.parametrize(
Expand All @@ -56,8 +66,12 @@ def test_extract_fork_blocks():
(9069000, ForkID(hash=to_bytes(hexstr='0x879d6e30'), next=9200000)),
# Last Istanbul and first Muir Glacier block
(9199999, ForkID(hash=to_bytes(hexstr='0x879d6e30'), next=9200000)),
(9200000, ForkID(hash=to_bytes(hexstr='0xe029e991'), next=0)), # First Muir Glacier block
(10000000, ForkID(hash=to_bytes(hexstr='0xe029e991'), next=0)), # Future Muir Glacier block
# First Muir Glacier block
(9200000, ForkID(hash=to_bytes(hexstr='0xe029e991'), next=12244000)),
# Last Muir Glacier block
(12244000 - 1, ForkID(hash=to_bytes(hexstr='0xe029e991'), next=12244000)),
(12244000, ForkID(hash=to_bytes(hexstr='0xeb440f6'), next=0)), # First Berlin
(20000000, ForkID(hash=to_bytes(hexstr='0xeb440f6'), next=0)), # Future Berlin
]
)
def test_mainnet_forkids(head, expected_forkid):
Expand All @@ -80,8 +94,10 @@ def test_mainnet_forkids(head, expected_forkid):
(6485845, ForkID(hash=to_bytes(hexstr='0xd6e2149b'), next=6485846)), # Last Petersburg
(6485846, ForkID(hash=to_bytes(hexstr='0x4bc66396'), next=7117117)), # First Istanbul
(7117116, ForkID(hash=to_bytes(hexstr='0x4bc66396'), next=7117117)), # Last Istanbul block
(7117117, ForkID(hash=to_bytes(hexstr='0x6727ef90'), next=0)), # First Muir Glacier block
(7500000, ForkID(hash=to_bytes(hexstr='0x6727ef90'), next=0)), # Future
(7117117, ForkID(hash=to_bytes(hexstr='0x6727ef90'), next=9812189)), # First Muir Glacier
(9812188, ForkID(hash=to_bytes(hexstr='0x6727ef90'), next=9812189)), # Last Muir Glacier
(9812189, ForkID(hash=to_bytes(hexstr='0xa157d377'), next=0)), # First Berlin
(10000000, ForkID(hash=to_bytes(hexstr='0xa157d377'), next=0)), # Future Berlin
]
)
def test_ropsten_forkids(head, expected_forkid):
Expand Down Expand Up @@ -170,13 +186,13 @@ def test_forkid():
ForkID(hash=to_bytes(hexstr='0xafec6b27'), next=0),
LocalChainIncompatibleOrStale),
# Local is mainnet Muir Glacier, far in the future. Remote announces Gopherium (non
# Local is mainnet Berlin, far in the future. Remote announces Gopherium (non
# existing fork) at some future block 88888888, for itself, but past block for local.
# Local is incompatible.
#
# This case detects non-upgraded nodes with majority hash power (typical Ropsten mess).
(88888888,
ForkID(hash=to_bytes(hexstr='0xe029e991'), next=88888888),
ForkID(hash=to_bytes(hexstr='0xeb440f6'), next=88888888),
LocalChainIncompatibleOrStale),
# Local is mainnet Byzantium. Remote is also in Byzantium, but announces Gopherium (non
Expand Down
18 changes: 16 additions & 2 deletions tests/core/p2p-proto/test_peer_block_body_validator_api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import asyncio
import os
import random
import time

import pytest

import rlp

from eth_utils import (
big_endian_to_int,
keccak,
to_tuple,
)
Expand All @@ -17,7 +19,7 @@
from trinity.rlp.block_body import BlockBody

from trinity.tools.factories import LatestETHPeerPairFactory
from trinity.tools.factories.transactions import SerializedTransactionFactory
from trinity.tools.factories.transactions import LegacyTransactionFactory


def mk_uncle(block_number):
Expand All @@ -31,7 +33,19 @@ def mk_uncle(block_number):


def mk_transaction():
return SerializedTransactionFactory()
return LegacyTransactionFactory(
nonce=0,
gas=21000,
gas_price=1,
to=os.urandom(20),
value=random.randint(0, 100),
data=b'',
vrs=(
27,
big_endian_to_int(os.urandom(32)),
big_endian_to_int(os.urandom(32)),
),
)


def mk_header_and_body(block_number, num_transactions, num_uncles):
Expand Down
17 changes: 13 additions & 4 deletions tests/core/p2p-proto/test_peer_receipts_validator_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import pytest

from eth_utils import to_tuple
from eth_utils.toolz import compose

from eth.db.trie import make_trie_root_and_nodes
from eth.rlp.headers import BlockHeader
from eth.rlp.receipts import Receipt

from trinity.rlp.sedes import strip_interpretation
from trinity.tools.factories import LatestETHPeerPairFactory


Expand Down Expand Up @@ -49,13 +51,20 @@ def mk_headers(*counts):
yield mk_header_and_receipts(idx, num_receipts)


def bundle_receipts(receipts, trie_roots_and_data):
return tuple(zip(
tuple(map(compose(tuple, strip_interpretation), receipts)),
trie_roots_and_data,
))


@pytest.mark.asyncio
async def test_eth_peer_get_receipts_round_trip_with_full_response(eth_peer_and_remote):
peer, remote = eth_peer_and_remote

headers_bundle = mk_headers(1, 3, 2, 5, 4)
headers, receipts, trie_roots_and_data = zip(*headers_bundle)
receipts_bundle = tuple(zip(receipts, trie_roots_and_data))
receipts_bundle = bundle_receipts(receipts, trie_roots_and_data)

async def send_receipts():
remote.eth_api.send_receipts(receipts)
Expand All @@ -76,7 +85,7 @@ async def test_eth_peer_get_receipts_round_trip_with_partial_response(eth_peer_a

headers_bundle = mk_headers(1, 3, 2, 5, 4)
headers, receipts, trie_roots_and_data = zip(*headers_bundle)
receipts_bundle = tuple(zip(receipts, trie_roots_and_data))
receipts_bundle = bundle_receipts(receipts, trie_roots_and_data)

async def send_receipts():
remote.eth_api.send_receipts((receipts[2], receipts[1], receipts[4]))
Expand All @@ -97,7 +106,7 @@ async def test_eth_peer_get_receipts_round_trip_with_noise(eth_peer_and_remote):

headers_bundle = mk_headers(1, 3, 2, 5, 4)
headers, receipts, trie_roots_and_data = zip(*headers_bundle)
receipts_bundle = tuple(zip(receipts, trie_roots_and_data))
receipts_bundle = bundle_receipts(receipts, trie_roots_and_data)

async def send_receipts():
remote.eth_api.send_transactions([])
Expand All @@ -122,7 +131,7 @@ async def test_eth_peer_get_receipts_round_trip_no_match_invalid_response(eth_pe

headers_bundle = mk_headers(1, 3, 2, 5, 4)
headers, receipts, trie_roots_and_data = zip(*headers_bundle)
receipts_bundle = tuple(zip(receipts, trie_roots_and_data))
receipts_bundle = bundle_receipts(receipts, trie_roots_and_data)

wrong_headers = mk_headers(4, 3, 8)
_, wrong_receipts, _ = zip(*wrong_headers)
Expand Down
10 changes: 8 additions & 2 deletions tests/core/p2p-proto/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from async_service import background_asyncio_service
from eth import MainnetChain
from eth_utils import decode_hex

from p2p.exceptions import PeerConnectionLost
Expand Down Expand Up @@ -81,6 +82,7 @@ async def test_proxy_peer_requests(request,
await stack.enter_async_context(background_asyncio_service(ETHRequestServer(
server_event_bus,
TO_NETWORKING_BROADCAST_CONFIG,
MainnetChain.vm_configuration,
AsyncChainDB(base_db),
)))
await stack.enter_async_context(background_asyncio_service(WitRequestServer(
Expand Down Expand Up @@ -200,7 +202,7 @@ async def test_proxy_peer_requests_with_timeouts(request,
# We just want an ETHRequestServer that doesn't answer us but we still have to run
# *something* to at least subscribe to the events. Otherwise Lahja's safety check will yell
# at us for sending requests into the void.
for event_type in ETHRequestServer(None, None, None)._subscribed_events:
for event_type in ETHRequestServer(None, None, (), None)._subscribed_events:
server_event_bus.subscribe(event_type, lambda _: None)

client_proxy_peer_pool = ETHProxyPeerPool(client_event_bus, TO_NETWORKING_BROADCAST_CONFIG)
Expand Down Expand Up @@ -250,6 +252,7 @@ async def test_requests_when_peer_in_client_vanishs(request,
await stack.enter_async_context(background_asyncio_service(ETHRequestServer(
server_event_bus,
TO_NETWORKING_BROADCAST_CONFIG,
MainnetChain.vm_configuration,
AsyncChainDB(chaindb_20.db)
)))
client_proxy_peer_pool = ETHProxyPeerPool(client_event_bus, TO_NETWORKING_BROADCAST_CONFIG)
Expand Down Expand Up @@ -304,7 +307,10 @@ async def test_no_duplicate_node_data(request, event_loop, event_bus, chaindb_fr
async with run_peer_pool_event_server(
event_bus, server_peer_pool, handler_type=ETHPeerPoolEventServer
), background_asyncio_service(ETHRequestServer(
event_bus, TO_NETWORKING_BROADCAST_CONFIG, AsyncChainDB(chaindb_20.db)
event_bus,
TO_NETWORKING_BROADCAST_CONFIG,
MainnetChain.vm_configuration,
AsyncChainDB(chaindb_20.db),
)):
root_hash = chaindb_20.get_canonical_head().state_root
state_root = chaindb_20.db[root_hash]
Expand Down

0 comments on commit ee15a20

Please sign in to comment.