33
44use async_stm:: { abort, atomically_or_err, retry, Stm , StmResult , TVar } ;
55use serde:: { de:: DeserializeOwned , Serialize } ;
6- use std:: fmt:: Debug ;
76use std:: hash:: Hash ;
7+ use std:: { fmt:: Debug , time:: Duration } ;
88
99use crate :: { BlockHash , BlockHeight } ;
1010
@@ -322,6 +322,7 @@ where
322322/// Poll the vote tally for new finalized blocks and publish a vote about them if the validator is part of the power table.
323323pub async fn publish_vote_loop < V , F > (
324324 vote_tally : VoteTally ,
325+ vote_interval : Duration ,
325326 key : libp2p:: identity:: Keypair ,
326327 subnet_id : ipc_api:: subnet_id:: SubnetID ,
327328 client : ipc_ipld_resolver:: Client < V > ,
@@ -331,7 +332,12 @@ pub async fn publish_vote_loop<V, F>(
331332 V : Serialize + DeserializeOwned ,
332333{
333334 let validator_key = ValidatorKey :: from ( key. public ( ) ) ;
335+
336+ let mut vote_interval = tokio:: time:: interval ( vote_interval) ;
337+ vote_interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
338+
334339 let mut prev_height = 0 ;
340+
335341 loop {
336342 let result = atomically_or_err ( || {
337343 let next_height = vote_tally. latest_height ( ) ?;
@@ -367,8 +373,6 @@ pub async fn publish_vote_loop<V, F>(
367373 }
368374 } ;
369375
370- // TODO (ENG-624): Throttle vote gossiping at periods of fast syncing.
371-
372376 if has_power && prev_height > 0 {
373377 tracing:: debug!( block_height = next_height, "publishing finality vote" ) ;
374378 match VoteRecord :: signed ( & key, subnet_id. clone ( ) , to_vote ( next_height, next_hash) ) {
@@ -381,6 +385,12 @@ pub async fn publish_vote_loop<V, F>(
381385 tracing:: error!( error = e. to_string( ) , "failed to sign vote" ) ;
382386 }
383387 }
388+
389+ // Throttle vote gossiping at periods of fast syncing. For example if we create a subnet contract on Friday
390+ // and bring up a local testnet on Monday, all nodes would be ~7000 blocks behind a Lotus parent. CometBFT
391+ // would be in-sync, and they could rapidly try to gossip votes on previous heights. GossipSub might not like
392+ // that, and we can just cast our votes every now and then to finalize multiple blocks.
393+ vote_interval. tick ( ) . await ;
384394 }
385395
386396 prev_height = next_height;
0 commit comments