diff --git a/components/clarity-repl/src/repl/datastore.rs b/components/clarity-repl/src/repl/datastore.rs index 113e76c2e..fed923c91 100644 --- a/components/clarity-repl/src/repl/datastore.rs +++ b/components/clarity-repl/src/repl/datastore.rs @@ -374,6 +374,10 @@ impl BurnDatastore { } } + pub fn get_current_epoch(&self) -> StacksEpochId { + self.current_epoch + } + pub fn get_current_block_height(&self) -> u32 { self.chain_height } diff --git a/components/clarity-repl/src/repl/interpreter.rs b/components/clarity-repl/src/repl/interpreter.rs index 47cd41cfa..7e64a83a1 100644 --- a/components/clarity-repl/src/repl/interpreter.rs +++ b/components/clarity-repl/src/repl/interpreter.rs @@ -7,7 +7,7 @@ use crate::repl::datastore::BurnDatastore; use crate::repl::datastore::Datastore; use crate::repl::Settings; use clarity::consts::CHAIN_ID_TESTNET; -use clarity::types::StacksEpochId; +use clarity::types::{StacksEpoch, StacksEpochId}; use clarity::vm::analysis::ContractAnalysis; use clarity::vm::ast::{build_ast_with_diagnostics, ContractAST}; #[cfg(feature = "cli")] @@ -1104,8 +1104,16 @@ impl ClarityInterpreter { self.set_tenure_height(); new_height } - pub fn advance_stacks_chaintip(&mut self, count: u32) -> u32 { - self.datastore.advance_chain_tip(count) + pub fn advance_stacks_chaintip(&mut self, count: u32) -> Result { + let current_epoch = self.burn_datastore.get_current_epoch(); + if current_epoch < StacksEpochId::Epoch30 { + Err(format!( + "stacks block height can't be advanced in {}", + current_epoch + )) + } else { + Ok(self.datastore.advance_chain_tip(count)) + } } pub fn set_tenure_height(&mut self) { diff --git a/components/clarity-repl/src/repl/session.rs b/components/clarity-repl/src/repl/session.rs index 9145b3e64..043e5333d 100644 --- a/components/clarity-repl/src/repl/session.rs +++ b/components/clarity-repl/src/repl/session.rs @@ -835,10 +835,12 @@ impl Session { } }; - let new_height = self.advance_stacks_chaintip(count); - format!("{} blocks simulated, new height: {}", count, new_height) - .green() - .to_string() + match self.advance_stacks_chaintip(count) { + Ok(new_height) => format!("{} blocks simulated, new height: {}", count, new_height) + .green() + .to_string(), + Err(msg) => format!("{}", msg.red()), + } } fn parse_and_advance_burn_chaintip(&mut self, command: &str) -> String { let args: Vec<_> = command.split(' ').collect(); @@ -860,7 +862,7 @@ impl Session { .to_string() } - pub fn advance_stacks_chaintip(&mut self, count: u32) -> u32 { + pub fn advance_stacks_chaintip(&mut self, count: u32) -> Result { self.interpreter.advance_stacks_chaintip(count) } pub fn advance_burn_chaintip(&mut self, count: u32) -> u32 {