Page MenuHomePhabricator

bloom: use Span instead of std::vector for `insert` and `contains`
ClosedPublic

Authored by PiRK on Apr 5 2024, 08:47.

Details

Summary

We can avoid many unnecessary std::vector allocations by changing
CBloomFilter to take Spans instead of std::vector's for the insert
and contains operations.

CBloomFilter currently converts types such as CDataStream and uint256
to std::vector on insert and contains. This is unnecessary because
CDataStreams and uint256 are already std::vectors internally. We just
need a way to point to the right data within those types. Span gives
us this ability.

Signed-off-by: William Casarin <jb55@jb55.com>

https://github.com/bitcoin/bitcoin/pull/23115/commits/2ba4ddf31d27bebc144b3729479967b40bbe0b6a

refactor: Remove unused MakeUCharSpan

https://github.com/bitcoin/bitcoin/pull/23137/commits/fac303c504ab19b863fddc7a0093068fee9d4ef3

This is a partial backport of core#23115 and core#23137

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Apr 5 2024, 08:47

Failed tests logs:

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

------- Stdout: -------
2024-04-05T09:06:01.679000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20240405_085832/abc_rpc_mocktime_262
2024-04-05T09:06:02.674000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/work/test/functional/test_framework/authproxy.py", line 125, in _request
    return self._get_response()
  File "/work/test/functional/test_framework/authproxy.py", line 215, in _get_response
    http_response = self.__conn.getresponse()
  File "/usr/lib/python3.9/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/lib/python3.9/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.9/http/client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.9/socket.py", line 704, in readinto
    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):
  File "/work/test/functional/test_framework/test_framework.py", line 147, in main
    self._run_test_internal()
  File "/work/test/functional/test_framework/test_framework.py", line 137, in _run_test_internal
    self.run_test()
  File "/work/test/functional/abc_rpc_mocktime.py", line 19, in run_test
    self.nodes[0].setmocktime(0)
  File "/work/test/functional/test_framework/coverage.py", line 46, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 174, in __call__
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 130, 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
2024-04-05T09:06:02.727000Z TestFramework (INFO): Stopping nodes
2024-04-05T09:06:02.727000Z TestFramework.node0 (ERROR): Unable to stop node.
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_node.py", line 501, in stop_node
    self.stop(wait=wait)
  File "/work/test/functional/test_framework/coverage.py", line 46, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 174, in __call__
    response, status = self._request(
  File "/work/test/functional/test_framework/authproxy.py", line 124, 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 1266, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/lib/python3.9/http/client.py", line 1092, in putrequest
    raise CannotSendRequest(self.__state)
http.client.CannotSendRequest: Request-sent
[node 0] Cleaning up leftover process
------- Stderr: -------
Traceback (most recent call last):
  File "/work/test/functional/abc_rpc_mocktime.py", line 32, in <module>
    MocktimeTest().main()
  File "/work/test/functional/test_framework/test_framework.py", line 170, in main
    exit_code = self.shutdown()
  File "/work/test/functional/test_framework/test_framework.py", line 396, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 645, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 513, in stop_node
    raise AssertionError(f"Unexpected stderr {stderr} != {expected_stderr}")
AssertionError: Unexpected stderr bitcoind: ../../src/util/time.cpp:78: static NodeClock::time_point NodeClock::now(): Assertion `ret > 0s' failed. !=

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

Failed tests logs:

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

Unrelated. Will rebase later. I will investigate this separately, it is the second time I see this failure.

This revision is now accepted and ready to land.Apr 5 2024, 11:24