Skip to content

Commit 7c4e518

Browse files
committed
Disable abort feature
1 parent 9ade6e1 commit 7c4e518

File tree

8 files changed

+34
-39
lines changed

8 files changed

+34
-39
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ extern "C" fn ibc_packet_timeout(env_ptr: u32, msg_ptr: u32) -> u32;
191191
```
192192

193193
`allocate` and `deallocate` allow the host to manage data within the Wasm VM. If
194-
you're using Rust, you can implement them by simply
195-
[re-exporting them from cosmwasm::exports](https://github.com/CosmWasm/cosmwasm/blob/v0.6.3/contracts/hackatom/src/lib.rs#L5).
196-
`instantiate`, `execute` and `query` must be defined by your contract.
194+
you're using Rust, you get them automatically by using the `cosmwasm-std` crate.
195+
Your contract can define the other entrypoints using the
196+
`cosmwasm_std::entry_point` macro to get strong typing instead of raw memory
197+
offsets.
197198

198199
### Imports
199200

devtools/check_workspace.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cargo fmt
1010
# default, min, all
1111
cargo check
1212
cargo check --no-default-features --features std
13-
cargo check --features std,abort,iterator,staking,stargate,cosmwasm_1_2
13+
cargo check --features std,iterator,staking,stargate,cosmwasm_1_2
1414
cargo wasm-debug
1515
cargo wasm-debug --features std,iterator,staking,stargate
1616
cargo clippy --all-targets --features std,iterator,staking,stargate -- -D warnings

docs/USING_COSMWASM_STD.md

+13-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ extern "C" fn deallocate(pointer: u32) { /* ... */ }
1616

1717
// Imports
1818
extern "C" {
19-
#[cfg(feature = "abort")]
2019
fn abort(source_ptr: u32);
2120

2221
fn db_read(key: u32) -> u32;
@@ -34,16 +33,16 @@ in the dependency tree. Otherwise conflicting C exports are created.
3433

3534
The library comes with the following features:
3635

37-
| Feature | Enabled by default | Description |
38-
| ------------ | ------------------ | ------------------------------------------------------------------------- |
39-
| iterator | x | Storage iterators |
40-
| abort | x | A panic handler that aborts the contract execution with a helpful message |
41-
| stargate | | Cosmos SDK 0.40+ features and IBC |
42-
| staking | | Access to the staking module |
43-
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
44-
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
45-
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
46-
| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain |
36+
| Feature | Enabled by default | Description |
37+
| ------------ | ------------------ | ------------------------------------------------------------------------------------ |
38+
| iterator | x | Storage iterators |
39+
| abort | x | DEPRECATED A panic handler that aborts the contract execution with a helpful message |
40+
| stargate | | Cosmos SDK 0.40+ features and IBC |
41+
| staking | | Access to the staking module |
42+
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
43+
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
44+
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
45+
| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain |
4746

4847
## The cosmwasm-std dependency for contract developers
4948

@@ -71,9 +70,9 @@ cosmwasm-std = { version = "1.2.0", features = ["stargate", "cosmwasm_1_2"] }
7170
When you are creating a library that uses cosmwasm-std, you should be incredibly
7271
careful with which features you require. The moment you add e.g. `cosmwasm_1_2`
7372
there it becomes impossible to use the contract in chains with lower CosmWasm
74-
versions. If you add `abort`, it becomes impossible for the contract developer
75-
to opt out of the abort feature due to your library. Since this affects the
76-
default features `abort` and `iterator`, you should always disable default
73+
versions. If you add `iterator`, it becomes impossible for the contract
74+
developer to opt out of the iterator feature due to your library. Since this
75+
affects the default feature `iterator`, you should always disable default
7776
features. However, you should make sure to keep the `std` feature enabled, as we
7877
might move certain existing functionality to that feature in the future.
7978

packages/std/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ readme = "README.md"
1212
features = ["abort", "cosmwasm_2_2", "staking", "stargate"]
1313

1414
[features]
15-
default = ["abort", "iterator", "std"]
15+
default = ["iterator", "std"]
16+
# abort used to enable the panic handler that hands a nice error message back to the host.
17+
# The feature is now deprecated and the panic handler is always enabled.
1618
abort = []
1719
std = []
1820
# iterator allows us to iterate over all DB items in a given range

packages/std/src/exports.rs

-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::ibc::{
2222
use crate::ibc::{IbcChannelOpenMsg, IbcChannelOpenResponse};
2323
use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
2424
use crate::memory::{Owned, Region};
25-
#[cfg(feature = "abort")]
2625
use crate::panic::install_panic_handler;
2726
use crate::query::CustomQuery;
2827
use crate::results::{ContractResult, QueryResponse, Reply, Response};
@@ -128,7 +127,6 @@ where
128127
C: CustomMsg,
129128
E: ToString,
130129
{
131-
#[cfg(feature = "abort")]
132130
install_panic_handler();
133131
let res = _do_instantiate(
134132
instantiate_fn,
@@ -158,7 +156,6 @@ where
158156
C: CustomMsg,
159157
E: ToString,
160158
{
161-
#[cfg(feature = "abort")]
162159
install_panic_handler();
163160
let res = _do_execute(
164161
execute_fn,
@@ -187,7 +184,6 @@ where
187184
C: CustomMsg,
188185
E: ToString,
189186
{
190-
#[cfg(feature = "abort")]
191187
install_panic_handler();
192188
let res = _do_migrate(
193189
migrate_fn,
@@ -218,7 +214,6 @@ where
218214
C: CustomMsg,
219215
E: ToString,
220216
{
221-
#[cfg(feature = "abort")]
222217
install_panic_handler();
223218
let res = _do_migrate_with_info(
224219
migrate_with_info_fn,
@@ -247,7 +242,6 @@ where
247242
C: CustomMsg,
248243
E: ToString,
249244
{
250-
#[cfg(feature = "abort")]
251245
install_panic_handler();
252246
let res = _do_sudo(
253247
sudo_fn,
@@ -274,7 +268,6 @@ where
274268
C: CustomMsg,
275269
E: ToString,
276270
{
277-
#[cfg(feature = "abort")]
278271
install_panic_handler();
279272
let res = _do_reply(
280273
reply_fn,
@@ -300,7 +293,6 @@ where
300293
M: DeserializeOwned,
301294
E: ToString,
302295
{
303-
#[cfg(feature = "abort")]
304296
install_panic_handler();
305297
let res = _do_query(
306298
query_fn,
@@ -327,7 +319,6 @@ where
327319
Q: CustomQuery,
328320
E: ToString,
329321
{
330-
#[cfg(feature = "abort")]
331322
install_panic_handler();
332323
let res = _do_ibc_channel_open(
333324
contract_fn,
@@ -356,7 +347,6 @@ where
356347
C: CustomMsg,
357348
E: ToString,
358349
{
359-
#[cfg(feature = "abort")]
360350
install_panic_handler();
361351
let res = _do_ibc_channel_connect(
362352
contract_fn,
@@ -385,7 +375,6 @@ where
385375
C: CustomMsg,
386376
E: ToString,
387377
{
388-
#[cfg(feature = "abort")]
389378
install_panic_handler();
390379
let res = _do_ibc_channel_close(
391380
contract_fn,
@@ -415,7 +404,6 @@ where
415404
C: CustomMsg,
416405
E: ToString,
417406
{
418-
#[cfg(feature = "abort")]
419407
install_panic_handler();
420408
let res = _do_ibc_packet_receive(
421409
contract_fn,
@@ -445,7 +433,6 @@ where
445433
C: CustomMsg,
446434
E: ToString,
447435
{
448-
#[cfg(feature = "abort")]
449436
install_panic_handler();
450437
let res = _do_ibc_packet_ack(
451438
contract_fn,
@@ -476,7 +463,6 @@ where
476463
C: CustomMsg,
477464
E: ToString,
478465
{
479-
#[cfg(feature = "abort")]
480466
install_panic_handler();
481467
let res = _do_ibc_packet_timeout(
482468
contract_fn,
@@ -497,7 +483,6 @@ where
497483
C: CustomMsg,
498484
E: ToString,
499485
{
500-
#[cfg(feature = "abort")]
501486
install_panic_handler();
502487
let res = _do_ibc_source_callback(
503488
contract_fn,
@@ -522,7 +507,6 @@ where
522507
C: CustomMsg,
523508
E: ToString,
524509
{
525-
#[cfg(feature = "abort")]
526510
install_panic_handler();
527511
let res = _do_ibc_destination_callback(
528512
contract_fn,

packages/std/src/imports.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const HUMAN_ADDRESS_BUFFER_LENGTH: usize = 90;
2727
// A complete documentation those functions is available in the VM that provides them:
2828
// https://github.com/CosmWasm/cosmwasm/blob/v1.0.0-beta/packages/vm/src/instance.rs#L89-L206
2929
extern "C" {
30-
#[cfg(feature = "abort")]
30+
3131
fn abort(source_ptr: u32);
3232

3333
fn db_read(key: u32) -> u32;
@@ -744,7 +744,6 @@ impl Querier for ExternalQuerier {
744744
}
745745
}
746746

747-
#[cfg(feature = "abort")]
748747
pub fn handle_panic(message: &str) {
749748
let region = Region::from_slice(message.as_bytes());
750749
let region_ptr = region.as_ptr() as u32;

packages/std/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,18 @@ pub use crate::timestamp::Timestamp;
118118
pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage};
119119
pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo};
120120

121-
// Exposed in wasm build only
121+
#[cfg(feature = "abort")]
122+
mod _warning {
123+
#[must_use = "cosmwasm-std feature `abort` is deprecated and will be removed in the next release. You can just remove the feature as this functionality is now the default"]
124+
struct CompileWarning;
125+
126+
#[allow(dead_code)]
127+
fn trigger_warning() {
128+
CompileWarning;
129+
}
130+
}
122131

132+
// Exposed in wasm build only
123133
#[cfg(target_arch = "wasm32")]
124134
mod exports;
125135
#[cfg(target_arch = "wasm32")]

packages/std/src/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
///
44
/// This overrides any previous panic handler. See <https://doc.rust-lang.org/std/panic/fn.set_hook.html>
55
/// for details.
6-
#[cfg(all(feature = "abort", target_arch = "wasm32"))]
6+
#[cfg(target_arch = "wasm32")]
77
pub fn install_panic_handler() {
88
use super::imports::handle_panic;
99
std::panic::set_hook(Box::new(|info| {

0 commit comments

Comments
 (0)