Skip to content

Commit e074d6c

Browse files
committed
Merge branch 'develop' into feat/clarity-cli-costs-json
2 parents 39b5fc8 + ba2aeef commit e074d6c

File tree

12 files changed

+1087
-725
lines changed

12 files changed

+1087
-725
lines changed

src/chainstate/stacks/db/headers.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,23 +279,6 @@ impl StacksChainState {
279279
}
280280
}
281281

282-
/// Get an ancestor block header given an index hash
283-
pub fn get_index_tip_ancestor_conn(
284-
conn: &StacksDBConn,
285-
tip_index_hash: &StacksBlockId,
286-
height: u64,
287-
) -> Result<Option<StacksHeaderInfo>, Error> {
288-
match conn
289-
.get_ancestor_block_hash(height, tip_index_hash)
290-
.map_err(Error::DBError)?
291-
{
292-
Some(bhh) => {
293-
StacksChainState::get_stacks_block_header_info_by_index_block_hash(conn, &bhh)
294-
}
295-
None => Ok(None),
296-
}
297-
}
298-
299282
/// Get a segment of headers from the canonical chain
300283
pub fn get_ancestors_headers(
301284
conn: &Connection,

src/chainstate/stacks/db/unconfirmed.rs

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ use crate::types::chainstate::{StacksBlockHeader, StacksBlockId, StacksMicrobloc
4141

4242
pub type UnconfirmedTxMap = HashMap<Txid, (StacksTransaction, BlockHeaderHash, u16)>;
4343

44+
pub struct ProcessedUnconfirmedState {
45+
pub total_burns: u128,
46+
pub total_fees: u128,
47+
// each element of this vector is a tuple, where each tuple contains a microblock
48+
// sequence number, and a vector of transaction receipts for that microblock
49+
pub receipts: Vec<(u16, Vec<StacksTransactionReceipt>)>,
50+
}
51+
52+
impl Default for ProcessedUnconfirmedState {
53+
fn default() -> Self {
54+
ProcessedUnconfirmedState {
55+
total_burns: 0,
56+
total_fees: 0,
57+
receipts: vec![],
58+
}
59+
}
60+
}
61+
4462
pub struct UnconfirmedState {
4563
pub confirmed_chain_tip: StacksBlockId,
4664
pub unconfirmed_chain_tip: StacksBlockId,
@@ -136,10 +154,10 @@ impl UnconfirmedState {
136154
chainstate: &StacksChainState,
137155
burn_dbconn: &dyn BurnStateDB,
138156
mblocks: Vec<StacksMicroblock>,
139-
) -> Result<(u128, u128, Vec<StacksTransactionReceipt>), Error> {
157+
) -> Result<ProcessedUnconfirmedState, Error> {
140158
if self.last_mblock_seq == u16::max_value() {
141159
// drop them -- nothing to do
142-
return Ok((0, 0, vec![]));
160+
return Ok(Default::default());
143161
}
144162

145163
debug!(
@@ -193,7 +211,7 @@ impl UnconfirmedState {
193211
&mblock_hash, mblock.header.sequence
194212
);
195213

196-
let (stx_fees, stx_burns, mut receipts) =
214+
let (stx_fees, stx_burns, receipts) =
197215
match StacksChainState::process_microblocks_transactions(
198216
&mut clarity_tx,
199217
&vec![mblock.clone()],
@@ -211,7 +229,7 @@ impl UnconfirmedState {
211229
total_fees += stx_fees;
212230
total_burns += stx_burns;
213231
num_new_mblocks += 1;
214-
all_receipts.append(&mut receipts);
232+
all_receipts.push((seq, receipts));
215233

216234
last_mblock = Some(mblock_header);
217235
last_mblock_seq = seq;
@@ -255,7 +273,11 @@ impl UnconfirmedState {
255273
self.bytes_so_far = 0;
256274
}
257275

258-
Ok((total_fees, total_burns, all_receipts))
276+
Ok(ProcessedUnconfirmedState {
277+
total_fees,
278+
total_burns,
279+
receipts: all_receipts,
280+
})
259281
}
260282

261283
/// Load up the Stacks microblock stream to process, composed of only the new microblocks
@@ -280,24 +302,25 @@ impl UnconfirmedState {
280302
}
281303

282304
/// Update the view of the current confiremd chain tip's unconfirmed microblock state
305+
/// Returns ProcessedUnconfirmedState for the microblocks newly added to the unconfirmed state
283306
pub fn refresh(
284307
&mut self,
285308
chainstate: &StacksChainState,
286309
burn_dbconn: &dyn BurnStateDB,
287-
) -> Result<(u128, u128, Vec<StacksTransactionReceipt>), Error> {
310+
) -> Result<ProcessedUnconfirmedState, Error> {
288311
assert!(
289312
!self.readonly,
290313
"BUG: code tried to write unconfirmed state to a read-only instance"
291314
);
292315

293316
if self.last_mblock_seq == u16::max_value() {
294317
// no-op
295-
return Ok((0, 0, vec![]));
318+
return Ok(Default::default());
296319
}
297320

298321
match self.load_child_microblocks(chainstate)? {
299322
Some(microblocks) => self.append_microblocks(chainstate, burn_dbconn, microblocks),
300-
None => Ok((0, 0, vec![])),
323+
None => Ok(Default::default()),
301324
}
302325
}
303326

@@ -375,15 +398,15 @@ impl StacksChainState {
375398
&self,
376399
burn_dbconn: &dyn BurnStateDB,
377400
anchored_block_id: StacksBlockId,
378-
) -> Result<(UnconfirmedState, u128, u128, Vec<StacksTransactionReceipt>), Error> {
401+
) -> Result<(UnconfirmedState, ProcessedUnconfirmedState), Error> {
379402
debug!("Make new unconfirmed state off of {}", &anchored_block_id);
380403
let mut unconfirmed_state = UnconfirmedState::new(self, anchored_block_id)?;
381-
let (fees, burns, receipts) = unconfirmed_state.refresh(self, burn_dbconn)?;
404+
let processed_unconfirmed_state = unconfirmed_state.refresh(self, burn_dbconn)?;
382405
debug!(
383406
"Made new unconfirmed state off of {} (at {})",
384407
&anchored_block_id, &unconfirmed_state.unconfirmed_chain_tip
385408
);
386-
Ok((unconfirmed_state, fees, burns, receipts))
409+
Ok((unconfirmed_state, processed_unconfirmed_state))
387410
}
388411

389412
/// Reload the unconfirmed view from a new chain tip.
@@ -395,7 +418,7 @@ impl StacksChainState {
395418
&mut self,
396419
burn_dbconn: &dyn BurnStateDB,
397420
canonical_tip: StacksBlockId,
398-
) -> Result<(u128, u128, Vec<StacksTransactionReceipt>), Error> {
421+
) -> Result<ProcessedUnconfirmedState, Error> {
399422
debug!("Reload unconfirmed state off of {}", &canonical_tip);
400423

401424
let unconfirmed_state = self.unconfirmed_state.take();
@@ -427,7 +450,7 @@ impl StacksChainState {
427450
self.drop_unconfirmed_state(unconfirmed_state);
428451
}
429452

430-
let (new_unconfirmed_state, fees, burns, receipts) =
453+
let (new_unconfirmed_state, processed_unconfirmed_state) =
431454
self.make_unconfirmed_state(burn_dbconn, canonical_tip)?;
432455

433456
debug!(
@@ -436,19 +459,19 @@ impl StacksChainState {
436459
);
437460

438461
self.unconfirmed_state = Some(new_unconfirmed_state);
439-
Ok((fees, burns, receipts))
462+
Ok(processed_unconfirmed_state)
440463
}
441464

442465
/// Refresh the current unconfirmed chain state
443466
pub fn refresh_unconfirmed_state(
444467
&mut self,
445468
burn_dbconn: &dyn BurnStateDB,
446-
) -> Result<(u128, u128, Vec<StacksTransactionReceipt>), Error> {
469+
) -> Result<ProcessedUnconfirmedState, Error> {
447470
let mut unconfirmed_state = self.unconfirmed_state.take();
448471
let res = if let Some(ref mut unconfirmed_state) = unconfirmed_state {
449472
if !unconfirmed_state.is_readable() {
450473
warn!("Unconfirmed state is not readable; it will soon be refreshed");
451-
return Ok((0, 0, vec![]));
474+
return Ok(Default::default());
452475
}
453476

454477
debug!(
@@ -465,7 +488,7 @@ impl StacksChainState {
465488
res
466489
} else {
467490
warn!("No unconfirmed state instantiated");
468-
Ok((0, 0, vec![]))
491+
Ok(Default::default())
469492
};
470493
self.unconfirmed_state = unconfirmed_state;
471494
res

0 commit comments

Comments
 (0)