feat: initialize Kurdistan SDK - independent fork of Polkadot SDK

This commit is contained in:
Kurdistan Tech Ministry committed 2025-12-13 15:44:15 +03:00
commit e4778b4576
6838 files changed
+1847450

No files matched your search

+129
View File
@@ -0,0 +1,129 @@
[package]
name = "sp-io"
version = "30.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage.workspace = true
repository.workspace = true
description = "I/O for Substrate runtimes"
documentation = "https://docs.rs/sp-io"
readme = "README.md"
build = "build.rs"
[lints]
workspace = true
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
bytes = { workspace = true }
codec = { features = ["bytes"], workspace = true }
secp256k1 = { features = [
"global-context",
"recovery",
], optional = true, workspace = true, default-features = true }
sp-core = { workspace = true }
sp-crypto-hashing = { workspace = true }
sp-externalities = { workspace = true }
sp-keystore = { optional = true, workspace = true }
sp-runtime-interface = { workspace = true }
sp-state-machine = { optional = true, workspace = true }
sp-tracing = { workspace = true }
sp-trie = { optional = true, workspace = true }
tracing = { workspace = true }
tracing-core = { workspace = true }
[target.'cfg(not(substrate_runtime))'.dependencies]
sp-keystore = { workspace = true, default-features = false }
sp-trie = { workspace = true, default-features = false }
sp-state-machine = { workspace = true, default-features = false }
log = { workspace = true, default-features = true }
libsecp256k1 = { workspace = true, default-features = false, features = [
"static-context",
] }
secp256k1 = { workspace = true, default-features = false, features = [
"alloc",
"recovery",
] }
# Required for backwards compatibility reason, but only used for verifying when `UseDalekExt` is set.
ed25519-dalek = { workspace = true }
docify = { workspace = true }
[target.'cfg(all(any(target_arch = "riscv32", target_arch = "riscv64"), substrate_runtime))'.dependencies]
polkavm-derive = { workspace = true }
[build-dependencies]
rustversion = { workspace = true }
[features]
default = ["std"]
std = [
"bytes/std",
"codec/std",
"ed25519-dalek/std",
"libsecp256k1/std",
"log/std",
"secp256k1/global-context",
"secp256k1/std",
"sp-core/std",
"sp-crypto-hashing/std",
"sp-externalities/std",
"sp-keystore/std",
"sp-runtime-interface/std",
"sp-state-machine/std",
"sp-tracing/std",
"sp-trie/std",
"tracing-core/std",
"tracing/std",
]
with-tracing = ["sp-tracing/with-tracing"]
# These two features are used for `no_std` builds for the environments which already provides
# `#[panic_handler]`, `#[alloc_error_handler]` and `#[global_allocator]`.
#
# For the regular wasm runtime builds those are not used.
disable_panic_handler = []
disable_oom = []
disable_allocator = []
# This feature flag controls the runtime's behavior when encountering
# a panic or when it runs out of memory, improving the diagnostics.
#
# When enabled the runtime will marshal the relevant error message
# to the host through the `PanicHandler::abort_on_panic` runtime interface.
# This gives the caller direct programmatic access to the error message.
#
# When disabled the error message will only be printed out in the
# logs, with the caller receiving a generic "wasm `unreachable` instruction executed"
# error message.
#
# This has no effect if both `disable_panic_handler` and `disable_oom`
# are enabled.
#
# WARNING: Enabling this feature flag requires the `PanicHandler::abort_on_panic`
# host function to be supported by the host. Do *not* enable it for your
# runtime without first upgrading your host client!
improved_panic_error_reporting = []
# This feature adds BLS crypto primitives.
# It should not be used in production since the implementation and interface may still
# be subject to significant changes.
bls-experimental = ["sp-core/bls-experimental", "sp-keystore/bls-experimental"]
# This feature adds Bandersnatch crypto primitives.
# It should not be used in production since the implementation and interface may still
# be subject to significant changes.
bandersnatch-experimental = [
"sp-core/bandersnatch-experimental",
"sp-keystore/bandersnatch-experimental",
]
runtime-benchmarks = [
"sp-runtime-interface/runtime-benchmarks",
"sp-state-machine?/runtime-benchmarks",
"sp-trie?/runtime-benchmarks",
]
+3
View File
@@ -0,0 +1,3 @@
I/O host interface for Substrate runtime.
License: Apache-2.0
+26
View File
@@ -0,0 +1,26 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[rustversion::before(1.68)]
fn main() {
if !cfg!(feature = "std") {
println!("cargo:rustc-cfg=enable_alloc_error_handler");
}
}
#[rustversion::since(1.68)]
fn main() {}
@@ -0,0 +1,19 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[global_allocator]
static ALLOCATOR: polkavm_derive::LeakingAllocator = polkavm_derive::LeakingAllocator;
@@ -0,0 +1,85 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use core::{
alloc::{GlobalAlloc, Layout},
ptr,
};
/// The type used to store the offset between the real pointer and the returned pointer.
type Offset = u16;
/// The length of [`Offset`].
const OFFSET_LENGTH: usize = core::mem::size_of::<Offset>();
/// Allocator used by Substrate from within the runtime.
///
/// The allocator needs to align the returned pointer to given layout. We assume that on the host
/// side the freeing-bump allocator is used with a fixed alignment of `8` and a `HEADER_SIZE` of
/// `8`. The freeing-bump allocator is storing the header in the 8 bytes before the actual pointer
/// returned by `alloc`. The problem is that the runtime not only sees pointers allocated by this
/// `RuntimeAllocator`, but also pointers allocated by the host. The header is stored as a
/// little-endian `u64`. The allocation header consists of 8 bytes. The first four bytes (as written
/// in memory) are used to store the order of the allocation (or the link to the next slot, if
/// unallocated). Then the least significant bit of the next byte determines whether a given slot is
/// occupied or free, and the last three bytes are unused.
///
/// The `RuntimeAllocator` aligns the pointer to the required alignment before returning it to the
/// user code. As we are assuming the freeing-bump allocator that already aligns by `8` by default,
/// we only need to take care of alignments above `8`. The offset is stored in two bytes before the
/// pointer that we return to the user. Depending on the alignment, we may write into the header,
/// but given the assumptions above this should be no problem.
struct RuntimeAllocator;
#[global_allocator]
static ALLOCATOR: RuntimeAllocator = RuntimeAllocator;
unsafe impl GlobalAlloc for RuntimeAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let align = layout.align();
let size = layout.size();
// Allocate for the required size, plus a potential alignment.
//
// As the host side already aligns the pointer by `8`, we only need to account for any
// excess.
let ptr = crate::allocator::malloc((size + align.saturating_sub(8)) as u32);
// Calculate the required alignment.
let ptr_offset = ptr.align_offset(align);
// Should never happen, but just to be sure.
if ptr_offset > u16::MAX as usize || ptr.is_null() {
return ptr::null_mut();
}
// Align the pointer.
let ptr = ptr.add(ptr_offset);
unsafe {
(ptr.sub(OFFSET_LENGTH) as *mut Offset).write_unaligned(ptr_offset as Offset);
}
ptr
}
unsafe fn dealloc(&self, ptr: *mut u8, _: Layout) {
let offset = unsafe { (ptr.sub(OFFSET_LENGTH) as *const Offset).read_unaligned() };
crate::allocator::free(ptr.sub(offset as usize))
}
}
File diff suppressed because it is too large. Load diff