33//! view into a single deterministic state transition.
44
55use bitcoin:: { block:: Block , params:: Params } ;
6- use strata_asm_common:: { AnchorState , AsmSpec , ChainViewState , Stage , SubprotocolManager } ;
6+ use strata_asm_common:: {
7+ AnchorState , AsmError , AsmSpec , ChainViewState , Stage , SubprotocolManager ,
8+ } ;
79use strata_asm_proto_bridge_v1:: BridgeV1Subproto ;
810use strata_asm_proto_core:: OLCoreSubproto ;
911
@@ -26,13 +28,13 @@ impl AsmSpec for StrataAsmSpec {
2628
2729/// Computes the next AnchorState by applying the Anchor State Machine (ASM) state transition
2830/// function (STF) to the given previous state and new L1 block.
29- pub fn asm_stf < S : AsmSpec > ( pre_state : AnchorState , block : Block ) -> AnchorState {
31+ pub fn asm_stf < S : AsmSpec > ( pre_state : AnchorState , block : Block ) -> Result < AnchorState , AsmError > {
3032 let mut pow_state = pre_state. chain_view . pow_state . clone ( ) ;
3133
3234 // 1. Validate and update PoW header continuity for the new block
3335 pow_state
3436 . check_and_update_continuity ( & block. header , & Params :: MAINNET )
35- . expect ( "header doesn't follow the consensus rules" ) ;
37+ . map_err ( AsmError :: InvalidL1Header ) ? ;
3638
3739 // 2. Filter the relevant transactions
3840 let all_relevant_transactions = group_txs_by_subprotocol ( & block. txdata ) ;
@@ -51,10 +53,10 @@ pub fn asm_stf<S: AsmSpec>(pre_state: AnchorState, block: Block) -> AnchorState
5153 let mut finish_stage = FinishStage :: new ( ) ;
5254 S :: call_subprotocols ( & mut finish_stage, & mut manager) ;
5355
54- let sections = finish_stage. into_sections ( ) ;
56+ let sections = finish_stage. into_sorted_sections ( ) ;
5557 let chain_view = ChainViewState { pow_state } ;
56- AnchorState {
58+ Ok ( AnchorState {
5759 chain_view,
5860 sections,
59- }
61+ } )
6062}
0 commit comments