Skip to content

Commit 056362e

Browse files
authored
Merge pull request #3035 from CounterpartyXCP/catchup
Optimize catch up
2 parents 397a4f9 + 97c6e62 commit 056362e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2296
-682
lines changed

.github/workflows/integrations_test.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ jobs:
2424
- name: Mainnet API Load
2525
test-path: integrations/load_test.py
2626
os: Linux-Large-1
27-
only_on_develop: true
27+
only_on_develop: false
28+
no_cov_report: true
2829

2930
# bootstrap, reparse 1000 blocks,
3031
# rollback 3 checkpoints and catchup
@@ -46,7 +47,7 @@ jobs:
4647
# bootstrap, reparse 1000 blocks,
4748
# rollback 3 checkpoints and catchup
4849
- name: Testnet4 Bootstrap And Catchup
49-
test-path: integrations/testnet4_test.py
50+
test-path: integrations/testnet4_test.py
5051

5152
- name: Testnet4 Start and Shutdown
5253
test-path: integrations/shutdown_test.py
@@ -61,11 +62,16 @@ jobs:
6162
- name: Compare Hashes
6263
test-path: integrations/comparehashes_test.py
6364

65+
- name: RSFetcher Test
66+
test-path: integrations/rsfetcher_test.py
67+
6468
# run pytest_action.yml for the matrix
6569
uses: ./.github/workflows/pytest_action.yml
6670
with:
6771
name: ${{ matrix.name }}
6872
test-path: ${{ matrix.test-path }}
6973
install_bitcoin: ${{ matrix.install_bitcoin || false }}
7074
only_on_develop: ${{ matrix.only_on_develop || false }}
75+
os: ${{ matrix.os || 'ubuntu-22.04' }}
76+
no_cov_report: ${{ matrix.no_cov_report || false }}
7177
secrets: inherit

.github/workflows/pytest_action.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ on:
1818
install_bitcoin:
1919
type: boolean
2020
default: false
21-
run_coveralls:
22-
type: boolean
23-
default: true
2421
only_on_develop:
2522
type: boolean
2623
default: false
24+
no_cov_report:
25+
type: boolean
26+
default: false
2727

2828
jobs:
2929
pytest:
@@ -67,9 +67,11 @@ jobs:
6767
- name: Run tests
6868
run: |
6969
cd counterparty-core
70-
hatch run pytest counterpartycore/test/${{ inputs.test-path }} -s -vv -x \
71-
--cov=counterpartycore/lib --cov-report=term-missing --cov-report=
72-
mv .coverage ../
70+
hatch run pytest counterpartycore/test/${{ inputs.test-path }} \
71+
${{ !inputs.no_cov_report && '-s -vv -x --cov=counterpartycore/lib --cov-report=term-missing --cov-report=' || '' }}
72+
if [ "${{ !inputs.no_cov_report }}" = "true" ]; then
73+
mv .coverage ../
74+
fi
7375
7476
- name: Upload coverage
7577
uses: codecov/codecov-action@v5

.github/workflows/ruff_scanner.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: chartboost/ruff-action@v1
1717
with:
1818
args: "format --check"
19-
version: 0.8.2
19+
version: 0.9.7
2020
- uses: chartboost/ruff-action@v1
2121
with:
22-
version: 0.8.2
22+
version: 0.9.7

.github/workflows/rust_test.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Rust Test
2+
3+
on:
4+
push:
5+
branches: "**"
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
Cargo:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install Rust toolchain
18+
uses: actions-rs/toolchain@v1
19+
with:
20+
toolchain: stable
21+
profile: minimal
22+
default: true
23+
24+
- name: Run tests
25+
run: |
26+
cd counterparty-rs
27+
cargo test

.github/workflows/scanners.yml

-100
This file was deleted.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM ubuntu:22.04
55

66
RUN apt update
77
# install dependencies
8-
RUN apt install -y python3 python3-dev python3-pip libleveldb-dev curl gnupg libclang-dev
8+
RUN apt install -y python3 python3-dev python3-pip libleveldb-dev curl gnupg libclang-dev pkg-config libssl-dev
99

1010
# install rust
1111
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

counterparty-core/counterpartycore/lib/api/wsgi.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,15 @@ def run(self, server_ready_value, shared_backend_height):
282282
CurrentState().set_backend_height_value(shared_backend_height)
283283
self.current_state_thread = NodeStatusCheckerThread(shared_backend_height)
284284
self.current_state_thread.start()
285-
self.server.run()
285+
try:
286+
self.server.run()
287+
except OSError as e:
288+
if e.errno == 9:
289+
logger.debug(
290+
"Ignoring OSError [Errno 9] Bad file descriptor during waitress server shutdown."
291+
)
292+
else:
293+
raise
286294

287295
def stop(self):
288296
self.current_state_thread.stop()

counterparty-core/counterpartycore/lib/backend/bitcoind.py

+34
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@ def list_unspent(source, allow_unconfirmed_inputs):
539539
return []
540540

541541

542+
def get_vin_info(vin, no_retry=False):
543+
vin_info = vin.get("info")
544+
if vin_info is None:
545+
logger.error(f"vin_info not found for vin {vin}")
546+
try:
547+
vin_ctx = get_decoded_transaction(vin["hash"], no_retry=no_retry)
548+
is_segwit = vin_ctx["segwit"]
549+
vout = vin_ctx["vout"][vin["n"]]
550+
return vout["value"], vout["script_pub_key"], is_segwit
551+
except exceptions.BitcoindRPCError as e:
552+
raise exceptions.DecodeError("vin not found") from e
553+
else:
554+
return vin_info["value"], vin_info["script_pub_key"], vin_info["is_segwit"]
555+
556+
542557
def get_vins_info(vins, no_retry=False):
543558
hashes = [vin["hash"] for vin in vins]
544559
inputs_txs = getrawtransaction_batch(hashes, verbose=False, return_dict=True, no_retry=no_retry)
@@ -554,6 +569,25 @@ def get_vins_info(vins, no_retry=False):
554569
return vins_info
555570

556571

572+
def complete_vins_info(decoded_tx, no_retry=False):
573+
missing_vins = []
574+
for vin in decoded_tx["vin"]:
575+
if "info" not in vin or vin["info"] is None:
576+
missing_vins.append(vin)
577+
578+
if len(missing_vins) > 0:
579+
missing_vins_info = get_vins_info(missing_vins, no_retry=no_retry)
580+
for i, vin in enumerate(missing_vins):
581+
vin_info = missing_vins_info[i]
582+
vin["info"] = {
583+
"value": vin_info[0],
584+
"script_pub_key": vin_info[1],
585+
"is_segwit": vin_info[2],
586+
}
587+
588+
return decoded_tx
589+
590+
557591
def get_transaction(tx_hash: str, format: str = "json"):
558592
"""
559593
Get a transaction from the blockchain

counterparty-core/counterpartycore/lib/backend/rsfetcher.py

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def start(self, start_height=0):
102102
self.prefetch_queue_initialized = False
103103

104104
def get_block(self, retry=0):
105-
logger.trace("Fetching block with Rust backend.")
106105
block = self.get_prefetched_block()
107106

108107
if block is None:

counterparty-core/counterpartycore/lib/cli/main.py

+8
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ def float_range_checker(arg):
393393
"help": "Catch up mode (default: normal)",
394394
},
395395
],
396+
[
397+
("--profile",),
398+
{
399+
"action": "store_true",
400+
"default": False,
401+
"help": "Enable cProfile profiling for catchup; dumps output to a file in the cache dir",
402+
},
403+
],
396404
]
397405

398406

0 commit comments

Comments
 (0)