web3 6.20.2__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ens/__init__.py +13 -2
- ens/_normalization.py +2 -17
- ens/async_ens.py +33 -21
- ens/base_ens.py +3 -1
- ens/ens.py +16 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +52 -63
- web3/__init__.py +20 -24
- web3/_utils/abi.py +115 -271
- web3/_utils/async_transactions.py +7 -4
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching.py +128 -5
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/contracts.py +130 -236
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +13 -23
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/ens.py +2 -1
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +66 -69
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +5 -3
- web3/_utils/http_session_manager.py +303 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +34 -36
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +0 -3
- web3/_utils/module_testing/eth_module.py +695 -643
- web3/_utils/module_testing/module_testing_utils.py +61 -34
- web3/_utils/module_testing/persistent_connection_provider.py +56 -25
- web3/_utils/module_testing/utils.py +258 -0
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +5 -32
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +14 -12
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +17 -17
- web3/auto/gethdev.py +7 -2
- web3/beacon/__init__.py +6 -1
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/{main.py → beacon.py} +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +47 -46
- web3/contract/base_contract.py +183 -158
- web3/contract/contract.py +49 -43
- web3/contract/utils.py +203 -59
- web3/datastructures.py +79 -31
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +39 -51
- web3/eth/base_eth.py +17 -10
- web3/eth/eth.py +30 -68
- web3/exceptions.py +108 -82
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +1 -254
- web3/main.py +75 -122
- web3/manager.py +316 -146
- web3/method.py +38 -31
- web3/middleware/__init__.py +67 -89
- web3/middleware/attrdict.py +36 -49
- web3/middleware/base.py +174 -0
- web3/middleware/buffered_gas_estimate.py +20 -21
- web3/middleware/filter.py +157 -117
- web3/middleware/formatting.py +124 -108
- web3/middleware/gas_price_strategy.py +20 -32
- web3/middleware/names.py +29 -26
- web3/middleware/proof_of_authority.py +68 -0
- web3/middleware/pythonic.py +2 -2
- web3/middleware/signing.py +74 -89
- web3/middleware/stalecheck.py +52 -79
- web3/middleware/validation.py +5 -13
- web3/module.py +54 -10
- web3/providers/__init__.py +10 -6
- web3/providers/async_base.py +117 -39
- web3/providers/auto.py +3 -3
- web3/providers/base.py +89 -33
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +1 -64
- web3/providers/eth_tester/main.py +99 -31
- web3/providers/eth_tester/middleware.py +45 -73
- web3/providers/ipc.py +42 -46
- web3/providers/{websocket/websocket.py → legacy_websocket.py} +32 -7
- web3/providers/persistent/__init__.py +22 -0
- web3/providers/persistent/async_ipc.py +153 -0
- web3/providers/{persistent.py → persistent/persistent.py} +106 -25
- web3/providers/persistent/persistent_connection.py +84 -0
- web3/providers/{websocket → persistent}/request_processor.py +94 -32
- web3/providers/persistent/utils.py +43 -0
- web3/providers/{websocket/websocket_v2.py → persistent/websocket.py} +29 -28
- web3/providers/rpc/__init__.py +11 -0
- web3/providers/rpc/async_rpc.py +171 -0
- web3/providers/rpc/rpc.py +179 -0
- web3/providers/rpc/utils.py +92 -0
- web3/testing.py +4 -4
- web3/tools/benchmark/main.py +22 -22
- web3/tools/benchmark/node.py +2 -8
- web3/tools/benchmark/reporting.py +2 -2
- web3/tools/benchmark/utils.py +1 -1
- web3/tracing.py +9 -5
- web3/types.py +30 -107
- web3/utils/__init__.py +58 -5
- web3/utils/abi.py +575 -10
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/caching.py +32 -13
- web3/utils/exception_handling.py +7 -5
- {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/LICENSE +1 -1
- web3-7.0.0.dist-info/METADATA +112 -0
- web3-7.0.0.dist-info/RECORD +167 -0
- {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/WHEEL +1 -1
- {web3-6.20.2.dist-info → web3-7.0.0.dist-info}/top_level.txt +0 -1
- ethpm/__init__.py +0 -20
- ethpm/_utils/__init__.py +0 -0
- ethpm/_utils/backend.py +0 -93
- ethpm/_utils/cache.py +0 -44
- ethpm/_utils/chains.py +0 -119
- ethpm/_utils/contract.py +0 -35
- ethpm/_utils/deployments.py +0 -145
- ethpm/_utils/ipfs.py +0 -116
- ethpm/_utils/protobuf/__init__.py +0 -0
- ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
- ethpm/_utils/registry.py +0 -29
- ethpm/assets/__init__.py +0 -0
- ethpm/assets/ens/v3.json +0 -1
- ethpm/assets/escrow/with_bytecode_v3.json +0 -1
- ethpm/assets/ipfs_file.proto +0 -32
- ethpm/assets/owned/output_v3.json +0 -1
- ethpm/assets/owned/with_contract_type_v3.json +0 -1
- ethpm/assets/registry/contracts/Authority.sol +0 -156
- ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
- ethpm/assets/registry/contracts/PackageDB.sol +0 -225
- ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
- ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
- ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
- ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
- ethpm/assets/registry/solc_input.json +0 -1
- ethpm/assets/registry/solc_output.json +0 -1
- ethpm/assets/registry/v3.json +0 -1
- ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
- ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
- ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
- ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
- ethpm/assets/simple-registry/solc_input.json +0 -33
- ethpm/assets/simple-registry/solc_output.json +0 -1
- ethpm/assets/simple-registry/v3.json +0 -1
- ethpm/assets/standard-token/output_v3.json +0 -1
- ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
- ethpm/assets/vyper_registry/0.1.0.json +0 -1
- ethpm/assets/vyper_registry/registry.vy +0 -216
- ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
- ethpm/backends/__init__.py +0 -0
- ethpm/backends/base.py +0 -43
- ethpm/backends/http.py +0 -108
- ethpm/backends/ipfs.py +0 -219
- ethpm/backends/registry.py +0 -154
- ethpm/constants.py +0 -17
- ethpm/contract.py +0 -187
- ethpm/dependencies.py +0 -58
- ethpm/deployments.py +0 -80
- ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
- ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
- ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
- ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
- ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
- ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
- ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/owned/v3.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
- ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
- ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
- ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
- ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
- ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
- ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
- ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
- ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
- ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
- ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
- ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
- ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
- ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
- ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
- ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
- ethpm/ethpm-spec/spec/package.spec.json +0 -379
- ethpm/ethpm-spec/spec/v3.spec.json +0 -483
- ethpm/exceptions.py +0 -68
- ethpm/package.py +0 -438
- ethpm/tools/__init__.py +0 -4
- ethpm/tools/builder.py +0 -930
- ethpm/tools/checker.py +0 -312
- ethpm/tools/get_manifest.py +0 -19
- ethpm/uri.py +0 -141
- ethpm/validation/__init__.py +0 -0
- ethpm/validation/manifest.py +0 -146
- ethpm/validation/misc.py +0 -39
- ethpm/validation/package.py +0 -80
- ethpm/validation/uri.py +0 -163
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/miner.py +0 -88
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -323
- web3/_utils/request.py +0 -265
- web3/middleware/abi.py +0 -11
- web3/middleware/async_cache.py +0 -99
- web3/middleware/cache.py +0 -374
- web3/middleware/exception_handling.py +0 -49
- web3/middleware/exception_retry_request.py +0 -188
- web3/middleware/fixture.py +0 -190
- web3/middleware/geth_poa.py +0 -81
- web3/middleware/normalize_request_parameters.py +0 -11
- web3/middleware/simulate_unmined_transaction.py +0 -43
- web3/pm.py +0 -602
- web3/providers/async_rpc.py +0 -99
- web3/providers/rpc.py +0 -98
- web3/providers/websocket/__init__.py +0 -11
- web3/providers/websocket/websocket_connection.py +0 -42
- web3/tools/__init__.py +0 -4
- web3/tools/pytest_ethereum/__init__.py +0 -0
- web3/tools/pytest_ethereum/_utils.py +0 -145
- web3/tools/pytest_ethereum/deployer.py +0 -48
- web3/tools/pytest_ethereum/exceptions.py +0 -22
- web3/tools/pytest_ethereum/linker.py +0 -128
- web3/tools/pytest_ethereum/plugins.py +0 -33
- web3-6.20.2.dist-info/METADATA +0 -103
- web3-6.20.2.dist-info/RECORD +0 -283
- web3-6.20.2.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import time
|
|
3
|
+
from typing import (
|
|
4
|
+
TYPE_CHECKING,
|
|
5
|
+
Any,
|
|
6
|
+
Dict,
|
|
7
|
+
Iterable,
|
|
8
|
+
List,
|
|
9
|
+
Optional,
|
|
10
|
+
Tuple,
|
|
11
|
+
Union,
|
|
12
|
+
cast,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from eth_typing import (
|
|
16
|
+
URI,
|
|
17
|
+
)
|
|
18
|
+
from eth_utils import (
|
|
19
|
+
to_dict,
|
|
20
|
+
)
|
|
21
|
+
import requests
|
|
22
|
+
|
|
23
|
+
from web3._utils.empty import (
|
|
24
|
+
Empty,
|
|
25
|
+
empty,
|
|
26
|
+
)
|
|
27
|
+
from web3._utils.http import (
|
|
28
|
+
construct_user_agent,
|
|
29
|
+
)
|
|
30
|
+
from web3.types import (
|
|
31
|
+
RPCEndpoint,
|
|
32
|
+
RPCResponse,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from ..._utils.batching import (
|
|
36
|
+
sort_batch_response_by_response_ids,
|
|
37
|
+
)
|
|
38
|
+
from ..._utils.caching import (
|
|
39
|
+
handle_request_caching,
|
|
40
|
+
)
|
|
41
|
+
from ..._utils.http_session_manager import (
|
|
42
|
+
HTTPSessionManager,
|
|
43
|
+
)
|
|
44
|
+
from ..base import (
|
|
45
|
+
JSONBaseProvider,
|
|
46
|
+
)
|
|
47
|
+
from .utils import (
|
|
48
|
+
ExceptionRetryConfiguration,
|
|
49
|
+
check_if_retry_on_failure,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
if TYPE_CHECKING:
|
|
53
|
+
from web3.middleware.base import ( # noqa: F401
|
|
54
|
+
Middleware,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class HTTPProvider(JSONBaseProvider):
|
|
59
|
+
logger = logging.getLogger("web3.providers.HTTPProvider")
|
|
60
|
+
endpoint_uri = None
|
|
61
|
+
_request_kwargs = None
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
endpoint_uri: Optional[Union[URI, str]] = None,
|
|
66
|
+
request_kwargs: Optional[Any] = None,
|
|
67
|
+
session: Optional[Any] = None,
|
|
68
|
+
exception_retry_configuration: Optional[
|
|
69
|
+
Union[ExceptionRetryConfiguration, Empty]
|
|
70
|
+
] = empty,
|
|
71
|
+
**kwargs: Any,
|
|
72
|
+
) -> None:
|
|
73
|
+
self._request_session_manager = HTTPSessionManager()
|
|
74
|
+
|
|
75
|
+
if endpoint_uri is None:
|
|
76
|
+
self.endpoint_uri = (
|
|
77
|
+
self._request_session_manager.get_default_http_endpoint()
|
|
78
|
+
)
|
|
79
|
+
else:
|
|
80
|
+
self.endpoint_uri = URI(endpoint_uri)
|
|
81
|
+
|
|
82
|
+
self._request_kwargs = request_kwargs or {}
|
|
83
|
+
self._exception_retry_configuration = exception_retry_configuration
|
|
84
|
+
|
|
85
|
+
if session:
|
|
86
|
+
self._request_session_manager.cache_and_return_session(
|
|
87
|
+
self.endpoint_uri, session
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
super().__init__(**kwargs)
|
|
91
|
+
|
|
92
|
+
def __str__(self) -> str:
|
|
93
|
+
return f"RPC connection {self.endpoint_uri}"
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def exception_retry_configuration(self) -> ExceptionRetryConfiguration:
|
|
97
|
+
if isinstance(self._exception_retry_configuration, Empty):
|
|
98
|
+
self._exception_retry_configuration = ExceptionRetryConfiguration(
|
|
99
|
+
errors=(
|
|
100
|
+
ConnectionError,
|
|
101
|
+
requests.HTTPError,
|
|
102
|
+
requests.Timeout,
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
return self._exception_retry_configuration
|
|
106
|
+
|
|
107
|
+
@exception_retry_configuration.setter
|
|
108
|
+
def exception_retry_configuration(
|
|
109
|
+
self, value: Union[ExceptionRetryConfiguration, Empty]
|
|
110
|
+
) -> None:
|
|
111
|
+
self._exception_retry_configuration = value
|
|
112
|
+
|
|
113
|
+
@to_dict
|
|
114
|
+
def get_request_kwargs(self) -> Iterable[Tuple[str, Any]]:
|
|
115
|
+
if "headers" not in self._request_kwargs:
|
|
116
|
+
yield "headers", self.get_request_headers()
|
|
117
|
+
yield from self._request_kwargs.items()
|
|
118
|
+
|
|
119
|
+
def get_request_headers(self) -> Dict[str, str]:
|
|
120
|
+
return {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
"User-Agent": construct_user_agent(type(self)),
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
def _make_request(self, method: RPCEndpoint, request_data: bytes) -> bytes:
|
|
126
|
+
"""
|
|
127
|
+
If exception_retry_configuration is set, retry on failure; otherwise, make
|
|
128
|
+
the request without retrying.
|
|
129
|
+
"""
|
|
130
|
+
if (
|
|
131
|
+
self.exception_retry_configuration is not None
|
|
132
|
+
and check_if_retry_on_failure(
|
|
133
|
+
method, self.exception_retry_configuration.method_allowlist
|
|
134
|
+
)
|
|
135
|
+
):
|
|
136
|
+
for i in range(self.exception_retry_configuration.retries):
|
|
137
|
+
try:
|
|
138
|
+
return self._request_session_manager.make_post_request(
|
|
139
|
+
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
140
|
+
)
|
|
141
|
+
except tuple(self.exception_retry_configuration.errors) as e:
|
|
142
|
+
if i < self.exception_retry_configuration.retries - 1:
|
|
143
|
+
time.sleep(
|
|
144
|
+
self.exception_retry_configuration.backoff_factor * 2**i
|
|
145
|
+
)
|
|
146
|
+
continue
|
|
147
|
+
else:
|
|
148
|
+
raise e
|
|
149
|
+
return None
|
|
150
|
+
else:
|
|
151
|
+
return self._request_session_manager.make_post_request(
|
|
152
|
+
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
@handle_request_caching
|
|
156
|
+
def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
|
|
157
|
+
self.logger.debug(
|
|
158
|
+
f"Making request HTTP. URI: {self.endpoint_uri}, Method: {method}"
|
|
159
|
+
)
|
|
160
|
+
request_data = self.encode_rpc_request(method, params)
|
|
161
|
+
raw_response = self._make_request(method, request_data)
|
|
162
|
+
response = self.decode_rpc_response(raw_response)
|
|
163
|
+
self.logger.debug(
|
|
164
|
+
f"Getting response HTTP. URI: {self.endpoint_uri}, "
|
|
165
|
+
f"Method: {method}, Response: {response}"
|
|
166
|
+
)
|
|
167
|
+
return response
|
|
168
|
+
|
|
169
|
+
def make_batch_request(
|
|
170
|
+
self, batch_requests: List[Tuple[RPCEndpoint, Any]]
|
|
171
|
+
) -> List[RPCResponse]:
|
|
172
|
+
self.logger.debug(f"Making batch request HTTP, uri: `{self.endpoint_uri}`")
|
|
173
|
+
request_data = self.encode_batch_rpc_request(batch_requests)
|
|
174
|
+
raw_response = self._request_session_manager.make_post_request(
|
|
175
|
+
self.endpoint_uri, request_data, **self.get_request_kwargs()
|
|
176
|
+
)
|
|
177
|
+
self.logger.debug("Received batch response HTTP.")
|
|
178
|
+
responses_list = cast(List[RPCResponse], self.decode_rpc_response(raw_response))
|
|
179
|
+
return sort_batch_response_by_response_ids(responses_list)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Sequence,
|
|
3
|
+
Type,
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
from pydantic import (
|
|
7
|
+
BaseModel,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
from web3.types import (
|
|
11
|
+
RPCEndpoint,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
REQUEST_RETRY_ALLOWLIST = [
|
|
15
|
+
"admin",
|
|
16
|
+
"net",
|
|
17
|
+
"txpool",
|
|
18
|
+
"testing",
|
|
19
|
+
"evm",
|
|
20
|
+
"eth_protocolVersion",
|
|
21
|
+
"eth_syncing",
|
|
22
|
+
"eth_chainId",
|
|
23
|
+
"eth_gasPrice",
|
|
24
|
+
"eth_accounts",
|
|
25
|
+
"eth_blockNumber",
|
|
26
|
+
"eth_getBalance",
|
|
27
|
+
"eth_getStorageAt",
|
|
28
|
+
"eth_getProof",
|
|
29
|
+
"eth_getCode",
|
|
30
|
+
"eth_getBlockByNumber",
|
|
31
|
+
"eth_getBlockByHash",
|
|
32
|
+
"eth_getBlockTransactionCountByNumber",
|
|
33
|
+
"eth_getBlockTransactionCountByHash",
|
|
34
|
+
"eth_getUncleCountByBlockNumber",
|
|
35
|
+
"eth_getUncleCountByBlockHash",
|
|
36
|
+
"eth_getTransactionByHash",
|
|
37
|
+
"eth_getTransactionByBlockHashAndIndex",
|
|
38
|
+
"eth_getTransactionByBlockNumberAndIndex",
|
|
39
|
+
"eth_getTransactionReceipt",
|
|
40
|
+
"eth_getTransactionCount",
|
|
41
|
+
"eth_getRawTransactionByHash",
|
|
42
|
+
"eth_call",
|
|
43
|
+
"eth_estimateGas",
|
|
44
|
+
"eth_createAccessList",
|
|
45
|
+
"eth_maxPriorityFeePerGas",
|
|
46
|
+
"eth_newBlockFilter",
|
|
47
|
+
"eth_newPendingTransactionFilter",
|
|
48
|
+
"eth_newFilter",
|
|
49
|
+
"eth_getFilterChanges",
|
|
50
|
+
"eth_getFilterLogs",
|
|
51
|
+
"eth_getLogs",
|
|
52
|
+
"eth_uninstallFilter",
|
|
53
|
+
"eth_getCompilers",
|
|
54
|
+
"eth_getWork",
|
|
55
|
+
"eth_sign",
|
|
56
|
+
"eth_signTypedData",
|
|
57
|
+
"eth_sendRawTransaction",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def check_if_retry_on_failure(
|
|
62
|
+
method: RPCEndpoint,
|
|
63
|
+
allowlist: Sequence[str] = None,
|
|
64
|
+
) -> bool:
|
|
65
|
+
if allowlist is None:
|
|
66
|
+
allowlist = REQUEST_RETRY_ALLOWLIST
|
|
67
|
+
|
|
68
|
+
if method in allowlist or method.split("_")[0] in allowlist:
|
|
69
|
+
return True
|
|
70
|
+
else:
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ExceptionRetryConfiguration(BaseModel):
|
|
75
|
+
errors: Sequence[Type[BaseException]]
|
|
76
|
+
retries: int
|
|
77
|
+
backoff_factor: float
|
|
78
|
+
method_allowlist: Sequence[str]
|
|
79
|
+
|
|
80
|
+
def __init__(
|
|
81
|
+
self,
|
|
82
|
+
errors: Sequence[Type[BaseException]] = None,
|
|
83
|
+
retries: int = 5,
|
|
84
|
+
backoff_factor: float = 0.125,
|
|
85
|
+
method_allowlist: Sequence[str] = None,
|
|
86
|
+
):
|
|
87
|
+
super().__init__(
|
|
88
|
+
errors=errors,
|
|
89
|
+
retries=retries,
|
|
90
|
+
backoff_factor=backoff_factor,
|
|
91
|
+
method_allowlist=method_allowlist or REQUEST_RETRY_ALLOWLIST,
|
|
92
|
+
)
|
web3/testing.py
CHANGED
|
@@ -12,21 +12,21 @@ from web3.module import (
|
|
|
12
12
|
|
|
13
13
|
class Testing(Module):
|
|
14
14
|
def timeTravel(self, timestamp: int) -> None:
|
|
15
|
-
|
|
15
|
+
self.w3.manager.request_blocking(RPC.testing_timeTravel, [timestamp])
|
|
16
16
|
|
|
17
17
|
def mine(self, num_blocks: int = 1) -> None:
|
|
18
|
-
|
|
18
|
+
self.w3.manager.request_blocking(RPC.evm_mine, [num_blocks])
|
|
19
19
|
|
|
20
20
|
def snapshot(self) -> int:
|
|
21
21
|
self.last_snapshot_idx = self.w3.manager.request_blocking(RPC.evm_snapshot, [])
|
|
22
22
|
return self.last_snapshot_idx
|
|
23
23
|
|
|
24
24
|
def reset(self) -> None:
|
|
25
|
-
|
|
25
|
+
self.w3.manager.request_blocking(RPC.evm_reset, [])
|
|
26
26
|
|
|
27
27
|
def revert(self, snapshot_idx: Optional[int] = None) -> None:
|
|
28
28
|
if snapshot_idx is None:
|
|
29
29
|
revert_target = self.last_snapshot_idx
|
|
30
30
|
else:
|
|
31
31
|
revert_target = snapshot_idx
|
|
32
|
-
|
|
32
|
+
self.w3.manager.request_blocking(RPC.evm_revert, [revert_target])
|
web3/tools/benchmark/main.py
CHANGED
|
@@ -20,10 +20,8 @@ from web3 import (
|
|
|
20
20
|
Web3,
|
|
21
21
|
)
|
|
22
22
|
from web3.middleware import (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
buffered_gas_estimate_middleware,
|
|
26
|
-
gas_price_strategy_middleware,
|
|
23
|
+
BufferedGasEstimateMiddleware,
|
|
24
|
+
GasPriceStrategyMiddleware,
|
|
27
25
|
)
|
|
28
26
|
from web3.tools.benchmark.node import (
|
|
29
27
|
GethBenchmarkFixture,
|
|
@@ -61,7 +59,7 @@ def build_web3_http(endpoint_uri: str) -> Web3:
|
|
|
61
59
|
wait_for_http(endpoint_uri)
|
|
62
60
|
_w3 = Web3(
|
|
63
61
|
HTTPProvider(endpoint_uri),
|
|
64
|
-
|
|
62
|
+
middleware=[GasPriceStrategyMiddleware, BufferedGasEstimateMiddleware],
|
|
65
63
|
)
|
|
66
64
|
return _w3
|
|
67
65
|
|
|
@@ -70,10 +68,7 @@ async def build_async_w3_http(endpoint_uri: str) -> AsyncWeb3:
|
|
|
70
68
|
await wait_for_aiohttp(endpoint_uri)
|
|
71
69
|
_w3 = AsyncWeb3(
|
|
72
70
|
AsyncHTTPProvider(endpoint_uri),
|
|
73
|
-
|
|
74
|
-
async_gas_price_strategy_middleware,
|
|
75
|
-
async_buffered_gas_estimate_middleware,
|
|
76
|
-
],
|
|
71
|
+
middleware=[GasPriceStrategyMiddleware, BufferedGasEstimateMiddleware],
|
|
77
72
|
)
|
|
78
73
|
return _w3
|
|
79
74
|
|
|
@@ -113,35 +108,36 @@ def main(logger: logging.Logger, num_calls: int) -> None:
|
|
|
113
108
|
asyncio.set_event_loop(loop)
|
|
114
109
|
|
|
115
110
|
# -- sync -- #
|
|
116
|
-
|
|
111
|
+
account = w3_http.eth.accounts[0]
|
|
117
112
|
|
|
118
113
|
# -- async -- #
|
|
119
114
|
async_w3_http = loop.run_until_complete(
|
|
120
115
|
build_async_w3_http(fixture.endpoint_uri)
|
|
121
116
|
)
|
|
122
|
-
|
|
117
|
+
async_accounts = loop.run_until_complete(async_w3_http.eth.accounts)
|
|
118
|
+
async_account = async_accounts[0]
|
|
123
119
|
|
|
124
120
|
methods = [
|
|
125
121
|
{
|
|
126
122
|
"name": "eth_gasPrice",
|
|
127
123
|
"params": {},
|
|
128
|
-
"exec": lambda: w3_http.eth.gas_price,
|
|
129
|
-
"async_exec": lambda: async_w3_http.eth.gas_price,
|
|
124
|
+
"exec": lambda w3_http=w3_http: w3_http.eth.gas_price,
|
|
125
|
+
"async_exec": lambda async_w3_http=async_w3_http: async_w3_http.eth.gas_price, # noqa: E501
|
|
130
126
|
},
|
|
131
127
|
{
|
|
132
128
|
"name": "eth_sendTransaction",
|
|
133
129
|
"params": {},
|
|
134
|
-
"exec": lambda: w3_http.eth.send_transaction(
|
|
130
|
+
"exec": lambda w3_http=w3_http, account=account: w3_http.eth.send_transaction( # noqa: E501
|
|
135
131
|
{
|
|
136
132
|
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
|
|
137
|
-
"from":
|
|
133
|
+
"from": account,
|
|
138
134
|
"value": Wei(1),
|
|
139
135
|
}
|
|
140
136
|
),
|
|
141
|
-
"async_exec": lambda: async_w3_http.eth.send_transaction(
|
|
137
|
+
"async_exec": lambda async_w3_http=async_w3_http, async_account=async_account: async_w3_http.eth.send_transaction( # noqa: E501
|
|
142
138
|
{
|
|
143
139
|
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
|
|
144
|
-
"from":
|
|
140
|
+
"from": async_account,
|
|
145
141
|
"value": Wei(1),
|
|
146
142
|
}
|
|
147
143
|
),
|
|
@@ -149,18 +145,22 @@ def main(logger: logging.Logger, num_calls: int) -> None:
|
|
|
149
145
|
{
|
|
150
146
|
"name": "eth_blockNumber",
|
|
151
147
|
"params": {},
|
|
152
|
-
"exec": lambda: w3_http.eth.block_number,
|
|
153
|
-
"async_exec": lambda: async_w3_http.eth.block_number,
|
|
148
|
+
"exec": lambda w3_http=w3_http: w3_http.eth.block_number,
|
|
149
|
+
"async_exec": lambda async_w3_http=async_w3_http: async_w3_http.eth.block_number, # noqa: E501
|
|
154
150
|
},
|
|
155
151
|
{
|
|
156
152
|
"name": "eth_getBlock",
|
|
157
153
|
"params": {},
|
|
158
|
-
"exec": lambda: w3_http.eth.get_block(1),
|
|
159
|
-
"async_exec": lambda: async_w3_http.eth.get_block(
|
|
154
|
+
"exec": lambda w3_http=w3_http: w3_http.eth.get_block(1),
|
|
155
|
+
"async_exec": lambda async_w3_http=async_w3_http: async_w3_http.eth.get_block( # noqa: E501
|
|
156
|
+
1
|
|
157
|
+
),
|
|
160
158
|
},
|
|
161
159
|
]
|
|
162
160
|
|
|
163
|
-
def benchmark(
|
|
161
|
+
def benchmark(
|
|
162
|
+
method: Dict[str, Any], loop: asyncio.AbstractEventLoop = loop
|
|
163
|
+
) -> None:
|
|
164
164
|
outcomes: Dict[str, Union[str, float]] = defaultdict(lambda: "N/A")
|
|
165
165
|
outcomes["name"] = method["name"]
|
|
166
166
|
outcomes["HTTPProvider"] = sync_benchmark(
|
web3/tools/benchmark/node.py
CHANGED
|
@@ -24,10 +24,7 @@ from web3.tools.benchmark.utils import (
|
|
|
24
24
|
kill_proc_gracefully,
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
-
GETH_FIXTURE_ZIP = "geth-1.
|
|
28
|
-
|
|
29
|
-
# use same coinbase value as in `web3.py/tests/integration/generate_fixtures/common.py`
|
|
30
|
-
COINBASE = "0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd"
|
|
27
|
+
GETH_FIXTURE_ZIP = "geth-1.14.5-fixture.zip"
|
|
31
28
|
|
|
32
29
|
|
|
33
30
|
class GethBenchmarkFixture:
|
|
@@ -84,7 +81,7 @@ class GethBenchmarkFixture:
|
|
|
84
81
|
"--dev.period",
|
|
85
82
|
"100",
|
|
86
83
|
"--datadir",
|
|
87
|
-
|
|
84
|
+
datadir,
|
|
88
85
|
"--nodiscover",
|
|
89
86
|
"--http",
|
|
90
87
|
"--http.port",
|
|
@@ -92,9 +89,6 @@ class GethBenchmarkFixture:
|
|
|
92
89
|
"--http.api",
|
|
93
90
|
"admin,eth,net,web3",
|
|
94
91
|
"--ipcdisable",
|
|
95
|
-
"--allow-insecure-unlock",
|
|
96
|
-
"--miner.etherbase",
|
|
97
|
-
COINBASE[2:],
|
|
98
92
|
"--password",
|
|
99
93
|
os.path.join(datadir, "keystore", "pw.txt"),
|
|
100
94
|
)
|
|
@@ -14,7 +14,7 @@ def print_header(logger: Logger, num_calls: int) -> None:
|
|
|
14
14
|
"HTTPProvider",
|
|
15
15
|
"AsyncHTTProvider",
|
|
16
16
|
"IPCProvider",
|
|
17
|
-
"
|
|
17
|
+
"WebSocketProvider",
|
|
18
18
|
)
|
|
19
19
|
)
|
|
20
20
|
logger.info("-" * 112)
|
|
@@ -30,7 +30,7 @@ def print_entry(
|
|
|
30
30
|
method_benchmarks["HTTPProvider"],
|
|
31
31
|
method_benchmarks["AsyncHTTPProvider"],
|
|
32
32
|
method_benchmarks["IPCProvider"],
|
|
33
|
-
method_benchmarks["
|
|
33
|
+
method_benchmarks["WebSocketProvider"],
|
|
34
34
|
)
|
|
35
35
|
)
|
|
36
36
|
|
web3/tools/benchmark/utils.py
CHANGED
|
@@ -17,7 +17,7 @@ def wait_for_socket(ipc_path: str, timeout: int = 30) -> None:
|
|
|
17
17
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
18
18
|
sock.connect(ipc_path)
|
|
19
19
|
sock.settimeout(timeout)
|
|
20
|
-
except
|
|
20
|
+
except OSError:
|
|
21
21
|
time.sleep(0.01)
|
|
22
22
|
else:
|
|
23
23
|
break
|
web3/tracing.py
CHANGED
|
@@ -53,10 +53,10 @@ class Tracing(Module):
|
|
|
53
53
|
self._default_block = value
|
|
54
54
|
|
|
55
55
|
def trace_replay_transaction_munger(
|
|
56
|
-
self,
|
|
57
|
-
block_identifier: Union[_Hash32, BlockIdentifier],
|
|
58
|
-
mode: TraceMode = ["trace"],
|
|
56
|
+
self, block_identifier: Union[_Hash32, BlockIdentifier], mode: TraceMode = None
|
|
59
57
|
) -> Tuple[Union[BlockIdentifier, _Hash32], TraceMode]:
|
|
58
|
+
if mode is None:
|
|
59
|
+
mode = ["trace"]
|
|
60
60
|
return (block_identifier, mode)
|
|
61
61
|
|
|
62
62
|
trace_replay_transaction: Method[Callable[..., BlockTrace]] = Method(
|
|
@@ -86,9 +86,11 @@ class Tracing(Module):
|
|
|
86
86
|
def trace_call_munger(
|
|
87
87
|
self,
|
|
88
88
|
transaction: TxParams,
|
|
89
|
-
mode: TraceMode =
|
|
89
|
+
mode: TraceMode = None,
|
|
90
90
|
block_identifier: Optional[BlockIdentifier] = None,
|
|
91
91
|
) -> Tuple[TxParams, TraceMode, BlockIdentifier]:
|
|
92
|
+
if mode is None:
|
|
93
|
+
mode = ["trace"]
|
|
92
94
|
if "from" not in transaction and is_checksum_address(
|
|
93
95
|
self.w3.eth.default_account
|
|
94
96
|
):
|
|
@@ -105,8 +107,10 @@ class Tracing(Module):
|
|
|
105
107
|
)
|
|
106
108
|
|
|
107
109
|
def trace_transactions_munger(
|
|
108
|
-
self, raw_transaction: HexStr, mode: TraceMode =
|
|
110
|
+
self, raw_transaction: HexStr, mode: TraceMode = None
|
|
109
111
|
) -> Tuple[HexStr, TraceMode]:
|
|
112
|
+
if mode is None:
|
|
113
|
+
mode = ["trace"]
|
|
110
114
|
return raw_transaction, mode
|
|
111
115
|
|
|
112
116
|
trace_raw_transaction: Method[Callable[..., BlockTrace]] = Method(
|