Skip to content

Commit 5db6e49

Browse files
committed
Global provider flag for CCIP Read renamed based discussion in pr #2503
1 parent 2c86f34 commit 5db6e49

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

docs/contracts.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ and forwarded to the contract function when applicable.
745745

746746
`EIP-3668 <https://eips.ethereum.org/EIPS/eip-3668>`_ introduced support for the ``OffchainLookup`` revert /
747747
CCIP Read support. CCIP Read is set to ``True`` for calls by default, as recommended in EIP-3668. This is done via a
748-
global ``ccip_read_calls_enabled`` flag on the provider. If raising the ``OffchainLookup`` revert is preferred for a
748+
global ``global_ccip_read_enabled`` flag on the provider. If raising the ``OffchainLookup`` revert is preferred for a
749749
specific call, the ``ccip_read_enabled`` flag on the call may be set to ``False``.
750750

751751
.. code-block:: python
@@ -758,14 +758,14 @@ Disabling CCIP Read support can be useful if a transaction needs to be sent to t
758758
"preflighting" with an ``eth_call``, handling the ``OffchainLookup``, and sending the data via a transaction may be
759759
necessary. See :ref:`ccip-read-example` in the examples section for how to preflight a transaction with a contract call.
760760

761-
Similarly, if CCIP Read is globally set to ``False`` via the ``ccip_read_calls_enabled`` flag on the provider, it may be
761+
Similarly, if CCIP Read is globally set to ``False`` via the ``global_ccip_read_enabled`` flag on the provider, it may be
762762
enabled on a per-call basis - overriding the global flag. This ensures only explicitly enabled calls will handle the
763763
``OffchainLookup`` revert appropriately.
764764

765765
.. code-block:: python
766766
767767
>>> # global flag set to `False`
768-
>>> w3.provider.ccip_read_calls_enabled = False
768+
>>> w3.provider.global_ccip_read_enabled = False
769769
770770
>>> # does not raise the revert since explicitly enabled on the call:
771771
>>> response = myContract.functions.revertsWithOffchainLookup(myData).call(ccip_read_enabled=True)

docs/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ CCIP Read support for offchain lookup
630630
-------------------------------------
631631

632632
Contract calls support CCIP Read by default, via a ``ccip_read_enabled`` flag on the call and, more globally, a
633-
``ccip_read_calls_enabled`` flag on the provider. The following should work by default without raising an
633+
``global_ccip_read_enabled`` flag on the provider. The following should work by default without raising an
634634
``OffchainLookup`` and instead handling it appropriately as per the specification outlined in
635635
`EIP-3668 <https://eips.ethereum.org/EIPS/eip-3668>`_.
636636

docs/web3.eth.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ The following methods are available on the ``web3.eth`` namespace.
10941094
Read support. In order to properly handle a call to a contract function that reverts with an ``OffchainLookup``
10951095
error for offchain data retrieval, the ``ccip_read_enabled`` flag has been added to the ``eth_call`` method.
10961096
``ccip_read_enabled`` is optional, yielding the default value for CCIP Read on calls to a global
1097-
``ccip_read_calls_enabled`` flag on the provider which is set to ``True`` by default. This means CCIP Read is
1097+
``global_ccip_read_enabled`` flag on the provider which is set to ``True`` by default. This means CCIP Read is
10981098
enabled by default for calls, as is recommended in EIP-3668. Therefore, calls to contract functions that revert with
10991099
an ``OffchainLookup`` will be handled appropriately by default.
11001100

newsfragments/2499.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add a global flag on the provider for enabling / disabling CCIP Read for calls: ``ccip_read_calls_enabled`` (defaults to ``True``).
1+
Add a global flag on the provider for enabling / disabling CCIP Read for calls: ``global_ccip_read_enabled`` (defaults to ``True``).

tests/core/contracts/test_offchain_lookup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(w3, offchain
8484
)
8585

8686
# test global flag on the provider
87-
w3.provider.ccip_read_calls_enabled = False
87+
w3.provider.global_ccip_read_enabled = False
8888

8989
with pytest.raises(OffchainLookup):
9090
offchain_lookup_contract.caller.testOffchainLookup(OFFCHAIN_LOOKUP_TEST_DATA)
@@ -94,7 +94,7 @@ def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(w3, offchain
9494
OFFCHAIN_LOOKUP_TEST_DATA
9595
)
9696

97-
w3.provider.ccip_read_calls_enabled = True # cleanup
97+
w3.provider.global_ccip_read_enabled = True # cleanup
9898

9999

100100
def test_offchain_lookup_call_flag_overrides_provider_flag(
@@ -107,14 +107,14 @@ def test_offchain_lookup_call_flag_overrides_provider_flag(
107107
mocked_json_data=WEB3PY_AS_HEXBYTES,
108108
)
109109

110-
w3.provider.ccip_read_calls_enabled = False
110+
w3.provider.global_ccip_read_enabled = False
111111

112112
response = offchain_lookup_contract.functions.testOffchainLookup(
113113
OFFCHAIN_LOOKUP_TEST_DATA
114114
).call(ccip_read_enabled=True)
115115
assert decode_abi(['string'], response)[0] == 'web3py'
116116

117-
w3.provider.ccip_read_calls_enabled = True
117+
w3.provider.global_ccip_read_enabled = True
118118

119119

120120
def test_offchain_lookup_raises_for_improperly_formatted_rest_request_response(

tests/core/web3-module/test_providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ def test_auto_provider_none():
2626

2727

2828
def test_provider_default_value_for_ccip_read_redirect(w3):
29-
assert w3.provider.ccip_read_calls_enabled
29+
assert w3.provider.global_ccip_read_enabled
3030
assert w3.provider.ccip_read_max_redirects == 4

web3/_utils/module_testing/eth_module.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,14 @@ async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(
802802
).call(ccip_read_enabled=False)
803803

804804
# test global flag on the provider
805-
async_w3.provider.ccip_read_calls_enabled = False
805+
async_w3.provider.global_ccip_read_enabled = False
806806

807807
with pytest.raises(OffchainLookup):
808808
await async_offchain_lookup_contract.functions.testOffchainLookup( # noqa: E501 type: ignore
809809
OFFCHAIN_LOOKUP_TEST_DATA
810810
).call()
811811

812-
async_w3.provider.ccip_read_calls_enabled = True # cleanup
812+
async_w3.provider.global_ccip_read_enabled = True # cleanup
813813

814814
@pytest.mark.asyncio
815815
async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
@@ -829,15 +829,15 @@ async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
829829
mocked_json_data=WEB3PY_AS_HEXBYTES,
830830
)
831831

832-
async_w3.provider.ccip_read_calls_enabled = False
832+
async_w3.provider.global_ccip_read_enabled = False
833833

834834
response = await async_offchain_lookup_contract.functions.testOffchainLookup(
835835
# noqa: E501 type: ignore
836836
OFFCHAIN_LOOKUP_TEST_DATA
837837
).call(ccip_read_enabled=True)
838838
assert async_w3.codec.decode_abi(['string'], response)[0] == 'web3py'
839839

840-
async_w3.provider.ccip_read_calls_enabled = True # cleanup
840+
async_w3.provider.global_ccip_read_enabled = True # cleanup
841841

842842
@pytest.mark.asyncio
843843
@pytest.mark.parametrize("max_redirects", range(-1, 4))
@@ -2552,12 +2552,12 @@ def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(
25522552
)
25532553

25542554
# test global flag on the provider
2555-
w3.provider.ccip_read_calls_enabled = False
2555+
w3.provider.global_ccip_read_enabled = False
25562556

25572557
with pytest.raises(OffchainLookup):
25582558
offchain_lookup_contract.functions.testOffchainLookup(OFFCHAIN_LOOKUP_TEST_DATA).call()
25592559

2560-
w3.provider.ccip_read_calls_enabled = True # cleanup
2560+
w3.provider.global_ccip_read_enabled = True # cleanup
25612561

25622562
def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
25632563
self,
@@ -2573,14 +2573,14 @@ def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
25732573
mocked_json_data=WEB3PY_AS_HEXBYTES,
25742574
)
25752575

2576-
w3.provider.ccip_read_calls_enabled = False
2576+
w3.provider.global_ccip_read_enabled = False
25772577

25782578
response = offchain_lookup_contract.functions.testOffchainLookup(
25792579
OFFCHAIN_LOOKUP_TEST_DATA
25802580
).call(ccip_read_enabled=True)
25812581
assert w3.codec.decode_abi(['string'], response)[0] == 'web3py'
25822582

2583-
w3.provider.ccip_read_calls_enabled = True # cleanup
2583+
w3.provider.global_ccip_read_enabled = True # cleanup
25842584

25852585
@pytest.mark.parametrize("max_redirects", range(-1, 4))
25862586
def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4(

web3/eth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ async def call(
415415
state_override: Optional[CallOverride] = None,
416416
ccip_read_enabled: Optional[bool] = None,
417417
) -> Union[bytes, bytearray]:
418-
ccip_read_enabled_on_provider = self.w3.provider.ccip_read_calls_enabled
418+
ccip_read_enabled_on_provider = self.w3.provider.global_ccip_read_enabled
419419
if (
420420
# default conditions:
421421
ccip_read_enabled_on_provider and ccip_read_enabled is not False
@@ -828,7 +828,7 @@ def call(
828828
state_override: Optional[CallOverride] = None,
829829
ccip_read_enabled: Optional[bool] = None,
830830
) -> Union[bytes, bytearray]:
831-
ccip_read_enabled_on_provider = self.w3.provider.ccip_read_calls_enabled
831+
ccip_read_enabled_on_provider = self.w3.provider.global_ccip_read_enabled
832832
if (
833833
# default conditions:
834834
ccip_read_enabled_on_provider and ccip_read_enabled is not False

web3/providers/async_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AsyncBaseProvider:
3636
# a tuple of (all_middlewares, request_func)
3737
_request_func_cache: Tuple[Tuple[Middleware, ...], Callable[..., RPCResponse]] = (None, None)
3838

39-
ccip_read_calls_enabled: bool = True
39+
global_ccip_read_enabled: bool = True
4040
ccip_read_max_redirects: int = 4
4141

4242
def __init__(self) -> None:

web3/providers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BaseProvider:
3535
# a tuple of (all_middlewares, request_func)
3636
_request_func_cache: Tuple[Tuple[Middleware, ...], Callable[..., RPCResponse]] = (None, None)
3737

38-
ccip_read_calls_enabled: bool = True
38+
global_ccip_read_enabled: bool = True
3939
ccip_read_max_redirects: int = 4
4040

4141
@property

0 commit comments

Comments
 (0)