-
Notifications
You must be signed in to change notification settings - Fork 37.6k
test: move sync_blocks and sync_mempool functions to test_framework.py #19208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,6 @@ | |
disconnect_nodes, | ||
get_datadir_path, | ||
initialize_datadir, | ||
sync_blocks, | ||
sync_mempools, | ||
) | ||
|
||
|
||
|
@@ -541,15 +539,54 @@ def join_network(self): | |
connect_nodes(self.nodes[1], 2) | ||
self.sync_all() | ||
|
||
def sync_blocks(self, nodes=None, **kwargs): | ||
sync_blocks(nodes or self.nodes, **kwargs) | ||
|
||
def sync_mempools(self, nodes=None, **kwargs): | ||
sync_mempools(nodes or self.nodes, **kwargs) | ||
|
||
def sync_all(self, nodes=None, **kwargs): | ||
self.sync_blocks(nodes, **kwargs) | ||
self.sync_mempools(nodes, **kwargs) | ||
def sync_blocks(self, nodes=None, wait=1, timeout=60): | ||
""" | ||
Wait until everybody has the same tip. | ||
sync_blocks needs to be called with an rpc_connections set that has least | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a question - it's probably not a big deal to require at least one node to be updated, but would it be appropriate to have an optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a use case like that in current code. But I think one benefit your idea will give is to shorten test run time if the block we need to sync to is not usually the tip. |
||
one node already synced to the latest, stable tip, otherwise there's a | ||
chance it might return before all nodes are stably synced. | ||
""" | ||
rpc_connections = nodes or self.nodes | ||
timeout = int(timeout * self.options.timeout_factor) | ||
stop_time = time.time() + timeout | ||
while time.time() <= stop_time: | ||
best_hash = [x.getbestblockhash() for x in rpc_connections] | ||
if best_hash.count(best_hash[0]) == len(rpc_connections): | ||
return | ||
# Check that each peer has at least one connection | ||
assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | ||
time.sleep(wait) | ||
raise AssertionError("Block sync timed out after {}s:{}".format( | ||
timeout, | ||
"".join("\n {!r}".format(b) for b in best_hash), | ||
)) | ||
|
||
def sync_mempools(self, nodes=None, wait=1, timeout=60, flush_scheduler=True): | ||
""" | ||
Wait until everybody has the same transactions in their memory | ||
pools | ||
""" | ||
rpc_connections = nodes or self.nodes | ||
timeout = int(timeout * self.options.timeout_factor) | ||
stop_time = time.time() + timeout | ||
while time.time() <= stop_time: | ||
pool = [set(r.getrawmempool()) for r in rpc_connections] | ||
if pool.count(pool[0]) == len(rpc_connections): | ||
if flush_scheduler: | ||
for r in rpc_connections: | ||
r.syncwithvalidationinterfacequeue() | ||
return | ||
# Check that each peer has at least one connection | ||
assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | ||
time.sleep(wait) | ||
raise AssertionError("Mempool sync timed out after {}s:{}".format( | ||
timeout, | ||
"".join("\n {!r}".format(m) for m in pool), | ||
)) | ||
|
||
def sync_all(self, nodes=None): | ||
self.sync_blocks(nodes) | ||
self.sync_mempools(nodes) | ||
|
||
# Private helper methods. These should not be accessed by the subclass test scripts. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed
**kwargs
which are not used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they might come in handy in the future. Is there a reason they will be unused forever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it's better to add it when it will be used in instead of putting it there up front just because some time in the future it might be used. What do you think?