1
1
use super :: utils:: { NetworkConfig , create_namespace} ;
2
- use crate :: { FinalizedEpoch , LightDataAvailabilityLayer } ;
2
+ use crate :: {
3
+ FinalizedEpoch , LightDataAvailabilityLayer , VerifiableEpoch ,
4
+ events:: { EventChannel , EventPublisher } ,
5
+ } ;
3
6
use anyhow:: { Result , anyhow} ;
4
7
use async_trait:: async_trait;
5
8
use celestia_types:: nmt:: Namespace ;
6
- use lumina_node:: { Node , NodeError , events:: EventSubscriber , store:: StoreError } ;
9
+ use lumina_node:: {
10
+ Node , NodeError ,
11
+ blockstore:: InMemoryBlockstore ,
12
+ store:: { EitherStore , InMemoryStore , StoreError } ,
13
+ } ;
7
14
use prism_errors:: DataAvailabilityError ;
8
15
use std:: { self , sync:: Arc } ;
9
16
use tokio:: sync:: { Mutex , RwLock } ;
@@ -17,8 +24,6 @@ use lumina_node::NodeBuilder;
17
24
#[ cfg( not( target_arch = "wasm32" ) ) ]
18
25
use {
19
26
blockstore:: EitherBlockstore ,
20
- lumina_node:: blockstore:: InMemoryBlockstore ,
21
- lumina_node:: store:: { EitherStore , InMemoryStore } ,
22
27
redb:: Database ,
23
28
tokio:: task:: spawn_blocking,
24
29
} ;
@@ -40,7 +45,7 @@ pub type LuminaNode = Node<
40
45
41
46
pub struct LightClientConnection {
42
47
pub node : Arc < RwLock < LuminaNode > > ,
43
- pub event_subscriber : Arc < Mutex < EventSubscriber > > ,
48
+ pub event_channel : Arc < EventChannel > ,
44
49
pub snark_namespace : Namespace ,
45
50
}
46
51
@@ -98,11 +103,16 @@ impl LightClientConnection {
98
103
. start_subscribed ( )
99
104
. await ?;
100
105
106
+ let lumina_sub = Arc :: new ( Mutex :: new ( event_subscriber) ) ;
107
+
108
+ // Creates an EventChannel that starts forwarding lumina events to the subscriber
109
+ let prism_chan = EventChannel :: from ( lumina_sub. clone ( ) ) ;
110
+
101
111
let snark_namespace = create_namespace ( & celestia_config. snark_namespace_id ) ?;
102
112
103
113
Ok ( LightClientConnection {
104
114
node : Arc :: new ( RwLock :: new ( node) ) ,
105
- event_subscriber : Arc :: new ( Mutex :: new ( event_subscriber ) ) ,
115
+ event_channel : Arc :: new ( prism_chan ) ,
106
116
snark_namespace,
107
117
} )
108
118
}
@@ -129,25 +139,33 @@ impl LightClientConnection {
129
139
. await ?;
130
140
let ( node, event_subscriber) = node_builder. start_subscribed ( ) . await ?;
131
141
142
+ let lumina_sub = Arc :: new ( Mutex :: new ( event_subscriber) ) ;
143
+
144
+ // Creates an EventChannel that starts forwarding lumina events to the subscriber
145
+ let prism_chan = EventChannel :: from ( lumina_sub. clone ( ) ) ;
146
+
132
147
let snark_namespace = create_namespace ( & celestia_config. snark_namespace_id ) ?;
133
148
134
149
Ok ( LightClientConnection {
135
150
node : Arc :: new ( RwLock :: new ( node) ) ,
136
- event_subscriber : Arc :: new ( Mutex :: new ( event_subscriber ) ) ,
151
+ event_channel : Arc :: new ( prism_chan ) ,
137
152
snark_namespace,
138
153
} )
139
154
}
155
+
156
+ pub fn event_publisher ( & self ) -> EventPublisher {
157
+ self . event_channel . publisher ( )
158
+ }
140
159
}
141
160
142
161
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
143
162
#[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
144
163
impl LightDataAvailabilityLayer for LightClientConnection {
145
- // since the lumina node is already started in the constructor, we don't need to start it again. We need the event_subscriber to start forwarding events.
146
- fn event_subscriber ( & self ) -> Option < Arc < Mutex < EventSubscriber > > > {
147
- Some ( self . event_subscriber . clone ( ) )
164
+ fn event_channel ( & self ) -> Arc < EventChannel > {
165
+ self . event_channel . clone ( )
148
166
}
149
167
150
- async fn get_finalized_epoch ( & self , height : u64 ) -> Result < Vec < FinalizedEpoch > > {
168
+ async fn get_finalized_epoch ( & self , height : u64 ) -> Result < Vec < VerifiableEpoch > > {
151
169
trace ! (
152
170
"searching for epoch on da layer at height {} under namespace" ,
153
171
height
@@ -167,10 +185,10 @@ impl LightDataAvailabilityLayer for LightClientConnection {
167
185
168
186
match node. request_all_blobs ( & header, self . snark_namespace , None ) . await {
169
187
Ok ( blobs) => {
170
- let epochs: Vec < FinalizedEpoch > = blobs
188
+ let epochs: Vec < VerifiableEpoch > = blobs
171
189
. into_iter ( )
172
190
. filter_map ( |blob| match FinalizedEpoch :: try_from ( & blob) {
173
- Ok ( epoch) => Some ( epoch) ,
191
+ Ok ( epoch) => Some ( Box :: new ( epoch) as VerifiableEpoch ) ,
174
192
Err ( _) => {
175
193
warn ! (
176
194
"marshalling blob from height {} to epoch json: {:?}" ,
0 commit comments