Skip to content

Commit 26e6998

Browse files
committed
fixes
1 parent 463a92e commit 26e6998

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

crates/asm/common/src/error.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
use std::fmt::{Debug, Display};
2+
13
use strata_primitives::l1::L1VerificationError;
24
use thiserror::Error;
35

46
use crate::SubprotocolId;
57

8+
/// A generic “expected vs actual” error.
9+
#[derive(Debug, Error)]
10+
#[error("expected {expected}, found {actual}")]
11+
pub struct Mismatched<T>
12+
where
13+
T: Debug + Display,
14+
{
15+
/// The value that was expected.
16+
pub expected: T,
17+
/// The value that was actually encountered.
18+
pub actual: T,
19+
}
20+
621
/// Errors that can occur while working with ASM subprotocols.
722
#[derive(Debug, Error)]
823
pub enum AsmError {
924
/// Subprotocol ID of a decoded section did not match the expected subprotocol ID.
10-
#[error("tried to decode section of ID {0} as ID {1}")]
11-
SubprotoIdMismatch(SubprotocolId, SubprotocolId),
25+
#[error(transparent)]
26+
SubprotoIdMismatch(#[from] Mismatched<SubprotocolId>),
1227

1328
/// The requested subprotocol ID was not found.
1429
#[error("subproto {0:?} does not exist")]

crates/asm/common/src/state.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use borsh::{BorshDeserialize, BorshSerialize};
22
use strata_primitives::l1::HeaderVerificationState;
33

4-
use crate::{AsmError, Subprotocol, SubprotocolId};
4+
use crate::{AsmError, Mismatched, Subprotocol, SubprotocolId};
55

66
/// Anchor state for the Anchor State Machine (ASM), the core of the Strata protocol.
77
///
@@ -69,7 +69,11 @@ impl SectionState {
6969
/// Tries to deserialize the section data as a particular subprotocol's state.
7070
pub fn try_to_state<S: Subprotocol>(&self) -> Result<S::State, AsmError> {
7171
if S::ID != self.id {
72-
return Err(AsmError::SubprotoIdMismatch(self.id, S::ID));
72+
return Err(Mismatched {
73+
expected: S::ID,
74+
actual: self.id,
75+
}
76+
.into());
7377
}
7478

7579
<S::State as BorshDeserialize>::try_from_slice(&self.data)

crates/asm/common/src/subprotocol.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ pub trait SubprotoHandler {
6868
/// as-is.
6969
fn id(&self) -> SubprotocolId;
7070

71-
/// Processes transactions that were previously collected.
71+
/// Process the transactions and extract all the relevant information from L1 for the
72+
/// subprotocol
73+
///
74+
/// Update it's own state and output a list of InterProtoMsg addressed to other subprotocols
7275
fn process_txs(&mut self, txs: &[TxInput<'_>], relayer: &mut dyn MsgRelayer);
7376

7477
/// Accepts a message. This is called while processing other subprotocols.

crates/asm/stf/src/manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl<S: Subprotocol, R: MsgRelayer> SubprotoHandler for HandlerImpl<S, R> {
5252
S::process_txs(&mut self.state, txs, relayer);
5353
}
5454

55-
fn process_msgs(&mut self) {
56-
S::finalize_state(&mut self.state, &self.interproto_msg_buf)
55+
fn process_buffered_msgs(&mut self) {
56+
S::process_msgs(&mut self.state, &self.interproto_msg_buf)
5757
}
5858

5959
fn to_section(&self) -> SectionState {
@@ -100,7 +100,7 @@ impl SubprotoManager {
100100
let h = self
101101
.get_handler_mut(S::ID)
102102
.expect("asm: unloaded subprotocol");
103-
h.process_msgs()
103+
h.process_buffered_msgs()
104104
}
105105

106106
fn insert_handler(&mut self, handler: Box<dyn SubprotoHandler>) {

crates/asm/subprotocols/bridge-v1/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Subprotocol for BridgeV1Subproto {
3737
todo!()
3838
}
3939

40-
fn finalize_state(_state: &mut Self::State, _msgs: &[Self::Msg]) {
40+
fn process_msgs(_state: &mut Self::State, _msgs: &[Self::Msg]) {
4141
todo!()
4242
}
4343
}

crates/asm/subprotocols/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Subprotocol for OLCoreSubproto {
5454
todo!()
5555
}
5656

57-
fn finalize_state(_state: &mut Self::State, _msgs: &[Self::Msg]) {
57+
fn process_msgs(_state: &mut Self::State, _msgs: &[Self::Msg]) {
5858
todo!()
5959
}
6060
}

0 commit comments

Comments
 (0)