Skip to content

Commit

Permalink
error on advance_stacks if epoch < 3
Browse files Browse the repository at this point in the history
  • Loading branch information
brady.ouren committed Jul 19, 2024
1 parent 4374d79 commit efa47c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 4 additions & 0 deletions components/clarity-repl/src/repl/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 11 additions & 3 deletions components/clarity-repl/src/repl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<u32, String> {
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) {
Expand Down
12 changes: 7 additions & 5 deletions components/clarity-repl/src/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<u32, String> {
self.interpreter.advance_stacks_chaintip(count)
}
pub fn advance_burn_chaintip(&mut self, count: u32) -> u32 {
Expand Down

0 comments on commit efa47c4

Please sign in to comment.