Skip to content

Commit 428395b

Browse files
committed
drop py2 support, use pyrlp 1.0, switch travis to py3
1 parent c8b6205 commit 428395b

18 files changed

+222
-163
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: python
2-
python: 2.7
2+
python: 3.6
33
sudo: required
44
dist: trusty
55
env:

dev_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bitcoin
22
coveralls
3+
https://github.com/ethereum/vyper/tarball/master
34
ethereum-serpent
45
py-ecc
56
pytest-timeout==1.0.0

ethereum/block.py

+38-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import rlp
2-
from ethereum.utils import normalize_address, hash32, trie_root, \
3-
big_endian_int, address, int256, encode_hex, decode_hex, encode_int, sha3
2+
from ethereum.utils import (
3+
normalize_address, hash32, trie_root, big_endian_int, address, int256,
4+
encode_hex, decode_hex, encode_int, sha3
5+
)
46
from rlp.sedes import big_endian_int, Binary, binary, CountableList
57
from ethereum import utils
68
from ethereum import trie
@@ -78,11 +80,11 @@ def __init__(self,
7880
gas_limit=default_config['GENESIS_GAS_LIMIT'],
7981
gas_used=0,
8082
timestamp=0,
81-
extra_data='',
83+
extra_data=b'',
8284
mixhash=default_config['GENESIS_MIXHASH'],
83-
nonce=''):
85+
nonce=b''):
8486
# at the beginning of a method, locals() is a dict of all arguments
85-
fields = {k: v for k, v in locals().items() if k != 'self'}
87+
fields = {k: v for k, v in locals().items() if k not in ['self', '__class__']}
8688
if len(fields['coinbase']) == 40:
8789
fields['coinbase'] = decode_hex(fields['coinbase'])
8890
assert len(fields['coinbase']) == 20
@@ -100,13 +102,37 @@ def hex_hash(self):
100102

101103
@property
102104
def mining_hash(self):
105+
106+
# exclude mixhash and nonce
107+
fields2 = [
108+
(field, sedes) for field, sedes in BlockHeader._meta.fields
109+
if field not in ["mixhash", "nonce"]
110+
]
111+
112+
class BlockHeader2(rlp.Serializable):
113+
fields = fields2
114+
115+
_self = BlockHeader2(**{f:getattr(self, f) for (f, sedes) in fields2})
116+
103117
return utils.sha3(rlp.encode(
104-
self, BlockHeader.exclude(['mixhash', 'nonce'])))
118+
_self, BlockHeader2))
105119

106120
@property
107121
def signing_hash(self):
122+
123+
# exclude extra_data
124+
fields3 = [
125+
(field, sedes) for field, sedes in BlockHeader._meta.fields
126+
if field not in ["extra_data"]
127+
]
128+
129+
class BlockHeader3(rlp.Serializable):
130+
fields = fields3
131+
132+
_self = BlockHeader3(**{f:getattr(self, f) for (f, sedes) in fields3})
133+
108134
return utils.sha3(rlp.encode(
109-
self, BlockHeader.exclude(['extra_data'])))
135+
_self, BlockHeader3))
110136

111137
def to_dict(self):
112138
"""Serialize the header to a readable dictionary."""
@@ -169,10 +195,11 @@ def __init__(self, header, transactions=None, uncles=None, db=None):
169195
# assert isinstance(db, BaseDB), "No database object given"
170196
# self.db = db
171197

172-
self.header = header
173-
self.transactions = transactions or []
174-
self.uncles = uncles or []
175-
self.uncles = list(self.uncles)
198+
super(Block, self).__init__(
199+
header=header,
200+
transactions=(transactions or []),
201+
uncles=list(uncles or []),
202+
)
176203

177204
def __getattribute__(self, name):
178205
try:

ethereum/common.py

+31-19
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,23 @@ def calc_difficulty(parent, timestamp, config=default_config):
6767

6868
# Given a parent state, initialize a block with the given arguments
6969
def mk_block_from_prevstate(chain, state=None, timestamp=None,
70-
coinbase=b'\x35' * 20, extra_data='moo ha ha says the laughing cow.'):
70+
coinbase=b'\x35' * 20, extra_data=b'moo ha ha says the laughing cow.'):
7171
state = state or chain.state
72-
blk = Block(BlockHeader())
7372
now = timestamp or chain.time()
74-
blk.header.number = state.prev_headers[0].number + 1
75-
blk.header.difficulty = calc_difficulty(
76-
state.prev_headers[0], now, chain.config)
77-
blk.header.gas_limit = calc_gaslimit(state.prev_headers[0], chain.config)
78-
blk.header.timestamp = max(now, state.prev_headers[0].timestamp + 1)
79-
blk.header.prevhash = state.prev_headers[0].hash
80-
blk.header.coinbase = coinbase
81-
blk.header.extra_data = extra_data
82-
blk.header.bloom = 0
83-
blk.transactions = []
73+
74+
blk = Block(
75+
header=BlockHeader(
76+
number = state.prev_headers[0].number + 1,
77+
difficulty = calc_difficulty(state.prev_headers[0], now, chain.config),
78+
gas_limit = calc_gaslimit(state.prev_headers[0], chain.config),
79+
timestamp = max(now, state.prev_headers[0].timestamp + 1),
80+
prevhash = state.prev_headers[0].hash,
81+
coinbase = coinbase,
82+
extra_data = extra_data,
83+
bloom = 0
84+
),
85+
transactions=[]
86+
)
8487
return blk
8588

8689

@@ -122,7 +125,7 @@ def validate_header(state, header):
122125
# Add transactions
123126
def add_transactions(state, block, txqueue, min_gasprice=0):
124127
if not txqueue:
125-
return
128+
return block
126129
pre_txs = len(block.transactions)
127130
log.info('Adding transactions, %d in txqueue, %d dunkles' %
128131
(len(txqueue.txs), pre_txs))
@@ -133,12 +136,15 @@ def add_transactions(state, block, txqueue, min_gasprice=0):
133136
break
134137
try:
135138
apply_transaction(state, tx)
136-
block.transactions.append(tx)
139+
block = block.copy(
140+
transactions=block.transactions + (tx,)
141+
)
137142
except (InsufficientBalance, BlockGasLimitReached, InsufficientStartGas,
138143
InvalidNonce, UnsignedTransaction) as e:
139144
log.error(e)
140145
log.info('Added %d transactions' % (len(block.transactions) - pre_txs))
141146

147+
return block
142148

143149
# Validate that the transaction list root is correct
144150
def validate_transaction_tree(state, block):
@@ -151,13 +157,19 @@ def validate_transaction_tree(state, block):
151157

152158
# Set state root, receipt root, etc
153159
def set_execution_results(state, block):
154-
block.header.receipts_root = mk_receipt_sha(state.receipts)
155-
block.header.tx_list_root = mk_transaction_sha(block.transactions)
156160
state.commit()
157-
block.header.state_root = state.trie.root_hash
158-
block.header.gas_used = state.gas_used
159-
block.header.bloom = state.bloom
161+
162+
block = block.copy(
163+
header = block.header.copy(
164+
receipts_root = mk_receipt_sha(state.receipts),
165+
tx_list_root = mk_transaction_sha(block.transactions),
166+
state_root = state.trie.root_hash,
167+
gas_used = state.gas_used,
168+
bloom = state.bloom
169+
)
170+
)
160171
log.info('Block pre-sealed, %d gas used' % state.gas_used)
172+
return block
161173

162174

163175
# Verify state root, receipt root, etc

ethereum/hybrid_casper/casper_initiating_transactions.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import pkg_resources
2-
from viper import compiler
2+
from vyper import compiler
33
from ethereum.transactions import Transaction
44
from ethereum.abi import ContractTranslator
55
import rlp
6+
from ethereum.utils import decode_hex
67

78
gasprice = 25 * 10**9
89

9-
viper_rlp_decoder_tx = rlp.hex_decode("0xf90237808506fc23ac00830330888080b902246102128061000e60003961022056600060007f010000000000000000000000000000000000000000000000000000000000000060003504600060c082121515585760f882121561004d5760bf820336141558576001905061006e565b600181013560f783036020035260005160f6830301361415585760f6820390505b5b368112156101c2577f010000000000000000000000000000000000000000000000000000000000000081350483602086026040015260018501945060808112156100d55760018461044001526001828561046001376001820191506021840193506101bc565b60b881121561014357608081038461044001526080810360018301856104600137608181141561012e5760807f010000000000000000000000000000000000000000000000000000000000000060018401350412151558575b607f81038201915060608103840193506101bb565b60c08112156101b857600182013560b782036020035260005160388112157f010000000000000000000000000000000000000000000000000000000000000060018501350402155857808561044001528060b6838501038661046001378060b6830301830192506020810185019450506101ba565bfe5b5b5b5061006f565b601f841315155857602060208502016020810391505b6000821215156101fc578082604001510182826104400301526020820391506101d8565b808401610420528381018161044003f350505050505b6000f31b2d4f", Transaction) # noqa: E501
10+
viper_rlp_decoder_tx = decode_hex("0xf90237808506fc23ac00830330888080b902246102128061000e60003961022056600060007f010000000000000000000000000000000000000000000000000000000000000060003504600060c082121515585760f882121561004d5760bf820336141558576001905061006e565b600181013560f783036020035260005160f6830301361415585760f6820390505b5b368112156101c2577f010000000000000000000000000000000000000000000000000000000000000081350483602086026040015260018501945060808112156100d55760018461044001526001828561046001376001820191506021840193506101bc565b60b881121561014357608081038461044001526080810360018301856104600137608181141561012e5760807f010000000000000000000000000000000000000000000000000000000000000060018401350412151558575b607f81038201915060608103840193506101bb565b60c08112156101b857600182013560b782036020035260005160388112157f010000000000000000000000000000000000000000000000000000000000000060018501350402155857808561044001528060b6838501038661046001378060b6830301830192506020810185019450506101ba565bfe5b5b5b5061006f565b601f841315155857602060208502016020810391505b6000821215156101fc578082604001510182826104400301526020820391506101d8565b808401610420528381018161044003f350505050505b6000f31b2d4f", Transaction) # noqa: E501
1011

11-
sig_hasher_tx = rlp.hex_decode("0xf9016d808506fc23ac0083026a508080b9015a6101488061000e6000396101565660007f01000000000000000000000000000000000000000000000000000000000000006000350460f8811215610038576001915061003f565b60f6810391505b508060005b368312156100c8577f01000000000000000000000000000000000000000000000000000000000000008335048391506080811215610087576001840193506100c2565b60b881121561009d57607f8103840193506100c1565b60c08112156100c05760b68103600185013560b783036020035260005101840193505b5b5b50610044565b81810360388112156100f4578060c00160005380836001378060010160002060e052602060e0f3610143565b61010081121561010557600161011b565b6201000081121561011757600261011a565b60035b5b8160005280601f038160f701815382856020378282600101018120610140526020610140f350505b505050505b6000f31b2d4f", Transaction) # noqa: E501
12+
sig_hasher_tx = decode_hex("0xf9016d808506fc23ac0083026a508080b9015a6101488061000e6000396101565660007f01000000000000000000000000000000000000000000000000000000000000006000350460f8811215610038576001915061003f565b60f6810391505b508060005b368312156100c8577f01000000000000000000000000000000000000000000000000000000000000008335048391506080811215610087576001840193506100c2565b60b881121561009d57607f8103840193506100c1565b60c08112156100c05760b68103600185013560b783036020035260005101840193505b5b5b50610044565b81810360388112156100f4578060c00160005380836001378060010160002060e052602060e0f3610143565b61010081121561010557600161011b565b6201000081121561011757600261011a565b60035b5b8160005280601f038160f701815382856020378282600101018120610140526020610140f350505b505050505b6000f31b2d4f", Transaction) # noqa: E501
1213

13-
purity_checker_tx = rlp.hex_decode("0xf90467808506fc23ac00830583c88080b904546104428061000e60003961045056600061033f537c0100000000000000000000000000000000000000000000000000000000600035047f80010000000000000000000000000000000000000030ffff1c0e00000000000060205263a1903eab8114156103f7573659905901600090523660048237600435608052506080513b806020015990590160009052818152602081019050905060a0526080513b600060a0516080513c6080513b8060200260200159905901600090528181526020810190509050610100526080513b806020026020015990590160009052818152602081019050905061016052600060005b602060a05103518212156103c957610100601f8360a051010351066020518160020a161561010a57fe5b80606013151561011e57607f811315610121565b60005b1561014f5780607f036101000a60018460a0510101510482602002610160510152605e8103830192506103b2565b60f18114801561015f5780610164565b60f282145b905080156101725780610177565b60f482145b9050156103aa5760028212151561019e5760606001830360200261010051015112156101a1565b60005b156101bc57607f6001830360200261010051015113156101bf565b60005b156101d157600282036102605261031e565b6004821215156101f057600360018303602002610100510151146101f3565b60005b1561020d57605a6002830360200261010051015114610210565b60005b1561022b57606060038303602002610100510151121561022e565b60005b1561024957607f60038303602002610100510151131561024c565b60005b1561025e57600482036102605261031d565b60028212151561027d57605a6001830360200261010051015114610280565b60005b1561029257600282036102605261031c565b6002821215156102b157609060018303602002610100510151146102b4565b60005b156102c657600282036102605261031b565b6002821215156102e65760806001830360200261010051015112156102e9565b60005b156103035760906001830360200261010051015112610306565b60005b1561031857600282036102605261031a565bfe5b5b5b5b5b604060405990590160009052600081526102605160200261016051015181602001528090502054156103555760016102a052610393565b60306102605160200261010051015114156103755760016102a052610392565b60606102605160200261010051015114156103915760016102a0525b5b5b6102a051151561039f57fe5b6001830192506103b1565b6001830192505b5b8082602002610100510152600182019150506100e0565b50506001604060405990590160009052600081526080518160200152809050205560016102e05260206102e0f35b63c23697a8811415610440573659905901600090523660048237600435608052506040604059905901600090526000815260805181602001528090502054610300526020610300f35b505b6000f31b2d4f", Transaction) # noqa: E501
14+
purity_checker_tx = decode_hex("0xf90467808506fc23ac00830583c88080b904546104428061000e60003961045056600061033f537c0100000000000000000000000000000000000000000000000000000000600035047f80010000000000000000000000000000000000000030ffff1c0e00000000000060205263a1903eab8114156103f7573659905901600090523660048237600435608052506080513b806020015990590160009052818152602081019050905060a0526080513b600060a0516080513c6080513b8060200260200159905901600090528181526020810190509050610100526080513b806020026020015990590160009052818152602081019050905061016052600060005b602060a05103518212156103c957610100601f8360a051010351066020518160020a161561010a57fe5b80606013151561011e57607f811315610121565b60005b1561014f5780607f036101000a60018460a0510101510482602002610160510152605e8103830192506103b2565b60f18114801561015f5780610164565b60f282145b905080156101725780610177565b60f482145b9050156103aa5760028212151561019e5760606001830360200261010051015112156101a1565b60005b156101bc57607f6001830360200261010051015113156101bf565b60005b156101d157600282036102605261031e565b6004821215156101f057600360018303602002610100510151146101f3565b60005b1561020d57605a6002830360200261010051015114610210565b60005b1561022b57606060038303602002610100510151121561022e565b60005b1561024957607f60038303602002610100510151131561024c565b60005b1561025e57600482036102605261031d565b60028212151561027d57605a6001830360200261010051015114610280565b60005b1561029257600282036102605261031c565b6002821215156102b157609060018303602002610100510151146102b4565b60005b156102c657600282036102605261031b565b6002821215156102e65760806001830360200261010051015112156102e9565b60005b156103035760906001830360200261010051015112610306565b60005b1561031857600282036102605261031a565bfe5b5b5b5b5b604060405990590160009052600081526102605160200261016051015181602001528090502054156103555760016102a052610393565b60306102605160200261010051015114156103755760016102a052610392565b60606102605160200261010051015114156103915760016102a0525b5b5b6102a051151561039f57fe5b6001830192506103b1565b6001830192505b5b8082602002610100510152600182019150506100e0565b50506001604060405990590160009052600081526080518160200152809050205560016102e05260206102e0f35b63c23697a8811415610440573659905901600090523660048237600435608052506040604059905901600090526000815260805181602001528090502054610300526020610300f35b505b6000f31b2d4f", Transaction) # noqa: E501
1415

1516
purity_checker_address = purity_checker_tx.creates
1617
purity_checker_abi = [{'name': 'check(address)', 'type': 'function', 'constant': True, 'inputs': [{'name': 'addr', 'type': 'address'}], 'outputs': [{'name': 'out', 'type': 'bool'}]}, {'name': 'submit(address)', 'type': 'function', 'constant': False, 'inputs': [{'name': 'addr', 'type': 'address'}], 'outputs': [{'name': 'out', 'type': 'bool'}]}] # noqa: E501

ethereum/hybrid_casper/casper_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ethereum.hybrid_casper import consensus
88
from ethereum.messages import apply_transaction
99
from ethereum.tools.tester import a0
10-
from viper import compiler
10+
from vyper import compiler
1111
import serpent
1212
import rlp
1313

ethereum/messages.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,25 @@ class Receipt(rlp.Serializable):
8989
('logs', CountableList(Log))
9090
]
9191

92-
def __init__(self, state_root, gas_used, logs, bloom=None):
93-
# does not call super.__init__ as bloom should not be an attribute but
94-
# a property
95-
self.state_root = state_root
96-
self.gas_used = gas_used
97-
self.logs = logs
98-
if bloom is not None and bloom != self.bloom:
99-
raise ValueError("Invalid bloom filter")
100-
self._cached_rlp = None
101-
self._mutable = True
102-
10392
@property
10493
def bloom(self):
10594
bloomables = [x.bloomables() for x in self.logs]
10695
return bloom.bloom_from_list(utils.flatten(bloomables))
10796

10897

10998
def mk_receipt(state, success, logs):
99+
bloomables = [x.bloomables() for x in logs]
100+
ret_bloom = bloom.bloom_from_list(utils.flatten(bloomables))
101+
110102
if state.is_METROPOLIS():
111-
o = Receipt(b'\x01' if success else b'', state.gas_used, logs)
112-
return o
103+
ret = Receipt(
104+
state_root=(b'\x01' if success else b''),
105+
gas_used=state.gas_used,
106+
bloom=ret_bloom,
107+
logs=logs)
108+
return ret
113109
else:
114-
return Receipt(state.trie.root_hash, state.gas_used, logs)
110+
return Receipt(state.trie.root_hash, state.gas_used, ret_bloom, logs)
115111

116112

117113
def config_fork_specific_validation(config, blknum, tx):

ethereum/meta.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def make_head_candidate(chain, txqueue=None,
4545
parent=None,
4646
timestamp=None,
4747
coinbase=b'\x35' * 20,
48-
extra_data='moo ha ha says the laughing cow.',
48+
extra_data=b'moo ha ha says the laughing cow.',
4949
min_gasprice=0):
5050
log.debug('Creating head candidate')
5151
if parent is None:
@@ -64,15 +64,19 @@ def make_head_candidate(chain, txqueue=None,
6464
coinbase,
6565
extra_data)
6666
# Find and set the uncles
67-
blk.uncles = cs.get_uncles(chain, temp_state)
68-
blk.header.uncles_hash = sha3(rlp.encode(blk.uncles))
67+
blk = blk.copy(
68+
uncles = cs.get_uncles(chain, temp_state)
69+
)
70+
blk = blk.copy(header = blk.header.copy(
71+
uncles_hash = sha3(rlp.encode(blk.uncles))
72+
))
6973
# Call the initialize state transition function
7074
cs.initialize(temp_state, blk)
7175
# Add transactions
72-
add_transactions(temp_state, blk, txqueue, min_gasprice)
76+
blk = add_transactions(temp_state, blk, txqueue, min_gasprice)
7377
# Call the finalize state transition function
7478
cs.finalize(temp_state, blk)
7579
# Set state root, receipt root, etc
76-
set_execution_results(temp_state, blk)
80+
blk = set_execution_results(temp_state, blk)
7781
log.debug('Created head candidate successfully')
7882
return blk, temp_state

ethereum/pow/ethpow.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ def mine(self, rounds=1000, start_nonce=0):
106106
blk = self.block
107107
bin_nonce, mixhash = mine(blk.number, blk.difficulty, blk.mining_hash,
108108
start_nonce=start_nonce, rounds=rounds)
109-
if bin_nonce:
110-
blk.header.mixhash = mixhash
111-
blk.header.nonce = bin_nonce
112-
# assert blk.check_pow()
113-
return blk
109+
if bin_nonce is not None:
110+
return bin_nonce, mixhash
111+
112+
return None, None
113+
114114

115115

116116
def mine(block_number, difficulty, mining_hash, start_nonce=0, rounds=1000):

ethereum/slogging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def _stringify_dict_keys(input_):
266266
res = {}
267267
for k, v in input_.items():
268268
v = _stringify_dict_keys(v)
269-
if not isinstance(k, (int, long, bool, None.__class__)):
269+
if not isinstance(k, (int, bool, None.__class__)):
270270
k = str(k)
271271
res[k] = v
272272
elif isinstance(input_, (list, tuple)):

0 commit comments

Comments
 (0)