Skip to content

Commit 946c4ab

Browse files
committed
Undoing the mixup between Chain ID and Network ID
- There were validations in place, remove them - Stop returning the network id instead of the chain ID - Always return chain id is None until a new method is added to the json-rpc suite
1 parent 4ada39f commit 946c4ab

File tree

6 files changed

+22
-30
lines changed

6 files changed

+22
-30
lines changed

docs/web3.net.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ The following properties are available on the ``web3.net`` namespace.
1717

1818
.. py:method:: Net.chainId(self)
1919
20-
* Delegates to ``net_version`` RPC Method
20+
This method is not implemented. You must manually determine your chain ID for now.
2121

22-
Returns the current network chainId/version and is an alias of ``web3.net.version``.
22+
It will always return `None`, which is a valid chainId to specify in the transaction.
23+
It means the transaction (may be) replayable on other forks of the network.
2324

2425
.. code-block:: python
2526
2627
>>> web3.net.chainId
27-
1
28-
28+
None
2929
3030
.. py:method:: Net.version(self)
3131

tests/core/contracts/test_contract_buildTransaction.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_build_transaction_with_contract_no_arguments(web3, math_contract, build
3535
'data': '0xd09de08a',
3636
'value': 0,
3737
'gasPrice': 1,
38-
'chainId': 1
38+
'chainId': None,
3939
}
4040

4141

@@ -46,7 +46,7 @@ def test_build_transaction_with_contract_fallback_function(web3, fallback_functi
4646
'data': '0x',
4747
'value': 0,
4848
'gasPrice': 1,
49-
'chainId': 1
49+
'chainId': None,
5050
}
5151

5252

@@ -65,7 +65,7 @@ def test_build_transaction_with_contract_class_method(
6565
'data': '0xd09de08a',
6666
'value': 0,
6767
'gasPrice': 1,
68-
'chainId': 1
68+
'chainId': None,
6969
}
7070

7171

@@ -79,7 +79,7 @@ def test_build_transaction_with_contract_default_account_is_set(
7979
'data': '0xd09de08a',
8080
'value': 0,
8181
'gasPrice': 1,
82-
'chainId': 1
82+
'chainId': None,
8383
}
8484

8585

@@ -93,7 +93,7 @@ def my_gas_price_strategy(web3, transaction_params):
9393
'data': '0xd09de08a',
9494
'value': 0,
9595
'gasPrice': 5,
96-
'chainId': 1
96+
'chainId': None,
9797
}
9898

9999

@@ -121,31 +121,31 @@ def test_build_transaction_with_contract_to_address_supplied_errors(web3,
121121
(
122122
{}, (5,), {}, {
123123
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
124-
'value': 0, 'gasPrice': 1, 'chainId': 1
124+
'value': 0, 'gasPrice': 1, 'chainId': None,
125125
}, False
126126
),
127127
(
128128
{'gas': 800000}, (5,), {}, {
129129
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
130-
'value': 0, 'gasPrice': 1, 'chainId': 1
130+
'value': 0, 'gasPrice': 1, 'chainId': None,
131131
}, False
132132
),
133133
(
134134
{'gasPrice': 21000000000}, (5,), {}, {
135135
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
136-
'value': 0, 'gasPrice': 21000000000, 'chainId': 1
136+
'value': 0, 'gasPrice': 21000000000, 'chainId': None,
137137
}, False
138138
),
139139
(
140140
{'nonce': 7}, (5,), {}, {
141141
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
142-
'value': 0, 'gasPrice': 1, 'nonce': 7, 'chainId': 1
142+
'value': 0, 'gasPrice': 1, 'nonce': 7, 'chainId': None,
143143
}, True
144144
),
145145
(
146146
{'value': 20000}, (5,), {}, {
147147
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
148-
'value': 20000, 'gasPrice': 1, 'chainId': 1
148+
'value': 20000, 'gasPrice': 1, 'chainId': None,
149149
}, False
150150
),
151151
),

tests/core/eth-module/test_transactions.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@
1212
'make_chain_id, expect_success',
1313
(
1414
(
15-
lambda web3: web3.version.network,
15+
lambda web3: web3.net.chainId,
1616
True,
1717
),
18-
(
19-
lambda web3: int(web3.version.network),
20-
True,
21-
),
22-
(
23-
lambda web3: int(web3.version.network) + 1,
24-
False,
25-
),
26-
(
27-
lambda web3: str(int(web3.version.network) + 1),
18+
pytest.param(
19+
lambda web3: 999999999999,
2820
False,
21+
marks=pytest.mark.xfail,
2922
),
3023
),
3124
)

web3/middleware/validation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
@curry
1717
def validate_chain_id(web3, chain_id):
18-
if chain_id == web3.version.network:
18+
if chain_id is None:
1919
return None
2020
else:
2121
raise ValidationError(
2222
"The transaction declared chain ID %r, "
2323
"but the connected node is on %r" % (
2424
chain_id,
25-
web3.version.network,
25+
"UNKNOWN",
2626
)
2727
)
2828

@@ -33,7 +33,6 @@ def transaction_normalizer(transaction):
3333

3434
def validation_middleware(make_request, web3):
3535
transaction_validator = apply_formatters_to_dict({
36-
'chainId': validate_chain_id(web3),
3736
})
3837

3938
transaction_sanitizer = compose(transaction_normalizer, transaction_validator)

web3/net.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def peerCount(self):
1414

1515
@property
1616
def chainId(self):
17-
return self.version
17+
return None
1818

1919
@property
2020
def version(self):

web3/utils/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'data': b'',
2727
'gas': lambda web3, tx: web3.eth.estimateGas(tx),
2828
'gasPrice': lambda web3, tx: web3.eth.generateGasPrice(tx) or web3.eth.gasPrice,
29-
'chainId': lambda web3, tx: int(web3.net.version),
29+
'chainId': lambda web3, tx: web3.net.chainId,
3030
}
3131

3232

0 commit comments

Comments
 (0)