Skip to content
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

[v11.0.0] testnet4 #2340

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions counterparty-core/counterpartycore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def float_range_checker(arg):
},
],
[
("--testcoin",),
("--testnet4",),
{
"action": "store_true",
"default": False,
"help": f"use the test {config.XCP_NAME} network on every blockchain",
"help": f"use {config.BTC_NAME} testnet4 addresses and block numbers",
},
],
[
Expand All @@ -79,13 +79,6 @@ def float_range_checker(arg):
"help": f"use {config.BTC_NAME} regtest addresses and block numbers",
},
],
[
("--customnet",),
{
"default": "",
"help": "use a custom network (specify as UNSPENDABLE_ADDRESS|ADDRESSVERSION|P2SH_ADDRESSVERSION with version bytes in HH hex format)",
},
],
[
("--api-limit-rows",),
{
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def pack(address):
raise e
except Exception as e: # noqa: F841
raise script.AddressError( # noqa: B904
f"The address {address} is not a valid bitcoin address ({'testnet' if config.TESTNET or config.REGTEST else 'mainnet'})"
f"The address {address} is not a valid bitcoin address ({config.NETWORK_NAME})."
)
else:
try:
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def api_root():
network = "mainnet"
if config.TESTNET:
network = "testnet"
elif config.TESTNET4:
network = "testnet4"
elif config.REGTEST:
network = "regtest"
elif config.TESTCOIN:
network = "testcoin"
return {
"server_ready": counterparty_height >= wsgi.BACKEND_HEIGHT,
"network": network,
Expand Down
1 change: 1 addition & 0 deletions counterparty-core/counterpartycore/lib/api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ def get_running_info():
"last_message_index": (last_message["message_index"] if last_message else -1),
"api_limit_rows": config.API_LIMIT_ROWS,
"running_testnet": config.TESTNET,
"running_testnet4": config.TESTNET4,
"running_regtest": config.REGTEST,
"running_testcoin": config.TESTCOIN,
"version_major": config.VERSION_MAJOR,
Expand Down
2 changes: 2 additions & 0 deletions counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def rpc_call(payload):
if response is None: # noqa: E711
if config.TESTNET:
network = "testnet"
elif config.TESTNET4:
network = "testnet4"
elif config.REGTEST:
network = "regtest"
else:
Expand Down
4 changes: 3 additions & 1 deletion counterparty-core/counterpartycore/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def parse_tx(db, tx):
message = None

# Protocol change.
rps_enabled = tx["block_index"] >= 308500 or config.TESTNET or config.REGTEST
rps_enabled = (
tx["block_index"] >= 308500 or config.TESTNET or config.TESTNET4 or config.REGTEST
)

supported = True

Expand Down
23 changes: 18 additions & 5 deletions counterparty-core/counterpartycore/lib/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,14 @@
},
}

CONSENSUS_HASH_VERSION_TESTNET4 = 1
CHECKPOINTS_TESTNET4 = {
config.BLOCK_FIRST_TESTNET4: {
"ledger_hash": "",
"txlist_hash": "",
},
}


class ConsensusError(Exception):
pass
Expand Down Expand Up @@ -857,6 +865,8 @@ def consensus_hash(db, field, previous_consensus_hash, content):
# Calculate current hash.
if config.TESTNET:
consensus_hash_version = CONSENSUS_HASH_VERSION_TESTNET
elif config.TESTNET4:
consensus_hash_version = CONSENSUS_HASH_VERSION_TESTNET4
elif config.REGTEST:
consensus_hash_version = CONSENSUS_HASH_VERSION_REGTEST
else:
Expand Down Expand Up @@ -884,6 +894,8 @@ def consensus_hash(db, field, previous_consensus_hash, content):
# Check against checkpoints.
if config.TESTNET:
checkpoints = CHECKPOINTS_TESTNET
elif config.TESTNET4:
checkpoints = CHECKPOINTS_TESTNET4
elif config.REGTEST:
checkpoints = CHECKPOINTS_REGTEST
else:
Expand Down Expand Up @@ -1017,11 +1029,12 @@ def database_version(db):
elif version_minor != config.VERSION_MINOR:
# Reparse transactions from the vesion block if minor version has changed.
message = f"Client minor version number mismatch. Triggering a reparse... ({version_minor} ≠ {config.VERSION_MINOR})"
need_reparse_from = (
config.NEED_REPARSE_IF_MINOR_IS_LESS_THAN_TESTNET
if config.TESTNET
else config.NEED_REPARSE_IF_MINOR_IS_LESS_THAN
)
if config.TESTNET:
need_reparse_from = config.NEED_REPARSE_IF_MINOR_IS_LESS_THAN_TESTNET
elif config.TESTNET4:
need_reparse_from = config.NEED_REPARSE_IF_MINOR_IS_LESS_THAN_TESTNET4
else:
need_reparse_from = config.NEED_REPARSE_IF_MINOR_IS_LESS_THAN
if need_reparse_from is not None:
min_version_minor, min_version_block_index = need_reparse_from
if version_minor < min_version_minor:
Expand Down
36 changes: 24 additions & 12 deletions counterparty-core/counterpartycore/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# means that we need to reparse from block 800000 if database minor version is less than 1
NEED_REPARSE_IF_MINOR_IS_LESS_THAN = (3, 0)
NEED_REPARSE_IF_MINOR_IS_LESS_THAN_TESTNET = (3, 0)
NEED_REPARSE_IF_MINOR_IS_LESS_THAN_TESTNET4 = None
# Counterparty protocol
TXTYPE_FORMAT = ">I"
SHORT_TXTYPE_FORMAT = "B"
Expand Down Expand Up @@ -53,61 +54,73 @@

DEFAULT_API_PORT_REGTEST = 24000
DEFAULT_API_PORT_TESTNET = 14000
DEFAULT_API_PORT_TESTNET4 = 44000
DEFAULT_API_PORT = 4000

DEFAULT_RPC_PORT_REGTEST = 24100
DEFAULT_RPC_PORT_TESTNET = 14100
DEFAULT_RPC_PORT_TESTNET4 = 44100
DEFAULT_RPC_PORT = 4100

DEFAULT_BACKEND_PORT_REGTEST = 18443
DEFAULT_BACKEND_PORT_TESTNET = 18332
DEFAULT_BACKEND_PORT_TESTNET4 = 48332
DEFAULT_BACKEND_PORT = 8332

DEFAULT_INDEXD_PORT_REGTEST = 18543
DEFAULT_INDEXD_PORT_TESTNET = 18432
DEFAULT_INDEXD_PORT_TESTNET4 = 48432
DEFAULT_INDEXD_PORT = 8432

DEFAULT_ZMQ_SEQUENCE_PORT_REGTEST = 29332
DEFAULT_ZMQ_SEQUENCE_PORT_TESTNET = 19332
DEFAULT_ZMQ_SEQUENCE_PORT_TESTNET4 = 49332
DEFAULT_ZMQ_SEQUENCE_PORT = 9332

DEFAULT_ZMQ_RAWBLOCK_PORT_REGTEST = 29333
DEFAULT_ZMQ_RAWBLOCK_PORT_TESTNET = 19333
DEFAULT_ZMQ_RAWBLOCK_PORT_TESTNET4 = 49333
DEFAULT_ZMQ_RAWBLOCK_PORT = 9333

DEFAULT_ZMQ_PUBLISHER_PORT_REGTEST = 24001
DEFAULT_ZMQ_PUBLISHER_PORT_TESTNET = 14001
DEFAULT_ZMQ_PUBLISHER_PORT_TESTNET4 = 44001
DEFAULT_ZMQ_PUBLISHER_PORT = 4001

UNSPENDABLE_REGTEST = "mvCounterpartyXXXXXXXXXXXXXXW24Hef"
UNSPENDABLE_TESTNET = "mvCounterpartyXXXXXXXXXXXXXXW24Hef"
UNSPENDABLE_TESTNET4 = "mvCounterpartyXXXXXXXXXXXXXXW24Hef"
UNSPENDABLE_MAINNET = "1CounterpartyXXXXXXXXXXXXXXXUWLpVr"

ADDRESSVERSION_TESTNET = b"\x6f"
P2SH_ADDRESSVERSION_TESTNET = b"\xc4"
PRIVATEKEY_VERSION_TESTNET = b"\xef"
MAGIC_BYTES_TESTNET = b"\xfa\xbf\xb5\xda" # For bip-0010

ADDRESSVERSION_TESTNET4 = b"\x6f"
P2SH_ADDRESSVERSION_TESTNET4 = b"\xc4"
PRIVATEKEY_VERSION_TESTNET4 = b"\xef"
MAGIC_BYTES_TESTNET4 = b"\xfa\xbf\xb5\xda" # For bip-0010

ADDRESSVERSION_MAINNET = b"\x00"
P2SH_ADDRESSVERSION_MAINNET = b"\x05"
PRIVATEKEY_VERSION_MAINNET = b"\x80"
MAGIC_BYTES_MAINNET = b"\xf9\xbe\xb4\xd9" # For bip-0010

ADDRESSVERSION_REGTEST = b"\x6f"
P2SH_ADDRESSVERSION_REGTEST = b"\xc4"
PRIVATEKEY_VERSION_REGTEST = b"\xef"
MAGIC_BYTES_TESTNET = b"\xfa\xbf\xb5\xda" # For bip-0010
MAGIC_BYTES_MAINNET = b"\xf9\xbe\xb4\xd9" # For bip-0010
MAGIC_BYTES_REGTEST = b"\xda\xb5\xbf\xfa"

BLOCK_FIRST_TESTNET_TESTCOIN = 310000
BURN_START_TESTNET_TESTCOIN = 310000
BURN_END_TESTNET_TESTCOIN = 4017708 # Fifty years, at ten minutes per block.

BLOCK_FIRST_TESTNET = 310000
BLOCK_FIRST_TESTNET_HASH = "000000001f605ec6ee8d2c0d21bf3d3ded0a31ca837acc98893876213828989d"
BURN_START_TESTNET = 310000
BURN_END_TESTNET = 4017708 # Fifty years, at ten minutes per block.

BLOCK_FIRST_MAINNET_TESTCOIN = 278270
BURN_START_MAINNET_TESTCOIN = 278310
BURN_END_MAINNET_TESTCOIN = 2500000 # A long time.
BLOCK_FIRST_TESTNET4 = 50000
BLOCK_FIRST_TESTNET4_HASH = "00000000e2c8c94ba126169a88997233f07a9769e2b009fb10cad0e893eff2cb"
BURN_START_TESTNET4 = 50000
BURN_END_TESTNET4 = 4017708 # Fifty years, at ten minutes per block.

BLOCK_FIRST_MAINNET = 278270
BLOCK_FIRST_MAINNET_HASH = "00000000000000017bac9a8e85660ad348050c789922d5f8fe544d473368be1a"
Expand All @@ -119,9 +132,6 @@
BURN_START_REGTEST = 101
BURN_END_REGTEST = 150000000

BLOCK_FIRST_REGTEST_TESTCOIN = 0
BURN_START_REGTEST_TESTCOIN = 101
BURN_END_REGTEST_TESTCOIN = 150

# Protocol defaults
# NOTE: If the DUST_SIZE constants are changed, they MUST also be changed in counterblockd/lib/config.py as well
Expand Down Expand Up @@ -166,6 +176,8 @@
BOOTSTRAP_URL_MAINNET_SIG = "https://bootstrap.counterparty.io/counterparty.latest.sig"
BOOTSTRAP_URL_TESTNET = "https://bootstrap.counterparty.io/counterparty-testnet.latest.tar.gz"
BOOTSTRAP_URL_TESTNET_SIG = "https://bootstrap.counterparty.io/counterparty-testnet.latest.sig"
BOOTSTRAP_URL_TESTNET4 = "https://bootstrap.counterparty.io/counterparty-testnet.latest.tar.gz"
BOOTSTRAP_URL_TESTNET4_SIG = "https://bootstrap.counterparty.io/counterparty-testnet.latest.sig"

API_MAX_LOG_SIZE = (
10 * 1024 * 1024
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/gettxinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def get_tx_info_legacy(decoded_tx, block_index):
data_chunk = data_pubkey[1 : data_chunk_length + 1]
data += data_chunk
elif len(asm) == 5 and (
block_index >= 293000 or config.TESTNET or config.REGTEST
block_index >= 293000 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
# Be strict.
pubkeyhash, address_version = get_pubkeyhash(script_pub_key, block_index)
Expand Down
4 changes: 3 additions & 1 deletion counterparty-core/counterpartycore/lib/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@

def price(numerator, denominator):
"""Return price as Fraction or Decimal."""
if util.CURRENT_BLOCK_INDEX >= 294500 or config.TESTNET or config.REGTEST: # Protocol change.
if (
Fixed Show fixed Hide fixed
util.CURRENT_BLOCK_INDEX >= 294500 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
return fractions.Fraction(numerator, denominator)
else:
numerator = D(numerator)
Expand Down
14 changes: 10 additions & 4 deletions counterparty-core/counterpartycore/lib/messages/bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def validate(
if expiration < 0:
problems.append("negative expiration")
if expiration == 0 and not (
block_index >= 317500 or config.TESTNET or config.REGTEST
block_index >= 317500 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
problems.append("zero expiration")

Expand Down Expand Up @@ -582,7 +582,9 @@ def match(db, tx):
tx1_counterwager_remaining = tx1["counterwager_remaining"]

bet_matches = ledger.get_matching_bets(db, tx1["feed_address"], counterbet_type)
if tx["block_index"] > 284500 or config.TESTNET or config.REGTEST: # Protocol change.
if (
tx["block_index"] > 284500 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
sorted(bet_matches, key=lambda x: x["tx_index"]) # Sort by tx index second.
sorted(
bet_matches, key=lambda x: ledger.price(x["wager_quantity"], x["counterwager_quantity"])
Expand Down Expand Up @@ -648,7 +650,9 @@ def match(db, tx):
if not forward_quantity:
logger.debug("Skipping: zero forward quantity.")
continue
if tx1["block_index"] >= 286500 or config.TESTNET or config.REGTEST: # Protocol change.
if (
tx1["block_index"] >= 286500 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
if not backward_quantity:
logger.debug("Skipping: zero backward quantity.")
continue
Expand Down Expand Up @@ -690,7 +694,9 @@ def match(db, tx):
}
logger.info("Bet %(bet_hash)s updated (%(tx_hash)s) [%(status)s]", log_data)

if tx1["block_index"] >= 292000 or config.TESTNET or config.REGTEST: # Protocol change
if (
tx1["block_index"] >= 292000 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change
if tx1_wager_remaining <= 0 or tx1_counterwager_remaining <= 0:
# Fill order, and recredit give_remaining.
tx1_status = "filled"
Expand Down
4 changes: 3 additions & 1 deletion counterparty-core/counterpartycore/lib/messages/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def validate(db, source, timestamp, value, fee_fraction_int, text, block_index):
elif timestamp <= last_broadcast["timestamp"]:
problems.append("feed timestamps not monotonically increasing")

if not (block_index >= 317500 or config.TESTNET or config.REGTEST): # Protocol change.
if not (
block_index >= 317500 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
if len(text) > 52:
problems.append("text too long")

Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/btcpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def validate(db, source, order_match_id, block_index):
# Check that source address is correct.
if order_match["backward_asset"] == config.BTC:
if source != order_match["tx1_address"] and not (
block_index >= 313900 or config.TESTNET or config.REGTEST
block_index >= 313900 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
problems.append("incorrect source address")
destination = order_match["tx0_address"]
Expand All @@ -91,7 +91,7 @@ def validate(db, source, order_match_id, block_index):
escrowed_quantity = order_match["forward_quantity"]
elif order_match["forward_asset"] == config.BTC:
if source != order_match["tx0_address"] and not (
block_index >= 313900 or config.TESTNET or config.REGTEST
block_index >= 313900 or config.TESTNET or config.TESTNET4 or config.REGTEST
): # Protocol change.
problems.append("incorrect source address")
destination = order_match["tx1_address"]
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/messages/burn.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def compose(db, source: str, quantity: int, overburn: bool = False):
def parse(db, tx, mainnet_burns, message=None):
burn_parse_cursor = db.cursor()

if config.TESTNET or config.REGTEST:
if config.TESTNET or config.TESTNET4 or config.REGTEST:
problems = []
status = "valid"

Expand Down
Loading
Loading