Skip to content

Commit adba578

Browse files
committed
feat: track neighbors with stale views
1 parent ec91821 commit adba578

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

stackslib/src/net/stackerdb/sync.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use crate::net::stackerdb::{
3333
StackerDBConfig, StackerDBSync, StackerDBSyncResult, StackerDBSyncState, StackerDBs,
3434
};
3535
use crate::net::{
36-
Error as net_error, NackData, Neighbor, NeighborAddress, NeighborKey, StackerDBChunkData,
37-
StackerDBChunkInvData, StackerDBGetChunkData, StackerDBGetChunkInvData, StackerDBPushChunkData,
38-
StacksMessageType,
36+
Error as net_error, NackData, NackErrorCodes, Neighbor, NeighborAddress, NeighborKey,
37+
StackerDBChunkData, StackerDBChunkInvData, StackerDBGetChunkData, StackerDBGetChunkInvData,
38+
StackerDBPushChunkData, StacksMessageType,
3939
};
4040

4141
const MAX_CHUNKS_IN_FLIGHT: usize = 6;
@@ -72,6 +72,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
7272
total_pushed: 0,
7373
last_run_ts: 0,
7474
need_resync: false,
75+
stale_neighbors: HashSet::new(),
7576
};
7677
dbsync.reset(None, config);
7778
dbsync
@@ -178,6 +179,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
178179
chunks_to_store: chunks,
179180
dead: self.comms.take_dead_neighbors(),
180181
broken: self.comms.take_broken_neighbors(),
182+
stale: std::mem::replace(&mut self.stale_neighbors, HashSet::new()),
181183
};
182184

183185
// keep all connected replicas, and replenish from config hints and the DB as needed
@@ -677,6 +679,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
677679
&network.get_chain_view().rc_consensus_hash,
678680
&db_data.rc_consensus_hash
679681
);
682+
self.connected_replicas.remove(&naddr);
680683
continue;
681684
}
682685
db_data
@@ -688,6 +691,10 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
688691
&naddr,
689692
data.error_code
690693
);
694+
self.connected_replicas.remove(&naddr);
695+
if data.error_code == NackErrorCodes::StaleView {
696+
self.stale_neighbors.insert(naddr);
697+
}
691698
continue;
692699
}
693700
x => {
@@ -800,10 +807,15 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
800807
&naddr,
801808
data.error_code
802809
);
810+
self.connected_replicas.remove(&naddr);
811+
if data.error_code == NackErrorCodes::StaleView {
812+
self.stale_neighbors.insert(naddr);
813+
}
803814
continue;
804815
}
805816
x => {
806817
info!("Received unexpected message {:?}", &x);
818+
self.connected_replicas.remove(&naddr);
807819
continue;
808820
}
809821
};
@@ -929,10 +941,14 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
929941
data.error_code
930942
);
931943
self.connected_replicas.remove(&naddr);
944+
if data.error_code == NackErrorCodes::StaleView {
945+
self.stale_neighbors.insert(naddr);
946+
}
932947
continue;
933948
}
934949
x => {
935950
info!("Received unexpected message {:?}", &x);
951+
self.connected_replicas.remove(&naddr);
936952
continue;
937953
}
938954
};
@@ -1072,6 +1088,9 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
10721088
data.error_code
10731089
);
10741090
self.connected_replicas.remove(&naddr);
1091+
if data.error_code == NackErrorCodes::StaleView {
1092+
self.stale_neighbors.insert(naddr);
1093+
}
10751094
continue;
10761095
}
10771096
x => {

0 commit comments

Comments
 (0)