Skip to content

Commit

Permalink
feat: gate block-info behavior on chain_id (leave inactive in primary…
Browse files Browse the repository at this point in the history
… testnet)
  • Loading branch information
kantai committed Oct 17, 2024
1 parent ec5a03a commit 4172711
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 21 additions & 15 deletions clarity/src/vm/functions/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::cmp;

use stacks_common::consts::CHAIN_ID_TESTNET;
use stacks_common::types::chainstate::StacksBlockId;
use stacks_common::types::StacksEpochId;

Expand Down Expand Up @@ -769,22 +770,27 @@ pub fn special_get_block_info(
_ => return Ok(Value::none()),
};

let height_value = if env.contract_context.get_clarity_version() < &ClarityVersion::Clarity3 {
if env.global_context.epoch_id < StacksEpochId::Epoch30 {
height_value
} else {
// interpretting height_value as a tenure height
let height_opt = env
.global_context
.database
.get_block_height_for_tenure_height(height_value)?;
match height_opt {
Some(x) => x,
None => return Ok(Value::none()),
}
}
} else {
// interpret height as a tenure height IFF
// * clarity version is less than Clarity3
// * the evaluated epoch is geq 3.0
// * we are not on (classic) primary testnet
let interpret_height_as_tenure_height = env.contract_context.get_clarity_version()
< &ClarityVersion::Clarity3
&& env.global_context.epoch_id >= StacksEpochId::Epoch30
&& env.global_context.chain_id != CHAIN_ID_TESTNET;

let height_value = if !interpret_height_as_tenure_height {
height_value
} else {
// interpretting height_value as a tenure height
let height_opt = env
.global_context
.database
.get_block_height_for_tenure_height(height_value)?;
match height_opt {
Some(x) => x,
None => return Ok(Value::none()),
}
};

let current_block_height = env.global_context.database.get_current_block_height();
Expand Down
4 changes: 4 additions & 0 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7374,6 +7374,7 @@ fn check_block_times() {
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
naka_conf.burnchain.chain_id = CHAIN_ID_TESTNET + 1;
let sender_sk = Secp256k1PrivateKey::new();
let sender_signer_sk = Secp256k1PrivateKey::new();
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
Expand Down Expand Up @@ -7771,6 +7772,8 @@ fn check_block_info() {

let mut signers = TestSigners::default();
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
// change the chain id so that it isn't the same as primary testnet
naka_conf.burnchain.chain_id = CHAIN_ID_TESTNET + 1;
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
let sender_sk = Secp256k1PrivateKey::new();
Expand Down Expand Up @@ -8362,6 +8365,7 @@ fn check_block_info_rewards() {
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
naka_conf.burnchain.chain_id = CHAIN_ID_TESTNET + 1;
let sender_sk = Secp256k1PrivateKey::new();
let sender_signer_sk = Secp256k1PrivateKey::new();
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
Expand Down

0 comments on commit 4172711

Please sign in to comment.