@@ -60,13 +60,7 @@ def __init__(
60
60
self .should_retry = should_retry
61
61
self .unstable_blocks = unstable_blocks
62
62
63
- provider = self ._construct_provider (node_url = self .node_url )
64
-
65
- # use the EthAdvanced class instead of the Eth class for w3.eth
66
- modules = get_default_modules ()
67
- modules ["eth" ] = EthAdvanced
68
-
69
- super ().__init__ (provider = provider , modules = modules )
63
+ super ().__init__ (provider = self ._construct_provider (node_url = self .node_url ), modules = self ._get_modules ())
70
64
71
65
self .middleware_onion .inject (ExtraDataToPOAMiddleware , layer = 0 , name = "poa" ) # required for pos chains
72
66
@@ -83,6 +77,34 @@ def __init__(
83
77
84
78
self .middleware_onion .inject (BatchRetryMiddleware , layer = 0 , name = "batch_retry" ) # split and retry batch requests
85
79
80
+ def __deepcopy__ (self , memo ):
81
+ # create new instance, but only call init of Web3.py, not our custom one.
82
+ new_instance = self .__class__ .__new__ (self .__class__ )
83
+ memo [id (self )] = new_instance
84
+ Web3 .__init__ (new_instance , provider = self ._construct_provider (node_url = self .node_url ), modules = self ._get_modules ())
85
+
86
+ # Copy over all our custom data instead of running the lengthy checks of our init again
87
+ new_instance .manager .middleware_onion = self .manager .middleware_onion
88
+ new_instance .node_url = self .node_url
89
+ new_instance .should_retry = self .should_retry
90
+ new_instance .unstable_blocks = self .unstable_blocks
91
+ new_instance .latest_seen_block = self .latest_seen_block
92
+ new_instance .filter_block_range = self .filter_block_range
93
+ new_instance .rpc_batch_max_size = self .rpc_batch_max_size
94
+ new_instance .revert_reason_available = self .revert_reason_available
95
+ new_instance .is_archive = self .is_archive
96
+ new_instance .overwrites_available = self .overwrites_available
97
+ new_instance .subsquid_available = self .subsquid_available
98
+
99
+ return new_instance
100
+
101
+ @staticmethod
102
+ def _get_modules ():
103
+ # use the EthAdvanced class instead of the Eth class for w3.eth
104
+ modules = get_default_modules ()
105
+ modules ["eth" ] = EthAdvanced
106
+ return modules
107
+
86
108
@staticmethod
87
109
def _construct_provider (node_url ):
88
110
assert "://" in node_url
0 commit comments