Skip to content

Commit c8482ec

Browse files
committed
duty-tracker: give every warn! in the csm a debug_assert! to keep demons away
1 parent 5b21391 commit c8482ec

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

crates/duty-tracker/src/contract_state_machine.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ impl ContractSM {
11471147
// TODO(proofofkeags): thoroughly review this code it is ALMOST CERTAINLY WRONG IN SOME
11481148
// SUBTLE WAY.
11491149

1150+
let deposit_txid = self.deposit_txid();
11501151
match &mut self.state.state {
11511152
ContractState::Requested {
11521153
peg_out_graph_inputs,
@@ -1156,14 +1157,6 @@ impl ContractSM {
11561157
graph_partials,
11571158
..
11581159
} => {
1159-
if peg_out_graph_inputs.contains_key(&signer) {
1160-
let deposit_txid = self.deposit_txid();
1161-
warn!("already received operator's ({signer}) deposit setup for contract {deposit_txid}");
1162-
1163-
// FIXME: (@Rajil1213) this should return an error
1164-
return Ok(vec![]);
1165-
}
1166-
11671160
let pog_input = PegOutGraphInput {
11681161
stake_outpoint: OutPoint::new(new_stake_tx.compute_txid(), STAKE_VOUT),
11691162
withdrawal_fulfillment_outpoint: OutPoint::new(
@@ -1174,6 +1167,20 @@ impl ContractSM {
11741167
wots_public_keys: new_wots_keys.clone(),
11751168
operator_pubkey,
11761169
};
1170+
1171+
if let Some(existing) = peg_out_graph_inputs.get(&signer) {
1172+
warn!(
1173+
"already received deposit setup from {signer} for contract {deposit_txid}"
1174+
);
1175+
debug_assert_eq!(
1176+
&pog_input, existing,
1177+
"conflicting deposit setup from {signer} for contract {deposit_txid}"
1178+
);
1179+
1180+
// FIXME: (@Rajil1213) this should return an error
1181+
return Ok(vec![]);
1182+
}
1183+
11771184
peg_out_graph_inputs.insert(signer, pog_input.clone());
11781185

11791186
if peg_out_graph_inputs.len() != self.cfg.operator_table.cardinality() {
@@ -1311,8 +1318,14 @@ impl ContractSM {
13111318
)));
13121319
};
13131320

1314-
if session_nonces.contains_key(&signer) {
1321+
if let Some(existing) = session_nonces.get(&signer) {
13151322
warn!(%claim_txid, %signer, "already received nonces for graph");
1323+
debug_assert_eq!(
1324+
&unpacked, existing,
1325+
"conflicting graph nonces received from {} for claim {}",
1326+
signer, claim_txid
1327+
);
1328+
13161329
// FIXME: (@Rajil1213) this should return an error
13171330
return Ok(None);
13181331
}
@@ -1413,8 +1426,14 @@ impl ContractSM {
14131426
)));
14141427
};
14151428

1416-
if session_partials.contains_key(&signer) {
1429+
if let Some(existing) = session_partials.get(&signer) {
14171430
warn!(%claim_txid, %signer, "already received signatures for graph");
1431+
debug_assert_eq!(
1432+
&unpacked, existing,
1433+
"conflicting graph signatures received from {} for claim {}",
1434+
&signer, &claim_txid
1435+
);
1436+
14181437
// FIXME: (@Rajil1213) this should return an error
14191438
return Ok(None);
14201439
}
@@ -1460,10 +1479,17 @@ impl ContractSM {
14601479
signer: P2POperatorPubKey,
14611480
nonce: PubNonce,
14621481
) -> Result<Option<OperatorDuty>, TransitionErr> {
1482+
let deposit_txid = self.deposit_txid();
14631483
match &mut self.state.state {
14641484
ContractState::Requested { root_nonces, .. } => {
1465-
if root_nonces.contains_key(&signer) {
1485+
if let Some(existing) = root_nonces.get(&signer) {
14661486
warn!(%signer, "already received nonce for root");
1487+
debug_assert_eq!(
1488+
&nonce, existing,
1489+
"conflicting root nonce received from {} for contract {}",
1490+
signer, deposit_txid,
1491+
);
1492+
14671493
// FIXME: (@Rajil1213) this should return an error
14681494
return Ok(None);
14691495
}
@@ -1527,10 +1553,17 @@ impl ContractSM {
15271553
signer: P2POperatorPubKey,
15281554
sig: PartialSignature,
15291555
) -> Result<Option<OperatorDuty>, TransitionErr> {
1556+
let deposit_txid = self.deposit_txid();
15301557
match &mut self.state.state {
15311558
ContractState::Requested { root_partials, .. } => {
1532-
if root_partials.contains_key(&signer) {
1559+
if let Some(existing) = root_partials.get(&signer) {
15331560
warn!(%signer, "already received signature for root");
1561+
debug_assert_eq!(
1562+
&sig, existing,
1563+
"conflicting root signature received from {} for contract {}",
1564+
signer, deposit_txid
1565+
);
1566+
15341567
// FIXME: (@Rajil1213) this should return an error
15351568
return Ok(None);
15361569
}

0 commit comments

Comments
 (0)