@@ -1075,35 +1075,41 @@ impl<'a> ClarityDatabase<'a> {
1075
1075
/// block height (i.e. that returned by `get_index_block_header_hash` for
1076
1076
/// `get_current_block_height`).
1077
1077
pub fn get_current_burnchain_block_height ( & mut self ) -> Result < u32 > {
1078
- let cur_stacks_height = self . store . get_current_block_height ( ) ;
1078
+ let epoch = self . get_clarity_epoch_version ( ) ?;
1079
+ match epoch {
1080
+ // Special case to preserve possibly incorrect behavior (inside at-block) in Epoch 3.0
1081
+ StacksEpochId :: Epoch30 => {
1082
+ self . burn_state_db
1083
+ . get_tip_burn_block_height ( )
1084
+ . ok_or_else ( || {
1085
+ InterpreterError :: Expect ( "Failed to get burnchain tip height." . into ( ) )
1086
+ . into ( )
1087
+ } )
1088
+ }
1089
+ _ => {
1090
+ let cur_stacks_height = self . store . get_current_block_height ( ) ;
1091
+
1092
+ // Before epoch 3.0, we can only access the burn block associated with the last block
1093
+ let last_mined_bhh = if epoch. clarity_uses_tip_burn_block ( ) {
1094
+ // In epoch 3+, we can access the current burnchain block
1095
+ self . get_index_block_header_hash ( cur_stacks_height)
1096
+ . or_else ( |_| self . get_index_block_header_hash ( cur_stacks_height - 1 ) ) ?
1097
+ } else if cur_stacks_height == 0 {
1098
+ return Ok ( self . burn_state_db . get_burn_start_height ( ) ) ;
1099
+ } else {
1100
+ // Safety note: normal subtraction is safe here, because we've already checked
1101
+ // that cur_stacks_height > 0.
1102
+ self . get_index_block_header_hash ( cur_stacks_height - 1 ) ?
1103
+ } ;
1079
1104
1080
- // Before epoch 3.0, we can only access the burn block associated with the last block
1081
- if !self
1082
- . get_clarity_epoch_version ( ) ?
1083
- . clarity_uses_tip_burn_block ( )
1084
- {
1085
- if cur_stacks_height == 0 {
1086
- return Ok ( self . burn_state_db . get_burn_start_height ( ) ) ;
1087
- } ;
1088
- // Safety note: normal subtraction is safe here, because we've already checked
1089
- // that cur_stacks_height > 0.
1090
- let last_mined_bhh = self . get_index_block_header_hash ( cur_stacks_height - 1 ) ?;
1091
-
1092
- self . get_burnchain_block_height ( & last_mined_bhh)
1093
- . ok_or_else ( || {
1094
- InterpreterError :: Expect ( format ! (
1095
- "Block header hash '{}' must return for provided stacks block height {}" ,
1096
- & last_mined_bhh, cur_stacks_height
1097
- ) )
1098
- . into ( )
1099
- } )
1100
- } else {
1101
- // In epoch 3+, we can access the current burnchain block
1102
- self . burn_state_db
1103
- . get_tip_burn_block_height ( )
1104
- . ok_or_else ( || {
1105
- InterpreterError :: Expect ( "Failed to get burnchain tip height." . into ( ) ) . into ( )
1106
- } )
1105
+ self . get_burnchain_block_height ( & last_mined_bhh)
1106
+ . ok_or_else ( || {
1107
+ InterpreterError :: Expect ( format ! (
1108
+ "Block header hash '{last_mined_bhh}' must return for provided stacks block height {cur_stacks_height}"
1109
+ ) )
1110
+ . into ( )
1111
+ } )
1112
+ }
1107
1113
}
1108
1114
}
1109
1115
0 commit comments