@@ -524,6 +524,13 @@ impl MaturedMinerPaymentSchedules {
524
524
}
525
525
}
526
526
527
+ /// Struct for the transaction events associated with
528
+ /// any operations handled in finish_block()
529
+ pub struct FinishBlockEvents {
530
+ pub lockup_events : Vec < StacksTransactionEvent > ,
531
+ pub sip31_event : Option < StacksTransactionEvent > ,
532
+ }
533
+
527
534
/// Struct containing information about the miners assigned in the
528
535
/// .miners stackerdb config
529
536
pub struct MinersDBInformation {
@@ -4350,7 +4357,9 @@ impl NakamotoChainState {
4350
4357
pub fn finish_block (
4351
4358
clarity_tx : & mut ClarityTx ,
4352
4359
miner_payouts : Option < & MaturedMinerRewards > ,
4353
- ) -> Result < Vec < StacksTransactionEvent > , ChainstateError > {
4360
+ new_tenure : bool ,
4361
+ chain_tip_burn_header_height : u32 ,
4362
+ ) -> Result < FinishBlockEvents , ChainstateError > {
4354
4363
// add miner payments
4355
4364
if let Some ( rewards) = miner_payouts {
4356
4365
// grant in order by miner, then users
@@ -4369,7 +4378,17 @@ impl NakamotoChainState {
4369
4378
4370
4379
clarity_tx. increment_ustx_liquid_supply ( new_unlocked_ustx) ;
4371
4380
4372
- Ok ( lockup_events)
4381
+ // process SIP-031 mint/transfers
4382
+ let sip31_event = if new_tenure {
4383
+ Self :: sip_031_mint_and_transfer_on_new_tenure ( clarity_tx, chain_tip_burn_header_height)
4384
+ } else {
4385
+ None
4386
+ } ;
4387
+
4388
+ Ok ( FinishBlockEvents {
4389
+ lockup_events,
4390
+ sip31_event,
4391
+ } )
4373
4392
}
4374
4393
4375
4394
/// Verify that the PoX bitvector from the block header is consistent with the block-commit's
@@ -4792,15 +4811,22 @@ impl NakamotoChainState {
4792
4811
. map ( |matured_miner_rewards| matured_miner_rewards. consolidate ( ) )
4793
4812
. unwrap_or_default ( ) ;
4794
4813
4795
- let mut lockup_events =
4796
- match Self :: finish_block ( & mut clarity_tx, matured_miner_rewards_opt. as_ref ( ) ) {
4797
- Err ( ChainstateError :: InvalidStacksBlock ( e) ) => {
4798
- clarity_tx. rollback_block ( ) ;
4799
- return Err ( ChainstateError :: InvalidStacksBlock ( e) ) ;
4800
- }
4801
- Err ( e) => return Err ( e) ,
4802
- Ok ( lockup_events) => lockup_events,
4803
- } ;
4814
+ let FinishBlockEvents {
4815
+ mut lockup_events,
4816
+ sip31_event,
4817
+ } = match Self :: finish_block (
4818
+ & mut clarity_tx,
4819
+ matured_miner_rewards_opt. as_ref ( ) ,
4820
+ new_tenure,
4821
+ chain_tip_burn_header_height,
4822
+ ) {
4823
+ Err ( ChainstateError :: InvalidStacksBlock ( e) ) => {
4824
+ clarity_tx. rollback_block ( ) ;
4825
+ return Err ( ChainstateError :: InvalidStacksBlock ( e) ) ;
4826
+ }
4827
+ Err ( e) => return Err ( e) ,
4828
+ Ok ( lockup_events) => lockup_events,
4829
+ } ;
4804
4830
4805
4831
// If any, append lockups events to the coinbase receipt
4806
4832
if let Some ( receipt) = tx_receipts. get_mut ( 0 ) {
@@ -4829,21 +4855,16 @@ impl NakamotoChainState {
4829
4855
}
4830
4856
}
4831
4857
4832
- if new_tenure {
4833
- if let Some ( event) = Self :: sip_031_mint_and_transfer_on_new_tenure (
4834
- & mut clarity_tx,
4835
- chain_tip_burn_header_height,
4836
- ) {
4837
- // for sip-031 we are safe in assuming coinbase is at index 1
4838
- if let Some ( receipt) = tx_receipts. get_mut ( 1 ) {
4839
- if receipt. is_coinbase_tx ( ) {
4840
- receipt. events . push ( event) ;
4841
- } else {
4842
- error ! ( "Unable to attach SIP-031 mint events, block's second transaction is not a coinbase transaction" )
4843
- }
4858
+ if let Some ( event) = sip31_event {
4859
+ // for sip-031 we are safe in assuming coinbase is at index 1
4860
+ if let Some ( receipt) = tx_receipts. get_mut ( 1 ) {
4861
+ if receipt. is_coinbase_tx ( ) {
4862
+ receipt. events . push ( event) ;
4844
4863
} else {
4845
- error ! ( "Unable to attach SIP-031 mint events, block's second transaction not available " )
4864
+ error ! ( "Unable to attach SIP-031 mint events, block's second transaction is not a coinbase transaction " )
4846
4865
}
4866
+ } else {
4867
+ error ! ( "Unable to attach SIP-031 mint events, block's second transaction not available" )
4847
4868
}
4848
4869
}
4849
4870
0 commit comments