File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
primitives/statement-store/src Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ const LOG_TARGET: &str = "statement-gossip";
88
88
89
89
struct Metrics {
90
90
propagated_statements : Counter < U64 > ,
91
+ known_statements_received : Counter < U64 > ,
91
92
}
92
93
93
94
impl Metrics {
@@ -100,6 +101,13 @@ impl Metrics {
100
101
) ?,
101
102
r,
102
103
) ?,
104
+ known_statements_received : register (
105
+ Counter :: new (
106
+ "substrate_sync_known_statement_received" ,
107
+ "Number of statements received via gossiping that were already in the statement store" ,
108
+ ) ?,
109
+ r,
110
+ ) ?,
103
111
} )
104
112
}
105
113
}
@@ -388,6 +396,13 @@ where
388
396
389
397
self . network . report_peer ( who, rep:: ANY_STATEMENT ) ;
390
398
399
+ if self . statement_store . has_statement ( & hash) {
400
+ if let Some ( ref metrics) = self . metrics {
401
+ metrics. known_statements_received . inc ( ) ;
402
+ }
403
+ continue ;
404
+ }
405
+
391
406
match self . pending_statements_peers . entry ( hash) {
392
407
Entry :: Vacant ( entry) => {
393
408
let ( completion_sender, completion_receiver) = oneshot:: channel ( ) ;
Original file line number Diff line number Diff line change @@ -833,6 +833,10 @@ impl StatementStore for Store {
833
833
)
834
834
}
835
835
836
+ fn has_statement ( & self , hash : & Hash ) -> bool {
837
+ self . index . read ( ) . entries . contains_key ( hash)
838
+ }
839
+
836
840
/// Return the data of all known statements which include all topics and have no `DecryptionKey`
837
841
/// field.
838
842
fn broadcasts ( & self , match_all_topics : & [ Topic ] ) -> Result < Vec < Vec < u8 > > > {
Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ pub trait StatementStore: Send + Sync {
75
75
/// Get statement by hash.
76
76
fn statement ( & self , hash : & Hash ) -> Result < Option < Statement > > ;
77
77
78
+ /// Check if statement exists in the store
79
+ ///
80
+ /// Fast index check without accessing the DB.
81
+ fn has_statement ( & self , hash : & Hash ) -> bool ;
82
+
78
83
/// Return the data of all known statements which include all topics and have no `DecryptionKey`
79
84
/// field.
80
85
fn broadcasts ( & self , match_all_topics : & [ Topic ] ) -> Result < Vec < Vec < u8 > > > ;
You can’t perform that action at this time.
0 commit comments