Skip to content

Commit 83a6b90

Browse files
authored
Merge branch 'develop' into feat/signature-count-endpoint
2 parents 08a62a2 + b5250c6 commit 83a6b90

File tree

23 files changed

+283
-563
lines changed

23 files changed

+283
-563
lines changed

stacks-signer/src/client/stacks_client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,10 @@ impl StacksClient {
590590
.map_err(|e| backoff::Error::transient(e.into()))?;
591591
let status = response.status();
592592
if status.is_success() {
593-
return response
594-
.json()
595-
.map_err(|e| backoff::Error::permanent(e.into()));
593+
return response.json().map_err(|e| {
594+
warn!("Failed to parse the GetStackers response: {e}");
595+
backoff::Error::permanent(e.into())
596+
});
596597
}
597598
let error_data = response.json::<GetStackersErrorResp>().map_err(|e| {
598599
warn!("Failed to parse the GetStackers error response: {e}");

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,10 +2228,10 @@ impl StacksBlockBuilder {
22282228

22292229
debug!("Block transaction selection begins (parent height = {tip_height})");
22302230
let result = {
2231-
let mut intermediate_result: Result<_, Error> = Ok(0);
2231+
let mut loop_result = Ok(());
22322232
while block_limit_hit != BlockLimitFunction::LIMIT_REACHED {
22332233
let mut num_considered = 0;
2234-
intermediate_result = mempool.iterate_candidates(
2234+
let intermediate_result = mempool.iterate_candidates(
22352235
epoch_tx,
22362236
&mut tx_events,
22372237
mempool_settings.clone(),
@@ -2390,16 +2390,27 @@ impl StacksBlockBuilder {
23902390
let _ = mempool.drop_and_blacklist_txs(&to_drop_and_blacklist);
23912391
}
23922392

2393-
if intermediate_result.is_err() {
2394-
break;
2393+
match intermediate_result {
2394+
Err(e) => {
2395+
loop_result = Err(e);
2396+
break;
2397+
}
2398+
Ok((_txs_considered, stop_reason)) => {
2399+
match stop_reason {
2400+
MempoolIterationStopReason::NoMoreCandidates => break,
2401+
MempoolIterationStopReason::DeadlineReached => break,
2402+
// if the iterator function exited, let the loop tick: it checks the block limits
2403+
MempoolIterationStopReason::IteratorExited => {}
2404+
}
2405+
}
23952406
}
23962407

23972408
if num_considered == 0 {
23982409
break;
23992410
}
24002411
}
24012412
debug!("Block transaction selection finished (parent height {}): {} transactions selected ({} considered)", &tip_height, num_txs, considered.len());
2402-
intermediate_result
2413+
loop_result
24032414
};
24042415

24052416
mempool.drop_txs(&invalidated_txs)?;

stackslib/src/chainstate/stacks/tests/block_construction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,6 +5072,7 @@ fn paramaterized_mempool_walk_test(
50725072
},
50735073
)
50745074
.unwrap()
5075+
.0
50755076
== 0
50765077
{
50775078
break;

stackslib/src/core/mempool.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ pub enum MemPoolSyncData {
144144
TxTags([u8; 32], Vec<TxTag>),
145145
}
146146

147+
pub enum MempoolIterationStopReason {
148+
NoMoreCandidates,
149+
DeadlineReached,
150+
/// If the iteration function supplied to mempool iteration exited
151+
/// (i.e., the transaction evaluator returned an early exit command)
152+
IteratorExited,
153+
}
154+
147155
impl StacksMessageCodec for MemPoolSyncData {
148156
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
149157
match *self {
@@ -1592,7 +1600,7 @@ impl MemPoolDB {
15921600
output_events: &mut Vec<TransactionEvent>,
15931601
settings: MemPoolWalkSettings,
15941602
mut todo: F,
1595-
) -> Result<u64, E>
1603+
) -> Result<(u64, MempoolIterationStopReason), E>
15961604
where
15971605
C: ClarityConnection,
15981606
F: FnMut(
@@ -1643,11 +1651,11 @@ impl MemPoolDB {
16431651
.query(NO_PARAMS)
16441652
.map_err(|err| Error::SqliteError(err))?;
16451653

1646-
loop {
1654+
let stop_reason = loop {
16471655
if start_time.elapsed().as_millis() > settings.max_walk_time_ms as u128 {
16481656
debug!("Mempool iteration deadline exceeded";
16491657
"deadline_ms" => settings.max_walk_time_ms);
1650-
break;
1658+
break MempoolIterationStopReason::DeadlineReached;
16511659
}
16521660

16531661
let start_with_no_estimate =
@@ -1687,7 +1695,7 @@ impl MemPoolDB {
16871695
),
16881696
None => {
16891697
debug!("No more transactions to consider in mempool");
1690-
break;
1698+
break MempoolIterationStopReason::NoMoreCandidates;
16911699
}
16921700
}
16931701
}
@@ -1875,7 +1883,7 @@ impl MemPoolDB {
18751883
}
18761884
None => {
18771885
debug!("Mempool iteration early exit from iterator");
1878-
break;
1886+
break MempoolIterationStopReason::IteratorExited;
18791887
}
18801888
}
18811889

@@ -1885,7 +1893,7 @@ impl MemPoolDB {
18851893
candidate_cache.len()
18861894
);
18871895
candidate_cache.reset();
1888-
}
1896+
};
18891897

18901898
// drop these rusqlite statements and queries, since their existence as immutable borrows on the
18911899
// connection prevents us from beginning a transaction below (which requires a mutable
@@ -1908,7 +1916,7 @@ impl MemPoolDB {
19081916
"considered_txs" => u128::from(total_considered),
19091917
"elapsed_ms" => start_time.elapsed().as_millis()
19101918
);
1911-
Ok(total_considered)
1919+
Ok((total_considered, stop_reason))
19121920
}
19131921

19141922
pub fn conn(&self) -> &DBConn {

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

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ pub struct NakamotoDownloadStateMachine {
115115
unconfirmed_tenure_downloads: HashMap<NeighborAddress, NakamotoUnconfirmedTenureDownloader>,
116116
/// Ongoing confirmed tenure downloads for when we know the start and end block hashes.
117117
tenure_downloads: NakamotoTenureDownloaderSet,
118-
/// resolved tenure-start blocks
119-
tenure_start_blocks: HashMap<StacksBlockId, NakamotoBlock>,
120118
/// comms to remote neighbors
121119
pub(super) neighbor_rpc: NeighborRPC,
122120
/// Nakamoto chain tip
@@ -140,7 +138,6 @@ impl NakamotoDownloadStateMachine {
140138
unconfirmed_tenure_download_schedule: VecDeque::new(),
141139
tenure_downloads: NakamotoTenureDownloaderSet::new(),
142140
unconfirmed_tenure_downloads: HashMap::new(),
143-
tenure_start_blocks: HashMap::new(),
144141
neighbor_rpc: NeighborRPC::new(),
145142
nakamoto_tip,
146143
last_unconfirmed_download_run_ms: 0,
@@ -367,48 +364,6 @@ impl NakamotoDownloadStateMachine {
367364
)
368365
}
369366

370-
/// Find all stored (but not necessarily processed) tenure-start blocks for a list
371-
/// of wanted tenures that this node has locally. NOTE: these tenure-start blocks
372-
/// do not correspond to the tenure; they correspond to the _parent_ tenure (since a
373-
/// `WantedTenure` captures the tenure-start block hash of the parent tenure; the same data
374-
/// captured by a sortition).
375-
///
376-
/// This method is static to ease testing.
377-
///
378-
/// Returns Ok(()) on success and fills in newly-discovered blocks into `tenure_start_blocks`.
379-
/// Returns Err(..) on DB error.
380-
pub(crate) fn load_tenure_start_blocks(
381-
wanted_tenures: &[WantedTenure],
382-
chainstate: &mut StacksChainState,
383-
tenure_start_blocks: &mut HashMap<StacksBlockId, NakamotoBlock>,
384-
) -> Result<(), NetError> {
385-
for wt in wanted_tenures {
386-
let candidate_tenure_start_blocks = chainstate
387-
.nakamoto_blocks_db()
388-
.get_nakamoto_tenure_start_blocks(&wt.tenure_id_consensus_hash)?;
389-
390-
for candidate_tenure_start_block in candidate_tenure_start_blocks.into_iter() {
391-
tenure_start_blocks.insert(
392-
candidate_tenure_start_block.block_id(),
393-
candidate_tenure_start_block,
394-
);
395-
}
396-
}
397-
Ok(())
398-
}
399-
400-
/// Update our local tenure start block data
401-
fn update_tenure_start_blocks(
402-
&mut self,
403-
chainstate: &mut StacksChainState,
404-
) -> Result<(), NetError> {
405-
Self::load_tenure_start_blocks(
406-
&self.wanted_tenures,
407-
chainstate,
408-
&mut self.tenure_start_blocks,
409-
)
410-
}
411-
412367
/// Update `self.wanted_tenures` with newly-discovered sortition data.
413368
fn extend_wanted_tenures(
414369
&mut self,
@@ -670,7 +625,6 @@ impl NakamotoDownloadStateMachine {
670625
&mut self,
671626
network: &PeerNetwork,
672627
sortdb: &SortitionDB,
673-
chainstate: &mut StacksChainState,
674628
) -> Result<(), NetError> {
675629
let sort_tip = &network.burnchain_tip;
676630

@@ -688,7 +642,6 @@ impl NakamotoDownloadStateMachine {
688642
// not at a reward cycle boundary, so just extend self.wanted_tenures
689643
debug!("Extend wanted tenures since no sort_rc change and we have tenure data");
690644
self.extend_wanted_tenures(network, sortdb)?;
691-
self.update_tenure_start_blocks(chainstate)?;
692645
return Ok(());
693646
}
694647

@@ -728,7 +681,6 @@ impl NakamotoDownloadStateMachine {
728681
self.wanted_tenures = new_wanted_tenures;
729682
self.reward_cycle = sort_rc;
730683

731-
self.update_tenure_start_blocks(chainstate)?;
732684
Ok(())
733685
}
734686

@@ -1485,21 +1437,6 @@ impl NakamotoDownloadStateMachine {
14851437
// run all downloaders
14861438
let new_blocks = self.tenure_downloads.run(network, &mut self.neighbor_rpc);
14871439

1488-
// give blocked downloaders their tenure-end blocks from other downloaders that have
1489-
// obtained their tenure-start blocks
1490-
let new_tenure_starts = self.tenure_downloads.find_new_tenure_start_blocks();
1491-
self.tenure_start_blocks
1492-
.extend(new_tenure_starts.into_iter());
1493-
1494-
let dead = self
1495-
.tenure_downloads
1496-
.handle_tenure_end_blocks(&self.tenure_start_blocks);
1497-
1498-
// bookkeeping
1499-
for naddr in dead.into_iter() {
1500-
self.neighbor_rpc.add_dead(network, &naddr);
1501-
}
1502-
15031440
new_blocks
15041441
}
15051442

@@ -1729,7 +1666,7 @@ impl NakamotoDownloadStateMachine {
17291666
) -> Result<HashMap<ConsensusHash, Vec<NakamotoBlock>>, NetError> {
17301667
self.nakamoto_tip = network.stacks_tip.block_id();
17311668
debug!("Downloader: Nakamoto tip is {:?}", &self.nakamoto_tip);
1732-
self.update_wanted_tenures(&network, sortdb, chainstate)?;
1669+
self.update_wanted_tenures(&network, sortdb)?;
17331670
self.update_processed_tenures(chainstate)?;
17341671
let new_blocks = self.run_downloads(burnchain_height, network, sortdb, chainstate, ibd);
17351672
self.last_sort_tip = Some(network.burnchain_tip.clone());

0 commit comments

Comments
 (0)