Skip to content

Commit

Permalink
Merge branch 'develop' into cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 15, 2025
2 parents 57d2b67 + 1f155a6 commit 4303533
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ Returns server information and the list of documented routes in JSON format.
"result": {
"server_ready": true,
"network": "mainnet",
"version": "10.9.0-rc.1",
"version": "10.9.0",
"backend_height": 850214,
"counterparty_height": 850214,
"documentation": "https://counterpartycore.docs.apiary.io/",
Expand Down
8 changes: 4 additions & 4 deletions counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def is_api_request():
return False


def rpc(method, params):
if is_api_request():
def rpc(method, params, no_retry=False):
if is_api_request() or no_retry:
return safe_rpc(method, params)

payload = {
Expand Down Expand Up @@ -212,8 +212,8 @@ def convert_to_psbt(rawtx):


@functools.lru_cache(maxsize=10000)
def getrawtransaction(tx_hash, verbose=False):
return rpc("getrawtransaction", [tx_hash, 1 if verbose else 0])
def getrawtransaction(tx_hash, verbose=False, no_retry=False):
return rpc("getrawtransaction", [tx_hash, 1 if verbose else 0], no_retry=no_retry)


def getrawtransaction_batch(tx_hashes, verbose=False, return_dict=False):
Expand Down
6 changes: 3 additions & 3 deletions counterparty-core/counterpartycore/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# Semantic Version
__version__ = "10.9.0-rc.1" # for hatch
__version__ = "10.9.0" # for hatch
VERSION_STRING = __version__
version = VERSION_STRING.split("-")[0].split(".")
VERSION_MAJOR = int(version[0])
Expand All @@ -30,8 +30,8 @@
]
NEED_REPARSE_IF_MINOR_IS_LESS_THAN_TESTNET4 = None

NEED_ROLLBACK_IF_MINOR_IS_LESS_THAN = [(8, 871780)]
NEED_ROLLBACK_IF_MINOR_IS_LESS_THAN_TESTNET = [(8, 3522632)]
NEED_ROLLBACK_IF_MINOR_IS_LESS_THAN = [(8, 871780), (9, 871780)]
NEED_ROLLBACK_IF_MINOR_IS_LESS_THAN_TESTNET = [(8, 3522632), (9, 3522632)]
NEED_ROLLBACK_IF_MINOR_IS_LESS_THAN_TESTNET4 = None

STATE_DB_NEED_REFRESH_ON_VERSION_UPDATE = ["10.9.0-rc.1", "10.9.0"]
Expand Down
5 changes: 3 additions & 2 deletions counterparty-core/counterpartycore/lib/parser/follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ def receive_sequence(self, body):
raw_tx = self.raw_tx_cache.get(item_hash)
if raw_tx is None:
try:
raw_tx = backend.bitcoind.getrawtransaction(item_hash)
raw_tx = backend.bitcoind.getrawtransaction(item_hash, no_retry=True)
except exceptions.BitcoindRPCError:
logger.trace("Transaction not found in bitcoind: %s", item_hash)
logger.warning("Transaction not found in bitcoind: %s", item_hash)
return
# add transaction to mempool block
# logger.trace("Adding transaction to mempool block: %s", item_hash)
Expand All @@ -203,6 +203,7 @@ def receive_sequence(self, body):
logger.trace("Waiting for new transactions in the mempool or a new block...")
# transaction removed from mempool for non-block inclusion reasons
elif label == "R":
logger.debug("Removing transaction from mempool: %s", item_hash)
mempool.clean_transaction_events(self.db, item_hash)

def receive_message(self, topic, body, seq):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Returns server information and the list of documented routes in JSON format.
"result": {
"server_ready": true,
"network": "mainnet",
"version": "10.9.0-rc.1",
"version": "10.9.0",
"backend_height": 850214,
"counterparty_height": 850214,
"documentation": "https://counterpartycore.docs.apiary.io/",
Expand Down
65 changes: 65 additions & 0 deletions counterparty-core/counterpartycore/test/regtest/regtestnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def start_bitcoin_node(self):
"-acceptnonstdtxn",
"-minrelaytxfee=0",
"-blockmintxfee=0",
"-mempoolfullrbf",
f"-datadir={self.datadir}",
_bg=True,
_out=sys.stdout,
Expand All @@ -386,6 +387,7 @@ def start_bitcoin_node_2(self):
"-minrelaytxfee=0",
"-blockmintxfee=0",
"-bind=127.0.0.1:2223=onion",
"-mempoolfullrbf",
_bg=True,
_out=sys.stdout,
)
Expand Down Expand Up @@ -1136,6 +1138,69 @@ def test_fee_calculation(self):
)
assert size * 3 - 3 <= unsigned_tx["btc_fee"] <= size * 3 + 3

def test_rbf(self):
self.start_and_wait_second_node()

unsigned_tx = self.compose(
self.addresses[0],
"send",
{
"destination": self.addresses[1],
"quantity": 1,
"asset": "XCP",
"exact_fee": 1,
"verbose": True,
"validate": False,
},
)["result"]
transaction = Transaction.from_raw(unsigned_tx["rawtransaction"])
raw_hexs = []
# create 10 transactions with increasing fees
for _i in range(10):
transaction.outputs[1].amount -= 170
new_raw_transaction = transaction.to_hex()
signed_tx = json.loads(
self.bitcoin_wallet("signrawtransactionwithwallet", new_raw_transaction).strip()
)["hex"]
raw_hexs.append(signed_tx)

# check that no transaction is in the mempool
mempool_event_count_before = self.api_call("mempool/events?event_name=TRANSACTION_PARSED")[
"result_count"
]
assert mempool_event_count_before == 0

# broadcast the transactions to the two nodes
tx_hahses = []
for i, raw_hex in enumerate(raw_hexs):
tx_hash = self.bitcoin_wallet("sendrawtransaction", raw_hex, 0).strip()
tx_hahses.append(tx_hash)
print(f"Transaction {i} sent: {tx_hash}")

# check that all transactions are in the mempool
mempool_event_count_after = self.api_call("mempool/events?event_name=TRANSACTION_PARSED")[
"result_count"
]
while mempool_event_count_after == 0:
time.sleep(1)
mempool_event_count_after = self.api_call(
"mempool/events?event_name=TRANSACTION_PARSED"
)["result_count"]
time.sleep(10)

print("Mempool event count: ", mempool_event_count_after)

# only one event should be in the mempool
assert mempool_event_count_after == 1
# check that RBFed transactions are removed from the mempool
for tx_hash in tx_hahses[:-1]:
assert f"Removing transaction from mempool: {tx_hash}" in self.server_out.getvalue()
event = self.api_call("mempool/events?event_name=TRANSACTION_PARSED")["result"][0]
# check that the last transaction is the one in the mempool
assert event["tx_hash"] == tx_hahses[-1]

print("RBF test successful")


class RegtestNodeThread(threading.Thread):
def __init__(self, wsgi_server="waitress", burn_in_one_block=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,52 @@
}
],
},
{
"title": "Attach DETACHA asset to UTXO",
"transaction": "attach",
"source": "$ADDRESS_10",
"params": {
"asset": "DETACHA",
"quantity": 1 * 10**8,
},
"set_variables": {
"ATTACH2_DETACHA_TX_HASH": "$TX_HASH",
},
"controls": [],
},
{
"title": "Move no confirmation",
"transaction": "movetoutxo",
"no_confirmation": True,
"source": "$ATTACH2_DETACHA_TX_HASH:0",
"params": {
"destination": "$ADDRESS_9",
"quantity": 1 * 10**8,
},
"controls": [
{
"url": "mempool/events?event_name=UTXO_MOVE",
"result": [
{
"event": "UTXO_MOVE",
"params": {
"asset": "DETACHA",
"block_index": 9999999,
"destination": "$TX_HASH:0",
"destination_address": "$ADDRESS_9",
"msg_index": 0,
"quantity": 100000000,
"send_type": "move",
"source": "$ATTACH2_DETACHA_TX_HASH:0",
"source_address": "$ADDRESS_10",
"status": "valid",
"tx_hash": "$TX_HASH",
"tx_index": "$TX_INDEX",
},
"tx_hash": "$TX_HASH",
}
],
}
],
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ def run_scenarios(serve=False, wsgi_server="gunicorn"):
regtest_node_thread.node.test_electrs()
print("Testing fee calculation...")
regtest_node_thread.node.test_fee_calculation()
print("Testing RBF...")
regtest_node_thread.node.test_rbf()
except KeyboardInterrupt:
print(regtest_node_thread.node.server_out.getvalue())
pass
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ hypothesis==6.116.0
bitcoin-utils==0.7.1
pyzstd==0.16.2
dredd_hooks==0.2.0
counterparty-rs==10.9.0-rc.1
counterparty-rs==10.9.0
2 changes: 1 addition & 1 deletion counterparty-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion counterparty-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "counterparty-rs"
version = "10.9.0-rc.1"
version = "10.9.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ x-bitcoind-common: &bitcoind-common
restart: unless-stopped

x-counterparty-common: &counterparty-common
image: counterparty/counterparty:v10.9.0-rc.1
image: counterparty/counterparty:v10.9.0
stop_grace_period: 1m
volumes:
- data:/root/.bitcoin
Expand Down
3 changes: 2 additions & 1 deletion release-notes/release-notes-v10.9.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Release Notes - Counterparty Core v10.9.0 (2025-01-??)
# Release Notes - Counterparty Core v10.9.0 (2025-01-15)

This release represents a major technical milestone in the development of Counterparty Core: Counterparty no longer has AddrIndexRs as an external dependency. Originally, AddrIndexRs was used for transaction construction, and at the end of 2023 it was accidentally turned into a consensus-critical dependency (causing a number of subsequent consensus breaks and reliability issues). As of today, the only external dependency for a Counterparty node is Bitcoin Core itself.

Expand Down Expand Up @@ -44,6 +44,7 @@ The following transaction construction parameters have been deprecated (but rema
- Handle correctly RPC call errors from the API
- Don't clean mempool on catchup
- Retry 5 times when getting invalid Json with status 200 from Bitcoin Core
- Don't retry RPC call when parsing mempool transactions


## Codebase
Expand Down

0 comments on commit 4303533

Please sign in to comment.