Skip to content

Commit 04a0e52

Browse files
authored
Merge pull request #1967 from CosmWasm/1760-remove-backtrace-feature
Remove backtraces feature
2 parents 8b3037c + ea7d630 commit 04a0e52

35 files changed

+308
-400
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ and this project adheres to
5858
`AnalysisReport::required_capabilities` a `BTreeSet`. ([#1949])
5959
- cosmwasm-std: Add `Checksum` type and change type of
6060
`CodeInfoResponse::checksum` to that. ([#1944])
61+
- cosmwasm-std: Removed `backtraces` feature, use the `RUST_BACKTRACE=1` env
62+
variable instead. Error variants that previously only contained a `backtrace`
63+
field with the feature enabled now always contain it. ([#1967])
64+
- cosmwasm-vm: Removed `backtraces` feature, use the `RUST_BACKTRACE=1` env
65+
variable instead. All `VmError` variants now have a `backtrace` field.
66+
([#1967])
6167

6268
[#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
6369
[#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876
@@ -73,6 +79,7 @@ and this project adheres to
7379
[#1941]: https://github.com/CosmWasm/cosmwasm/pull/1941
7480
[#1944]: https://github.com/CosmWasm/cosmwasm/pull/1944
7581
[#1949]: https://github.com/CosmWasm/cosmwasm/pull/1949
82+
[#1967]: https://github.com/CosmWasm/cosmwasm/pull/1967
7683

7784
### Removed
7885

MIGRATING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ major releases of `cosmwasm`. Note that you can also view the
2121

2222
If you were using cosmwasm-std's `ibc3` feature, you can remove it, as it is
2323
the default now. Depending on your usage, you might have to enable the
24-
`stargate` feature instead, since it was previously implied by `ibc3`.
24+
`stargate` feature instead, since it was previously implied by `ibc3`. Also
25+
remove any uses of the `backtraces` feature. You can use a `RUST_BACKTRACE=1`
26+
env variable for this now.
2527

2628
- `ContractInfoResponse::new` now takes all fields of the response as
2729
parameters:
@@ -125,6 +127,14 @@ major releases of `cosmwasm`. Note that you can also view the
125127
+CosmosMsg::Any(AnyMsg { type_url, value })
126128
```
127129

130+
- Replace all direct construction of `StdError` with use of the corresponding
131+
constructor:
132+
133+
```diff
134+
-StdError::GenericErr { msg }
135+
+StdError::generic_err(msg)
136+
```
137+
128138
## 1.4.x -> 1.5.0
129139

130140
- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):

contracts/burner/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
30+
3331

3432
[dependencies]
3533
cosmwasm-schema = { path = "../../packages/schema" }

contracts/crypto-verify/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3330

3431
[dependencies]
3532
cosmwasm-schema = { path = "../../packages/schema" }

contracts/crypto-verify/src/contract.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,13 @@ mod tests {
317317

318318
let res = query(deps.as_ref(), mock_env(), verify_msg);
319319
assert!(res.is_err());
320-
assert_eq!(
320+
assert!(matches!(
321321
res.unwrap_err(),
322322
StdError::VerificationErr {
323-
source: VerificationError::InvalidPubkeyFormat
323+
source: VerificationError::InvalidPubkeyFormat,
324+
..
324325
}
325-
)
326+
))
326327
}
327328

328329
#[test]
@@ -605,12 +606,13 @@ mod tests {
605606
};
606607
let res = query(deps.as_ref(), mock_env(), verify_msg);
607608
assert!(res.is_err());
608-
assert_eq!(
609+
assert!(matches!(
609610
res.unwrap_err(),
610611
StdError::VerificationErr {
611612
source: VerificationError::InvalidPubkeyFormat,
613+
..
612614
}
613-
)
615+
))
614616
}
615617

616618
#[test]
@@ -670,12 +672,13 @@ mod tests {
670672
};
671673
let res = query(deps.as_ref(), mock_env(), verify_msg);
672674
assert!(res.is_err());
673-
assert_eq!(
675+
assert!(matches!(
674676
res.unwrap_err(),
675677
StdError::VerificationErr {
676-
source: VerificationError::InvalidPubkeyFormat
678+
source: VerificationError::InvalidPubkeyFormat,
679+
..
677680
}
678-
)
681+
))
679682
}
680683

681684
#[test]

contracts/cyberpunk/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ overflow-checks = true
2525
default = []
2626
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2727
cranelift = ["cosmwasm-vm/cranelift"]
28-
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
29-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3028

3129
[dependencies]
3230
cosmwasm-schema = { path = "../../packages/schema" }

contracts/empty/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3330

3431
[dependencies]
3532
cosmwasm-schema = { path = "../../packages/schema" }

contracts/floaty/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
31-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3230

3331
[dependencies]
3432
cosmwasm-schema = { path = "../../packages/schema" }

contracts/hackatom/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
31-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3230

3331
[dependencies]
3432
cosmwasm-schema = { path = "../../packages/schema" }

contracts/ibc-reflect-send/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3330

3431
[dependencies]
3532
cosmwasm-schema = { path = "../../packages/schema" }

contracts/ibc-reflect/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3330

3431
[dependencies]
3532
cosmwasm-schema = { path = "../../packages/schema" }

contracts/queue/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
31-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3230
# this is to demonstrate conditional entry-points for cosmwasm-plus style
3331
library = []
3432

@@ -40,4 +38,4 @@ schemars = "0.8.3"
4038
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
4139

4240
[dev-dependencies]
43-
cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] }
41+
cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] }

contracts/reflect/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ overflow-checks = true
2828
default = []
2929
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
3030
cranelift = ["cosmwasm-vm/cranelift"]
31-
# for quicker tests, cargo test --lib
32-
# for more explicit tests, cargo test --features=backtraces
33-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3431

3532
[dependencies]
3633
cosmwasm-schema = { path = "../../packages/schema" }

contracts/staking/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3330

3431
[dependencies]
3532
cosmwasm-schema = { path = "../../packages/schema" }

contracts/virus/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ overflow-checks = true
2727
default = []
2828
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
2929
cranelift = ["cosmwasm-vm/cranelift"]
30-
# for quicker tests, cargo test --lib
31-
# for more explicit tests, cargo test --features=backtraces
32-
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
3330

3431
[dependencies]
3532
cosmwasm-schema = { path = "../../packages/schema" }

docs/USING_COSMWASM_STD.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ in the dependency tree. Otherwise conflicting C exports are created.
3232

3333
## cosmwasm-std features
3434

35-
The libarary comes with the following features:
35+
The library comes with the following features:
3636

3737
| Feature | Enabled by default | Description |
3838
| ------------ | ------------------ | ------------------------------------------------------------------------- |
3939
| iterator | x | Storage iterators |
4040
| abort | x | A panic handler that aborts the contract execution with a helpful message |
4141
| stargate | | Cosmos SDK 0.40+ features and IBC |
4242
| staking | | Access to the staking module |
43-
| backtraces | | Add backtraces to errors (for unit testing) |
4443
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
4544
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
4645
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |

packages/crypto/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ license = "Apache-2.0"
99

1010
[features]
1111
default = []
12-
# backtraces provides much better context at runtime errors (in non-wasm code)
13-
# at the cost of a bit of code size and performance.
14-
# This feature requires Rust nightly because it depends on the unstable backtrace feature.
15-
backtraces = []
1612

1713
[lib]
1814
# See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options

packages/crypto/src/backtrace.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use core::fmt::{Debug, Display, Formatter, Result};
2+
use std::backtrace::Backtrace;
3+
4+
/// This wraps an actual backtrace to achieve two things:
5+
/// - being able to fill this with a stub implementation in `no_std` environments
6+
/// - being able to use this in conjunction with [`thiserror::Error`]
7+
pub struct BT(Backtrace);
8+
9+
impl BT {
10+
#[track_caller]
11+
pub fn capture() -> Self {
12+
BT(Backtrace::capture())
13+
}
14+
}
15+
16+
impl Debug for BT {
17+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
18+
Debug::fmt(&self.0, f)
19+
}
20+
}
21+
22+
impl Display for BT {
23+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
24+
Display::fmt(&self.0, f)
25+
}
26+
}

packages/crypto/src/errors.rs

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#[cfg(feature = "backtraces")]
2-
use std::backtrace::Backtrace;
1+
use crate::BT;
32
use std::fmt::Debug;
43
use thiserror::Error;
54

@@ -8,81 +7,55 @@ pub type CryptoResult<T> = core::result::Result<T, CryptoError>;
87
#[derive(Error, Debug)]
98
pub enum CryptoError {
109
#[error("Batch verify error: {msg}")]
11-
BatchErr {
12-
msg: String,
13-
#[cfg(feature = "backtraces")]
14-
backtrace: Backtrace,
15-
},
10+
BatchErr { msg: String, backtrace: BT },
1611
#[error("Crypto error: {msg}")]
17-
GenericErr {
18-
msg: String,
19-
#[cfg(feature = "backtraces")]
20-
backtrace: Backtrace,
21-
},
12+
GenericErr { msg: String, backtrace: BT },
2213
#[error("Invalid hash format")]
23-
InvalidHashFormat {
24-
#[cfg(feature = "backtraces")]
25-
backtrace: Backtrace,
26-
},
14+
InvalidHashFormat { backtrace: BT },
2715
#[error("Invalid public key format")]
28-
InvalidPubkeyFormat {
29-
#[cfg(feature = "backtraces")]
30-
backtrace: Backtrace,
31-
},
16+
InvalidPubkeyFormat { backtrace: BT },
3217
#[error("Invalid signature format")]
33-
InvalidSignatureFormat {
34-
#[cfg(feature = "backtraces")]
35-
backtrace: Backtrace,
36-
},
18+
InvalidSignatureFormat { backtrace: BT },
3719
#[error("Invalid recovery parameter. Supported values: 0 and 1.")]
38-
InvalidRecoveryParam {
39-
#[cfg(feature = "backtraces")]
40-
backtrace: Backtrace,
41-
},
20+
InvalidRecoveryParam { backtrace: BT },
4221
}
4322

4423
impl CryptoError {
4524
pub fn batch_err(msg: impl Into<String>) -> Self {
4625
CryptoError::BatchErr {
4726
msg: msg.into(),
48-
#[cfg(feature = "backtraces")]
49-
backtrace: Backtrace::capture(),
27+
backtrace: BT::capture(),
5028
}
5129
}
5230

5331
pub fn generic_err(msg: impl Into<String>) -> Self {
5432
CryptoError::GenericErr {
5533
msg: msg.into(),
56-
#[cfg(feature = "backtraces")]
57-
backtrace: Backtrace::capture(),
34+
backtrace: BT::capture(),
5835
}
5936
}
6037

6138
pub fn invalid_hash_format() -> Self {
6239
CryptoError::InvalidHashFormat {
63-
#[cfg(feature = "backtraces")]
64-
backtrace: Backtrace::capture(),
40+
backtrace: BT::capture(),
6541
}
6642
}
6743

6844
pub fn invalid_pubkey_format() -> Self {
6945
CryptoError::InvalidPubkeyFormat {
70-
#[cfg(feature = "backtraces")]
71-
backtrace: Backtrace::capture(),
46+
backtrace: BT::capture(),
7247
}
7348
}
7449

7550
pub fn invalid_signature_format() -> Self {
7651
CryptoError::InvalidSignatureFormat {
77-
#[cfg(feature = "backtraces")]
78-
backtrace: Backtrace::capture(),
52+
backtrace: BT::capture(),
7953
}
8054
}
8155

8256
pub fn invalid_recovery_param() -> Self {
8357
CryptoError::InvalidRecoveryParam {
84-
#[cfg(feature = "backtraces")]
85-
backtrace: Backtrace::capture(),
58+
backtrace: BT::capture(),
8659
}
8760
}
8861

packages/crypto/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
//! Please don't use any of these types directly, as
33
//! they might change frequently, or be removed in the future.
44
//! This crate does not adhere to semantic versioning.
5-
#![cfg_attr(feature = "backtraces", feature(error_generic_member_access))]
6-
#![cfg_attr(feature = "backtraces", feature(provide_any))]
7-
5+
mod backtrace;
86
mod ed25519;
97
mod errors;
108
mod identity_digest;
@@ -20,3 +18,4 @@ pub use crate::errors::{CryptoError, CryptoResult};
2018
pub use crate::secp256k1::{secp256k1_recover_pubkey, secp256k1_verify};
2119
#[doc(hidden)]
2220
pub use crate::secp256k1::{ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, MESSAGE_HASH_MAX_LEN};
21+
pub(crate) use backtrace::BT;

0 commit comments

Comments
 (0)