Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'polkadot-native-assets' into polkadot-native-assets-fro…
Browse files Browse the repository at this point in the history
…m-upper-stream
  • Loading branch information
yrong committed Sep 12, 2024
2 parents ba1d261 + 64cd74a commit 1a5b02a
Show file tree
Hide file tree
Showing 64 changed files with 1,613 additions and 741 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions prdoc/pr_4851.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Add support for deprecation metadata in `RuntimeMetadataIr` entries.

doc:
- audience:
- Runtime dev
- Runtime user
description: |
Changes introduced are listed below.
Adds `DeprecationStatusIR` enum to sp_metadata_ir.
- Is a deprecation info for simple items.
Adds `DeprecationInfoIR` enum to sp_metadata_ir.
- It is a deprecation info for an enums/errors/calls. Contains `DeprecationStatusIR`.
Also denotes full/partial deprecation of the type or its variants/calls.
Adds `deprecation_info` field to
- `RuntimeApiMetadataIR`
- `RuntimeApiMethodMetadataIR`
- `StorageEntryMetadataIR`
- `PalletConstantMetadataIR`
- `PalletCallMetadataIR`
- `PalletMetadataIR`
- `PalletEventMetadataIR`
- `PalletErrorMetadataIR`
Examples of the deprecation info produced can be seen inside
- Tests for `frame-support`
- hackmd link https://hackmd.io/@Zett98/Bys0YgbcR

crates:
- name: frame-support-procedural
bump: patch
- name: frame-support
bump: major
- name: sp-api-proc-macro
bump: patch
- name: sp-api
bump: patch
- name: sp-metadata-ir
bump: major
11 changes: 11 additions & 0 deletions prdoc/pr_5664.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: Calling an address without associated code is a balance transfer

doc:
- audience: Runtime Dev
description: |
This makes pallet_revive behave like EVM where a balance transfer
is just a call to a plain wallet.

crates:
- name: pallet-revive
bump: patch
17 changes: 17 additions & 0 deletions prdoc/pr_5665.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "[pallet-contracts] remove riscv support"

doc:
- audience: Runtime Dev
description: |
RISC-V support is now being built inside the new fork pallet-revive

crates:
- name: pallet-contracts
bump: patch
- name: pallet-contracts-fixtures
bump: patch
- name: pallet-contracts-uapi
bump: patch
14 changes: 14 additions & 0 deletions prdoc/pr_5678.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: 'rpc server: fix deny unsafe on RpcMethods::Auto'
doc:
- audience: Node User
description: |-
Close #5677

I made a nit when I moved this code: https://github.com/paritytech/polkadot-sdk/blob/v1.14.0-rc1/substrate/client/service/src/lib.rs#L379-#L385 in https://github.com/paritytech/polkadot-sdk/pull/4792

Thus:
- (ip.is_loopback(), RpcMethods::Auto) -> allow unsafe
- (!ip.is_loopback(), RpcMethods::Auto) -> deny unsafe
crates:
- name: sc-rpc-server
bump: patch
2 changes: 1 addition & 1 deletion substrate/client/rpc-servers/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub(crate) fn get_proxy_ip<B>(req: &http::Request<B>) -> Option<IpAddr> {
/// Get the `deny_unsafe` setting based on the address and the RPC methods exposed by the interface.
pub fn deny_unsafe(addr: &SocketAddr, methods: &RpcMethods) -> DenyUnsafe {
match (addr.ip().is_loopback(), methods) {
| (_, RpcMethods::Unsafe) | (false, RpcMethods::Auto) => DenyUnsafe::No,
(_, RpcMethods::Unsafe) | (true, RpcMethods::Auto) => DenyUnsafe::No,
_ => DenyUnsafe::Yes,
}
}
Expand Down
4 changes: 0 additions & 4 deletions substrate/frame/contracts/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ parity-wasm = { workspace = true }
tempfile = { workspace = true }
toml = { workspace = true }
twox-hash = { workspace = true, default-features = true }
polkavm-linker = { workspace = true, optional = true }
anyhow = { workspace = true, default-features = true }

[features]
riscv = ["polkavm-linker"]
64 changes: 1 addition & 63 deletions substrate/frame/contracts/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Compile contracts to wasm and RISC-V binaries.
//! Compile contracts to wasm.
use anyhow::{bail, Context, Result};
use parity_wasm::elements::{deserialize_file, serialize_to_file, Internal};
use std::{
Expand Down Expand Up @@ -89,12 +89,6 @@ impl Entry {
fn out_wasm_filename(&self) -> String {
format!("{}.wasm", self.name())
}

/// Return the name of the RISC-V polkavm file.
#[cfg(feature = "riscv")]
fn out_riscv_filename(&self) -> String {
format!("{}.polkavm", self.name())
}
}

/// Collect all contract entries from the given source directory.
Expand Down Expand Up @@ -236,53 +230,6 @@ fn post_process_wasm(input_path: &Path, output_path: &Path) -> Result<()> {
serialize_to_file(output_path, module).map_err(Into::into)
}

/// Build contracts for RISC-V.
#[cfg(feature = "riscv")]
fn invoke_riscv_build(current_dir: &Path) -> Result<()> {
let encoded_rustflags = [
"-Crelocation-model=pie",
"-Clink-arg=--emit-relocs",
"-Clink-arg=--export-dynamic-symbol=__polkavm_symbol_export_hack__*",
]
.join("\x1f");

let build_res = Command::new(env::var("CARGO")?)
.current_dir(current_dir)
.env_clear()
.env("PATH", env::var("PATH").unwrap_or_default())
.env("CARGO_ENCODED_RUSTFLAGS", encoded_rustflags)
.env("RUSTUP_TOOLCHAIN", "rve-nightly")
.env("RUSTUP_HOME", env::var("RUSTUP_HOME").unwrap_or_default())
.args(["build", "--release", "--target=riscv32ema-unknown-none-elf"])
.output()
.expect("failed to execute process");

if build_res.status.success() {
return Ok(())
}

let stderr = String::from_utf8_lossy(&build_res.stderr);

if stderr.contains("'rve-nightly' is not installed") {
eprintln!("RISC-V toolchain is not installed.\nDownload and install toolchain from https://github.com/paritytech/rustc-rv32e-toolchain.");
eprintln!("{}", stderr);
} else {
eprintln!("{}", stderr);
}

bail!("Failed to build contracts");
}
/// Post-process the compiled wasm contracts.
#[cfg(feature = "riscv")]
fn post_process_riscv(input_path: &Path, output_path: &Path) -> Result<()> {
let mut config = polkavm_linker::Config::default();
config.set_strip(true);
let orig = fs::read(input_path).with_context(|| format!("Failed to read {:?}", input_path))?;
let linked = polkavm_linker::program_from_elf(config, orig.as_ref())
.map_err(|err| anyhow::format_err!("Failed to link polkavm program: {}", err))?;
fs::write(output_path, linked.as_bytes()).map_err(Into::into)
}

/// Write the compiled contracts to the given output directory.
fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec<Entry>) -> Result<()> {
for entry in entries {
Expand All @@ -292,12 +239,6 @@ fn write_output(build_dir: &Path, out_dir: &Path, entries: Vec<Entry>) -> Result
&out_dir.join(&wasm_output),
)?;

#[cfg(feature = "riscv")]
post_process_riscv(
&build_dir.join("target/riscv32ema-unknown-none-elf/release").join(entry.name()),
&out_dir.join(entry.out_riscv_filename()),
)?;

entry.update_cache(out_dir)?;
}

Expand Down Expand Up @@ -347,9 +288,6 @@ fn main() -> Result<()> {

invoke_wasm_build(tmp_dir_path)?;

#[cfg(feature = "riscv")]
invoke_riscv_build(tmp_dir_path)?;

write_output(tmp_dir_path, &out_dir, entries)?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ pub use uapi::{HostFn, HostFnImpl as api};
fn panic(_info: &core::panic::PanicInfo) -> ! {
#[cfg(target_arch = "wasm32")]
core::arch::wasm32::unreachable();

#[cfg(target_arch = "riscv32")]
// Safety: The unimp instruction is guaranteed to trap
unsafe {
core::arch::asm!("unimp");
core::hint::unreachable_unchecked();
}
}

/// Utility macro to read input passed to a contract.
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/contracts/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ mod test {
fn out_dir_should_have_compiled_mocks() {
let out_dir: std::path::PathBuf = env!("OUT_DIR").into();
assert!(out_dir.join("dummy.wasm").exists());
#[cfg(feature = "riscv")]
assert!(out_dir.join("dummy.polkavm").exists());
}
}
3 changes: 0 additions & 3 deletions substrate/frame/contracts/uapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ codec = { features = [
"max-encoded-len",
], optional = true, workspace = true }

[target.'cfg(target_arch = "riscv32")'.dependencies]
polkavm-derive = { workspace = true }

[package.metadata.docs.rs]
default-target = ["wasm32-unknown-unknown"]

Expand Down
5 changes: 1 addition & 4 deletions substrate/frame/contracts/uapi/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use paste::paste;
#[cfg(target_arch = "wasm32")]
mod wasm32;

#[cfg(target_arch = "riscv32")]
mod riscv32;

macro_rules! hash_fn {
( $name:ident, $bytes:literal ) => {
paste! {
Expand Down Expand Up @@ -66,7 +63,7 @@ fn ptr_or_sentinel(data: &Option<&[u8]>) -> *const u8 {
/// Implements [`HostFn`] for each supported target architecture.
pub enum HostFnImpl {}

/// Defines all the host apis implemented by both wasm and RISC-V vms.
/// Defines all the host apis implemented by the wasm vm.
pub trait HostFn: private::Sealed {
/// Returns the number of times specified contract exists on the call stack. Delegated calls are
/// not counted as separate calls.
Expand Down
Loading

0 comments on commit 1a5b02a

Please sign in to comment.