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

Timestamping commitments #222

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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)?;
Expand Down
13 changes: 13 additions & 0 deletions src/bitcoin/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ impl<'a> BuildingCheckpointMut<'a> {
nbtc_accounts: &Accounts<Nbtc>,
recovery_scripts: &Map<orga::coins::Address, Adapter<bitcoin::Script>>,
external_outputs: impl Iterator<Item = Result<bitcoin::TxOut>>,
timestamping_commitment: Vec<u8>,
config: &Config,
) -> Result<BuildingAdvanceRes> {
self.0.status = CheckpointStatus::Signing;
Expand All @@ -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(&timestamping_commitment),
};

let fee_rate = self.fee_rate;

let mut checkpoint_batch = self
Expand All @@ -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![];
Expand Down Expand Up @@ -1236,6 +1245,7 @@ impl CheckpointQueue {
}

#[cfg(feature = "full")]
#[allow(clippy::too_many_arguments)]
pub fn maybe_step(
&mut self,
sig_keys: &Map<ConsensusKey, Xpub>,
Expand All @@ -1244,6 +1254,7 @@ impl CheckpointQueue {
external_outputs: impl Iterator<Item = Result<bitcoin::TxOut>>,
btc_height: u32,
should_allow_deposits: bool,
timestamping_commitment: Vec<u8>,
) -> Result<bool> {
if !self.should_push(sig_keys)? {
return Ok(false);
Expand All @@ -1266,6 +1277,7 @@ impl CheckpointQueue {
nbtc_accounts,
recovery_scripts,
external_outputs,
timestamping_commitment,
&config,
)?;

Expand Down Expand Up @@ -1756,6 +1768,7 @@ mod test {
.into_iter(),
btc_height,
true,
vec![1, 2, 3],
)
.unwrap();
};
Expand Down
5 changes: 4 additions & 1 deletion src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ impl Bitcoin {
pub fn begin_block_step(
&mut self,
external_outputs: impl Iterator<Item = Result<bitcoin::TxOut>>,
timestamping_commitment: Vec<u8>,
) -> Result<Vec<ConsensusKey>> {
let has_completed_cp = if let Err(Error::Orga(OrgaError::App(err))) =
self.checkpoints.last_completed_index()
Expand Down Expand Up @@ -757,6 +758,7 @@ impl Bitcoin {
external_outputs,
self.headers.height()?,
!reached_capacity_limit,
timestamping_commitment,
)
.map_err(|err| OrgaError::App(err.to_string()))?;

Expand Down Expand Up @@ -1095,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);
Expand Down
Loading