Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[alias]
stacks-node = "run --package stacks-node --"
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
clippy-stacks = "clippy -p stx-genesis -p libstackerdb -p stacks-signer -p pox-locking -p clarity-types -p clarity -p libsigner -p stacks-common -p clarity-cli -p stacks-cli -p stacks-inspect --no-deps --tests --all-features -- -D warnings"
clippy-stacks = "clippy -p stx-genesis -p libstackerdb -p stacks-signer -p pox-locking -p clarity-types -p clarity -p libsigner -p stacks-common -p clarity-cli -p stacks-cli -p stacks-inspect --no-deps --tests --all-features -- -D warnings -Aclippy::unnecessary_lazy_evaluations"
clippy-stackslib = "clippy -p stackslib --no-deps -- -Aclippy::all -Wclippy::indexing_slicing -Wclippy::nonminimal_bool -Wclippy::clone_on_copy"

# Uncomment to improve performance slightly, at the cost of portability
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the versioning scheme outlined in the [README.md](README.md).

## [Unreleased]
## [3.3.0.0.4]

### Added

- New `/v3/tenures/tip_metadata` endpoint for returning some metadata along with the normal tenure tip information.


## [3.3.0.0.3]

### Added

Expand Down
2 changes: 2 additions & 0 deletions clarity-types/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ pub enum RuntimeError {
PoxAlreadyLocked,
/// Block time unavailable during execution.
BlockTimeNotAvailable,
/// A Clarity string used as a token name for a post-condition is not a valid Clarity name.
BadTokenName(String),
}

#[derive(Debug, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions clarity-types/src/tests/types/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::collections::HashSet;
use std::collections::BTreeSet;

use crate::errors::analysis::CommonCheckErrorKind;
use crate::representations::CONTRACT_MAX_NAME_LENGTH;
Expand Down Expand Up @@ -370,7 +370,7 @@ fn test_least_supertype() {
}),
];
let list_union2 = ListUnionType(callables2.clone().into());
let list_union_merged = ListUnionType(HashSet::from_iter(
let list_union_merged = ListUnionType(BTreeSet::from_iter(
[callables, callables2].concat().iter().cloned(),
));
let callable_principals = [
Expand Down
8 changes: 4 additions & 4 deletions clarity-types/src/types/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::collections::btree_map::Entry;
use std::collections::{BTreeMap, HashSet};
use std::collections::{BTreeMap, BTreeSet};
use std::hash::Hash;
use std::sync::Arc;
use std::{cmp, fmt};
Expand Down Expand Up @@ -293,7 +293,7 @@ pub enum TypeSignature {
// data structure to maintain the set of types in the list, so that when
// we reach the place where the coercion needs to happen, we can perform
// the check -- see `concretize` method.
ListUnionType(HashSet<CallableSubtype>),
ListUnionType(BTreeSet<CallableSubtype>),
// This is used only below epoch 2.1. It has been replaced by CallableType.
TraitReferenceType(TraitIdentifier),
}
Expand Down Expand Up @@ -326,7 +326,7 @@ pub enum StringSubtype {
UTF8(StringUTF8Length),
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, PartialOrd, Ord)]
pub enum CallableSubtype {
Principal(QualifiedContractIdentifier),
Trait(TraitIdentifier),
Expand Down Expand Up @@ -1223,7 +1223,7 @@ impl TypeSignature {
if x == y {
Ok(a.clone())
} else {
Ok(ListUnionType(HashSet::from([x.clone(), y.clone()])))
Ok(ListUnionType(BTreeSet::from([x.clone(), y.clone()])))
}
}
(ListUnionType(l), CallableType(c)) | (CallableType(c), ListUnionType(l)) => {
Expand Down
16 changes: 14 additions & 2 deletions clarity/src/vm/functions/post_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

use std::collections::HashMap;

use clarity_types::errors::RuntimeError;
use clarity_types::types::{AssetIdentifier, PrincipalData, StandardPrincipalData};
use clarity_types::ClarityName;

use crate::vm::analysis::type_checker::v2_1::natives::post_conditions::MAX_ALLOWANCES;
use crate::vm::contexts::AssetMap;
Expand Down Expand Up @@ -135,7 +137,12 @@ fn eval_allowance(
};

let asset_name = eval(&rest[1], env, context)?;
let asset_name = asset_name.expect_string_ascii()?.as_str().into();
let asset_name = match ClarityName::try_from(asset_name.expect_string_ascii()?) {
Ok(name) => name,
Err(_) => {
return Err(RuntimeError::BadTokenName(rest[1].to_string()).into());
}
};

let asset = AssetIdentifier {
contract_identifier,
Expand Down Expand Up @@ -165,7 +172,12 @@ fn eval_allowance(
};

let asset_name = eval(&rest[1], env, context)?;
let asset_name = asset_name.expect_string_ascii()?.as_str().into();
let asset_name = match ClarityName::try_from(asset_name.expect_string_ascii()?) {
Ok(name) => name,
Err(_) => {
return Err(RuntimeError::BadTokenName(rest[1].to_string()).into());
}
};

let asset = AssetIdentifier {
contract_identifier,
Expand Down
124 changes: 124 additions & 0 deletions docs/rpc/components/schemas/tenure-tip-metadata.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
description: |
JSON encoding of `BlockHeaderWithMetadata` returned by /v3/tenures/tip_metadata.
Exactly one variant property will be present: either `Epoch2` or `Nakamoto`.
type: object
required:
- anchored_header
properties:
burn_view:
type: string
description: Hex-encoded bitcoin block hash
anchored_header:
oneOf:
- title: Epoch2HeaderVariant
type: object
required: [Epoch2]
additionalProperties: false
properties:
Epoch2:
type: object
description: Header structure for a Stacks 2.x anchored block.
required:
- version
- total_work
- proof
- parent_block
- parent_microblock
- parent_microblock_sequence
- tx_merkle_root
- state_index_root
- microblock_pubkey_hash
properties:
version:
type: integer
minimum: 0
total_work:
type: object
required: [burn, work]
properties:
burn:
type: integer
format: uint64
work:
type: integer
format: uint64
proof:
type: string
description: Hex-encoded VRF proof
parent_block:
type: string
description: 32-byte hex of the parent block header hash
parent_microblock:
type: string
description: 32-byte hex of the parent microblock header hash
parent_microblock_sequence:
type: integer
tx_merkle_root:
type: string
description: Hex-encoded merkle root of the transactions in the block
state_index_root:
type: string
description: Hex-encoded MARF trie root after this block
microblock_pubkey_hash:
type: string
description: Hash160 (20-byte hex) of the microblock public key
additionalProperties: false
- title: NakamotoHeaderVariant
type: object
required: [Nakamoto]
additionalProperties: false
properties:
Nakamoto:
type: object
description: Header structure for a Nakamoto-epoch Stacks block.
required:
- version
- chain_length
- burn_spent
- consensus_hash
- parent_block_id
- tx_merkle_root
- state_index_root
- timestamp
- miner_signature
- signer_signature
- pox_treatment
properties:
version:
type: integer
minimum: 0
chain_length:
type: integer
format: uint64
description: Number of ancestor blocks including Stacks 2.x blocks
burn_spent:
type: integer
format: uint64
description: Total BTC spent by the sortition that elected this block
consensus_hash:
type: string
description: 20-byte hex consensus hash that identifies the tenure
parent_block_id:
type: string
description: 32-byte hex identifier of the parent block (hash+consensus)
tx_merkle_root:
type: string
description: Hex-encoded merkle root of all transactions in the block
state_index_root:
type: string
description: Hex-encoded MARF trie root after this block
timestamp:
type: integer
description: Unix timestamp (seconds)
miner_signature:
type: string
description: Recoverable ECDSA signature from the miner
signer_signature:
type: array
description: Signer-set signatures over the block header
items:
type: string
pox_treatment:
type: string
description: Bit-vector, hex-encoded, indicating PoX reward treatment
additionalProperties: false
33 changes: 33 additions & 0 deletions docs/rpc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ components:
$ref: ./components/schemas/tenure-info.schema.yaml
TenureTip:
$ref: ./components/schemas/tenure-tip.schema.yaml
TenureTipMetadata:
$ref: ./components/schemas/tenure-tip-metadata.schema.yaml
GetStackerSet:
$ref: ./components/schemas/get-stacker-set.schema.yaml
TenureBlocks:
Expand Down Expand Up @@ -2062,6 +2064,37 @@ paths:
"500":
$ref: "#/components/responses/InternalServerError"

/v3/tenures/tip_metadata/{consensus_hash}:
get:
summary: Get tenure tip with metadata
tags:
- Blocks
security: []
operationId: getTenureTipMetadata
description: |
Get the tip block and associated metadata of a tenure identified by consensus hash.
parameters:
- name: consensus_hash
in: path
required: true
description: Consensus hash (40 characters)
schema:
type: string
pattern: "^[0-9a-f]{40}$"
responses:
"200":
description: Tenure tip block information
content:
application/json:
schema:
$ref: "#/components/schemas/TenureTipMetadata"
"400":
$ref: "#/components/responses/BadRequest"
"404":
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalServerError"

/v2/transactions/unconfirmed/{txid}:
get:
summary: Get unconfirmed transaction
Expand Down
12 changes: 8 additions & 4 deletions stacks-node/src/tests/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
let latest_block = self
.stacks_client
.get_tenure_tip(&sortition_prior.consensus_hash)
.unwrap();
.unwrap()
.anchored_header;
let latest_block_id =
StacksBlockId::new(&sortition_prior.consensus_hash, &latest_block.block_hash());

Expand Down Expand Up @@ -642,7 +643,8 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
let latest_block = self
.stacks_client
.get_tenure_tip(sortition_prior.stacks_parent_ch.as_ref().unwrap())
.unwrap();
.unwrap()
.anchored_header;
let latest_block_id = StacksBlockId::new(
sortition_prior.stacks_parent_ch.as_ref().unwrap(),
&latest_block.block_hash(),
Expand Down Expand Up @@ -904,7 +906,8 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
let latest_block = self
.stacks_client
.get_tenure_tip(&sortition_prior.consensus_hash)
.unwrap();
.unwrap()
.anchored_header;
let latest_block_id =
StacksBlockId::new(&sortition_prior.consensus_hash, &latest_block.block_hash());

Expand Down Expand Up @@ -984,7 +987,8 @@ impl<Z: SpawnedSignerTrait> SignerTest<Z> {
let latest_block = self
.stacks_client
.get_tenure_tip(&sortition_parent.consensus_hash)
.unwrap();
.unwrap()
.anchored_header;
let latest_block_id =
StacksBlockId::new(&sortition_parent.consensus_hash, &latest_block.block_hash());

Expand Down
Loading