Skip to content

MICRO: Chore/debug assert warnings #131

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

Merged
merged 3 commits into from
May 14, 2025
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
57 changes: 45 additions & 12 deletions crates/duty-tracker/src/contract_state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ impl ContractSM {
// TODO(proofofkeags): thoroughly review this code it is ALMOST CERTAINLY WRONG IN SOME
// SUBTLE WAY.

let deposit_txid = self.deposit_txid();
match &mut self.state.state {
ContractState::Requested {
peg_out_graph_inputs,
Expand All @@ -1156,14 +1157,6 @@ impl ContractSM {
graph_partials,
..
} => {
if peg_out_graph_inputs.contains_key(&signer) {
let deposit_txid = self.deposit_txid();
warn!("already received operator's ({signer}) deposit setup for contract {deposit_txid}");

// FIXME: (@Rajil1213) this should return an error
return Ok(vec![]);
}

let pog_input = PegOutGraphInput {
stake_outpoint: OutPoint::new(new_stake_tx.compute_txid(), STAKE_VOUT),
withdrawal_fulfillment_outpoint: OutPoint::new(
Expand All @@ -1174,6 +1167,20 @@ impl ContractSM {
wots_public_keys: new_wots_keys.clone(),
operator_pubkey,
};

if let Some(existing) = peg_out_graph_inputs.get(&signer) {
warn!(
"already received deposit setup from {signer} for contract {deposit_txid}"
);
debug_assert_eq!(
&pog_input, existing,
"conflicting deposit setup from {signer} for contract {deposit_txid}"
);

// FIXME: (@Rajil1213) this should return an error
return Ok(vec![]);
}

peg_out_graph_inputs.insert(signer, pog_input.clone());

if peg_out_graph_inputs.len() != self.cfg.operator_table.cardinality() {
Expand Down Expand Up @@ -1311,8 +1318,14 @@ impl ContractSM {
)));
};

if session_nonces.contains_key(&signer) {
if let Some(existing) = session_nonces.get(&signer) {
warn!(%claim_txid, %signer, "already received nonces for graph");
debug_assert_eq!(
&unpacked, existing,
"conflicting graph nonces received from {} for claim {}",
signer, claim_txid
);

// FIXME: (@Rajil1213) this should return an error
return Ok(None);
}
Expand Down Expand Up @@ -1413,8 +1426,14 @@ impl ContractSM {
)));
};

if session_partials.contains_key(&signer) {
if let Some(existing) = session_partials.get(&signer) {
warn!(%claim_txid, %signer, "already received signatures for graph");
debug_assert_eq!(
&unpacked, existing,
"conflicting graph signatures received from {} for claim {}",
&signer, &claim_txid
);

// FIXME: (@Rajil1213) this should return an error
return Ok(None);
}
Expand Down Expand Up @@ -1460,10 +1479,17 @@ impl ContractSM {
signer: P2POperatorPubKey,
nonce: PubNonce,
) -> Result<Option<OperatorDuty>, TransitionErr> {
let deposit_txid = self.deposit_txid();
match &mut self.state.state {
ContractState::Requested { root_nonces, .. } => {
if root_nonces.contains_key(&signer) {
if let Some(existing) = root_nonces.get(&signer) {
warn!(%signer, "already received nonce for root");
debug_assert_eq!(
&nonce, existing,
"conflicting root nonce received from {} for contract {}",
signer, deposit_txid,
);

// FIXME: (@Rajil1213) this should return an error
return Ok(None);
}
Expand Down Expand Up @@ -1527,10 +1553,17 @@ impl ContractSM {
signer: P2POperatorPubKey,
sig: PartialSignature,
) -> Result<Option<OperatorDuty>, TransitionErr> {
let deposit_txid = self.deposit_txid();
match &mut self.state.state {
ContractState::Requested { root_partials, .. } => {
if root_partials.contains_key(&signer) {
if let Some(existing) = root_partials.get(&signer) {
warn!(%signer, "already received signature for root");
debug_assert_eq!(
&sig, existing,
"conflicting root signature received from {} for contract {}",
signer, deposit_txid
);

// FIXME: (@Rajil1213) this should return an error
return Ok(None);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tx-graph/src/peg_out_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
///
/// This data is shared between various operators and verifiers and is used to construct the peg out
/// graph deterministically.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PegOutGraphInput {
/// The [`OutPoint`] of the stake transaction
pub stake_outpoint: OutPoint,
Expand Down
2 changes: 1 addition & 1 deletion crates/tx-graph/src/pog_musig_functor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::transactions::{

/// Functor like data structure for holding an arbitrary data structure that is matched with each of
/// the inputs of the peg-out graph.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PogMusigF<T> {
/// Data associated with the challenge transaction input.
pub challenge: T,
Expand Down
Loading