Skip to content

Commit e5cc717

Browse files
jcnelsonkantai
authored andcommitted
fix: set miner stackerdb sync frequency to 1 sec; stackerdb sync pushchunks should not retry indefinitely; check for the absence of neighbors to sync to as a stopping condition for pushchunks
1 parent 95a6bb7 commit e5cc717

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4104,7 +4104,7 @@ impl NakamotoChainState {
41044104
Ok(StackerDBConfig {
41054105
chunk_size: MAX_PAYLOAD_LEN.into(),
41064106
signers,
4107-
write_freq: 5,
4107+
write_freq: 0,
41084108
max_writes: u32::MAX, // no limit on number of writes
41094109
max_neighbors: 200, // TODO: const -- just has to be equal to or greater than the number of signers
41104110
hint_replicas: vec![], // TODO: is there a way to get the IP addresses of stackers' preferred nodes?

stackslib/src/net/stackerdb/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ pub struct StackerDBSync<NC: NeighborComms> {
401401
num_attempted_connections: u64,
402402
/// How many connections have been made in the last pass (gets reset)
403403
num_connections: u64,
404+
/// Number of state machine passes
405+
rounds: u128,
406+
/// Round when we last pushed
407+
push_round: u128,
404408
}
405409

406410
impl StackerDBSyncResult {

stackslib/src/net/stackerdb/sync.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
7474
stale_neighbors: HashSet::new(),
7575
num_connections: 0,
7676
num_attempted_connections: 0,
77+
rounds: 0,
78+
push_round: 0,
7779
};
7880
dbsync.reset(None, config);
7981
dbsync
@@ -215,6 +217,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
215217
self.state = StackerDBSyncState::ConnectBegin;
216218
self.num_connections = 0;
217219
self.num_attempted_connections = 0;
220+
self.rounds += 1;
218221
result
219222
}
220223

@@ -407,6 +410,16 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
407410
thread_rng().gen::<u32>() % chunk_inv.num_outbound_replicas == 0
408411
};
409412

413+
debug!(
414+
"{:?}: Can push chunk StackerDBChunk(db={},id={},ver={}) to {}. Replicate? {}",
415+
&network.get_local_peer(),
416+
&self.smart_contract_id,
417+
our_chunk.chunk_data.slot_id,
418+
our_chunk.chunk_data.slot_version,
419+
&naddr,
420+
do_replicate
421+
);
422+
410423
if !do_replicate {
411424
continue;
412425
}
@@ -1000,9 +1013,11 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
10001013
/// Returns true if there are no more chunks to push.
10011014
/// Returns false if there are
10021015
pub fn pushchunks_begin(&mut self, network: &mut PeerNetwork) -> Result<bool, net_error> {
1003-
if self.chunk_push_priorities.len() == 0 {
1016+
if self.chunk_push_priorities.len() == 0 && self.push_round != self.rounds {
1017+
// only do this once per round
10041018
let priorities = self.make_chunk_push_schedule(&network)?;
10051019
self.chunk_push_priorities = priorities;
1020+
self.push_round = self.rounds;
10061021
}
10071022
if self.chunk_push_priorities.len() == 0 {
10081023
// done
@@ -1017,8 +1032,6 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
10171032
self.chunk_push_priorities.len()
10181033
);
10191034

1020-
let mut pushed = 0;
1021-
10221035
// fill up our comms with $capacity requests
10231036
for _i in 0..self.request_capacity {
10241037
if self.comms.count_inflight() >= self.request_capacity {
@@ -1030,7 +1043,8 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
10301043
.1
10311044
.iter()
10321045
.enumerate()
1033-
.find(|(_i, naddr)| !self.comms.has_inflight(naddr));
1046+
// .find(|(_i, naddr)| !self.comms.has_inflight(naddr));
1047+
.find(|(_i, _naddr)| true);
10341048

10351049
let (idx, selected_neighbor) = if let Some(x) = selected_neighbor_opt {
10361050
x
@@ -1072,8 +1086,6 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
10721086
continue;
10731087
}
10741088

1075-
pushed += 1;
1076-
10771089
// record what we just sent
10781090
self.chunk_push_receipts
10791091
.insert(selected_neighbor.clone(), (slot_id, slot_version));
@@ -1088,7 +1100,13 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
10881100
return Err(net_error::PeerNotConnected);
10891101
}
10901102
self.next_chunk_push_priority = cur_priority;
1091-
Ok(self.chunk_push_priorities.len() == 0)
1103+
Ok(self
1104+
.chunk_push_priorities
1105+
.iter()
1106+
.fold(0usize, |acc, (_chunk, num_naddrs)| {
1107+
acc.saturating_add(num_naddrs.len())
1108+
})
1109+
== 0)
10921110
}
10931111

10941112
/// Collect push-chunk replies from neighbors.
@@ -1138,7 +1156,14 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
11381156
}
11391157
}
11401158

1141-
self.comms.count_inflight() == 0
1159+
let inflight = self.comms.count_inflight();
1160+
debug!(
1161+
"{:?}: inflight messages for {}: {:?}",
1162+
network.get_local_peer(),
1163+
&self.smart_contract_id,
1164+
inflight
1165+
);
1166+
inflight == 0
11421167
}
11431168

11441169
/// Recalculate the download schedule based on chunkinvs received on push
@@ -1189,8 +1214,9 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
11891214

11901215
loop {
11911216
debug!(
1192-
"{:?}: stacker DB sync state is {:?}",
1217+
"{:?}: stacker DB sync state for {} is {:?}",
11931218
network.get_local_peer(),
1219+
&self.smart_contract_id,
11941220
&self.state
11951221
);
11961222
let mut blocked = true;

0 commit comments

Comments
 (0)