From 277b2e9f93b0a8c07803861c722b00edf599f11b Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 11 Oct 2023 19:44:09 -0500 Subject: [PATCH 1/4] Add block hash timestamping to checkpoints --- src/app.rs | 2 +- src/bitcoin/checkpoint.rs | 11 +++++++++++ src/bitcoin/mod.rs | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 8aaa2c14..f7ada40c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -495,7 +495,7 @@ mod abci { }; let offline_signers = self .bitcoin - .begin_block_step(external_outputs.into_iter().map(Ok))?; + .begin_block_step(external_outputs.into_iter().map(Ok), ctx.hash.clone())?; for cons_key in offline_signers { let address = self.staking.address_by_consensus_key(cons_key)?.unwrap(); self.staking.punish_downtime(address)?; diff --git a/src/bitcoin/checkpoint.rs b/src/bitcoin/checkpoint.rs index 9e6239cd..5b62036a 100644 --- a/src/bitcoin/checkpoint.rs +++ b/src/bitcoin/checkpoint.rs @@ -921,6 +921,7 @@ impl<'a> BuildingCheckpointMut<'a> { nbtc_accounts: &Accounts, recovery_scripts: &Map>, external_outputs: impl Iterator>, + timestamping_commitment: Vec, config: &Config, ) -> Result { self.0.status = CheckpointStatus::Signing; @@ -933,6 +934,11 @@ impl<'a> BuildingCheckpointMut<'a> { .output_script(&[0u8], config.sigset_threshold)?, }; + let timestamping_commitment_out = bitcoin::TxOut { + value: 0, + script_pubkey: bitcoin::Script::new_op_return(×tamping_commitment), + }; + let fee_rate = self.fee_rate; let mut checkpoint_batch = self @@ -942,6 +948,9 @@ impl<'a> BuildingCheckpointMut<'a> { .unwrap(); let mut checkpoint_tx = checkpoint_batch.get_mut(0)?.unwrap(); + checkpoint_tx + .output + .push_front(Adapter::new(timestamping_commitment_out))?; checkpoint_tx.output.push_front(Adapter::new(reserve_out))?; let mut excess_inputs = vec![]; @@ -1244,6 +1253,7 @@ impl CheckpointQueue { external_outputs: impl Iterator>, btc_height: u32, should_allow_deposits: bool, + timestamping_commitment: Vec, ) -> Result { if !self.should_push(sig_keys)? { return Ok(false); @@ -1266,6 +1276,7 @@ impl CheckpointQueue { nbtc_accounts, recovery_scripts, external_outputs, + timestamping_commitment, &config, )?; diff --git a/src/bitcoin/mod.rs b/src/bitcoin/mod.rs index 850c5da6..d2ca7bb4 100644 --- a/src/bitcoin/mod.rs +++ b/src/bitcoin/mod.rs @@ -729,6 +729,7 @@ impl Bitcoin { pub fn begin_block_step( &mut self, external_outputs: impl Iterator>, + timestamping_commitment: Vec, ) -> Result> { let has_completed_cp = if let Err(Error::Orga(OrgaError::App(err))) = self.checkpoints.last_completed_index() @@ -757,6 +758,7 @@ impl Bitcoin { external_outputs, self.headers.height()?, !reached_capacity_limit, + timestamping_commitment, ) .map_err(|err| OrgaError::App(err.to_string()))?; From 803bdb6ef0cdcfe81a7f89aea54f07d3f9d62b5b Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 12 Oct 2023 14:13:09 -0500 Subject: [PATCH 2/4] Fix test --- src/bitcoin/checkpoint.rs | 1 + src/bitcoin/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bitcoin/checkpoint.rs b/src/bitcoin/checkpoint.rs index 5b62036a..09404ca0 100644 --- a/src/bitcoin/checkpoint.rs +++ b/src/bitcoin/checkpoint.rs @@ -1767,6 +1767,7 @@ mod test { .into_iter(), btc_height, true, + vec![1, 2, 3], ) .unwrap(); }; diff --git a/src/bitcoin/mod.rs b/src/bitcoin/mod.rs index d2ca7bb4..688e0d4f 100644 --- a/src/bitcoin/mod.rs +++ b/src/bitcoin/mod.rs @@ -1097,7 +1097,8 @@ mod tests { let maybe_step = || { let mut btc = btc.borrow_mut(); - btc.begin_block_step(vec![].into_iter()).unwrap(); + btc.begin_block_step(vec![].into_iter(), vec![1, 2, 3]) + .unwrap(); }; set_time(0); From b81263d50e18ebc6505645527040d15b81038d6a Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 12 Oct 2023 14:27:32 -0500 Subject: [PATCH 3/4] Bump CONSENSUS_VERSION --- src/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index f7ada40c..acf77f9d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -106,7 +106,7 @@ pub struct InnerApp { #[orga] impl InnerApp { - pub const CONSENSUS_VERSION: u8 = 6; + pub const CONSENSUS_VERSION: u8 = 7; #[cfg(feature = "full")] fn configure_faucets(&mut self) -> Result<()> { From 9f7da2b8dee62a30f41bdc36ee0bfb8cfea1d461 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 12 Oct 2023 14:29:03 -0500 Subject: [PATCH 4/4] Suppress warning --- src/bitcoin/checkpoint.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bitcoin/checkpoint.rs b/src/bitcoin/checkpoint.rs index 09404ca0..a0d16f31 100644 --- a/src/bitcoin/checkpoint.rs +++ b/src/bitcoin/checkpoint.rs @@ -1245,6 +1245,7 @@ impl CheckpointQueue { } #[cfg(feature = "full")] + #[allow(clippy::too_many_arguments)] pub fn maybe_step( &mut self, sig_keys: &Map,