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

fix: remove sweep transaction message #1060

Merged
merged 13 commits into from
Dec 9, 2024
55 changes: 1 addition & 54 deletions protobufs/stacks/signer/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "stacks/signer/v1/requests.proto";

// Messages exchanged between signers
message SignerMessage {
reserved 9;
/// The bitcoin chain tip defining the signers view of the blockchain at the time the message was created
bitcoin.BitcoinBlockHash bitcoin_chain_tip = 1;
// The message payload
Expand All @@ -30,66 +31,12 @@ message SignerMessage {
// Contains all variants for DKG and WSTS signing rounds
WstsMessage wsts_message = 8;
// Information about a new sweep transaction
SweepTransactionInfo sweep_transaction_info = 9;
// Information about a new sweep transaction
BitcoinPreSignRequest bitcoin_pre_sign_request = 10;
// Represents an acknowledgment of a BitcoinPreSignRequest
BitcoinPreSignAck bitcoin_pre_sign_ack = 11;
}
}

// Represents information about a deposit request being swept-in by a sweep transaction.
message SweptDeposit {
// The index of the deposit input in the sBTC sweep transaction.
uint32 input_index = 1;
// The Bitcoin txid of the deposit request UTXO being swept-in by this
// transaction.
bitcoin.BitcoinTxid deposit_request_txid = 2;
// The Bitcoin output index of the deposit request UTXO being swept-in by
// this transaction.
uint32 deposit_request_output_index = 3;
}

// Represents information about a withdrawal request being swept-out by a sweep transaction.
message SweptWithdrawal {
// The index of the withdrawal output in the sBTC sweep transaction.
uint32 output_index = 1;
// The public request id of the withdrawal request serviced by this
// transaction.
uint64 withdrawal_request_id = 2;
// The Stacks block hash of the Stacks block which included the withdrawal
// request transaction.
stacks.StacksBlockId withdrawal_request_block_hash = 3;
}

// Represents information about a new sweep transaction.
message SweepTransactionInfo {
// The Bitcoin transaction id of the sweep transaction.
bitcoin.BitcoinTxid txid = 1;
// The transaction id of the signer UTXO consumed by this transaction.
bitcoin.BitcoinTxid signer_prevout_txid = 2;
// The index of the signer UTXO consumed by this transaction.
uint32 signer_prevout_output_index = 3;
// The amount of the signer UTXO consumed by this transaction.
uint64 signer_prevout_amount = 4;
// The public key of the signer UTXO consumed by this transaction.
bytes signer_prevout_script_pubkey = 5;
// The total **output** amount of this transaction.
uint64 amount = 6;
// The fee paid for this transaction.
uint64 fee = 7;
// The virtual size of this transaction (in bytes).
uint32 vsize = 8;
// The Bitcoin block hash at which this transaction was created.
bitcoin.BitcoinBlockHash created_at_block_hash = 9;
// The market fee rate at the time of this transaction.
double market_fee_rate = 10;
// List of deposits which were swept-in by this transaction.
repeated SweptDeposit swept_deposits = 11;
// List of withdrawals which were swept-out by this transaction.
repeated SweptWithdrawal swept_withdrawals = 12;
}

// A wsts message.
message WstsMessage {
// The transaction ID this message relates to, will be a dummy ID for DKG messages
Expand Down
3 changes: 3 additions & 0 deletions signer/migrations/0009__drop_sweep_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE sbtc_signer.swept_withdrawals;
DROP TABLE sbtc_signer.swept_deposits;
DROP TABLE sbtc_signer.sweep_transactions;
4 changes: 4 additions & 0 deletions signer/migrations/0010__add_bitcoin_tx_related_indices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE INDEX ix_bitcoin_tx_inputs_prevout_outpoint ON sbtc_signer.bitcoin_tx_inputs(prevout_txid, prevout_output_index);
CREATE INDEX ix_completed_deposit_events_outpoint ON sbtc_signer.completed_deposit_events(bitcoin_txid, output_index);
CREATE INDEX ix_stacks_blocks_bitcoin_anchor ON sbtc_signer.stacks_blocks(bitcoin_anchor);
CREATE INDEX ix_stacks_blocks_parent_hash ON sbtc_signer.stacks_blocks(parent_hash);
3 changes: 0 additions & 3 deletions signer/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ mod tests {
#[test_case(PhantomData::<message::BitcoinTransactionSignRequest> ; "BitcoinTransactionSignRequest")]
#[test_case(PhantomData::<message::BitcoinTransactionSignAck> ; "BitcoinTransactionSignAck")]
#[test_case(PhantomData::<message::WstsMessage> ; "WstsMessage")]
#[test_case(PhantomData::<message::SweepTransactionInfo> ; "SweepTransactionInfo")]
#[test_case(PhantomData::<message::BitcoinPreSignRequest> ; "BitcoinPreSignRequest")]
#[test_case(PhantomData::<message::BitcoinPreSignAck> ; "BitcoinPreSignAck")]
fn payload_signing_recovery<T>(_: PhantomData<T>)
Expand Down Expand Up @@ -326,7 +325,6 @@ mod tests {
#[test_case(PhantomData::<message::BitcoinTransactionSignRequest> ; "BitcoinTransactionSignRequest")]
#[test_case(PhantomData::<message::BitcoinTransactionSignAck> ; "BitcoinTransactionSignAck")]
#[test_case(PhantomData::<message::WstsMessage> ; "WstsMessage")]
#[test_case(PhantomData::<message::SweepTransactionInfo> ; "SweepTransactionInfo")]
#[test_case(PhantomData::<message::BitcoinPreSignRequest> ; "BitcoinPreSignRequest")]
#[test_case(PhantomData::<message::BitcoinPreSignAck> ; "BitcoinPreSignAck")]
fn payload_signing_failing_validation<T>(_: PhantomData<T>)
Expand Down Expand Up @@ -415,7 +413,6 @@ mod tests {
#[test_case(PhantomData::<message::BitcoinTransactionSignRequest> ; "BitcoinTransactionSignRequest")]
#[test_case(PhantomData::<message::BitcoinTransactionSignAck> ; "BitcoinTransactionSignAck")]
#[test_case(PhantomData::<message::WstsMessage> ; "WstsMessage")]
#[test_case(PhantomData::<message::SweepTransactionInfo> ; "SweepTransactionInfo")]
#[test_case(PhantomData::<message::BitcoinPreSignRequest> ; "BitcoinPreSignRequest")]
#[test_case(PhantomData::<message::BitcoinPreSignAck> ; "BitcoinPreSignAck")]
fn backwards_compatible_updates<T>(_: PhantomData<T>)
Expand Down
123 changes: 0 additions & 123 deletions signer/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use secp256k1::ecdsa::RecoverableSignature;
use crate::bitcoin::utxo::Fees;
use crate::bitcoin::validation::TxRequestIds;
use crate::keys::PublicKey;
use crate::keys::SignerScriptPubKey as _;
use crate::stacks::contracts::StacksTx;
use crate::storage::model::BitcoinBlockHash;
use crate::storage::model::StacksTxId;
Expand Down Expand Up @@ -36,8 +35,6 @@ pub enum Payload {
BitcoinTransactionSignAck(BitcoinTransactionSignAck),
/// Contains all variants for DKG and WSTS signing rounds
WstsMessage(WstsMessage),
/// Information about a new sweep transaction
SweepTransactionInfo(SweepTransactionInfo),
/// Information about a new Bitcoin block sign request
BitcoinPreSignRequest(BitcoinPreSignRequest),
/// An acknowledgment of a BitconPreSignRequest
Expand Down Expand Up @@ -75,7 +72,6 @@ impl std::fmt::Display for Payload {
}
write!(f, ")")
}
Self::SweepTransactionInfo(_) => write!(f, "SweepTransactionInfo(..)"),
Self::BitcoinPreSignRequest(_) => write!(f, "BitcoinPreSignRequest(..)"),
Self::BitcoinPreSignAck(_) => write!(f, "BitcoinPreSignAck(..)"),
}
Expand Down Expand Up @@ -134,12 +130,6 @@ impl From<WstsMessage> for Payload {
}
}

impl From<SweepTransactionInfo> for Payload {
fn from(value: SweepTransactionInfo) -> Self {
Self::SweepTransactionInfo(value)
}
}

impl From<BitcoinPreSignRequest> for Payload {
fn from(value: BitcoinPreSignRequest) -> Self {
Self::BitcoinPreSignRequest(value)
Expand All @@ -152,117 +142,6 @@ impl From<BitcoinPreSignAck> for Payload {
}
}

/// Represents information about a new sweep transaction.
#[derive(Debug, Clone, PartialEq)]
pub struct SweepTransactionInfo {
/// The Bitcoin transaction id of the sweep transaction.
pub txid: bitcoin::Txid,
/// The transaction id of the signer UTXO consumed by this transaction.
pub signer_prevout_txid: bitcoin::Txid,
/// The index of the signer UTXO consumed by this transaction.
pub signer_prevout_output_index: u32,
/// The amount of the signer UTXO consumed by this transaction.
pub signer_prevout_amount: u64,
/// The public key of the signer UTXO consumed by this transaction.
pub signer_prevout_script_pubkey: bitcoin::ScriptBuf,
/// The total **output** amount of this transaction.
pub amount: u64,
/// The fee paid for this transaction.
pub fee: u64,
/// The virtual size of this transaction (in bytes).
pub vsize: u32,
/// The Bitcoin block hash at which this transaction was created.
pub created_at_block_hash: bitcoin::BlockHash,
/// The market fee rate at the time of this transaction.
pub market_fee_rate: f64,
/// List of deposits which were swept-in by this transaction.
pub swept_deposits: Vec<SweptDeposit>,
/// List of withdrawals which were swept-out by this transaction.
pub swept_withdrawals: Vec<SweptWithdrawal>,
}

impl SweepTransactionInfo {
/// Creates a [`SweepTransactionInfo`] from an [`UnsignedTransaction`] and a
/// Bitcoin block hash.
pub fn from_unsigned_at_block(
block_hash: &bitcoin::BlockHash,
unsigned: &crate::bitcoin::utxo::UnsignedTransaction,
) -> SweepTransactionInfo {
let swept_deposits = unsigned
.requests
.iter()
.filter_map(|request| request.as_deposit())
.enumerate()
.map(|(index, request)| {
SweptDeposit {
input_index: index as u32 + 1, // Account for the signer's UTXO
deposit_request_txid: request.outpoint.txid,
deposit_request_output_index: request.outpoint.vout,
}
})
.collect();

let swept_withdrawals = unsigned
.requests
.iter()
.filter_map(|request| request.as_withdrawal())
.enumerate()
.map(|(index, withdrawal)| {
SweptWithdrawal {
output_index: index as u32 + 2, // Account for the signer's UTXO and OP_RETURN
withdrawal_request_id: withdrawal.request_id,
withdrawal_request_block_hash: *withdrawal.block_hash.as_bytes(),
}
})
.collect();

SweepTransactionInfo {
txid: unsigned.tx.compute_txid(),
signer_prevout_txid: unsigned.signer_utxo.utxo.outpoint.txid,
signer_prevout_output_index: unsigned.signer_utxo.utxo.outpoint.vout,
signer_prevout_amount: unsigned.signer_utxo.utxo.amount,
signer_prevout_script_pubkey: unsigned
.signer_utxo
.utxo
.public_key
.signers_script_pubkey(),
amount: unsigned.output_amounts(),
fee: unsigned.tx_fee,
vsize: unsigned.tx_vsize,
market_fee_rate: unsigned.signer_utxo.fee_rate,
created_at_block_hash: *block_hash,
swept_deposits,
swept_withdrawals,
}
}
}

/// Represents information about a deposit request being swept-in by a sweep transaction.
#[derive(Debug, Clone, PartialEq)]
pub struct SweptDeposit {
/// The index of the deposit input in the sBTC sweep transaction.
pub input_index: u32,
/// The Bitcoin txid of the deposit request UTXO being swept-in by this
/// transaction.
pub deposit_request_txid: bitcoin::Txid,
/// The Bitcoin output index of the deposit request UTXO being swept-in by
/// this transaction.
pub deposit_request_output_index: u32,
}

/// Represents information about a withdrawal request being swept-out by a sweep transaction.
#[derive(Debug, Clone, PartialEq)]
pub struct SweptWithdrawal {
/// The index of the withdrawal output in the sBTC sweep transaction.
pub output_index: u32,
/// The public request id of the withdrawal request serviced by this
/// transaction.
pub withdrawal_request_id: u64,
/// The Stacks block hash of the Stacks block which included the withdrawal
/// request transaction.
pub withdrawal_request_block_hash: StacksBlockHash,
}

/// Represents a decision related to signer deposit
#[derive(Debug, Clone, PartialEq)]
pub struct SignerDepositDecision {
Expand Down Expand Up @@ -386,7 +265,6 @@ mod tests {
#[test_case(PhantomData::<BitcoinTransactionSignRequest> ; "BitcoinTransactionSignRequest")]
#[test_case(PhantomData::<BitcoinTransactionSignAck> ; "BitcoinTransactionSignAck")]
#[test_case(PhantomData::<WstsMessage> ; "WstsMessage")]
#[test_case(PhantomData::<SweepTransactionInfo> ; "SweepTransactionInfo")]
#[test_case(PhantomData::<BitcoinPreSignRequest> ; "BitcoinPreSignRequest")]
fn signer_messages_should_be_signable_with_type<P>(_: PhantomData<P>)
where
Expand All @@ -409,7 +287,6 @@ mod tests {
#[test_case(PhantomData::<BitcoinTransactionSignRequest> ; "BitcoinTransactionSignRequest")]
#[test_case(PhantomData::<BitcoinTransactionSignAck> ; "BitcoinTransactionSignAck")]
#[test_case(PhantomData::<WstsMessage> ; "WstsMessage")]
#[test_case(PhantomData::<SweepTransactionInfo> ; "SweepTransactionInfo")]
#[test_case(PhantomData::<BitcoinPreSignRequest> ; "BitcoinPreSignRequest")]
fn signer_messages_should_be_encodable_with_type<P>(_: PhantomData<P>)
where
Expand Down
Loading
Loading