@@ -98,6 +98,12 @@ fn create_gossipsub_behavior(author: PeerId) -> gossipsub::Behaviour {
98
98
/// and check their fields based on whether they exist or not.
99
99
const VALIDATION_MODE : ValidationMode = ValidationMode :: Permissive ;
100
100
101
+ /// Heartbeat interval in seconds
102
+ const HEARTBEAT_INTERVAL_SECS : u64 = 10 ;
103
+
104
+ /// Duplicate cache time in seconds
105
+ const DUPLICATE_CACHE_TIME_SECS : u64 = 120 ;
106
+
101
107
/// Gossip cache TTL in seconds
102
108
const GOSSIP_TTL_SECS : u64 = 100 ;
103
109
@@ -111,6 +117,10 @@ fn create_gossipsub_behavior(author: PeerId) -> gossipsub::Behaviour {
111
117
/// because we don't need historic messages at all
112
118
const MAX_IHAVE_LENGTH : usize = 100 ;
113
119
120
+ /// Max size of the send queue
121
+ /// This helps to avoid memory exhaustion during high load
122
+ const MAX_SEND_QUEUE_SIZE : usize = 400 ;
123
+
114
124
// message id's are simply hashes of the message data
115
125
let message_id_fn = |message : & Message | {
116
126
let mut hasher = hash_map:: DefaultHasher :: new ( ) ;
@@ -123,15 +133,17 @@ fn create_gossipsub_behavior(author: PeerId) -> gossipsub::Behaviour {
123
133
Behaviour :: new (
124
134
MessageAuthenticity :: Author ( author) ,
125
135
ConfigBuilder :: default ( )
126
- . heartbeat_interval ( Duration :: from_secs ( 10 ) )
127
- . max_transmit_size ( MAX_TRANSMIT_SIZE ) // 256 KB
136
+ . heartbeat_interval ( Duration :: from_secs ( HEARTBEAT_INTERVAL_SECS ) )
137
+ . max_transmit_size ( MAX_TRANSMIT_SIZE )
128
138
. message_id_fn ( message_id_fn)
139
+ . message_capacity ( MESSAGE_CAPACITY )
129
140
. message_ttl ( Duration :: from_secs ( MESSAGE_TTL_SECS ) )
130
141
. gossip_ttl ( Duration :: from_secs ( GOSSIP_TTL_SECS ) )
131
- . message_capacity ( MESSAGE_CAPACITY )
142
+ . duplicate_cache_time ( Duration :: from_secs ( DUPLICATE_CACHE_TIME_SECS ) )
143
+ . max_ihave_length ( MAX_IHAVE_LENGTH )
144
+ . send_queue_size ( MAX_SEND_QUEUE_SIZE )
132
145
. validation_mode ( VALIDATION_MODE )
133
146
. validate_messages ( )
134
- . max_ihave_length ( MAX_IHAVE_LENGTH )
135
147
. build ( )
136
148
. expect ( "Valid config" ) , // TODO: better error handling
137
149
)
0 commit comments