Skip to content

Commit

Permalink
Merge pull request #281 from nomic-io/stakenet-8
Browse files Browse the repository at this point in the history
Stakenet 8 staging
  • Loading branch information
mappum authored Feb 16, 2024
2 parents 4743a33 + e8982b8 commit de4cd2b
Show file tree
Hide file tree
Showing 12 changed files with 2,641 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nomic"
version = "7.1.0"
version = "8.0.0"
authors = ["The Turbofish Team <[email protected]>"]
edition = "2021"
default-run = "nomic"
Expand Down Expand Up @@ -66,7 +66,7 @@ toml = { version = "0.7.2", features = ["parse"] }
semver = "1.0.18"

[features]
default = ["full", "feat-ibc", "testnet"]
default = ["full", "feat-ibc", "legacy-bin"]
full = [
"bitcoincore-rpc-async",
"clap",
Expand Down
25 changes: 25 additions & 0 deletions kujira-header.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": {
"block": "11",
"app": "0"
},
"chain_id": "kaiyo-1",
"height": "17274076",
"time": "2024-02-14T23:37:35.000396121Z",
"last_block_id": {
"hash": "3910A03BA4686B473FDE2ABE3841B173912A1CB3639D3CD3D035C1958E5EF2C5",
"parts": {
"total": 1,
"hash": "A747F8D9E14838810BB6D11679599F7AEDFE96FC576986C128395B95FA322175"
}
},
"last_commit_hash": "67E596145966D25D571179EF61EAE1F88CE073928133E9A47CFB289685A2986C",
"data_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"validators_hash": "FA2DD25B68A8F66E2F51423B752BA1E021743E16AB5DCFF0FAA1447A29C67CCD",
"next_validators_hash": "FA2DD25B68A8F66E2F51423B752BA1E021743E16AB5DCFF0FAA1447A29C67CCD",
"consensus_hash": "733AA1E31667798A5FE820CBA8F8A5BE6C2591CAC7E9A867B7F40C4CC2928D88",
"app_hash": "86AEC05E1D422E76D342B35AC2C036C2858AF0675BB9935C2FAB9A6D458C4FBE",
"last_results_hash": "25259CDADBA8BD3D94CC0B8FDEB9CEF35C07E7733CABEB0B180FE6362EEB6F81",
"evidence_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"proposer_address": "A8CB605C4A9722FF690A6C66951B04591E3508F5"
}
2 changes: 1 addition & 1 deletion networks/stakenet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ btc_relayer = [
"https://relayer.nomic.mappum.io:8443"
]

legacy_version = "6.0.x"
legacy_version = "7.0.x"

genesis = """
{
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ impl ConvertSdkTx for InnerApp {
Ok(PaidCall { payer, paid })
}

"nomic/PayToFeePool" => {
"nomic/MsgPayToFeePool" => {
let msg = msg
.value
.as_object()
Expand Down
51 changes: 48 additions & 3 deletions src/app/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use crate::incentives::Incentives;
use crate::{
bitcoin::{
adapter::Adapter,
header_queue::{WorkHeader, WrappedHeader},
},
incentives::Incentives,
};

use super::{InnerAppV0, InnerAppV1, InnerAppV2, InnerAppV3, InnerAppV4, InnerAppV5};
use bitcoin::{
util::{uint::Uint256, BitArray},
BlockHeader,
};
use orga::{
coins::Take,
ibc::Ibc,
Expand Down Expand Up @@ -89,10 +99,45 @@ impl MigrateFrom<InnerAppV3> for InnerAppV4 {
}

impl MigrateFrom<InnerAppV4> for InnerAppV5 {
fn migrate_from(other: InnerAppV4) -> Result<Self> {
#[allow(unused_mut)]
fn migrate_from(mut other: InnerAppV4) -> Result<Self> {
#[cfg(not(feature = "testnet"))]
{
todo!()
other.bitcoin.checkpoints.config.max_age = 60 * 60 * 24 * 30 * 4;
other.bitcoin.headers.config.max_length = 24_192;

// remove headers and revert to checkpoint so we can regain history which was pruned
other
.bitcoin
.headers
.deque
.retain_unordered(|_| Ok(false))?;
let checkpoint_json = include_str!("../bitcoin/checkpoint.json");
let header: (u32, BlockHeader) = serde_json::from_str(checkpoint_json)?;
let wrapped_header = WrappedHeader::new(Adapter::new(header.1), header.0);
let work_header = WorkHeader::new(wrapped_header.clone(), wrapped_header.work());
other.bitcoin.headers.current_work = Adapter::new(work_header.work());
other.bitcoin.headers.deque.push_back(work_header)?;

// backfill checkpoint history
use bitcoin::hashes::hex::FromHex;
let scripts = include_str!("../../stakenet_reserve_scripts.csv")
.lines()
.map(|line| {
let mut parts = line.split(',');
parts.next().unwrap();
parts.next().unwrap()
})
.map(|script_hex| bitcoin::Script::from_hex(script_hex).unwrap());
other.bitcoin.checkpoints.backfill(
4285,
scripts,
other.bitcoin.checkpoints.config.sigset_threshold,
)?;

other
.ibc
.update_client_from_header(0, 1, include_str!("../../kujira-header.json"))?;
}

Ok(Self {
Expand Down
17 changes: 12 additions & 5 deletions src/bin/nomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,8 @@ pub struct RecoverDepositCmd {
channel: Option<String>,
#[clap(long)]
remote_addr: Option<String>,
#[clap(long)]
remote_prefix: Option<String>,

#[clap(long)]
nomic_addr: Address,
Expand Down Expand Up @@ -2005,9 +2007,16 @@ impl RecoverDepositCmd {
}

async fn run(&self) -> Result<()> {
if self.channel.is_some() != self.remote_addr.is_some() {
let mut remote_addr = self.remote_addr.clone();
if let Some(remote_prefix) = &self.remote_prefix {
let data = bech32::decode(&self.nomic_addr.to_string()).unwrap().1;
remote_addr =
Some(bech32::encode(remote_prefix, data, bech32::Variant::Bech32).unwrap());
}

if self.channel.is_some() != remote_addr.is_some() {
return Err(nomic::error::Error::Orga(orga::Error::App(
"Both --channel and --remote-prefix must be specified".to_string(),
"Both --channel and --remote-prefix or --remote-addr must be specified".to_string(),
)));
}

Expand All @@ -2034,9 +2043,7 @@ impl RecoverDepositCmd {

dbg!(sigsets.len());

if let (Some(channel), Some(remote_addr)) =
(self.channel.as_ref(), self.remote_addr.as_ref())
{
if let (Some(channel), Some(remote_addr)) = (self.channel.as_ref(), remote_addr.as_ref()) {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
Expand Down
14 changes: 7 additions & 7 deletions src/bitcoin/checkpoint.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
739872,
802368,
{
"version": 939515904,
"prev_blockhash": "000000000000000000050c04aa3e3ca62420b6366e20ebea29ed3042320d2e4b",
"merkle_root": "627d7b1d4e9a6978bd178e34232e4f58aadecb1786cc503af3c80afc0124976a",
"time": 1654686448,
"bits": 386485098,
"nonce": 61613729
"version": 1073676288,
"prev_blockhash": "000000000000000000034e1a8f7c1efee7c36209a1556a377568d6368431dd17",
"merkle_root": "7718a5c199d9a5b6ad3d1424db6d4212bbbc1cbfe573caf58f129d24e40b15eb",
"time": 1691584068,
"bits": 386228059,
"nonce": 4602308
}
]
2 changes: 1 addition & 1 deletion src/bitcoin/header_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl Config {
pub struct HeaderQueue {
pub(crate) deque: Deque<WorkHeader>,
pub(crate) current_work: Adapter<Uint256>,
config: Config,
pub(crate) config: Config,
}

impl MigrateFrom<HeaderQueueV0> for HeaderQueueV1 {
Expand Down
6 changes: 0 additions & 6 deletions src/bitcoin/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,6 @@ impl Relayer {
batch[0].height(),
batch.len(),
);
app_client(&self.app_client_addr)
.call(
|app| build_call!(app.bitcoin.headers.add(batch.clone().into_iter().collect())),
|app| build_call!(app.app_noop()),
)
.await?;
let res = app_client(&self.app_client_addr)
.call(
move |app| build_call!(app.bitcoin.headers.add(batch.clone().into())),
Expand Down
Loading

0 comments on commit de4cd2b

Please sign in to comment.