@@ -10,10 +10,13 @@ use commonware_codec::{Decode, Error as CodecError};
1010use commonware_coding:: Scheme ;
1111use commonware_cryptography:: { Hasher , PublicKey } ;
1212use commonware_p2p:: Recipients ;
13+ use commonware_runtime:: Metrics ;
1314use futures:: channel:: oneshot;
15+ use prometheus_client:: metrics:: gauge:: Gauge ;
1416use std:: {
1517 collections:: { btree_map:: Entry , BTreeMap } ,
1618 ops:: Deref ,
19+ time:: Instant ,
1720} ;
1821use thiserror:: Error ;
1922use tracing:: debug;
6164 ///
6265 /// These blocks are evicted by marshal after they are delivered to the application.
6366 reconstructed_blocks : BTreeMap < CodingCommitment , CodedBlock < B , S > > ,
67+
68+ block_broadcast_duration : Gauge ,
69+ shard_broadcast_duration : Gauge ,
70+ erasure_decode_duration : Gauge ,
6471}
6572
6673impl < S , H , B , P > ShardMailbox < S , H , B , P >
@@ -70,12 +77,40 @@ where
7077 B : Block < Commitment = CodingCommitment > ,
7178 P : PublicKey ,
7279{
73- pub fn new ( mailbox : buffered:: Mailbox < P , Shard < S , H > > , block_codec_cfg : B :: Cfg ) -> Self {
80+ pub fn new (
81+ context : impl Metrics ,
82+ mailbox : buffered:: Mailbox < P , Shard < S , H > > ,
83+ block_codec_cfg : B :: Cfg ,
84+ ) -> Self {
85+ let block_broadcast_duration = Gauge :: default ( ) ;
86+ context. register (
87+ "block_broadcast_duration" ,
88+ "Duration of proposer broadcast in milliseconds" ,
89+ block_broadcast_duration. clone ( ) ,
90+ ) ;
91+
92+ let shard_broadcast_duration = Gauge :: default ( ) ;
93+ context. register (
94+ "shard_broadcast_duration" ,
95+ "Duration of individual shard broadcast in milliseconds" ,
96+ shard_broadcast_duration. clone ( ) ,
97+ ) ;
98+
99+ let erasure_decode_duration = Gauge :: default ( ) ;
100+ context. register (
101+ "erasure_decode_duration" ,
102+ "Duration of erasure decoding in milliseconds" ,
103+ erasure_decode_duration. clone ( ) ,
104+ ) ;
105+
74106 Self {
75107 mailbox,
76108 block_codec_cfg,
77109 block_subscriptions : BTreeMap :: new ( ) ,
78110 reconstructed_blocks : BTreeMap :: new ( ) ,
111+ block_broadcast_duration,
112+ shard_broadcast_duration,
113+ erasure_decode_duration,
79114 }
80115 }
81116
@@ -91,12 +126,15 @@ where
91126 "number of participants must equal number of shards"
92127 ) ;
93128
129+ let start = Instant :: now ( ) ;
94130 for ( index, peer) in participants. into_iter ( ) . enumerate ( ) {
95131 let message = block
96132 . shard ( index)
97133 . expect ( "peer index impossibly out of bounds" ) ;
98134 let _peers = self . mailbox . broadcast ( Recipients :: One ( peer) , message) . await ;
99135 }
136+ self . block_broadcast_duration
137+ . set ( start. elapsed ( ) . as_millis ( ) as i64 ) ;
100138 }
101139
102140 /// Broadcasts a local [Shard] of a block to all peers, if the [Shard] is present
@@ -133,7 +171,11 @@ where
133171
134172 // Broadcast the weak shard to all peers for reconstruction.
135173 let reshard = Shard :: new ( commitment, index, DistributionShard :: Weak ( reshard) ) ;
174+
175+ let start = Instant :: now ( ) ;
136176 let _peers = self . mailbox . broadcast ( Recipients :: All , reshard) . await ;
177+ self . shard_broadcast_duration
178+ . set ( start. elapsed ( ) . as_millis ( ) as i64 ) ;
137179
138180 debug ! ( %commitment, index, "broadcasted local shard to all peers" ) ;
139181 } else {
@@ -218,13 +260,16 @@ where
218260 }
219261
220262 // Attempt to reconstruct the encoded blob
263+ let start = Instant :: now ( ) ;
221264 let decoded = S :: decode (
222265 & config,
223266 & commitment. inner ( ) ,
224267 checking_data. clone ( ) ,
225268 checked_shards. as_slice ( ) ,
226269 )
227270 . map_err ( ReconstructionError :: CodingRecovery ) ?;
271+ self . erasure_decode_duration
272+ . set ( start. elapsed ( ) . as_millis ( ) as i64 ) ;
228273
229274 // Attempt to decode the block from the encoded blob
230275 let block = CodedBlock :: < B , S > :: decode_cfg ( decoded. as_slice ( ) , & self . block_codec_cfg ) ?;
@@ -418,7 +463,8 @@ mod test {
418463 PublicKey ,
419464 Shard < ReedSolomon < Sha256 > , Sha256 > ,
420465 > :: new ( context. clone ( ) , config) ;
421- let shard_mailbox = SMailbox :: new ( engine_mailbox, ( ) ) ;
466+ let shard_mailbox =
467+ SMailbox :: new ( context. with_label ( "shard_mailbox" ) , engine_mailbox, ( ) ) ;
422468 mailboxes. insert ( peer. clone ( ) , shard_mailbox) ;
423469
424470 engine. start ( network) ;
0 commit comments