Page MenuHomePhabricator

refactor: make GetRand a template, remove GetRandInt
ClosedPublic

Authored by PiRK on Nov 21 2023, 13:56.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCe041fc0369a2: refactor: make GetRand a template, remove GetRandInt
Summary

makes GetRand a template for which any integral type can be used, where the default behavior is to return a random integral up to the max of the integral unless a max is provided.
This simplifies a lot of code from GetRand(std::numeric_limits<uint64_t>::max() -> GetRand<uint64_t>()

This is a backport of core#24925

Depends on D14827

Test Plan

ninja all check-all

Event Timeline

PiRK requested review of this revision.Nov 21 2023, 13:56
Fabien requested changes to this revision.Nov 21 2023, 15:03
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/avalanche/test/processor_tests.cpp
173 ↗(On Diff #43193)
src/test/net_tests.cpp
65 ↗(On Diff #43193)
This revision now requires changes to proceed.Nov 21 2023, 15:03

use uint32_t for random IP

Failed tests logs:

====== Bitcoin ABC functional tests: wallet_multiwallet.py ======

------- Stdout: -------
2023-11-21T15:40:44.888000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_  _20231121_154042/wallet_multiwallet_2
2023-11-21T15:41:01.476000Z TestFramework (INFO): Check for per-wallet settxfee call
2023-11-21T15:41:01.486000Z TestFramework (INFO): Test dynamic wallet loading
2023-11-21T15:41:02.453000Z TestFramework (INFO): Load first wallet
2023-11-21T15:41:02.479000Z TestFramework (INFO): Load second wallet
2023-11-21T15:41:02.497000Z TestFramework (INFO): Concurrent wallet loading
2023-11-21T15:41:02.715000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 142, in main
    self.run_test()
  File "/work/test/functional/wallet_multiwallet.py", line 378, in run_test
    assert_equal(got_loading_error, True)
  File "/work/test/functional/test_framework/util.py", line 62, in assert_equal
    raise AssertionError(
AssertionError: not(False == True)
2023-11-21T15:41:02.766000Z TestFramework (INFO): Stopping nodes
[node 0] Cleaning up leftover process
------- Stderr: -------
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/work/test/functional/test_framework/authproxy.py", line 126, in _request
    return self._get_response()
  File "/work/test/functional/test_framework/authproxy.py", line 216, in _get_response
Exception in thread Thread-1:
Traceback (most recent call last):
Exception in thread Thread-3:
  File "/work/test/functional/test_framework/authproxy.py", line 126, in _request
    http_response = self.__conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1347, in getresponse
Traceback (most recent call last):
    return self._get_response()
  File "/work/test/functional/test_framework/authproxy.py", line 126, in _request
  File "/work/test/functional/test_framework/authproxy.py", line 216, in _get_response
    response.begin()
    http_response = self.__conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1347, in getresponse
  File "/usr/lib/python3.9/http/client.py", line 307, in begin
    return self._get_response()
  File "/work/test/functional/test_framework/authproxy.py", line 216, in _get_response
    http_response = self.__conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1347, in getresponse
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 276, in _read_status
    response.begin()
    raise RemoteDisconnected("Remote end closed connection without"
    response.begin()
  File "/usr/lib/python3.9/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
http.client.RemoteDisconnected: Remote end closed connection without response
  File "/usr/lib/python3.9/http/client.py", line 268, in _read_status

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/http/client.py", line 307, in begin
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.9/socket.py", line 704, in readinto
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 276, in _read_status
    self._target(*self._args, **self._kwargs)
  File "/work/test/functional/wallet_multiwallet.py", line 29, in test_load_unload
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    node.loadwallet(name)
    raise RemoteDisconnected("Remote end closed connection without"
  File "/work/test/functional/test_framework/coverage.py", line 47, in __call__
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 175, in __call__
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 131, in _request
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self.run()
    self.__conn.request(method, path, postdata, headers)
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._target(*self._args, **self._kwargs)
  File "/work/test/functional/wallet_multiwallet.py", line 29, in test_load_unload
  File "/work/test/functional/wallet_multiwallet.py", line 30, in test_load_unload
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    node.unloadwallet(name)
  File "/work/test/functional/test_framework/coverage.py", line 47, in __call__
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    node.loadwallet(name)
  File "/work/test/functional/test_framework/coverage.py", line 47, in __call__
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 175, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
  File "/work/test/functional/test_framework/authproxy.py", line 175, in __call__
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 131, in _request
    self.connect()
  File "/usr/lib/python3.9/http/client.py", line 921, in connect
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 131, in _request
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    self.__conn.request(method, path, postdata, headers)
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    raise err
    self.__conn.request(method, path, postdata, headers)
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
    sock.connect(sa)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
ConnectionRefusedError: [Errno 111] Connection refused
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3.9/http/client.py", line 921, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3.9/http/client.py", line 921, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Traceback (most recent call last):
  File "/work/test/functional/test_framework/authproxy.py", line 125, in _request
    self.__conn.request(method, path, postdata, headers)
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1049, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.9/http/client.py", line 971, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/test/functional/wallet_multiwallet.py", line 604, in <module>
    MultiWalletTest().main()
  File "/work/test/functional/test_framework/test_framework.py", line 165, in main
    exit_code = self.shutdown()
  File "/work/test/functional/test_framework/test_framework.py", line 391, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 636, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 502, in stop_node
    self.stop(wait=wait)
  File "/work/test/functional/test_framework/coverage.py", line 47, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 175, in __call__
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 131, in _request
    self.__conn.request(method, path, postdata, headers)
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3.9/http/client.py", line 921, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Each failure log is accessible here:
Bitcoin ABC functional tests: wallet_multiwallet.py

PiRK planned changes to this revision.Nov 21 2023, 16:39

investigating the build failure

PiRK requested review of this revision.Nov 21 2023, 16:59

The failure seems unrelated. That test attempts to cause a race in wallet loading, so it would make sense that it can sometimes fail, but it should be really really unlikely.

This revision is now accepted and ready to land.Nov 21 2023, 21:32