Skip to content

Commit

Permalink
Add testnet4 (#4135)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Dec 19, 2024
1 parent ee0281b commit afe27e3
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 20 deletions.
4 changes: 2 additions & 2 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ axum-server = "0.5.0"
base64 = "0.22.0"
bip322 = "0.0.8"
bip39 = "2.0.0"
bitcoin = { version = "=0.32.3", features = ["rand"] }
bitcoin = { version = "0.32.5", features = ["rand"] }
bitcoincore-rpc = "0.19.0"
boilerplate = { version = "1.0.0", features = ["axum"] }
brotli = "7.0.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/mockcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/ordinals/ord"

[dependencies]
base64 = "0.22.0"
bitcoin = { version = "0.32.3", features = ["serde", "rand"] }
bitcoin = { version = "0.32.5", features = ["serde", "rand"] }
hex = "0.4.3"
jsonrpc-core = "18.0.0"
jsonrpc-derive = "18.0.0"
Expand Down
5 changes: 3 additions & 2 deletions crates/mockcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ impl Handle {
pub fn network(&self) -> String {
match self.state().network {
Network::Bitcoin => "mainnet".to_string(),
Network::Testnet => Network::Testnet.to_string(),
Network::Signet => Network::Signet.to_string(),
Network::Regtest => Network::Regtest.to_string(),
Network::Signet => Network::Signet.to_string(),
Network::Testnet4 => Network::Testnet4.to_string(),
Network::Testnet => Network::Testnet.to_string(),
_ => panic!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ordinals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "CC0-1.0"
rust-version = "1.74.0"

[dependencies]
bitcoin = { version = "=0.32.3", features = ["rand"] }
bitcoin = { version = "0.32.5", features = ["rand"] }
derive_more = { version = "1.0.0", features = ["display", "from_str"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_with = "3.7.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/ordinals/src/sat_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Encodable for SatPoint {
}

impl Decodable for SatPoint {
fn consensus_decode<D: bitcoin::io::Read + bitcoin::io::BufRead + ?Sized>(
fn consensus_decode<D: bitcoin::io::Read + ?Sized>(
d: &mut D,
) -> Result<Self, bitcoin::consensus::encode::Error> {
Ok(SatPoint {
Expand Down
7 changes: 6 additions & 1 deletion deploy/setup
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ case $CHAIN in
CSP_ORIGIN=signet.ordinals.com
ufw allow 38333
;;
test)
testnet3)
COOKIE_FILE_DIR=/var/lib/bitcoind/testnet3
CSP_ORIGIN=testnet.ordinals.com
ufw allow 18333
;;
testnet4)
COOKIE_FILE_DIR=/var/lib/bitcoind/testnet4
CSP_ORIGIN=testnet4.ordinals.com
ufw allow 48333
;;
*)
echo "Unknown chain: $CHAIN"
exit 1
Expand Down
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ deploy-signet branch='master' remote='ordinals/ord': \
(deploy branch remote 'signet' 'signet.ordinals.net')

deploy-testnet branch='master' remote='ordinals/ord': \
(deploy branch remote 'test' 'testnet.ordinals.net')
(deploy branch remote 'testnet3' 'testnet.ordinals.net')

deploy-testnet4 branch='master' remote='ordinals/ord': \
(deploy branch remote 'testnet4' 'testnet4.ordinals.net')

deploy-all: \
deploy-testnet \
deploy-testnet4 \
deploy-signet \
deploy-mainnet-alpha \
deploy-mainnet-bravo \
Expand All @@ -66,7 +70,7 @@ delete-indices: \
delete-index domain:
ssh root@{{domain}} 'systemctl stop ord && rm -f /var/lib/ord/*/index.redb'

servers := 'alpha bravo charlie signet testnet'
servers := 'alpha bravo charlie signet testnet3 testnet4'

initialize-server-keys:
#!/usr/bin/env bash
Expand Down
23 changes: 16 additions & 7 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ pub enum Chain {
#[default]
#[value(alias("main"))]
Mainnet,
Regtest,
Signet,
#[value(alias("test"))]
Testnet,
Signet,
Regtest,
Testnet4,
}

impl Chain {
Expand All @@ -23,13 +24,14 @@ impl Chain {
Self::Regtest => 18443,
Self::Signet => 38332,
Self::Testnet => 18332,
Self::Testnet4 => 48332,
}
}

pub(crate) fn inscription_content_size_limit(self) -> Option<usize> {
match self {
Self::Mainnet | Self::Regtest => None,
Self::Testnet | Self::Signet => Some(1024),
Self::Testnet | Self::Testnet4 | Self::Signet => Some(1024),
}
}

Expand All @@ -39,6 +41,7 @@ impl Chain {
Self::Regtest => 0,
Self::Signet => 112402,
Self::Testnet => 2413343,
Self::Testnet4 => 0,
}
}

Expand All @@ -52,6 +55,7 @@ impl Chain {
Self::Regtest => 110,
Self::Signet => 175392,
Self::Testnet => 2544192,
Self::Testnet4 => 0,
}
}

Expand All @@ -73,9 +77,10 @@ impl Chain {
pub(crate) fn join_with_data_dir(self, data_dir: impl AsRef<Path>) -> PathBuf {
match self {
Self::Mainnet => data_dir.as_ref().to_owned(),
Self::Testnet => data_dir.as_ref().join("testnet3"),
Self::Signet => data_dir.as_ref().join("signet"),
Self::Regtest => data_dir.as_ref().join("regtest"),
Self::Signet => data_dir.as_ref().join("signet"),
Self::Testnet => data_dir.as_ref().join("testnet3"),
Self::Testnet4 => data_dir.as_ref().join("testnet4"),
}
}
}
Expand All @@ -84,9 +89,10 @@ impl From<Chain> for Network {
fn from(chain: Chain) -> Network {
match chain {
Chain::Mainnet => Network::Bitcoin,
Chain::Testnet => Network::Testnet,
Chain::Signet => Network::Signet,
Chain::Regtest => Network::Regtest,
Chain::Signet => Network::Signet,
Chain::Testnet => Network::Testnet,
Chain::Testnet4 => Network::Testnet4,
}
}
}
Expand All @@ -101,6 +107,7 @@ impl Display for Chain {
Self::Regtest => "regtest",
Self::Signet => "signet",
Self::Testnet => "testnet",
Self::Testnet4 => "testnet4",
}
)
}
Expand All @@ -115,6 +122,7 @@ impl FromStr for Chain {
"regtest" => Ok(Self::Regtest),
"signet" => Ok(Self::Signet),
"testnet" => Ok(Self::Testnet),
"testnet4" => Ok(Self::Testnet4),
_ => Err(SnafuError::InvalidChain {
chain: s.to_string(),
}),
Expand All @@ -132,6 +140,7 @@ mod tests {
assert_eq!("regtest".parse::<Chain>().unwrap(), Chain::Regtest);
assert_eq!("signet".parse::<Chain>().unwrap(), Chain::Signet);
assert_eq!("testnet".parse::<Chain>().unwrap(), Chain::Testnet);
assert_eq!("testnet4".parse::<Chain>().unwrap(), Chain::Testnet4);
assert_eq!(
"foo".parse::<Chain>().unwrap_err().to_string(),
"Invalid chain `foo`"
Expand Down
4 changes: 3 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
#[command(group(
ArgGroup::new("chains")
.required(false)
.args(&["chain_argument", "signet", "regtest", "testnet"]),
.args(&["chain_argument", "signet", "regtest", "testnet", "testnet4"]),
))]
pub struct Options {
#[arg(long, help = "Load Bitcoin Core data dir from <BITCOIN_DATA_DIR>.")]
Expand Down Expand Up @@ -82,4 +82,6 @@ pub struct Options {
pub(crate) signet: bool,
#[arg(long, short, help = "Use testnet. Equivalent to `--chain testnet`.")]
pub(crate) testnet: bool,
#[arg(long, help = "Use testnet4. Equivalent to `--chain testnet4`.")]
pub(crate) testnet4: bool,
}
27 changes: 26 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl Settings {
.then_some(Chain::Signet)
.or(options.regtest.then_some(Chain::Regtest))
.or(options.testnet.then_some(Chain::Testnet))
.or(options.testnet4.then_some(Chain::Testnet4))
.or(options.chain_argument),
commit_interval: options.commit_interval,
config: options.config,
Expand Down Expand Up @@ -431,9 +432,10 @@ impl Settings {
Ok(blockchain_info) => {
break match blockchain_info.chain.to_string().as_str() {
"bitcoin" => Chain::Mainnet,
"testnet" => Chain::Testnet,
"regtest" => Chain::Regtest,
"signet" => Chain::Signet,
"testnet" => Chain::Testnet,
"testnet4" => Chain::Testnet4,
other => bail!("Bitcoin RPC server on unknown chain: {other}"),
}
}
Expand Down Expand Up @@ -760,6 +762,20 @@ mod tests {
} else {
"/Bitcoin/signet/.cookie"
}));

let cookie_file = parse(&["--testnet4"])
.cookie_file()
.unwrap()
.display()
.to_string();

assert!(cookie_file.ends_with(if cfg!(target_os = "linux") {
"/.bitcoin/testnet4/.cookie"
} else if cfg!(windows) {
r"\Bitcoin\testnet4\.cookie"
} else {
"/Bitcoin/testnet4/.cookie"
}));
}

#[test]
Expand Down Expand Up @@ -817,6 +833,7 @@ mod tests {

#[test]
fn network_accepts_aliases() {
#[track_caller]
fn check_network_alias(alias: &str, suffix: &str) {
let data_dir = parse(&["--chain", alias]).data_dir().display().to_string();

Expand Down Expand Up @@ -857,6 +874,14 @@ mod tests {
"ord/testnet3"
},
);
check_network_alias(
"testnet4",
if cfg!(windows) {
r"ord\testnet4"
} else {
"ord/testnet4"
},
);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/subcommand/wallet/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult {
Chain::Regtest => "http://localhost/inscription/",
Chain::Signet => "https://signet.ordinals.com/inscription/",
Chain::Testnet => "https://testnet.ordinals.com/inscription/",
Chain::Testnet4 => "https://testnet4.ordinals.com/inscription/",
};

let mut output = Vec::new();
Expand Down

0 comments on commit afe27e3

Please sign in to comment.