Skip to content

Commit 4172711

Browse files
committed
feat: gate block-info behavior on chain_id (leave inactive in primary testnet)
1 parent ec5a03a commit 4172711

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

clarity/src/vm/functions/database.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use std::cmp;
1818

19+
use stacks_common::consts::CHAIN_ID_TESTNET;
1920
use stacks_common::types::chainstate::StacksBlockId;
2021
use stacks_common::types::StacksEpochId;
2122

@@ -769,22 +770,27 @@ pub fn special_get_block_info(
769770
_ => return Ok(Value::none()),
770771
};
771772

772-
let height_value = if env.contract_context.get_clarity_version() < &ClarityVersion::Clarity3 {
773-
if env.global_context.epoch_id < StacksEpochId::Epoch30 {
774-
height_value
775-
} else {
776-
// interpretting height_value as a tenure height
777-
let height_opt = env
778-
.global_context
779-
.database
780-
.get_block_height_for_tenure_height(height_value)?;
781-
match height_opt {
782-
Some(x) => x,
783-
None => return Ok(Value::none()),
784-
}
785-
}
786-
} else {
773+
// interpret height as a tenure height IFF
774+
// * clarity version is less than Clarity3
775+
// * the evaluated epoch is geq 3.0
776+
// * we are not on (classic) primary testnet
777+
let interpret_height_as_tenure_height = env.contract_context.get_clarity_version()
778+
< &ClarityVersion::Clarity3
779+
&& env.global_context.epoch_id >= StacksEpochId::Epoch30
780+
&& env.global_context.chain_id != CHAIN_ID_TESTNET;
781+
782+
let height_value = if !interpret_height_as_tenure_height {
787783
height_value
784+
} else {
785+
// interpretting height_value as a tenure height
786+
let height_opt = env
787+
.global_context
788+
.database
789+
.get_block_height_for_tenure_height(height_value)?;
790+
match height_opt {
791+
Some(x) => x,
792+
None => return Ok(Value::none()),
793+
}
788794
};
789795

790796
let current_block_height = env.global_context.database.get_current_block_height();

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7374,6 +7374,7 @@ fn check_block_times() {
73747374
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
73757375
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
73767376
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
7377+
naka_conf.burnchain.chain_id = CHAIN_ID_TESTNET + 1;
73777378
let sender_sk = Secp256k1PrivateKey::new();
73787379
let sender_signer_sk = Secp256k1PrivateKey::new();
73797380
let sender_signer_addr = tests::to_addr(&sender_signer_sk);
@@ -7771,6 +7772,8 @@ fn check_block_info() {
77717772

77727773
let mut signers = TestSigners::default();
77737774
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
7775+
// change the chain id so that it isn't the same as primary testnet
7776+
naka_conf.burnchain.chain_id = CHAIN_ID_TESTNET + 1;
77747777
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
77757778
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
77767779
let sender_sk = Secp256k1PrivateKey::new();
@@ -8362,6 +8365,7 @@ fn check_block_info_rewards() {
83628365
let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None);
83638366
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
83648367
naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
8368+
naka_conf.burnchain.chain_id = CHAIN_ID_TESTNET + 1;
83658369
let sender_sk = Secp256k1PrivateKey::new();
83668370
let sender_signer_sk = Secp256k1PrivateKey::new();
83678371
let sender_signer_addr = tests::to_addr(&sender_signer_sk);

0 commit comments

Comments
 (0)