Skip to content

Commit 483f1ad

Browse files
authored
Merge pull request #6570 from obycode/chore/stacks-block-time
chore: update `block-time` --> `stacks-block-time`
2 parents 93fd7b6 + a3cbcea commit 483f1ad

File tree

8 files changed

+37
-26
lines changed

8 files changed

+37
-26
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to the versioning scheme outlined in the [README.md](README.md).
77

8+
## Unreleased
9+
10+
### Changed
11+
12+
- Renamed Clarity 4's new `block-time` to `stacks-block-time`
13+
814
## [3.2.0.0.2]
915

1016
### Added

clarity/src/vm/analysis/arithmetic_checker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl ArithmeticOnlyChecker<'_> {
143143
match native_var {
144144
ContractCaller | TxSender | TotalLiquidMicroSTX | BlockHeight | BurnBlockHeight
145145
| Regtest | TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight
146-
| BlockTime | CurrentContract => Err(Error::VariableForbidden(native_var)),
146+
| StacksBlockTime | CurrentContract => Err(Error::VariableForbidden(native_var)),
147147
NativeNone | NativeTrue | NativeFalse => Ok(()),
148148
}
149149
} else {

clarity/src/vm/analysis/type_checker/v2_05/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ fn type_reserved_variable(variable_name: &str) -> Result<Option<TypeSignature>,
330330
NativeFalse => TypeSignature::BoolType,
331331
TotalLiquidMicroSTX => TypeSignature::UIntType,
332332
Regtest => TypeSignature::BoolType,
333-
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight | BlockTime | CurrentContract => {
333+
TxSponsor | Mainnet | ChainId | StacksBlockHeight | TenureHeight | StacksBlockTime | CurrentContract => {
334334
return Err(CheckErrors::Expects(
335-
"tx-sponsor, mainnet, chain-id, stacks-block-height, tenure-height, block-time, and current-contract should not reach here in 2.05".into(),
335+
"tx-sponsor, mainnet, chain-id, stacks-block-height, tenure-height, stacks-block-time, and current-contract should not reach here in 2.05".into(),
336336
)
337337
.into())
338338
}

clarity/src/vm/analysis/type_checker/v2_1/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ fn type_reserved_variable(
10231023
Mainnet => TypeSignature::BoolType,
10241024
ChainId => TypeSignature::UIntType,
10251025
CurrentContract => TypeSignature::PrincipalType,
1026-
BlockTime => TypeSignature::UIntType,
1026+
StacksBlockTime => TypeSignature::UIntType,
10271027
};
10281028
Ok(Some(var_type))
10291029
} else {

clarity/src/vm/docs/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ At the start of epoch 3.0, `tenure-height` will return the same value as `block-
154154
};
155155

156156
const BLOCK_TIME_KEYWORD: SimpleKeywordAPI = SimpleKeywordAPI {
157-
name: "block-time",
158-
snippet: "block-time",
157+
name: "stacks-block-time",
158+
snippet: "stacks-block-time",
159159
output_type: "uint",
160160
description: "Returns the Unix timestamp (in seconds) of the current Stacks block. Introduced
161161
in Clarity 4. Provides access to the timestamp of the current block, which is
162162
not available with `get-stacks-block-info?`.",
163-
example: "(>= block-time u1755820800) ;; returns true if current block timestamp is at or after 2025-07-22.",
163+
example: "(>= stacks-block-time u1755820800) ;; returns true if current block timestamp is at or after 2025-07-22.",
164164
};
165165

166166
const TX_SENDER_KEYWORD: SimpleKeywordAPI = SimpleKeywordAPI {
@@ -2700,7 +2700,7 @@ pub fn make_keyword_reference(variable: &NativeVariables) -> Option<KeywordAPI>
27002700
NativeVariables::ChainId => CHAINID_KEYWORD.clone(),
27012701
NativeVariables::TxSponsor => TX_SPONSOR_KEYWORD.clone(),
27022702
NativeVariables::CurrentContract => CURRENT_CONTRACT_KEYWORD.clone(),
2703-
NativeVariables::BlockTime => BLOCK_TIME_KEYWORD.clone(),
2703+
NativeVariables::StacksBlockTime => BLOCK_TIME_KEYWORD.clone(),
27042704
};
27052705
Some(KeywordAPI {
27062706
name: keyword.name,

clarity/src/vm/tests/variables.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ fn test_block_time(
11101110
epoch: StacksEpochId,
11111111
mut tl_env_factory: TopLevelMemoryEnvironmentGenerator,
11121112
) {
1113-
let contract = "(define-read-only (test-func) block-time)";
1113+
let contract = "(define-read-only (test-func) stacks-block-time)";
11141114

11151115
let placeholder_context =
11161116
ContractContext::new(QualifiedContractIdentifier::transient(), version);
@@ -1125,11 +1125,11 @@ fn test_block_time(
11251125
type_check_version(&contract_identifier, &mut exprs, db, true, epoch, version)
11261126
});
11271127

1128-
// block-time should only be available in Clarity 4
1128+
// stacks-block-time should only be available in Clarity 4
11291129
if version < ClarityVersion::Clarity4 {
11301130
let err = analysis.unwrap_err();
11311131
assert_eq!(
1132-
CheckErrors::UndefinedVariable("block-time".to_string()),
1132+
CheckErrors::UndefinedVariable("stacks-block-time".to_string()),
11331133
*err.err
11341134
);
11351135
} else {
@@ -1156,7 +1156,9 @@ fn test_block_time(
11561156
if version < ClarityVersion::Clarity4 {
11571157
let err = eval_result.unwrap_err();
11581158
assert_eq!(
1159-
Error::Unchecked(CheckErrors::UndefinedVariable("block-time".to_string(),)),
1159+
Error::Unchecked(CheckErrors::UndefinedVariable(
1160+
"stacks-block-time".to_string(),
1161+
)),
11601162
err
11611163
);
11621164
} else {
@@ -1173,11 +1175,11 @@ fn test_block_time_in_expressions() {
11731175

11741176
let contract = r#"
11751177
(define-read-only (time-comparison (threshold uint))
1176-
(>= block-time threshold))
1178+
(>= stacks-block-time threshold))
11771179
(define-read-only (time-arithmetic)
1178-
(+ block-time u100))
1180+
(+ stacks-block-time u100))
11791181
(define-read-only (time-in-response)
1180-
(ok block-time))
1182+
(ok stacks-block-time))
11811183
"#;
11821184

11831185
let placeholder_context =

clarity/src/vm/variables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ define_versioned_named_enum_with_max!(NativeVariables(ClarityVersion) {
4040
ChainId("chain-id", ClarityVersion::Clarity2, None),
4141
StacksBlockHeight("stacks-block-height", ClarityVersion::Clarity3, None),
4242
TenureHeight("tenure-height", ClarityVersion::Clarity3, None),
43-
BlockTime("block-time", ClarityVersion::Clarity4, None),
43+
StacksBlockTime("stacks-block-time", ClarityVersion::Clarity4, None),
4444
CurrentContract("current-contract", ClarityVersion::Clarity4, None)
4545
});
4646

@@ -140,7 +140,7 @@ pub fn lookup_reserved_variable(
140140
let contract = env.contract_context.contract_identifier.clone();
141141
Ok(Some(Value::Principal(PrincipalData::Contract(contract))))
142142
}
143-
NativeVariables::BlockTime => {
143+
NativeVariables::StacksBlockTime => {
144144
runtime_cost(ClarityCostFunction::FetchVar, env, 1)?;
145145
let block_time = env.global_context.database.get_current_block_time()?;
146146
Ok(Some(Value::UInt(u128::from(block_time))))

stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15050,7 +15050,7 @@ fn contract_limit_percentage_mempool_strategy_low_limit() {
1505015050

1505115051
#[test]
1505215052
#[ignore]
15053-
/// Verify the block timestamp using `block-time`.
15053+
/// Verify the block timestamp using `stacks-block-time`.
1505415054
fn check_block_time_keyword() {
1505515055
if env::var("BITCOIND_TEST") != Ok("1".into()) {
1505615056
return;
@@ -15157,25 +15157,25 @@ fn check_block_time_keyword() {
1515715157
let mut sender_nonce = 0;
1515815158
let contract_name = "test-contract";
1515915159
let contract = r#"
15160-
(define-constant deploy-time block-time)
15160+
(define-constant deploy-time stacks-block-time)
1516115161
(define-constant deploy-height stacks-block-height)
1516215162
(define-read-only (get-current-time)
15163-
block-time
15163+
stacks-block-time
1516415164
)
1516515165
(define-read-only (get-ihh (height uint)) (get-stacks-block-info? id-header-hash height))
1516615166
(define-read-only (get-time (height uint)) (get-stacks-block-info? time height))
1516715167
(define-read-only (get-height) stacks-block-height)
1516815168
(define-read-only (get-previous-time (height uint))
1516915169
(ok (at-block (unwrap! (get-stacks-block-info? id-header-hash height) (err u100))
15170-
block-time
15170+
stacks-block-time
1517115171
))
1517215172
)
1517315173
(define-public (get-current-time-call)
15174-
(ok block-time)
15174+
(ok stacks-block-time)
1517515175
)
1517615176
(define-public (get-previous-time-call (height uint))
1517715177
(ok (at-block (unwrap! (get-stacks-block-info? id-header-hash height) (err u100))
15178-
block-time
15178+
stacks-block-time
1517915179
))
1518015180
)
1518115181
"#;
@@ -15221,7 +15221,7 @@ fn check_block_time_keyword() {
1522115221
let current_time = current_time_value.expect_u128().unwrap();
1522215222
assert!(
1522315223
current_time > deploy_time,
15224-
"block-time should be greater than the time at deployment"
15224+
"stacks-block-time should be greater than the time at deployment"
1522515225
);
1522615226

1522715227
let previous_time_result = call_read_only(
@@ -15292,13 +15292,16 @@ fn check_block_time_keyword() {
1529215292
match contract_call.function_name.as_str() {
1529315293
"get-current-time-call" => {
1529415294
info!("Current time: {}", time);
15295-
assert!(time > current_time, "block-time should have advanced");
15295+
assert!(
15296+
time > current_time,
15297+
"stacks-block-time should have advanced"
15298+
);
1529615299
}
1529715300
"get-previous-time-call" => {
1529815301
info!("Previous time: {}", time);
1529915302
assert_eq!(
1530015303
time, deploy_time,
15301-
"block-time should be the same as at deployment"
15304+
"stacks-block-time should be the same as at deployment"
1530215305
);
1530315306
}
1530415307
_ => panic!("Unexpected contract call"),

0 commit comments

Comments
 (0)