Skip to content

Commit b195f58

Browse files
cmichipeterwhtevilrobot-01
authored
Add feature flag to compile contracts for pallet-revive (#2319)
* hack together RiscV support for ink! -- works! * fix: various fixes for xcm and pallet-revive-uapi integration (#1) * fix(revive): apply xcm fix from pallet_contracts * build(deps): align pallet-revive-uapi dependency * fix: update pallet-revive-uapi integration * chore: remove workspace.xml * fix: improve output type length handling * fix: various fixes and improvements * fix(caller): use to_account_id host fn * chore: update cargo.lock * Introduce feature flag `revive` * Cleanup prior commits * Update changelog * Debugging faulty `std` import * Make sure `panic_impl` of `sp-io` is not enabled * Clean up changes * Update `Cargo.lock` * Make `[build.rustflags]` an array * Replace `panic`'s with `todo`'s * Revert changes to `Cargo.toml`'s * Convert spaces to tabs * Add `caller_is_root` * Introduce `#[ink::polkadot_derive]` re-export * Forward `std` * Configure `sp-io` * Configure `sp-io` * Forward `std` * Remove unused attribute * Use correct `ErrorCode` enum * Update test fixtures * Fix clippy errors --------- Co-authored-by: Peter White <[email protected]> Co-authored-by: Frank Bell <[email protected]>
1 parent 8ac9899 commit b195f58

File tree

37 files changed

+1497
-56
lines changed

37 files changed

+1497
-56
lines changed

.cargo/config.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[env]
22
# We need to enable `RUSTC_BOOTSTRAP` so that the nightly ink!
33
# features still work on stable.
4-
RUSTC_BOOTSTRAP = "1"
4+
RUSTC_BOOTSTRAP = "1"
5+
6+
[build]
7+
rustflags = ["--cfg", "substrate_runtime"]

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Restrict which `cfg` attributes can be used ‒ [#2313](https://github.com/use-ink/ink/pull/2313)
1111

1212
## Added
13+
- Add feature flag to compile contracts for `pallet-revive`[#2318](https://github.com/use-ink/ink/pull/2318)
1314
- Support for `caller_is_root` - [#2332] (https://github.com/use-ink/ink/pull/2332)
1415

1516
## Fixed

Cargo.lock

Lines changed: 107 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ pallet-contracts = { version = "38.0.0", default-features = false }
9191
pallet-balances = { version = "39.0.0", default-features = false }
9292
pallet-timestamp = { version = "37.0.0", default-features = false }
9393
pallet-contracts-uapi = { version = "12.0.0", default-features = false }
94+
pallet-revive-uapi = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2412-rc2", default-features = false }
95+
# TODO include mock-network for revive
9496
pallet-contracts-mock-network = { version = "14.0.0", default-features = false }
9597
sp-externalities = { version = "0.29.0", default-features = false }
9698
sp-io = { version = "38.0.0", default-features = false }
@@ -101,6 +103,9 @@ sp-runtime = { version = "39.0.2", default-features = false }
101103
sp-weights = { version = "31.0.0", default-features = false }
102104
xcm = { package = "staging-xcm", version = "14.2.0", default-features = false }
103105

106+
# PolkaVM dependencies
107+
polkavm-derive = { version = "0.17.1", default-features = false }
108+
104109
# Local dependencies
105110
ink = { version = "=5.1.0", path = "crates/ink", default-features = false }
106111
ink_allocator = { version = "=5.1.0", path = "crates/allocator", default-features = false }

crates/allocator/src/bump.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const PAGE_SIZE: usize = 64 * 1024;
2828

2929
static mut INNER: Option<InnerAlloc> = None;
3030

31+
#[cfg(target_arch = "riscv32")]
32+
static mut RISCV_HEAP: [u8; 1024 * 1024] = [0; 1024 * 1024];
33+
3134
/// A bump allocator suitable for use in a Wasm environment.
3235
pub struct BumpAllocator;
3336

@@ -146,15 +149,14 @@ impl InnerAlloc {
146149
Some(prev_page * PAGE_SIZE)
147150
}
148151
} else if #[cfg(target_arch = "riscv32")] {
149-
const fn heap_start() -> usize {
150-
// Placeholder value until we specified our riscv VM
151-
0x7000_0000
152+
fn heap_start() -> usize {
153+
unsafe {
154+
RISCV_HEAP.as_mut_ptr() as usize
155+
}
152156
}
153157

154-
const fn heap_end() -> usize {
155-
// Placeholder value until we specified our riscv VM
156-
// Let's just assume a cool megabyte of mem for now
157-
0x7000_0400
158+
fn heap_end() -> usize {
159+
Self::heap_start() + unsafe { RISCV_HEAP.len() }
158160
}
159161

160162
fn request_pages(&mut self, _pages: usize) -> Option<usize> {

crates/e2e/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ sandbox = [
7878
"pallet-contracts-mock-network",
7979
"ink_e2e_macro/sandbox",
8080
]
81+
revive = [
82+
"ink/revive",
83+
"ink_env/revive"
84+
]

crates/engine/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
1818
ink_primitives = { workspace = true }
1919
scale = { workspace = true }
2020
pallet-contracts-uapi = { workspace = true }
21+
pallet-revive-uapi = { workspace = true }
2122
derive_more = { workspace = true, features = ["from", "display"] }
2223

2324
sha2 = { workspace = true }
@@ -32,6 +33,7 @@ default = [ "std" ]
3233
std = [
3334
"ink_primitives/std",
3435
"scale/std",
35-
"secp256k1",
36+
"secp256k1",
3637
"derive_more/std"
3738
]
39+
revive = []

crates/engine/src/ext.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ use crate::{
3131
BlockTimestamp,
3232
},
3333
};
34+
#[cfg(not(feature = "revive"))]
3435
pub use pallet_contracts_uapi::ReturnErrorCode as Error;
36+
#[cfg(feature = "revive")]
37+
pub use pallet_revive_uapi::ReturnErrorCode as Error;
3538
use scale::Encode;
3639
use std::panic::panic_any;
3740

@@ -320,6 +323,7 @@ impl Engine {
320323
set_output(output, &block_timestamp[..])
321324
}
322325

326+
#[cfg(not(feature = "revive"))]
323327
pub fn gas_left(&self, _output: &mut &mut [u8]) {
324328
unimplemented!("off-chain environment does not yet support `gas_left`");
325329
}

0 commit comments

Comments
 (0)