-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubprotocol.rs
More file actions
109 lines (92 loc) · 3.43 KB
/
subprotocol.rs
File metadata and controls
109 lines (92 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! Debug subprotocol implementation.
//!
//! This module contains the core subprotocol implementation that integrates
//! with the Strata Anchor State Machine (ASM).
use ssz_derive::{Decode, Encode};
use strata_asm_bridge_msgs::{BridgeIncomingMsg, DispatchWithdrawalPayload};
use strata_asm_common::{
AsmError, AsmLogEntry, MsgRelayer, NullMsg, Subprotocol, SubprotocolId, TxInputRef,
VerifiedAuxData, logging,
};
use strata_identifiers::L1BlockCommitment;
use crate::{
constants::DEBUG_SUBPROTOCOL_ID,
txs::{ParsedDebugTx, parse_debug_tx},
};
/// Debug subprotocol implementation.
///
/// This subprotocol provides testing capabilities by processing special
/// L1 transactions that inject mock data into the ASM.
#[derive(Copy, Clone, Debug)]
pub struct DebugSubproto;
#[derive(Copy, Clone, Debug, Default, Encode, Decode)]
pub struct DebugState;
impl Subprotocol for DebugSubproto {
const ID: SubprotocolId = DEBUG_SUBPROTOCOL_ID;
type Msg = NullMsg<DEBUG_SUBPROTOCOL_ID>;
type InitConfig = ();
type State = DebugState;
fn init(_config: &Self::InitConfig) -> Self::State {
logging::info!("Initializing debug subprotocol state");
DebugState
}
fn process_txs(
_state: &mut Self::State,
txs: &[TxInputRef<'_>],
_l1ref: &L1BlockCommitment,
_verified_aux_data: &VerifiedAuxData,
relayer: &mut impl MsgRelayer,
) {
for tx_ref in txs {
logging::debug!(
tx_type = tx_ref.tag().tx_type(),
"Processing debug transaction"
);
match parse_debug_tx(tx_ref) {
Ok(parsed_tx) => {
if let Err(e) = process_parsed_debug_tx(parsed_tx, relayer) {
logging::warn!("Failed to process debug transaction: {}", e);
}
}
Err(e) => {
logging::warn!("Failed to parse debug transaction: {}", e);
}
}
}
}
fn process_msgs(_state: &mut Self::State, _msgs: &[Self::Msg], _l1ref: &L1BlockCommitment) {
// No messages to process for the debug subprotocol
}
}
/// Process a parsed debug transaction.
fn process_parsed_debug_tx(
parsed_tx: ParsedDebugTx,
relayer: &mut impl MsgRelayer,
) -> Result<(), AsmError> {
match parsed_tx {
ParsedDebugTx::MockAsmLog(log_info) => {
logging::info!("Processing ASM log injection");
// Create log entry directly from raw bytes
// The log_info contains the raw bytes that represent the log
let log_entry = match AsmLogEntry::from_raw(log_info.bytes) {
Ok(entry) => entry,
Err(err) => {
logging::warn!("Skipping ASM log injection: {err}");
return Ok(());
}
};
relayer.emit_log(log_entry);
logging::info!("Successfully emitted ASM log");
}
ParsedDebugTx::MockWithdrawIntent((output, selected_operator)) => {
logging::info!(amount = output.amt.to_sat(), "Processing mock withdrawal");
let bridge_msg = BridgeIncomingMsg::DispatchWithdrawal(DispatchWithdrawalPayload {
output,
selected_operator,
});
relayer.relay_msg(&bridge_msg);
logging::info!("Successfully sent mock withdrawal intent to bridge");
}
}
Ok(())
}