Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pallet-revive #231

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
7c2eac2
feat: pallet assets pop api integration
Daanvdplas Apr 5, 2024
418aa63
style: renaming assets example
Daanvdplas Apr 12, 2024
3d385df
refactor: chain extension tests
Daanvdplas Apr 22, 2024
fd46a27
fix: add error handling other than ModuleError
Daanvdplas Jun 4, 2024
1022926
test: add transfer
Daanvdplas Jun 6, 2024
ecc82e2
chore: remove polkadot launch
Daanvdplas Jun 6, 2024
e81f78a
# This is a combination of 8 commits.
Daanvdplas Jun 6, 2024
f824801
refactor: error handling
Daanvdplas Jun 20, 2024
4670503
refactor: clarify todos
Daanvdplas Jun 20, 2024
2283161
refactor: error handling comments part 1
Daanvdplas Jun 24, 2024
f88dd89
refactor: apply comments part 2
Daanvdplas Jun 25, 2024
61b3a17
refactor: tests local fungibles
Daanvdplas Jun 26, 2024
c1616a3
refactor: naming pallet error
Daanvdplas Jun 26, 2024
13e947e
refactor: optimising pop api and additional logic + test
Daanvdplas Jun 26, 2024
7757319
refactor: runtime
Daanvdplas Jul 3, 2024
924df85
refactor: draft final design
Daanvdplas Jul 2, 2024
972e4c9
feat: add more interfaces
Daanvdplas Jul 5, 2024
47e2ea6
refactor: final bits
Daanvdplas Jul 5, 2024
9dcfccb
fix: compiling
Daanvdplas Jul 6, 2024
b067eda
fix: cannot find macro vec error
Daanvdplas Jul 16, 2024
8730f90
refactor: decoding failed and commenting out unimplemented tests
Daanvdplas Jul 17, 2024
b591222
style: renaming
Daanvdplas Jul 17, 2024
c2acbb5
refactor: bits and pieces
Daanvdplas Jul 18, 2024
3639320
docs: add docs to code
Daanvdplas Jul 18, 2024
81e9844
fix: replace test code to api fungibles
Daanvdplas Jul 18, 2024
023d3dc
fix: own review + fixing CI fail
Daanvdplas Jul 18, 2024
e683e16
refactor: add Error variants index + clippy allowance
Daanvdplas Jul 19, 2024
28d971b
feat: api fungibles pallet (#113)
Daanvdplas Jul 26, 2024
4e4512e
refactor: streamline error from the decoded method by returning `Resu…
chungquantin Jul 26, 2024
02dffc6
merge main
Daanvdplas Jul 26, 2024
027cb85
refactor: build chain extension method (#121)
chungquantin Jul 26, 2024
30ff91a
fix: clean up imports (#135)
chungquantin Jul 27, 2024
9820e7f
refactor: remove read state encoding (#122)
Daanvdplas Jul 28, 2024
5ac5a9a
feat: transfer_from and decrease_allowance (#134)
chungquantin Jul 31, 2024
d8ac5bd
refactor: api integration tests (#133)
Daanvdplas Aug 6, 2024
00c5903
refactor: remove bare_call code duplication in integration test (#168)
chungquantin Aug 9, 2024
1acbd21
merge main
Daanvdplas Aug 13, 2024
9ebe162
fix: compilation
Daanvdplas Aug 13, 2024
545bd33
fix: try-runtime error
Daanvdplas Aug 13, 2024
99d0f6d
refactor: generic extension crate to de-duplicate code between runtim…
chungquantin Aug 13, 2024
8b4f595
feat: api events (#153)
Daanvdplas Aug 14, 2024
f13b39c
docs: pop api (#190)
Daanvdplas Aug 16, 2024
7c94284
refactor: extension
Daanvdplas Aug 16, 2024
5934fa8
fix: remove old api code from deprecated examples
Daanvdplas Aug 16, 2024
f2ef7a1
refactor: runtime devnet
Daanvdplas Aug 16, 2024
b3dd993
refactor: fungibles pallet
Daanvdplas Aug 16, 2024
0811598
style: fix tests asset_asset parameter
Daanvdplas Aug 19, 2024
6482a43
fix: invalid imported crates & crate visibility (#214)
chungquantin Aug 19, 2024
09f4106
refactor: generic extension
evilrobot-01 Aug 18, 2024
2a83e8a
refactor: builder to decoder
evilrobot-01 Aug 19, 2024
02a126e
refactor: improve api
evilrobot-01 Aug 19, 2024
f36fc87
refactor: readable
evilrobot-01 Aug 19, 2024
c2a6579
refactor: improve matching
evilrobot-01 Aug 19, 2024
8d48ebb
refactor: porting logging and comments
evilrobot-01 Aug 20, 2024
f4db433
refactor: relocate pop-api specifics to api pallet
evilrobot-01 Aug 20, 2024
f2af0ec
refactor: address clippy warnings
evilrobot-01 Aug 20, 2024
025db4b
refactor: replace extension
evilrobot-01 Aug 20, 2024
6b7553d
fix: align with existing encoding convention
evilrobot-01 Aug 20, 2024
6538722
refactor: improve logging
evilrobot-01 Aug 20, 2024
c1b183a
refactor: improve matching api
evilrobot-01 Aug 20, 2024
6def916
refactor: error conversion
evilrobot-01 Aug 20, 2024
50a8ae1
refactor: remove irrelevant comments
evilrobot-01 Aug 20, 2024
6bd77e0
fix: type resolution and dependencies
evilrobot-01 Aug 20, 2024
bce8eef
fix: missing import
evilrobot-01 Aug 20, 2024
2dcf75a
refactor: error handling
evilrobot-01 Aug 21, 2024
052e36d
build(deps): restore dev dependency
evilrobot-01 Aug 21, 2024
9b8b589
fix: standardise on decoding failed error
evilrobot-01 Aug 21, 2024
b0450fd
refactor: separate versioning
evilrobot-01 Aug 21, 2024
eda7ca8
refactor: reuse decoding failed error
evilrobot-01 Aug 21, 2024
e70b83d
fix: import
evilrobot-01 Aug 21, 2024
da145b9
refactor: collapse module
evilrobot-01 Aug 21, 2024
89d6dd8
refactor: support read result versioning
evilrobot-01 Aug 22, 2024
d26790c
fix: resolve type clash
evilrobot-01 Aug 22, 2024
22a683a
fix: update import
evilrobot-01 Aug 22, 2024
702b158
feat: add pallet-revive
chungquantin Aug 23, 2024
f87aa2b
Merge branch 'frank/extension' into chungquantin/feat-revive
chungquantin Aug 23, 2024
cf27913
fix: toml file
chungquantin Aug 23, 2024
ccadad1
Merge branch 'main' into chungquantin/feat-revive
chungquantin Aug 23, 2024
faa6ea8
fix: merge main
chungquantin Aug 23, 2024
a6bd2fb
fix: remove pallet-contract, rename pallet-revive
chungquantin Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,069 changes: 1,229 additions & 840 deletions Cargo.lock

Large diffs are not rendered by default.

122 changes: 78 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,109 @@
panic = "unwind"

[profile.production]
codegen-units = 1
inherits = "release"
lto = true
codegen-units = 1

[workspace.package]
authors = ["R0GUE <go@r0gue.io>"]
description = "Pop Network makes it easy for smart contract developers to use the Power of Polkadot."
edition = "2021"
homepage = "https://r0gue.io"
license = "Unlicense"
repository = "https://github.com/r0gue-io/pop-node/"
description = "Pop Network makes it easy for smart contract developers to use the Power of Polkadot."

[workspace]
exclude = ["pop-api", "tests/contracts"]
members = [
"node",
"runtime/devnet",
"runtime/testnet",
"integration-tests",
"pallets/*",
"primitives",
]
exclude = ["pop-api", "tests/contracts"]

resolver = "2"

[workspace.dependencies]
clap = { version = "4.4.18", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
futures = "0.3.28"
hex-literal = "0.4.1"
impl-trait-for-tuples = "0.2.2"
jsonrpsee = { version = "0.23.2", features = ["server"] }
log = { version = "0.4.21", default-features = false }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
] }
smallvec = "1.11.2"
serde = "1.0.197"
clap = { version = "4.4.18", features = ["derive"] }
jsonrpsee = { version = "0.23.2", features = ["server"] }
futures = "0.3.28"
serde_json = "1.0.114"
tracing-subscriber = { version = "0.3", default-features = false }
smallvec = "1.11.2"
subxt = "0.34.0"
subxt-signer = "0.34.0"
tokio = { version = "1.36", features = ["macros", "time", "rt-multi-thread"] }
tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "time"] }
tracing-subscriber = { version = "0.3", default-features = false }

# Build
substrate-build-script-utils = "11.0.0"
substrate-wasm-builder = "23.0.0"

# Experimental pallet-revive dependencies
anyhow = { version = "1.0.81" }
array-bytes = { version = "6.2.2", default-features = false }
assert_matches = { version = "1.5.0" }
bitflags = { version = "1.3.2" }
environmental = { version = "1.1.4", default-features = false }
pallet-contracts = { path = "pallets/contracts", default-features = false }
pallet-contracts-fixtures = { path = "pallets/contracts/fixtures", default-features = false }
pallet-contracts-mock-network = { default-features = false, path = "pallets/contracts/mock-network" }
pallet-contracts-proc-macro = { path = "pallets/contracts/proc-macro", default-features = false }
pallet-contracts-uapi = { path = "pallets/contracts/uapi", default-features = false }
pallet-insecure-randomness-collective-flip = { version = "25.0.0", default-features = false }
pretty_assertions = { version = "1.3.0" }
proc-macro2 = { version = "1.0.64" }
polkavm-derive = "0.9.1"
polkavm-linker = "0.9.2"
parity-wasm = { version = "0.45.0" }
paste = { version = "1.0.15", default-features = false }
rand = { version = "0.8.5", default-features = false }
rand_pcg = { version = "0.3.1" }
wasm-instrument = { version = "0.4", default-features = false }
wasmi = { version = "0.32.3", default-features = false }
wat = { version = "1.0.0" }
sp-tracing = { version = "17.0.0", default-features = false }
syn = { version = "2.0.53" }
quote = { version = "1.0.36" }
tempfile = { version = "3.8.1" }
toml = { version = "0.8.8" }
twox-hash = { version = "1.6.3", default-features = false }

# Local
pallet-api = { path = "pallets/api", default-features = false }
pop-chain-extension = { path = "./extension", default-features = false }
pop-runtime-devnet = { path = "runtime/devnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-testnet = { path = "runtime/testnet", default-features = true } # default-features=true required for `-p pop-node` builds
pop-runtime-common = { path = "runtime/common", default-features = false }
pop-primitives = { path = "./primitives", default-features = false }

# Substrate
sc-basic-authorship = "0.42.0"
sc-chain-spec = "35.0.0"
sc-cli = "0.44.0"
sc-client-api = "35.1.0"
sc-offchain = "37.0.0"
sc-consensus = "0.41.0"
sc-executor = "0.39.0"
sc-network = "0.42.0"
sc-network-sync = "0.41.0"
sc-rpc = "37.0.0"
sc-service = "0.43.0"
sc-sysinfo = "35.0.0"
sc-telemetry = "22.0.0"
sc-tracing = "35.0.0"
sc-transaction-pool = "35.0.0"
sc-transaction-pool-api = "35.0.0"
frame-benchmarking = { version = "36.0.0", default-features = false }
frame-benchmarking-cli = "40.0.0"
frame-executive = { version = "36.0.0", default-features = false }
frame-metadata-hash-extension = { version = "0.4.0", default-features = false }
frame-support = { version = "36.0.0", default-features = false }
frame-system = { version = "36.1.0", default-features = false }
frame-system-benchmarking = { version = "36.0.0", default-features = false }
frame-system-rpc-runtime-api = { version = "33.0.0", default-features = false }
frame-try-runtime = { version = "0.42.0", default-features = false }
frame-metadata-hash-extension = { version = "0.4.0", default-features = false }
pallet-assets = { version = "37.0.0", default-features = false }
pallet-aura = { version = "35.0.0", default-features = false }
pallet-authorship = { version = "36.0.0", default-features = false }
pallet-assets = { version = "37.0.0", default-features = false }
pallet-balances = { version = "37.0.0", default-features = false }
pallet-contracts = { version = "35.0.0", default-features = false }
# pallet-contracts = { version = "35.0.0", default-features = false }
pallet-message-queue = { version = "39.0.0", default-features = false }
pallet-multisig = { version = "36.0.0", default-features = false }
pallet-nft-fractionalization = { version = "18.0.0", default-features = false }
Expand All @@ -103,6 +121,22 @@ pallet-transaction-payment-rpc = "38.0.0"
pallet-transaction-payment-rpc-runtime-api = { version = "36.0.0", default-features = false }
pallet-utility = { version = "36.0.0", default-features = false }
prometheus-endpoint = { version = "0.17.0", default-features = false, package = "substrate-prometheus-endpoint" }
sc-basic-authorship = "0.42.0"
sc-chain-spec = "35.0.0"
sc-cli = "0.44.0"
sc-client-api = "35.1.0"
sc-consensus = "0.41.0"
sc-executor = "0.39.0"
sc-network = "0.42.0"
sc-network-sync = "0.41.0"
sc-offchain = "37.0.0"
sc-rpc = "37.0.0"
sc-service = "0.43.0"
sc-sysinfo = "35.0.0"
sc-telemetry = "22.0.0"
sc-tracing = "35.0.0"
sc-transaction-pool = "35.0.0"
sc-transaction-pool-api = "35.0.0"
sp-api = { version = "33.0.0", default-features = false }
sp-authority-discovery = { version = "33.0.0", default-features = false }
sp-block-builder = { version = "33.0.0", default-features = false }
Expand All @@ -112,57 +146,57 @@ sp-consensus-babe = { version = "0.39.0", default-features = false }
sp-consensus-beefy = { version = "20.0.0", default-features = false }
sp-consensus-grandpa = { version = "20.0.0", default-features = false }
sp-core = { version = "34.0.0", default-features = false }
sp-keystore = "0.40.0"
sp-io = { version = "37.0.0", default-features = false }
sp-genesis-builder = { version = "0.14.0", default-features = false }
sp-inherents = { version = "33.0.0", default-features = false }
sp-io = { version = "37.0.0", default-features = false }
sp-keystore = "0.40.0"
sp-offchain = { version = "33.0.0", default-features = false }
sp-runtime = { version = "38.0.0", default-features = false }
sp-timestamp = "33.0.0"
substrate-frame-rpc-system = "36.0.0"
sp-session = { version = "34.0.0", default-features = false }
sp-std = { version = "14.0.0", default-features = false }
sp-timestamp = "33.0.0"
sp-transaction-pool = { version = "33.0.0", default-features = false }
sp-version = { version = "36.0.0", default-features = false }
substrate-frame-rpc-system = "36.0.0"

# Polkadot
pallet-xcm = { version = "15.0.0", default-features = false }
polkadot-cli = "15.0.0"
polkadot-parachain-primitives = { version = "13.0.0", default-features = false }
polkadot-runtime-parachains = { version = "15.0.3", default-features = false }
polkadot-primitives = { version = "14.0.0", default-features = false }
polkadot-runtime-common = { version = "15.0.0", default-features = false }
rococo-runtime-constants = { version = "15.0.0", default-features = false }
polkadot-runtime-parachains = { version = "15.0.3", default-features = false }
rococo-runtime = { version = "15.0.0", default-features = false }
rococo-runtime-constants = { version = "15.0.0", default-features = false }
xcm = { version = "14.0.3", package = "staging-xcm", default-features = false }
xcm-builder = { version = "15.0.0", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "15.0.0", package = "staging-xcm-executor", default-features = false }

# Cumulus
asset-hub-rococo-runtime = { version = "0.19.0", default-features = false }
asset-test-utils = { version = "15.0.0", default-features = false }
color-print = "0.3.4"
cumulus-client-cli = "0.15.0"
cumulus-client-collator = "0.15.0"
cumulus-client-consensus-aura = "0.15.0"
cumulus-client-consensus-common = "0.15.0"
cumulus-client-consensus-proposer = "0.14.0"
cumulus-client-service = "0.15.0"
cumulus-pallet-aura-ext = { version = "0.15.0", default-features = false }
cumulus-pallet-parachain-system = { version = "0.15.0", default-features = false }
cumulus-pallet-session-benchmarking = { version = "17.0.0", default-features = false }
cumulus-pallet-xcm = { version = "0.15.0", default-features = false }
cumulus-pallet-xcmp-queue = { version = "0.15.0", default-features = false }
cumulus-primitives-aura = { version = "0.14.0", default-features = false }
cumulus-primitives-core = { version = "0.14.0", default-features = false }
cumulus-primitives-parachain-inherent = "0.14.0"
cumulus-primitives-storage-weight-reclaim = { version = "6.0.2", default-features = false }
cumulus-primitives-utility = { version = "0.15.0", default-features = false }
cumulus-relay-chain-interface = "0.15.0"
emulated-integration-tests-common = { version = "11.0.0", default-features = false }
pallet-collator-selection = { version = "17.0.0", default-features = false }
parachains-common = { version = "15.0.0", default-features = false }
parachain-info = { version = "0.15.0", package = "staging-parachain-info", default-features = false }
cumulus-primitives-parachain-inherent = "0.14.0"
cumulus-relay-chain-interface = "0.15.0"
color-print = "0.3.4"
cumulus-client-cli = "0.15.0"
cumulus-client-collator = "0.15.0"
cumulus-client-consensus-aura = "0.15.0"
cumulus-client-consensus-common = "0.15.0"
cumulus-client-consensus-proposer = "0.14.0"
cumulus-client-service = "0.15.0"
parachains-common = { version = "15.0.0", default-features = false }

# TODO: Paseo (note: using polkadot as stopgap until paseo updated to polkadot sdk v1.14.0)
asset-hub-paseo-runtime = { git = "https://github.com/polkadot-fellows/runtimes", default-features = false, package = "asset-hub-polkadot-runtime" }
Expand Down
48 changes: 48 additions & 0 deletions extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "pop-chain-extension"
version = "0.1.0"
authors.workspace = true
description.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
edition.workspace = true
publish = false

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec.workspace = true
impl-trait-for-tuples.workspace = true
log.workspace = true

# Substrate
frame-support.workspace = true
frame-system.workspace = true
pallet-contracts.workspace = true
sp-core.workspace = true
sp-runtime.workspace = true
sp-std.workspace = true

[dev-dependencies]
rand = "0.8.5"

[features]
default = ["std"]
std = [
"log/std",
"codec/std",
"frame-support/std",
"frame-system/std",
"pallet-contracts/std",
"sp-runtime/std",
"sp-core/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
53 changes: 53 additions & 0 deletions extension/src/decoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use super::*;
use pallet_contracts::chain_extension::BufIn;
use pallet_contracts::WeightInfo;
use sp_runtime::DispatchError;
use sp_std::vec::Vec;

/// Trait for decoding data read from contract memory.
pub trait Decode {
/// The output type to be decoded.
type Output: codec::Decode;
/// An optional processor, for performing any additional processing on data read from the contract before decoding.
type Processor: Processor<Value = Vec<u8>>;
/// The error to return if decoding fails.
type Error: Get<DispatchError>;

/// The log target.
const LOG_TARGET: &'static str;

/// Decodes data read from contract memory.
///
/// # Parameters
/// - `env` - The current execution environment.
fn decode<E: Ext, S: BufIn>(env: &mut Environment<E, S>) -> Result<Self::Output> {
// Charge appropriate weight, based on input length, prior to decoding.
// reference: https://github.com/paritytech/polkadot-sdk/blob/117a9433dac88d5ac00c058c9b39c511d47749d2/substrate/frame/contracts/src/wasm/runtime.rs#L267
let len = env.in_len();
let weight = <E::T as pallet_contracts::Config>::WeightInfo::seal_return(len);
env.charge_weight(weight)?;
log::debug!(target: Self::LOG_TARGET, "pre-decode weight charged: len={len}, weight={weight}");
// Read encoded input supplied by contract for buffer.
let mut input = env.read(len)?;
log::debug!(target: Self::LOG_TARGET, "input read: input={input:?}");
// Perform any additional processing required. Any implementation is expected to charge weight as appropriate.
input = Self::Processor::process(input, env);
// Finally decode and return.
Self::Output::decode(&mut &input[..]).map_err(|_| Self::Error::get())
}
}

/// Default implementation for decoding data read from contract memory.
pub struct Decodes<O, E, P = (), L = ()>(PhantomData<(O, E, P, L)>);
impl<
Output: codec::Decode,
Error: Get<DispatchError>,
ValueProcessor: Processor<Value = Vec<u8>>,
Logger: LogTarget,
> Decode for Decodes<Output, Error, ValueProcessor, Logger>
{
type Output = Output;
type Processor = ValueProcessor;
type Error = Error;
const LOG_TARGET: &'static str = Logger::LOG_TARGET;
}
Loading