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

Testnet 9.2 merge #325

Merged
merged 28 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bddad8b
Start Frost signer in `nomic signer`
keppel Sep 27, 2024
6e4fc1f
Update frost-secp256k1-tr dependency
keppel Sep 27, 2024
9f2ea08
Merge pull request #309 from nomic-io/frost-updates
mappum Sep 28, 2024
55eb146
Expose grpc server config
keppel Oct 9, 2024
0ac14bb
Merge remote-tracking branch 'origin/stakenet-9' into grpc-cmd
keppel Oct 11, 2024
be74869
Add miner fee and sigset index to pending deposits
keppel Oct 11, 2024
0c600db
Add bridge fee rate for pending deposits
keppel Oct 11, 2024
f1bc220
Add destination-specific bridge fee rate quotes to relayer
keppel Oct 11, 2024
f450f81
Add --rpc-url option to Bitcoin relayer command
keppel Oct 11, 2024
925b4f8
Use camelCase for pending deposit info
keppel Oct 11, 2024
0fc2438
Use camelCase for bridge fee overrides
keppel Oct 11, 2024
b17f972
Update orga
keppel Oct 11, 2024
f1297a4
Allow configurable Nomic RPC in gRPC command
keppel Oct 11, 2024
4656af7
Add more data to relayer `/sigset` endpoint response
keppel Oct 12, 2024
edf46b9
Merge pull request #315 from nomic-io/grpc-cmd
mappum Oct 12, 2024
0ee79f2
Merge pull request #316 from nomic-io/pending-deposit-detail
mappum Oct 12, 2024
638043f
Merge pull request #318 from nomic-io/btc-rpc-url
mappum Oct 12, 2024
a7906c5
Merge branch 'stakenet-9' into relayer-chkpt-data
mappum Oct 12, 2024
379ce59
Merge pull request #319 from nomic-io/relayer-chkpt-data
mappum Oct 12, 2024
f42ae84
Merge branch 'stakenet-9' into testnet-9.1
mappum Oct 15, 2024
6b61405
Add pending transfers query
keppel Oct 18, 2024
ace4aba
Fix empty pending deposits response
keppel Oct 22, 2024
2a0d98a
Update IbcDest encoding, and add legacy encoding
mappum Oct 23, 2024
1cf6f1d
Bump versions for network upgrade
mappum Oct 23, 2024
3e41338
v9.2.0
mappum Oct 23, 2024
ffaea4e
Upgrade orga dependency
mappum Oct 23, 2024
e4b2462
Merge branch 'testnet-9.1' into testnet-9.2-merge
mappum Oct 28, 2024
197d75d
Merge branch 'develop' into testnet-9.2-merge
mappum Oct 28, 2024
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
582 changes: 295 additions & 287 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "nomic"
version = "9.1.4"
version = "9.2.0"
authors = ["Nomic DAO Foundation <[email protected]>"]
edition = "2021"
default-run = "nomic"

[dependencies]
orga = { git = "https://github.com/nomic-io/orga.git", rev = "35988d76b58008e37794064c41f3d0ba102ca0c8", features = [
bitcoin = { version = "0.29.2", features = ["serde", "rand"] }
orga = { git = "https://github.com/nomic-io/orga.git", rev = "3b3d25ade40d81cb64f19335535e3a47bb47778f", features = [
"merk-verify",
"feat-ibc",
] }
Expand Down Expand Up @@ -53,7 +54,6 @@ ripemd = "0.1.3"
frost-secp256k1-tr = { git = "https://github.com/ZcashFoundation/frost", rev = "51fa7d09f3742563a35d065afcff6ad486430dac", features = [
"nightly",
], optional = true }
bitcoin = { version = "0.29.2", features = ["serde", "rand"] }
serde-hex = "0.1.0"
alloy-core = { version = "0.8.5", optional = true }
alloy-sol-types = { version = "0.8.5", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions networks/testnet.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
state_sync_rpc = [
"http://147.182.171.216:26657",
"http://147.182.171.216:26657",
"http://147.182.171.216:26657",
"http://147.182.171.216:26657",
]
tendermint_flags = ["--p2p.seeds", """
[email protected]:26656,\
"""]
btc_relayer = ["https://relayer.nomic-testnet.mappum.io:8443"]

legacy_version = "8.1.x"
legacy_version = "9.1.x"

genesis = """
{
Expand Down
6 changes: 3 additions & 3 deletions rest/Cargo.lock

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

67 changes: 59 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use orga::encoding::{Decode, Encode, LengthString, LengthVec};
use orga::ibc::ibc_rs::apps::transfer::types::Memo;
use orga::ibc::ClientIdKey as ClientId;
use sha2::{Digest, Sha256};

use std::io::Read;
use std::str::FromStr;
Expand Down Expand Up @@ -103,7 +104,7 @@
#[cfg(feature = "ethereum")]
const ETH_CREATE_CONNECTION_FEE_USATS: u64 = 10_000_000_000;

const OSMOSIS_CHANNEL_ID: &str = "channel-1";
pub const OSMOSIS_CHANNEL_ID: &str = "channel-1";

#[cfg(feature = "frost")]
const FROST_GROUP_INTERVAL: i64 = 10 * 60;
Expand Down Expand Up @@ -201,7 +202,7 @@
/// breaking changes are made to either the state encoding or logic of the
/// protocol, and requires a network upgrade to be coordinated via the
/// upgrade module.
pub const CONSENSUS_VERSION: u8 = 13;
pub const CONSENSUS_VERSION: u8 = 14;

#[cfg(feature = "full")]
fn configure_faucets(&mut self) -> Result<()> {
Expand Down Expand Up @@ -1609,7 +1610,7 @@
pub receiver: LengthString<u8>,
pub sender: LengthString<u8>,
pub timeout_timestamp: u64,
pub memo: LengthString<u8>,
pub memo: LengthString<u16>,
}

impl IbcDest {
Expand Down Expand Up @@ -1696,16 +1697,56 @@
Ok(())
}

pub fn legacy_encode(&self) -> Result<Vec<u8>> {
pub fn legacy_encode(&self) -> Result<Vec<Vec<u8>>> {
let mut encodings = vec![];

let mut bytes = vec![];
self.source_port.encode_into(&mut bytes)?;
self.source_channel.encode_into(&mut bytes)?;
EdAdapter(self.receiver_signer()?).encode_into(&mut bytes)?;
EdAdapter(self.sender_signer()?).encode_into(&mut bytes)?;
self.timeout_timestamp.encode_into(&mut bytes)?;
self.memo.encode_into(&mut bytes)?;
encodings.push(Sha256::digest(bytes).to_vec());

if self.memo.len() < 256 {
let mut bytes = vec![];
self.source_port.encode_into(&mut bytes)?;
self.source_channel.encode_into(&mut bytes)?;
self.receiver.encode_into(&mut bytes)?;
self.sender.encode_into(&mut bytes)?;
self.timeout_timestamp.encode_into(&mut bytes)?;
LengthString::<u8>::new(self.memo.len() as u8, self.memo.to_string())
.encode_into(&mut bytes)?;

let hash = Sha256::digest(bytes);
let mut bytes = Vec::with_capacity(hash.len() + 1);
bytes.push(0); // version byte
bytes.extend_from_slice(&hash);
encodings.push(bytes);
}

Ok(bytes)
Ok(encodings)
}
}

impl Migrate for IbcDest {
fn migrate(_src: Store, _dest: Store, mut bytes: &mut &[u8]) -> Result<Self> {
let source_port = LengthString::<u8>::decode(&mut bytes)?;

Check failure on line 1735 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:1735:54 | 1735 | let source_port = LengthString::<u8>::decode(&mut bytes)?; | ^^^^^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `-D clippy::needless-borrows-for-generic-args` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrows_for_generic_args)]`
let source_channel = LengthString::<u8>::decode(&mut bytes)?;

Check failure on line 1736 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:1736:57 | 1736 | let source_channel = LengthString::<u8>::decode(&mut bytes)?; | ^^^^^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let receiver = LengthString::<u8>::decode(&mut bytes)?;

Check failure on line 1737 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:1737:51 | 1737 | let receiver = LengthString::<u8>::decode(&mut bytes)?; | ^^^^^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let sender = LengthString::<u8>::decode(&mut bytes)?;

Check failure on line 1738 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:1738:49 | 1738 | let sender = LengthString::<u8>::decode(&mut bytes)?; | ^^^^^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let timeout_timestamp = u64::decode(&mut bytes)?;

Check failure on line 1739 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:1739:45 | 1739 | let timeout_timestamp = u64::decode(&mut bytes)?; | ^^^^^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
let memo = LengthString::<u8>::decode(&mut bytes)?;

Check failure on line 1740 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:1740:47 | 1740 | let memo = LengthString::<u8>::decode(&mut bytes)?; | ^^^^^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

Ok(IbcDest {
source_port,
source_channel,
receiver,
sender,
timeout_timestamp,
memo: memo.to_string().try_into().unwrap(),
})
}
}

Expand Down Expand Up @@ -1920,11 +1961,11 @@
}

// TODO: remove once there are no legacy commitments in-flight
pub fn legacy_commitment_bytes(&self) -> Result<Vec<u8>> {
pub fn legacy_commitment_bytes(&self) -> Result<Vec<Vec<u8>>> {
use sha2::{Digest, Sha256};
let bytes = match self {
Dest::NativeAccount { address } => address.bytes().into(),
Dest::Ibc { data } => Sha256::digest(data.legacy_encode()?).to_vec(),
Dest::NativeAccount { address } => vec![address.bytes().into()],
Dest::Ibc { data } => data.legacy_encode()?,
_ => return Err(Error::App("Invalid dest for legacy commitment".to_string())),
};

Expand Down Expand Up @@ -2003,6 +2044,16 @@

impl Migrate for Dest {
fn migrate(src: Store, dest: Store, bytes: &mut &[u8]) -> Result<Self> {
// TODO: !!!!!!!! remove from here once there are no legacy IBC dests
// Migrate IBC dests
let mut maybe_ibc_bytes = &mut &**bytes;
let variant = u8::decode(&mut maybe_ibc_bytes)?;

Check failure on line 2050 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> src/app.rs:2050:34 | 2050 | let variant = u8::decode(&mut maybe_ibc_bytes)?; | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `maybe_ibc_bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
if variant == 1 {
let ibc_dest = IbcDest::migrate(src, dest, maybe_ibc_bytes)?;
return Ok(Self::Ibc { data: ibc_dest });
}
// TODO: !!!!!!!! remove to here once there are no legacy IBC dests

Self::load(src, bytes)
}
}
Expand Down
42 changes: 30 additions & 12 deletions src/bin/nomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ pub enum Command {
BabylonRelayer(BabylonRelayerCmd),
#[cfg(feature = "babylon")]
StakeNbtc(StakeNbtcCmd),
#[cfg(feature = "frost")]
FrostSigner(FrostSignerCmd),
#[cfg(feature = "ethereum")]
RelayEthereum(RelayEthereumCmd),
#[cfg(feature = "ethereum")]
Expand Down Expand Up @@ -264,8 +262,6 @@ impl Command {
BabylonRelayer(cmd) => cmd.run().await,
#[cfg(feature = "babylon")]
StakeNbtc(cmd) => cmd.run().await,
#[cfg(feature = "frost")]
FrostSigner(cmd) => cmd.run().await,
#[cfg(feature = "ethereum")]
RelayEthereum(cmd) => cmd.run().await,
#[cfg(feature = "ethereum")]
Expand Down Expand Up @@ -1346,7 +1342,7 @@ impl ClaimAirdropCmd {
/// Relays data between the Bitcoin and Nomic networks.
#[derive(Parser, Debug)]
pub struct RelayerCmd {
/// The port of the Bitcoin RPC server.
/// The port of the local Bitcoin RPC server.
// TODO: get the default based on the network
#[clap(short = 'p', long, default_value_t = 8332)]
rpc_port: u16,
Expand All @@ -1359,14 +1355,22 @@ pub struct RelayerCmd {
#[clap(short = 'P', long)]
rpc_pass: Option<String>,

/// The URL for the Bitcoin RPC server, e.g. http://localhost:8332.
#[clap(short = 'r', long, conflicts_with = "rpc-port")]
rpc_url: Option<String>,

#[clap(flatten)]
config: nomic::network::Config,
}

impl RelayerCmd {
/// Builds Bitcoin RPC client.
async fn btc_client(&self) -> Result<BtcClient> {
let rpc_url = format!("http://localhost:{}", self.rpc_port);
let rpc_url = if let Some(rpc) = self.rpc_url.clone() {
rpc
} else {
format!("http://localhost:{}", self.rpc_port)
};
let auth = match (self.rpc_user.clone(), self.rpc_pass.clone()) {
(Some(user), Some(pass)) => Auth::UserPass(user, pass),
_ => Auth::None,
Expand Down Expand Up @@ -1503,7 +1507,17 @@ impl SignerCmd {

let relaunch = relaunch_on_migrate(&self.config);

futures::try_join!(signer, relaunch).unwrap();
#[cfg(feature = "frost")]
let frost_signer = {
let frost_cmd = FrostSignerCmd {
config: self.config.clone(),
};
frost_cmd.run()
};
#[cfg(not(feature = "frost"))]
let frost_signer = async { Ok(()) };

futures::try_join!(signer, relaunch, frost_signer).unwrap();

Ok(())
}
Expand Down Expand Up @@ -1806,8 +1820,10 @@ impl EthTransferNbtcCmd {
#[derive(Parser, Debug)]
pub struct GrpcCmd {
/// The port to listen on.
#[clap(default_value_t = 9001)]
#[clap(long, default_value_t = 9001)]
port: u16,
#[clap(long, default_value = "127.0.0.1")]
host: String,

#[clap(flatten)]
config: nomic::network::Config,
Expand All @@ -1817,12 +1833,14 @@ impl GrpcCmd {
/// Runs the `grpc` command.
async fn run(&self) -> Result<()> {
use orga::ibc::GrpcOpts;
std::panic::set_hook(Box::new(|_| {}));
std::panic::set_hook(Box::new(|e| {
log::error!("{}", e.to_string());
}));
log::info!("Starting gRPC server on {}:{}", self.host, self.port);
orga::ibc::start_grpc(
// TODO: support configuring RPC address
|| nomic::app_client("http://localhost:26657").sub(|app| Ok(app.ibc.ctx)),
|| self.config.client().sub(|app| Ok(app.ibc.ctx)),
&GrpcOpts {
host: "127.0.0.1".to_string(),
host: self.host.to_string(),
port: self.port,
chain_id: self.config.chain_id.clone().unwrap(),
},
Expand Down
13 changes: 13 additions & 0 deletions src/bitcoin/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,19 @@ impl CheckpointQueue {

Ok(())
}

/// Returns the pending transfers for the building checkpoint.
///
/// This query is a temporary workaround for a client iteration issue.
#[query]
pub fn pending(&self) -> Result<Vec<(Dest, Identity, u64)>> {
let mut pending = vec![];
for entry in self.building()?.pending.iter()? {
let (dest, coin) = entry?;
pending.push((dest.0.clone(), dest.1, coin.amount.into()));
}
Ok(pending)
}
}

/// Takes a previous fee rate and returns a new fee rate, adjusted up or down by
Expand Down
34 changes: 12 additions & 22 deletions src/bitcoin/deposit_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Deposit {
txid: Txid,
vout: u32,
amount: u64,
height: Option<u64>,
}

impl Deposit {
pub fn new(txid: Txid, vout: u32, amount: u64, height: Option<u64>) -> Self {
Self {
txid,
vout,
amount,
height,
}
}
pub txid: Txid,
pub vout: u32,
pub amount: u64,
pub height: Option<u64>,
pub sigset_index: u32,
pub miner_fee_rate: f64,
pub bridge_fee_rate: f64,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -96,13 +89,10 @@ impl DepositIndex {
None => 0,
};

// TODO
if confirmations == 0 {
deposits.push(DepositInfo {
deposit: deposit.clone(),
confirmations,
});
}
deposits.push(DepositInfo {
deposit: deposit.clone(),
confirmations,
});
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,18 @@ impl Bitcoin {
let expected_script =
sigset.output_script(&dest_bytes, self.checkpoints.config.sigset_threshold)?;
if output.script_pubkey != expected_script {
dest_bytes = dest.legacy_commitment_bytes()?;
let expected_script =
sigset.output_script(&dest_bytes, self.checkpoints.config.sigset_threshold)?;
if output.script_pubkey != expected_script {
let legacy_commitments = dest.legacy_commitment_bytes()?;
let mut matched = false;
for bytes in legacy_commitments {
let expected_script =
sigset.output_script(&dest_bytes, self.checkpoints.config.sigset_threshold)?;
if output.script_pubkey == expected_script {
matched = true;
dest_bytes = bytes;
break;
}
}
if !matched {
return Err(OrgaError::App(
"Output script does not match signer set".to_string(),
))?;
Expand Down
Loading
Loading