Skip to content

Commit 7f77a5b

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into fix/clippy-ci-stacks-lib-needless-borrow
2 parents af9f7ea + 1f1bf2c commit 7f77a5b

File tree

109 files changed

+2480
-1755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2480
-1755
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[alias]
22
stacks-node = "run --package stacks-node --"
33
fmt-stacks = "fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module"
4+
clippy-stacks = "clippy -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings"
45

56
# Uncomment to improve performance slightly, at the cost of portability
67
# * Note that native binaries may not run on CPUs that are different from the build machine

.github/workflows/bitcoin-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ jobs:
167167
- tests::nakamoto_integrations::sip029_coinbase_change
168168
- tests::nakamoto_integrations::clarity_cost_spend_down
169169
- tests::nakamoto_integrations::v3_blockbyheight_api_endpoint
170+
- tests::nakamoto_integrations::mine_invalid_principal_from_consensus_buff
170171
- tests::nakamoto_integrations::test_tenure_extend_from_flashblocks
171172
# TODO: enable these once v1 signer is supported by a new nakamoto epoch
172173
# - tests::signer::v1::dkg

.github/workflows/clippy.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,4 @@ jobs:
3434
components: clippy
3535
- name: Clippy
3636
id: clippy
37-
uses: actions-rs/clippy-check@v1
38-
with:
39-
token: ${{ secrets.GITHUB_TOKEN }}
40-
args: -p libstackerdb -p stacks-signer -p pox-locking -p clarity -p libsigner -p stacks-common --no-deps --tests --all-features -- -D warnings
37+
run: cargo clippy-stacks

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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]
8+
## [3.1.0.0.4]
99

1010
### Added
1111

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,18 @@ You can automatically reformat your commit via:
387387
cargo fmt-stacks
388388
```
389389

390+
## Clippy Warnings
391+
392+
PRs will be checked against `clippy` and will _fail_ if any clippy warnings are generated.
393+
Unfortunately, not all existing clippy warnings have been addressed throughout stacks-core, so arguments must be passed via the command line.
394+
Therefore, we handle `clippy` configurations using a Cargo alias: `cargo clippy-stacks`
395+
396+
You can check what warnings need to be addressed locally via:
397+
398+
```bash
399+
cargo clippy-stacks
400+
```
401+
390402
## Comments
391403

392404
Comments are very important for the readability and correctness of the codebase. The purpose of comments is:

clarity/src/libclarity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub mod boot_util {
6060
pub fn boot_code_id(name: &str, mainnet: bool) -> QualifiedContractIdentifier {
6161
let addr = boot_code_addr(mainnet);
6262
QualifiedContractIdentifier::new(
63-
addr.into(),
63+
addr.try_into()
64+
.expect("FATAL: boot contract addr is not a legal principal"),
6465
ContractName::try_from(name.to_string())
6566
.expect("FATAL: boot contract name is not a legal ContractName"),
6667
)

clarity/src/vm/contexts.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,20 +2134,14 @@ mod test {
21342134
mut tl_env_factory: TopLevelMemoryEnvironmentGenerator,
21352135
) {
21362136
let mut env = tl_env_factory.get_env(epoch);
2137-
let u1 = StacksAddress {
2138-
version: 0,
2139-
bytes: Hash160([1; 20]),
2140-
};
2141-
let u2 = StacksAddress {
2142-
version: 0,
2143-
bytes: Hash160([2; 20]),
2144-
};
2137+
let u1 = StacksAddress::new(0, Hash160([1; 20])).unwrap();
2138+
let u2 = StacksAddress::new(0, Hash160([2; 20])).unwrap();
21452139
// insufficient balance must be a non-includable transaction. it must error here,
21462140
// not simply rollback the tx and squelch the error as includable.
21472141
let e = env
21482142
.stx_transfer(
2149-
&PrincipalData::from(u1),
2150-
&PrincipalData::from(u2),
2143+
&PrincipalData::try_from(u1).unwrap(),
2144+
&PrincipalData::try_from(u2).unwrap(),
21512145
1000,
21522146
&BuffData::empty(),
21532147
)

clarity/src/vm/functions/conversions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::vm::errors::{
2020
check_argument_count, CheckErrors, InterpreterError, InterpreterResult as Result,
2121
};
2222
use crate::vm::representations::SymbolicExpression;
23+
use crate::vm::types::serialization::SerializationError;
2324
use crate::vm::types::SequenceSubtype::BufferType;
2425
use crate::vm::types::TypeSignature::SequenceType;
2526
use crate::vm::types::{
@@ -276,6 +277,9 @@ pub fn from_consensus_buff(
276277
env.epoch().value_sanitizing(),
277278
) {
278279
Ok(value) => value,
280+
Err(SerializationError::UnexpectedSerialization) => {
281+
return Err(CheckErrors::Expects("UnexpectedSerialization".into()).into())
282+
}
279283
Err(_) => return Ok(Value::none()),
280284
};
281285
if !type_arg.admits(env.epoch(), &result)? {

clarity/src/vm/functions/crypto.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ use crate::vm::errors::{
2727
check_argument_count, CheckErrors, InterpreterError, InterpreterResult as Result,
2828
};
2929
use crate::vm::representations::SymbolicExpression;
30-
use crate::vm::types::{
31-
BuffData, SequenceData, StacksAddressExtensions, TypeSignature, Value, BUFF_32, BUFF_33,
32-
BUFF_65,
33-
};
30+
use crate::vm::types::{BuffData, SequenceData, TypeSignature, Value, BUFF_32, BUFF_33, BUFF_65};
3431
use crate::vm::{eval, ClarityVersion, Environment, LocalContext};
3532

3633
macro_rules! native_hash_func {
@@ -120,7 +117,7 @@ pub fn special_principal_of(
120117
} else {
121118
pubkey_to_address_v1(pub_key)?
122119
};
123-
let principal = addr.to_account_principal();
120+
let principal = addr.into();
124121
Ok(Value::okay(Value::Principal(principal))
125122
.map_err(|_| InterpreterError::Expect("Failed to construct ok".into()))?)
126123
} else {

clarity/src/vm/functions/principals.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,10 @@ pub fn special_is_standard(
5858
runtime_cost(ClarityCostFunction::IsStandard, env, 0)?;
5959
let owner = eval(&args[0], env, context)?;
6060

61-
let version = match owner {
62-
Value::Principal(PrincipalData::Standard(StandardPrincipalData(version, _bytes))) => {
63-
version
64-
}
65-
Value::Principal(PrincipalData::Contract(QualifiedContractIdentifier {
66-
issuer,
67-
name: _,
68-
})) => issuer.0,
69-
_ => return Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, owner).into()),
61+
let version = if let Value::Principal(ref p) = owner {
62+
p.version()
63+
} else {
64+
return Err(CheckErrors::TypeValueError(TypeSignature::PrincipalType, owner).into());
7065
};
7166

7267
Ok(Value::Bool(version_matches_current_network(
@@ -161,10 +156,12 @@ pub fn special_principal_destruct(
161156
let principal = eval(&args[0], env, context)?;
162157

163158
let (version_byte, hash_bytes, name_opt) = match principal {
164-
Value::Principal(PrincipalData::Standard(StandardPrincipalData(version, bytes))) => {
159+
Value::Principal(PrincipalData::Standard(p)) => {
160+
let (version, bytes) = p.destruct();
165161
(version, bytes, None)
166162
}
167163
Value::Principal(PrincipalData::Contract(QualifiedContractIdentifier { issuer, name })) => {
164+
let issuer = issuer.destruct();
168165
(issuer.0, issuer.1, Some(name))
169166
}
170167
_ => {
@@ -254,7 +251,7 @@ pub fn special_principal_construct(
254251
// Construct the principal.
255252
let mut transfer_buffer = [0u8; 20];
256253
transfer_buffer.copy_from_slice(verified_hash_bytes);
257-
let principal_data = StandardPrincipalData(version_byte, transfer_buffer);
254+
let principal_data = StandardPrincipalData::new(version_byte, transfer_buffer)?;
258255

259256
let principal = if let Some(name) = name_opt {
260257
// requested a contract principal. Verify that the `name` is a valid ContractName.

0 commit comments

Comments
 (0)