Skip to content

Commit dfb3e5e

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feat/log-not-starting-metrics
2 parents 4cc87c7 + 21a196a commit dfb3e5e

33 files changed

+2621
-1188
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1717
- `get-tenure-info?` added
1818
- `get-block-info?` removed
1919
- Added `/v3/signer/{signer_pubkey}/{reward_cycle}` endpoint
20+
- Added optional `timeout_ms` to `events_observer` configuration
2021

2122
## [2.5.0.0.7]
2223

stacks-common/src/libcommon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub mod consts {
8484

8585
/// this should be updated to the latest network epoch version supported by
8686
/// this node. this will be checked by the `validate_epochs()` method.
87-
pub const PEER_NETWORK_EPOCH: u32 = PEER_VERSION_EPOCH_2_5 as u32;
87+
pub const PEER_NETWORK_EPOCH: u32 = PEER_VERSION_EPOCH_3_0 as u32;
8888

8989
/// set the fourth byte of the peer version
9090
pub const PEER_VERSION_MAINNET: u32 = PEER_VERSION_MAINNET_MAJOR | PEER_NETWORK_EPOCH;

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3810,6 +3810,15 @@ impl NakamotoChainState {
38103810
active_reward_set: &RewardSet,
38113811
) -> Result<(), ChainstateError> {
38123812
if !tenure_block_commit.treatment.is_empty() {
3813+
let address_to_indeces: HashMap<_, Vec<_>> = active_reward_set
3814+
.rewarded_addresses
3815+
.iter()
3816+
.enumerate()
3817+
.fold(HashMap::new(), |mut map, (ix, addr)| {
3818+
map.entry(addr).or_insert_with(Vec::new).push(ix);
3819+
map
3820+
});
3821+
38133822
// our block commit issued a punishment, check the reward set and bitvector
38143823
// to ensure that this was valid.
38153824
for treated_addr in tenure_block_commit.treatment.iter() {
@@ -3820,24 +3829,19 @@ impl NakamotoChainState {
38203829
}
38213830
// otherwise, we need to find the indices in the rewarded_addresses
38223831
// corresponding to this address.
3823-
let address_indices = active_reward_set
3824-
.rewarded_addresses
3825-
.iter()
3826-
.enumerate()
3827-
.filter_map(|(ix, addr)| {
3828-
if addr == treated_addr.deref() {
3829-
Some(ix)
3830-
} else {
3831-
None
3832-
}
3833-
});
3832+
let empty_vec = vec![];
3833+
let address_indices = address_to_indeces
3834+
.get(treated_addr.deref())
3835+
.unwrap_or(&empty_vec);
3836+
38343837
// if any of them are 0, punishment is okay.
38353838
// if all of them are 1, punishment is not okay.
38363839
// if all of them are 0, *must* have punished
38373840
let bitvec_values: Result<Vec<_>, ChainstateError> = address_indices
3841+
.iter()
38383842
.map(
38393843
|ix| {
3840-
let ix = u16::try_from(ix)
3844+
let ix = u16::try_from(*ix)
38413845
.map_err(|_| ChainstateError::InvalidStacksBlock("Reward set index outside of u16".into()))?;
38423846
let bitvec_value = block_bitvec.get(ix)
38433847
.unwrap_or_else(|| {

stackslib/src/net/download/nakamoto/tenure.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,12 @@ impl TenureStartEnd {
325325
wt_start.winning_block_id.clone(),
326326
wt_end.winning_block_id.clone(),
327327
rc,
328-
downloader_block_height_to_reward_cycle(
329-
pox_constants,
330-
first_burn_height,
331-
wt_start.burn_height,
332-
)
333-
.expect(&format!(
334-
"FATAL: tenure from before system start ({} <= {})",
335-
wt_start.burn_height, first_burn_height
336-
)),
328+
pox_constants
329+
.block_height_to_reward_cycle(first_burn_height, wt_start.burn_height)
330+
.expect(&format!(
331+
"FATAL: tenure from before system start ({} <= {})",
332+
wt_start.burn_height, first_burn_height
333+
)),
337334
wt.processed,
338335
);
339336
tenure_start_end.fetch_end_block = true;

stackslib/src/net/download/nakamoto/tenure_downloader_set.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ impl NakamotoTenureDownloaderSet {
407407
continue;
408408
};
409409

410+
info!("Download tenure {}", &ch;
411+
"tenure_start_block" => %tenure_info.start_block_id,
412+
"tenure_end_block" => %tenure_info.end_block_id,
413+
"tenure_start_reward_cycle" => tenure_info.start_reward_cycle,
414+
"tenure_end_reward_cycle" => tenure_info.end_reward_cycle);
415+
410416
debug!(
411417
"Download tenure {} (start={}, end={}) (rc {},{})",
412418
&ch,

stackslib/src/net/inv/nakamoto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ impl NakamotoTenureInv {
679679
}
680680
StacksMessageType::Nack(nack_data) => {
681681
info!("{:?}: remote peer NACKed our GetNakamotoInv", network.get_local_peer();
682+
"remote_peer" => %self.neighbor_address,
682683
"error_code" => nack_data.error_code);
683684

684685
if nack_data.error_code != NackErrorCodes::NoSuchBurnchainBlock {

stackslib/src/net/p2p.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4998,7 +4998,7 @@ impl PeerNetwork {
49984998
/// Log our neighbors.
49994999
/// Used for testing and debuggin
50005000
fn log_neighbors(&mut self) {
5001-
if self.get_connection_opts().log_neighbors_freq == 0 {
5001+
if !cfg!(test) && self.get_connection_opts().log_neighbors_freq == 0 {
50025002
return;
50035003
}
50045004

stackslib/src/net/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl NetworkState {
8989
}
9090

9191
fn bind_address(addr: &SocketAddr) -> Result<mio_net::TcpListener, net_error> {
92-
if !cfg!(test) {
92+
if !cfg!(test) && !cfg!(feature = "testing") {
9393
mio_net::TcpListener::bind(addr).map_err(|e| {
9494
error!("Failed to bind to {:?}: {:?}", addr, e);
9595
net_error::BindError

stackslib/src/net/stackerdb/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ pub struct StackerDBSync<NC: NeighborComms> {
443443
rounds: u128,
444444
/// Round when we last pushed
445445
push_round: u128,
446+
/// time we last deliberately evicted a peer
447+
last_eviction_time: u64,
446448
}
447449

448450
impl StackerDBSyncResult {

stackslib/src/net/stackerdb/sync.rs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
7979
num_attempted_connections: 0,
8080
rounds: 0,
8181
push_round: 0,
82+
last_eviction_time: get_epoch_time_secs(),
8283
};
8384
dbsync.reset(None, config);
8485
dbsync
@@ -217,9 +218,36 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
217218
self.expected_versions.clear();
218219
self.downloaded_chunks.clear();
219220

220-
// reset comms, but keep all connected replicas pinned
221+
// reset comms, but keep all connected replicas pinned.
222+
// Randomly evict one every so often.
221223
self.comms.reset();
222224
if let Some(network) = network {
225+
let mut eviction_index = None;
226+
if self.last_eviction_time + 60 < get_epoch_time_secs() {
227+
self.last_eviction_time = get_epoch_time_secs();
228+
if self.replicas.len() > 0 {
229+
eviction_index = Some(thread_rng().gen_range(0..self.replicas.len()));
230+
}
231+
}
232+
233+
let remove_naddr = eviction_index.and_then(|idx| {
234+
let removed = self.replicas.iter().nth(idx).cloned();
235+
if let Some(naddr) = removed.as_ref() {
236+
debug!(
237+
"{:?}: {}: don't reuse connection for replica {:?}",
238+
network.get_local_peer(),
239+
&self.smart_contract_id,
240+
&naddr,
241+
);
242+
}
243+
removed
244+
});
245+
246+
if let Some(naddr) = remove_naddr {
247+
self.replicas.remove(&naddr);
248+
}
249+
250+
// retain the remaining replica connections
223251
for naddr in self.replicas.iter() {
224252
if let Some(event_id) = network.get_event_id(&naddr.to_neighbor_key(network)) {
225253
self.comms.pin_connection(event_id);
@@ -668,7 +696,8 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
668696
/// We might not be connected to any yet.
669697
/// Clears self.replicas, and fills in self.connected_replicas with already-connected neighbors
670698
/// Returns Ok(true) if we can proceed to sync
671-
/// Returns Ok(false) if we have no known peers
699+
/// Returns Ok(false) if we should try this again
700+
/// Returns Err(NoSuchNeighbor) if we don't have anyone to talk to
672701
/// Returns Err(..) on DB query error
673702
pub fn connect_begin(&mut self, network: &mut PeerNetwork) -> Result<bool, net_error> {
674703
if self.replicas.len() == 0 {
@@ -686,7 +715,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
686715
);
687716
if self.replicas.len() == 0 {
688717
// nothing to do
689-
return Ok(false);
718+
return Err(net_error::NoSuchNeighbor);
690719
}
691720

692721
let naddrs = mem::replace(&mut self.replicas, HashSet::new());
@@ -729,11 +758,12 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
729758
);
730759
self.num_attempted_connections += 1;
731760
self.num_connections += 1;
761+
self.connected_replicas.insert(naddr);
732762
}
733763
Ok(false) => {
734764
// need to retry
735-
self.replicas.insert(naddr);
736765
self.num_attempted_connections += 1;
766+
self.replicas.insert(naddr);
737767
}
738768
Err(_e) => {
739769
debug!(
@@ -746,7 +776,7 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
746776
}
747777
}
748778
}
749-
Ok(self.replicas.len() == 0)
779+
Ok(self.connected_replicas.len() > 0)
750780
}
751781

752782
/// Finish up connecting to our replicas.
@@ -1154,7 +1184,8 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
11541184
);
11551185

11561186
// fill up our comms with $capacity requests
1157-
for _i in 0..self.request_capacity {
1187+
let mut num_sent = 0;
1188+
for _i in 0..self.chunk_push_priorities.len() {
11581189
if self.comms.count_inflight() >= self.request_capacity {
11591190
break;
11601191
}
@@ -1173,6 +1204,9 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
11731204
chunk_push.chunk_data.slot_id,
11741205
chunk_push.chunk_data.slot_version,
11751206
);
1207+
1208+
// next-prioritized chunk
1209+
cur_priority = (cur_priority + 1) % self.chunk_push_priorities.len();
11761210
continue;
11771211
};
11781212

@@ -1213,6 +1247,11 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
12131247

12141248
// next-prioritized chunk
12151249
cur_priority = (cur_priority + 1) % self.chunk_push_priorities.len();
1250+
1251+
num_sent += 1;
1252+
if num_sent > self.request_capacity {
1253+
break;
1254+
}
12161255
}
12171256
self.next_chunk_push_priority = cur_priority;
12181257
Ok(self
@@ -1370,14 +1409,22 @@ impl<NC: NeighborComms> StackerDBSync<NC> {
13701409
let mut blocked = true;
13711410
match self.state {
13721411
StackerDBSyncState::ConnectBegin => {
1373-
let done = self.connect_begin(network)?;
1412+
let done = match self.connect_begin(network) {
1413+
Ok(done) => done,
1414+
Err(net_error::NoSuchNeighbor) => {
1415+
// nothing to do
1416+
self.state = StackerDBSyncState::Finished;
1417+
blocked = false;
1418+
false
1419+
}
1420+
Err(e) => {
1421+
return Err(e);
1422+
}
1423+
};
13741424
if done {
13751425
self.state = StackerDBSyncState::ConnectFinish;
1376-
} else {
1377-
// no replicas; try again
1378-
self.state = StackerDBSyncState::Finished;
1426+
blocked = false;
13791427
}
1380-
blocked = false;
13811428
}
13821429
StackerDBSyncState::ConnectFinish => {
13831430
let done = self.connect_try_finish(network)?;

0 commit comments

Comments
 (0)