@@ -41,6 +41,24 @@ use crate::types::chainstate::{StacksBlockHeader, StacksBlockId, StacksMicrobloc
41
41
42
42
pub type UnconfirmedTxMap = HashMap < Txid , ( StacksTransaction , BlockHeaderHash , u16 ) > ;
43
43
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
+
44
62
pub struct UnconfirmedState {
45
63
pub confirmed_chain_tip : StacksBlockId ,
46
64
pub unconfirmed_chain_tip : StacksBlockId ,
@@ -136,10 +154,10 @@ impl UnconfirmedState {
136
154
chainstate : & StacksChainState ,
137
155
burn_dbconn : & dyn BurnStateDB ,
138
156
mblocks : Vec < StacksMicroblock > ,
139
- ) -> Result < ( u128 , u128 , Vec < StacksTransactionReceipt > ) , Error > {
157
+ ) -> Result < ProcessedUnconfirmedState , Error > {
140
158
if self . last_mblock_seq == u16:: max_value ( ) {
141
159
// drop them -- nothing to do
142
- return Ok ( ( 0 , 0 , vec ! [ ] ) ) ;
160
+ return Ok ( Default :: default ( ) ) ;
143
161
}
144
162
145
163
debug ! (
@@ -193,7 +211,7 @@ impl UnconfirmedState {
193
211
& mblock_hash, mblock. header. sequence
194
212
) ;
195
213
196
- let ( stx_fees, stx_burns, mut receipts) =
214
+ let ( stx_fees, stx_burns, receipts) =
197
215
match StacksChainState :: process_microblocks_transactions (
198
216
& mut clarity_tx,
199
217
& vec ! [ mblock. clone( ) ] ,
@@ -211,7 +229,7 @@ impl UnconfirmedState {
211
229
total_fees += stx_fees;
212
230
total_burns += stx_burns;
213
231
num_new_mblocks += 1 ;
214
- all_receipts. append ( & mut receipts) ;
232
+ all_receipts. push ( ( seq , receipts) ) ;
215
233
216
234
last_mblock = Some ( mblock_header) ;
217
235
last_mblock_seq = seq;
@@ -255,7 +273,11 @@ impl UnconfirmedState {
255
273
self . bytes_so_far = 0 ;
256
274
}
257
275
258
- Ok ( ( total_fees, total_burns, all_receipts) )
276
+ Ok ( ProcessedUnconfirmedState {
277
+ total_fees,
278
+ total_burns,
279
+ receipts : all_receipts,
280
+ } )
259
281
}
260
282
261
283
/// Load up the Stacks microblock stream to process, composed of only the new microblocks
@@ -280,24 +302,25 @@ impl UnconfirmedState {
280
302
}
281
303
282
304
/// 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
283
306
pub fn refresh (
284
307
& mut self ,
285
308
chainstate : & StacksChainState ,
286
309
burn_dbconn : & dyn BurnStateDB ,
287
- ) -> Result < ( u128 , u128 , Vec < StacksTransactionReceipt > ) , Error > {
310
+ ) -> Result < ProcessedUnconfirmedState , Error > {
288
311
assert ! (
289
312
!self . readonly,
290
313
"BUG: code tried to write unconfirmed state to a read-only instance"
291
314
) ;
292
315
293
316
if self . last_mblock_seq == u16:: max_value ( ) {
294
317
// no-op
295
- return Ok ( ( 0 , 0 , vec ! [ ] ) ) ;
318
+ return Ok ( Default :: default ( ) ) ;
296
319
}
297
320
298
321
match self . load_child_microblocks ( chainstate) ? {
299
322
Some ( microblocks) => self . append_microblocks ( chainstate, burn_dbconn, microblocks) ,
300
- None => Ok ( ( 0 , 0 , vec ! [ ] ) ) ,
323
+ None => Ok ( Default :: default ( ) ) ,
301
324
}
302
325
}
303
326
@@ -375,15 +398,15 @@ impl StacksChainState {
375
398
& self ,
376
399
burn_dbconn : & dyn BurnStateDB ,
377
400
anchored_block_id : StacksBlockId ,
378
- ) -> Result < ( UnconfirmedState , u128 , u128 , Vec < StacksTransactionReceipt > ) , Error > {
401
+ ) -> Result < ( UnconfirmedState , ProcessedUnconfirmedState ) , Error > {
379
402
debug ! ( "Make new unconfirmed state off of {}" , & anchored_block_id) ;
380
403
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) ?;
382
405
debug ! (
383
406
"Made new unconfirmed state off of {} (at {})" ,
384
407
& anchored_block_id, & unconfirmed_state. unconfirmed_chain_tip
385
408
) ;
386
- Ok ( ( unconfirmed_state, fees , burns , receipts ) )
409
+ Ok ( ( unconfirmed_state, processed_unconfirmed_state ) )
387
410
}
388
411
389
412
/// Reload the unconfirmed view from a new chain tip.
@@ -395,7 +418,7 @@ impl StacksChainState {
395
418
& mut self ,
396
419
burn_dbconn : & dyn BurnStateDB ,
397
420
canonical_tip : StacksBlockId ,
398
- ) -> Result < ( u128 , u128 , Vec < StacksTransactionReceipt > ) , Error > {
421
+ ) -> Result < ProcessedUnconfirmedState , Error > {
399
422
debug ! ( "Reload unconfirmed state off of {}" , & canonical_tip) ;
400
423
401
424
let unconfirmed_state = self . unconfirmed_state . take ( ) ;
@@ -427,7 +450,7 @@ impl StacksChainState {
427
450
self . drop_unconfirmed_state ( unconfirmed_state) ;
428
451
}
429
452
430
- let ( new_unconfirmed_state, fees , burns , receipts ) =
453
+ let ( new_unconfirmed_state, processed_unconfirmed_state ) =
431
454
self . make_unconfirmed_state ( burn_dbconn, canonical_tip) ?;
432
455
433
456
debug ! (
@@ -436,19 +459,19 @@ impl StacksChainState {
436
459
) ;
437
460
438
461
self . unconfirmed_state = Some ( new_unconfirmed_state) ;
439
- Ok ( ( fees , burns , receipts ) )
462
+ Ok ( processed_unconfirmed_state )
440
463
}
441
464
442
465
/// Refresh the current unconfirmed chain state
443
466
pub fn refresh_unconfirmed_state (
444
467
& mut self ,
445
468
burn_dbconn : & dyn BurnStateDB ,
446
- ) -> Result < ( u128 , u128 , Vec < StacksTransactionReceipt > ) , Error > {
469
+ ) -> Result < ProcessedUnconfirmedState , Error > {
447
470
let mut unconfirmed_state = self . unconfirmed_state . take ( ) ;
448
471
let res = if let Some ( ref mut unconfirmed_state) = unconfirmed_state {
449
472
if !unconfirmed_state. is_readable ( ) {
450
473
warn ! ( "Unconfirmed state is not readable; it will soon be refreshed" ) ;
451
- return Ok ( ( 0 , 0 , vec ! [ ] ) ) ;
474
+ return Ok ( Default :: default ( ) ) ;
452
475
}
453
476
454
477
debug ! (
@@ -465,7 +488,7 @@ impl StacksChainState {
465
488
res
466
489
} else {
467
490
warn ! ( "No unconfirmed state instantiated" ) ;
468
- Ok ( ( 0 , 0 , vec ! [ ] ) )
491
+ Ok ( Default :: default ( ) )
469
492
} ;
470
493
self . unconfirmed_state = unconfirmed_state;
471
494
res
0 commit comments