From 405bd752a2ceeb049434dc3058e48d121a0d559c Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Thu, 12 Aug 2021 14:45:14 +0300 Subject: [PATCH 01/12] Add Programmable Pools pallet to core For now, it only contains dummy code copied from the template pallet --- node/src/chain_spec.rs | 6 +- pallets/pp/Cargo.toml | 37 +++++++++ pallets/pp/LICENSE | 21 +++++ pallets/pp/README.md | 1 + pallets/pp/src/benchmarking.rs | 40 ++++++++++ pallets/pp/src/lib.rs | 140 +++++++++++++++++++++++++++++++++ pallets/pp/src/mock.rs | 78 ++++++++++++++++++ pallets/pp/src/tests.rs | 39 +++++++++ runtime/Cargo.toml | 1 + runtime/src/lib.rs | 7 ++ 10 files changed, 368 insertions(+), 2 deletions(-) create mode 100644 pallets/pp/Cargo.toml create mode 100644 pallets/pp/LICENSE create mode 100644 pallets/pp/README.md create mode 100644 pallets/pp/src/benchmarking.rs create mode 100644 pallets/pp/src/lib.rs create mode 100644 pallets/pp/src/mock.rs create mode 100644 pallets/pp/src/tests.rs diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index b042815..b32e6e9 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -2,7 +2,7 @@ use sp_core::{Pair, Public, sr25519}; use node_template_runtime::{ AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, SudoConfig, SystemConfig, WASM_BINARY, Signature, - pallet_utxo, UtxoConfig}; + pallet_utxo, UtxoConfig, PpConfig}; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_runtime::traits::{Verify, IdentifyAccount}; @@ -174,10 +174,12 @@ fn testnet_genesis( // Assign network admin rights. key: root_key, }, - pallet_utxo: UtxoConfig { genesis_utxos: vec![genesis], _marker: Default::default() + }, + pallet_pp: PpConfig { + _marker: Default::default() } } } diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml new file mode 100644 index 0000000..d259743 --- /dev/null +++ b/pallets/pp/Cargo.toml @@ -0,0 +1,37 @@ +[package] +authors = ['Mintlayer'] +description = 'Programmable pools pallet' +edition = '2018' +license = 'MIT' +name = 'pallet-pp' +readme = 'README.md' +version = '3.0.0' + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] + +[dependencies] +# external dependencies +codec = {default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0'} + +# Substrate dependencies +frame-benchmarking = {default-features = false, optional = true, version = '3.1.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +frame-support = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +frame-system = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} + +[dev-dependencies] +serde = '1.0.119' +sp-core = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +sp-io = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +sp-runtime = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} + +[features] +default = ['std'] +runtime-benchmarks = ['frame-benchmarking'] +std = [ + 'codec/std', + 'frame-support/std', + 'frame-system/std', + 'frame-benchmarking/std', +] +try-runtime = ['frame-support/try-runtime'] diff --git a/pallets/pp/LICENSE b/pallets/pp/LICENSE new file mode 100644 index 0000000..45fabc8 --- /dev/null +++ b/pallets/pp/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 RBB S.r.l + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/pallets/pp/README.md b/pallets/pp/README.md new file mode 100644 index 0000000..8d751a4 --- /dev/null +++ b/pallets/pp/README.md @@ -0,0 +1 @@ +License: Unlicense \ No newline at end of file diff --git a/pallets/pp/src/benchmarking.rs b/pallets/pp/src/benchmarking.rs new file mode 100644 index 0000000..426941d --- /dev/null +++ b/pallets/pp/src/benchmarking.rs @@ -0,0 +1,40 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +//! Benchmarking setup for pallet-pp + +use super::*; + +use frame_system::RawOrigin; +use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite}; +#[allow(unused)] +use crate::Pallet as PP; + +benchmarks! { + do_something { + let s in 0 .. 100; + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller), s) + verify { + assert_eq!(Something::::get(), Some(s)); + } +} + +impl_benchmark_test_suite!( + PP, + crate::mock::new_test_ext(), + crate::mock::Test, +); diff --git a/pallets/pp/src/lib.rs b/pallets/pp/src/lib.rs new file mode 100644 index 0000000..1345fa5 --- /dev/null +++ b/pallets/pp/src/lib.rs @@ -0,0 +1,140 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +#![cfg_attr(not(feature = "std"), no_std)] + +/// Edit this file to define custom logic or remove it if it is not needed. +/// Learn more about FRAME and the core library of Substrate FRAME pallets: +/// + +pub use pallet::*; + +#[cfg(test)] +mod mock; + +#[cfg(test)] +mod tests; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +#[frame_support::pallet] +pub mod pallet { + use frame_support::{dispatch::{DispatchResult}, pallet_prelude::*}; + use frame_system::pallet_prelude::*; + + /// Configure the pallet by specifying the parameters and types on which it depends. + #[pallet::config] + pub trait Config: frame_system::Config { + /// Because this pallet emits events, it depends on the runtime's definition of an event. + type Event: From> + IsType<::Event>; + } + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + // The pallet's runtime storage items. + // https://substrate.dev/docs/en/knowledgebase/runtime/storage + #[pallet::storage] + #[pallet::getter(fn something)] + // Learn more about declaring storage items: + // https://substrate.dev/docs/en/knowledgebase/runtime/storage#declaring-storage-items + pub type Something = StorageValue<_, u32>; + + // Pallets use events to inform users when important changes are made. + // https://substrate.dev/docs/en/knowledgebase/runtime/events + #[pallet::event] + #[pallet::metadata(T::AccountId = "AccountId")] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + /// Event documentation should end with an array that provides descriptive names for event + /// parameters. [something, who] + SomethingStored(u32, T::AccountId), + } + + // Errors inform users that something went wrong. + #[pallet::error] + pub enum Error { + /// Error names should be descriptive. + NoneValue, + /// Errors should have helpful documentation associated with them. + StorageOverflow, + } + + #[pallet::hooks] + impl Hooks> for Pallet {} + + // Dispatchable functions allows users to interact with the pallet and invoke state changes. + // These functions materialize as "extrinsics", which are often compared to transactions. + // Dispatchable functions must be annotated with a weight and must return a DispatchResult. + #[pallet::call] + impl Pallet { + /// An example dispatchable that takes a singles value as a parameter, writes the value to + /// storage and emits an event. This function must be dispatched by a signed extrinsic. + #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] + pub fn do_something(origin: OriginFor, something: u32) -> DispatchResult { + // Check that the extrinsic was signed and get the signer. + // This function will return an error if the extrinsic is not signed. + // https://substrate.dev/docs/en/knowledgebase/runtime/origin + let who = ensure_signed(origin)?; + + // Update storage. + >::put(something); + + // Emit an event. + Self::deposit_event(Event::SomethingStored(something, who)); + // Return a successful DispatchResultWithPostInfo + Ok(()) + } + + /// An example dispatchable that may throw a custom error. + #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + pub fn cause_error(origin: OriginFor) -> DispatchResult { + let _who = ensure_signed(origin)?; + + // Read a value from storage. + match >::get() { + // Return an error if the value has not been set. + None => Err(Error::::NoneValue)?, + Some(old) => { + // Increment the value read from storage; will error in the event of overflow. + let new = old.checked_add(1).ok_or(Error::::StorageOverflow)?; + // Update the value in storage with the incremented result. + >::put(new); + Ok(()) + }, + } + } + } + + #[pallet::genesis_config] + pub struct GenesisConfig { + pub _marker: PhantomData + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self { _marker: Default::default() } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) {} + } +} diff --git a/pallets/pp/src/mock.rs b/pallets/pp/src/mock.rs new file mode 100644 index 0000000..b9d81af --- /dev/null +++ b/pallets/pp/src/mock.rs @@ -0,0 +1,78 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +use crate as pallet_pp; +use sp_core::H256; +use frame_support::parameter_types; +use sp_runtime::{ + traits::{BlakeTwo256, IdentityLookup}, testing::Header, +}; +use frame_system as system; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +// Configure a mock runtime to test the pallet. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + PpModule: pallet_pp::{Pallet, Call, Storage, Event}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; +} + +impl system::Config for Test { + type BaseCallFilter = (); + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Origin = Origin; + type Call = Call; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = SS58Prefix; + type OnSetCode = (); +} + +impl pallet_pp::Config for Test { + type Event = Event; +} + +// Build genesis storage according to the mock runtime. +pub fn new_test_ext() -> sp_io::TestExternalities { + system::GenesisConfig::default().build_storage::().unwrap().into() +} diff --git a/pallets/pp/src/tests.rs b/pallets/pp/src/tests.rs new file mode 100644 index 0000000..75f3a7a --- /dev/null +++ b/pallets/pp/src/tests.rs @@ -0,0 +1,39 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +use crate::{Error, mock::*}; +use frame_support::{assert_ok, assert_noop}; + +#[test] +fn it_works_for_default_value() { + new_test_ext().execute_with(|| { + // Dispatch a signed extrinsic. + assert_ok!(PpModule::do_something(Origin::signed(1), 42)); + // Read pallet storage and assert an expected result. + assert_eq!(PpModule::something(), Some(42)); + }); +} + +#[test] +fn correct_error_for_none_value() { + new_test_ext().execute_with(|| { + // Ensure the expected error is thrown when no value is present. + assert_noop!( + PpModule::cause_error(Origin::signed(1)), + Error::::NoneValue + ); + }); +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index a45a66c..d44099f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -48,6 +48,7 @@ sp-version = {default-features = false, version = '3.0.0', git = 'https://github # local dependencies pallet-template = {default-features = false, version = '3.0.0', path = '../pallets/template'} pallet-utxo = {default-features = false, path = "../pallets/utxo" } +pallet-pp = {default-features = false, path = "../pallets/pp" } [features] default = ['std'] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9ca0025..8e95248 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -43,6 +43,7 @@ use pallet_transaction_payment::CurrencyAdapter; pub use pallet_template; pub use pallet_utxo; +pub use pallet_pp; use sp_runtime::transaction_validity::{TransactionValidityError, InvalidTransaction}; /// An index to a block. @@ -290,6 +291,10 @@ impl pallet_utxo::Config for Runtime { } } +impl pallet_pp::Config for Runtime { + type Event = Event; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -308,6 +313,7 @@ construct_runtime!( // Include the custom logic from the pallet-template in the runtime. TemplateModule: pallet_template::{Pallet, Call, Storage, Event}, Utxo: pallet_utxo::{Pallet, Call, Config, Storage, Event}, + Pp: pallet_pp::{Pallet, Call, Config, Storage, Event}, } ); @@ -515,6 +521,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_timestamp, Timestamp); add_benchmark!(params, batches, pallet_template, TemplateModule); add_benchmark!(params, batches, pallet_utxo, Utxo); + add_benchmark!(params, batches, pallet_pp, Pp); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) From cd3f0c51689cb90a6014ddffe44a84ab2f25d7ab Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Thu, 12 Aug 2021 14:56:32 +0300 Subject: [PATCH 02/12] Introduce ScriptPubKey This struct, part of TransactionOutput, contains all scripting related information of the transaction entry. For now, it only contains type, size and the script itself and maximum size for script is set to 10,000 bytes. --- pallets/utxo/src/lib.rs | 5 ++ pallets/utxo/src/mock.rs | 2 +- pallets/utxo/src/script.rs | 94 ++++++++++++++++++++++++++++++++++++++ pallets/utxo/src/tests.rs | 18 +++++++- 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 pallets/utxo/src/script.rs diff --git a/pallets/utxo/src/lib.rs b/pallets/utxo/src/lib.rs index 59b7fc6..aa85f26 100644 --- a/pallets/utxo/src/lib.rs +++ b/pallets/utxo/src/lib.rs @@ -17,6 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub use script::*; pub use header::*; pub use pallet::*; @@ -30,6 +31,7 @@ mod tests; mod benchmarking; mod header; +mod script; pub mod weights; #[frame_support::pallet] @@ -39,6 +41,7 @@ pub mod pallet { use serde::{Deserialize, Serialize}; use crate::{validate_header, SignatureMethod, TXOutputHeader, TXOutputHeaderImpls, TokenType}; + use crate::ScriptPubKey; use codec::{Decode, Encode}; use frame_support::{ dispatch::{DispatchResultWithPostInfo, Vec}, @@ -103,6 +106,7 @@ pub mod pallet { pub(crate) value: Value, pub(crate) pub_key: H256, pub(crate) header: TXOutputHeader, + pub(crate) script: ScriptPubKey, } impl TransactionOutput { @@ -115,6 +119,7 @@ pub mod pallet { value, pub_key, header: 0, + script: ScriptPubKey::new(), } } } diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index 7fc223e..2ea234a 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -42,7 +42,7 @@ pub const ALICE_PHRASE: &str = // BlakeHash of TransactionOutput::new(100, H256::from(alice_pub_key)) in fn new_test_ext() pub const GENESIS_UTXO: [u8; 32] = - hex!("931fe49afe365072e71771cd99e13cfb54fa28fad479e23556ff9de6a3dd19a9"); + hex!("01a9fbfde6f0584e88dcff57b5cf4fc9d538bca4e91b1945437b325af7860b3a"); // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( diff --git a/pallets/utxo/src/script.rs b/pallets/utxo/src/script.rs new file mode 100644 index 0000000..52f1f29 --- /dev/null +++ b/pallets/utxo/src/script.rs @@ -0,0 +1,94 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +use codec::{Decode, Encode}; +use frame_support::dispatch::Vec; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + +// TODO what is the limit we want to set? +const SCRIPT_MAX_SIZE: u16 = 10_000; + +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, Hash, Debug)] +pub enum ScriptType { + P2pkh = 0, +} + +impl Default for ScriptType { + fn default() -> Self { + return ScriptType::P2pkh; + } +} + +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, Debug, Hash, Default)] +pub struct ScriptPubKey { + pub(crate) stype: ScriptType, + pub(crate) size: u16, + pub(crate) script: Vec, +} + +impl ScriptPubKey { + /// Crete new ScriptPubKey which defaults to an empty script with type P2PKH + pub fn new() -> Self { + Self { + stype: ScriptType::default(), + size: 0, + script: Vec::new(), + } + } + + /// Set script and type for it + pub fn set_script(&mut self, stype: ScriptType, script: &Vec) -> Result<(), &'static str> { + if script.len() > SCRIPT_MAX_SIZE.into() { + return Err("Input script is too big!"); + } + + self.stype = stype; + self.script = script.clone(); + self.size = self.script.len() as u16; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use frame_support::{assert_err, assert_ok}; + + #[test] + fn new_script() { + let script = ScriptPubKey::new(); + assert_eq!(script.stype, ScriptType::P2pkh); + assert_eq!(script.size, 0); + assert_eq!(script.script.len(), 0); + } + + #[test] + fn edit_script() { + let mut script = ScriptPubKey::new(); + + let asm = vec![0u8; 128]; + assert_ok!(script.set_script(ScriptType::P2pkh, &asm)); + + let asm = vec![0u8; (SCRIPT_MAX_SIZE + 1).into()]; + assert_err!( + script.set_script(ScriptType::P2pkh, &asm), + "Input script is too big!" + ); + } +} diff --git a/pallets/utxo/src/tests.rs b/pallets/utxo/src/tests.rs index 583e8f4..8a0df29 100644 --- a/pallets/utxo/src/tests.rs +++ b/pallets/utxo/src/tests.rs @@ -15,7 +15,7 @@ // // Author(s): C. Yap -use crate::{mock::*, Transaction, TransactionInput, TransactionOutput, UtxoStore, Value, RewardTotal}; +use crate::{mock::*, Transaction, TransactionInput, TransactionOutput, UtxoStore, Value, RewardTotal, ScriptType}; use codec::Encode; use frame_support::{ assert_err, assert_noop, assert_ok, @@ -261,3 +261,19 @@ fn test_reward() { assert_eq!(reward, 10); }) } + +#[test] +fn test_script() { + execute_with_alice(|alice_pub_key| { + let mut tx = Transaction { + inputs: vec![tx_input_gen_no_signature()], + outputs: vec![TransactionOutput::new(90, H256::from(alice_pub_key))], + }; + + assert_ok!(tx.outputs[0].script.set_script(ScriptType::P2pkh, &Vec::new())); + + let alice_sig = crypto::sr25519_sign(SR25519, &alice_pub_key, &tx.encode()).unwrap(); + tx.inputs[0].sig_script = H512::from(alice_sig); + assert_ok!(Utxo::spend(Origin::signed(0), tx.clone())); + }) +} From 3e9bb2160ca4392424105ed48b2ead23b2e17fce Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Thu, 12 Aug 2021 15:23:20 +0300 Subject: [PATCH 03/12] Add ProgrammablePool trait to UTXO config When UTXO code encouters a transaction with a special opcode such as OP_CREATE, it dispatches the processing of that transaction to the programmable pool which is made callable for the UTXO pallet through this trait. For now, only a dummy create() function is implemented --- pallets/pp/Cargo.toml | 1 + pallets/pp/src/lib.rs | 9 +++++++++ pallets/utxo/Cargo.toml | 1 + pallets/utxo/src/lib.rs | 3 +++ pallets/utxo/src/mock.rs | 14 ++++++++++++-- runtime/src/lib.rs | 1 + traits/contract-provider/Cargo.toml | 18 ++++++++++++++++++ traits/contract-provider/src/lib.rs | 7 +++++++ 8 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 traits/contract-provider/Cargo.toml create mode 100644 traits/contract-provider/src/lib.rs diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml index d259743..c87d1be 100644 --- a/pallets/pp/Cargo.toml +++ b/pallets/pp/Cargo.toml @@ -18,6 +18,7 @@ codec = {default-features = false, features = ['derive'], package = 'parity-scal frame-benchmarking = {default-features = false, optional = true, version = '3.1.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} frame-support = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} frame-system = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +contract-provider = { default-features = false, path = "../../traits/contract-provider/" } [dev-dependencies] serde = '1.0.119' diff --git a/pallets/pp/src/lib.rs b/pallets/pp/src/lib.rs index 1345fa5..d18cd14 100644 --- a/pallets/pp/src/lib.rs +++ b/pallets/pp/src/lib.rs @@ -31,6 +31,9 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; +use frame_support::dispatch::Vec; +use contract_provider::ContractProvider; + #[frame_support::pallet] pub mod pallet { use frame_support::{dispatch::{DispatchResult}, pallet_prelude::*}; @@ -138,3 +141,9 @@ pub mod pallet { fn build(&self) {} } } + +impl ContractProvider for Pallet { + fn create(_code: &Vec) -> Result<(), &'static str> { + Ok(()) + } +} diff --git a/pallets/utxo/Cargo.toml b/pallets/utxo/Cargo.toml index 7f62abc..497d76e 100644 --- a/pallets/utxo/Cargo.toml +++ b/pallets/utxo/Cargo.toml @@ -27,6 +27,7 @@ frame-benchmarking = { default-features = false, version = '3.1.0', optional = t frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} frame-system = { default-features = false, version ='3.0.0' ,git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} sp-core = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +contract-provider = { default-features = false, path = "../../traits/contract-provider/" } [dev-dependencies] sp-consensus-aura = { version = "0.9.0", git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} diff --git a/pallets/utxo/src/lib.rs b/pallets/utxo/src/lib.rs index aa85f26..24fcadc 100644 --- a/pallets/utxo/src/lib.rs +++ b/pallets/utxo/src/lib.rs @@ -42,6 +42,7 @@ pub mod pallet { use crate::{validate_header, SignatureMethod, TXOutputHeader, TXOutputHeaderImpls, TokenType}; use crate::ScriptPubKey; + use contract_provider::ContractProvider; use codec::{Decode, Encode}; use frame_support::{ dispatch::{DispatchResultWithPostInfo, Vec}, @@ -73,6 +74,8 @@ pub mod pallet { type WeightInfo: WeightInfo; + type ProgrammablePool: ContractProvider; + fn authorities() -> Vec; } diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index 2ea234a..7d497d7 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -14,9 +14,9 @@ // limitations under the License. // // Author(s): C. Yap - use crate as pallet_utxo; use pallet_utxo::TransactionOutput; +use contract_provider::ContractProvider; use frame_support::{ parameter_types, @@ -28,7 +28,7 @@ use frame_support::{ traits::GenesisBuild, }; use sp_consensus_aura::sr25519::AuthorityId as AuraId; -use sp_core::{sp_std::vec, sr25519::Public, testing::SR25519, H256}; +use sp_core::{sp_std::{vec, marker::PhantomData}, sr25519::Public, testing::SR25519, H256}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; // need to manually import this crate since its no include by default @@ -44,6 +44,15 @@ pub const ALICE_PHRASE: &str = pub const GENESIS_UTXO: [u8; 32] = hex!("01a9fbfde6f0584e88dcff57b5cf4fc9d538bca4e91b1945437b325af7860b3a"); +// Dummy programmable pool for testing +pub struct MockPool(PhantomData); + +impl ContractProvider for MockPool { + fn create(_code: &Vec) -> Result<(), &'static str> { + Ok(()) + } +} + // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( pub enum Test where @@ -110,6 +119,7 @@ impl pallet_utxo::Config for Test { type Event = Event; type Call = Call; type WeightInfo = crate::weights::WeightInfo; + type ProgrammablePool = MockPool; fn authorities() -> Vec { Aura::authorities() diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 8e95248..5692e50 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -279,6 +279,7 @@ impl pallet_utxo::Config for Runtime { type Event = Event; type Call = Call; type WeightInfo = pallet_utxo::weights::WeightInfo; + type ProgrammablePool = pallet_pp::Pallet; fn authorities() -> Vec { Aura::authorities() diff --git a/traits/contract-provider/Cargo.toml b/traits/contract-provider/Cargo.toml new file mode 100644 index 0000000..e433d85 --- /dev/null +++ b/traits/contract-provider/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "contract-provider" +version = "3.0.0" +edition = "2018" +authors = ['Mintlayer'] +description = "Contract provider trait filled by programmable pools" +license = "MIT" + +[features] +default = ['std'] +std = [ + 'frame-support/std', + 'sp-std/std', +] + +[dependencies] +sp-std = { version = '3.0', default-features = false } +frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} diff --git a/traits/contract-provider/src/lib.rs b/traits/contract-provider/src/lib.rs new file mode 100644 index 0000000..5a5e2df --- /dev/null +++ b/traits/contract-provider/src/lib.rs @@ -0,0 +1,7 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_support::dispatch::Vec; + +pub trait ContractProvider { + fn create(code: &Vec) -> Result<(), &'static str>; +} From 826e52eaa0e636cb148df5298135eff2154e283b Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Fri, 13 Aug 2021 09:44:43 +0300 Subject: [PATCH 04/12] Add skeleton RPC API for UTXO --- node/Cargo.toml | 2 + node/src/rpc.rs | 4 ++ pallets/utxo/rpc/Cargo.toml | 21 +++++++ pallets/utxo/rpc/README.md | 3 + pallets/utxo/rpc/runtime-api/Cargo.toml | 26 +++++++++ pallets/utxo/rpc/runtime-api/src/lib.rs | 23 ++++++++ pallets/utxo/rpc/src/lib.rs | 78 +++++++++++++++++++++++++ pallets/utxo/src/lib.rs | 6 ++ runtime/Cargo.toml | 2 + runtime/src/lib.rs | 6 ++ 10 files changed, 171 insertions(+) create mode 100644 pallets/utxo/rpc/Cargo.toml create mode 100644 pallets/utxo/rpc/README.md create mode 100644 pallets/utxo/rpc/runtime-api/Cargo.toml create mode 100644 pallets/utxo/rpc/runtime-api/src/lib.rs create mode 100644 pallets/utxo/rpc/src/lib.rs diff --git a/node/Cargo.toml b/node/Cargo.toml index f000835..a0d700a 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -53,6 +53,8 @@ substrate-frame-rpc-system = {version = '3.0.0', git = 'https://github.com/parit # local dependencies node-template-runtime = {version = '3.0.0', path = '../runtime'} +pallet-utxo-rpc = { path = "../pallets/utxo/rpc" } +pallet-utxo-rpc-runtime-api = { path = "../pallets/utxo/rpc/runtime-api" } #bls_sigs_ref = {version = '0.3.0', path = '../../BLS'} [features] diff --git a/node/src/rpc.rs b/node/src/rpc.rs index c1f0e0a..753b913 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -34,11 +34,13 @@ pub fn create_full( C: Send + Sync + 'static, C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, + C::Api: pallet_utxo_rpc::UtxoRuntimeApi, C::Api: BlockBuilder, P: TransactionPool + 'static, { use substrate_frame_rpc_system::{FullSystem, SystemApi}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; + use pallet_utxo_rpc::{Utxo, UtxoApi}; let mut io = jsonrpc_core::IoHandler::default(); let FullDeps { @@ -55,6 +57,8 @@ pub fn create_full( TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())) ); + io.extend_with(UtxoApi::to_delegate(Utxo::new(client.clone()))); + // Extend this RPC with a custom API by using the following syntax. // `YourRpcStruct` should have a reference to a client, which is needed // to call into the runtime. diff --git a/pallets/utxo/rpc/Cargo.toml b/pallets/utxo/rpc/Cargo.toml new file mode 100644 index 0000000..6e40c75 --- /dev/null +++ b/pallets/utxo/rpc/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "pallet-utxo-rpc" +version = "0.1.0" +authors = ["Mintlayer"] +edition = "2018" + +[dependencies] +pallet-utxo-rpc-runtime-api = { path = "./runtime-api" } + +# General +serde = { version = "1.0.104", features = ["derive"] } +jsonrpc-core = "15.0.0" +jsonrpc-core-client = "15.0.0" +jsonrpc-derive = "15.0.0" + +sp-blockchain = { version = "3.0.0", default_features = false, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +sp-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +sp-runtime = { version = "3.0.0", default_features = false, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05' } +frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} + diff --git a/pallets/utxo/rpc/README.md b/pallets/utxo/rpc/README.md new file mode 100644 index 0000000..6766c31 --- /dev/null +++ b/pallets/utxo/rpc/README.md @@ -0,0 +1,3 @@ +# UTXO RPC interface + +TODO document calls and add examples diff --git a/pallets/utxo/rpc/runtime-api/Cargo.toml b/pallets/utxo/rpc/runtime-api/Cargo.toml new file mode 100644 index 0000000..50fb6fa --- /dev/null +++ b/pallets/utxo/rpc/runtime-api/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "pallet-utxo-rpc-runtime-api" +version = "0.1.0" +authors = ["Mintlayer"] +edition = "2018" + +[dependencies] +serde = { version = "1.0.104", optional = true, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +sp-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +sp-runtime = { version = "3.0.0", default_features = false, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05' } +frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} + +[dev-dependencies] +serde_json = "1.0.48" + +[features] +default = ["std"] +std = [ + "serde", + "sp-api/std", + "codec/std", + "sp-runtime/std", + "frame-support/std", +] +try-runtime = ['frame-support/try-runtime'] diff --git a/pallets/utxo/rpc/runtime-api/src/lib.rs b/pallets/utxo/rpc/runtime-api/src/lib.rs new file mode 100644 index 0000000..add7b4f --- /dev/null +++ b/pallets/utxo/rpc/runtime-api/src/lib.rs @@ -0,0 +1,23 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +#![cfg_attr(not(feature = "std"), no_std)] + +sp_api::decl_runtime_apis! { + pub trait UtxoApi { + fn send() -> u32; + } +} diff --git a/pallets/utxo/rpc/src/lib.rs b/pallets/utxo/rpc/src/lib.rs new file mode 100644 index 0000000..9599a7b --- /dev/null +++ b/pallets/utxo/rpc/src/lib.rs @@ -0,0 +1,78 @@ +// Copyright (c) 2021 RBB S.r.l +// opensource@mintlayer.org +// SPDX-License-Identifier: MIT +// Licensed under the MIT License; +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://spdx.org/licenses/MIT +// +// 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. +// +// Author(s): A. Altonen +use jsonrpc_core::{Error as RpcError, ErrorCode, Result}; +use jsonrpc_derive::rpc; +pub use pallet_utxo_rpc_runtime_api::{UtxoApi as UtxoRuntimeApi}; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_runtime::{generic::BlockId, traits::Block as BlockT}; +use std::sync::Arc; + +#[rpc] +pub trait UtxoApi { + #[rpc(name = "utxo_send")] + fn send(&self, at: Option) -> Result; +} + +/// A struct that implements the [`UtxoApi`]. +pub struct Utxo { + client: Arc, + _marker: std::marker::PhantomData, +} + +impl Utxo { + /// Create new `Utxo` instance with the given reference to the client. + pub fn new(client: Arc) -> Self { + Self { + client, + _marker: Default::default(), + } + } +} + +/// Error type of this RPC API. +pub enum Error { + /// The transaction was not decodable. + DecodeError = 1, + /// The call to runtime failed. + RuntimeError = 2, +} + +impl UtxoApi<::Hash> for Utxo +where + Block: BlockT, + C: Send + Sync + 'static, + C: ProvideRuntimeApi, + C: HeaderBackend, + C::Api: UtxoRuntimeApi, +{ + fn send( + &self, + at: Option<::Hash>, + ) -> Result { + let api = self.client.runtime_api(); + let at = BlockId::hash(at.unwrap_or_else(|| + // If the block hash is not supplied assume the best block. + self.client.info().best_hash)); + + api.send(&at).map_err(|e| RpcError { + code: ErrorCode::ServerError(Error::RuntimeError as i64), + message: "Unable to query dispatch info.".into(), + data: Some(format!("{:?}", e).into()), + }) + } +} diff --git a/pallets/utxo/src/lib.rs b/pallets/utxo/src/lib.rs index 24fcadc..c75ec99 100644 --- a/pallets/utxo/src/lib.rs +++ b/pallets/utxo/src/lib.rs @@ -407,3 +407,9 @@ pub mod pallet { } } } + +impl Pallet { + pub fn send() -> u32 { + 1337 + } +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d44099f..c0a36bd 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -48,6 +48,7 @@ sp-version = {default-features = false, version = '3.0.0', git = 'https://github # local dependencies pallet-template = {default-features = false, version = '3.0.0', path = '../pallets/template'} pallet-utxo = {default-features = false, path = "../pallets/utxo" } +pallet-utxo-rpc-runtime-api = {default-features = false, path = "../pallets/utxo/rpc/runtime-api" } pallet-pp = {default-features = false, path = "../pallets/pp" } [features] @@ -79,6 +80,7 @@ std = [ 'pallet-timestamp/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', + 'pallet-utxo-rpc-runtime-api/std', 'pallet-utxo/std', 'sp-api/std', 'sp-block-builder/std', diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5692e50..88543e3 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -491,6 +491,12 @@ impl_runtime_apis! { } } + impl pallet_utxo_rpc_runtime_api::UtxoApi for Runtime { + fn send() -> u32 { + Utxo::send() + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn dispatch_benchmark( From 3004f332d375fb749ebd21ccd42cd1c61d26b0dc Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Mon, 16 Aug 2021 07:49:59 +0300 Subject: [PATCH 05/12] Update node to the latest version Update node from version v3.0.0+monthly-2021-05 to v3.0.0+monthly-2021-08. This is needed because the earlier version did not have support for the latest Contracts pallet. --- node/Cargo.toml | 178 +++++++++++++--- node/src/chain_spec.rs | 14 +- node/src/rpc.rs | 3 +- node/src/service.rs | 262 ++++++++++++++---------- pallets/pp/Cargo.toml | 64 ++++-- pallets/pp/src/mock.rs | 2 +- pallets/template/Cargo.toml | 59 ++++-- pallets/template/src/mock.rs | 2 +- pallets/utxo/Cargo.toml | 71 +++++-- pallets/utxo/rpc/Cargo.toml | 40 +++- pallets/utxo/rpc/runtime-api/Cargo.toml | 34 ++- pallets/utxo/src/mock.rs | 4 +- runtime/Cargo.toml | 224 ++++++++++++++++---- runtime/src/lib.rs | 15 +- traits/contract-provider/Cargo.toml | 16 +- 15 files changed, 728 insertions(+), 260 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index a0d700a..ef9178c 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -21,41 +21,155 @@ substrate-build-script-utils = {version = '3.0.0', git = 'https://github.com/par [dependencies] jsonrpc-core = '15.1.0' structopt = '0.3.8' - -# Substrate dependencies -frame-benchmarking = {version = '3.1.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-benchmarking-cli = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-transaction-payment-rpc = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-basic-authorship = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-cli = {features = ['wasmtime'], version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-client-api = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-consensus = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-consensus-aura = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-executor = {features = ['wasmtime'], version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-finality-grandpa = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-keystore = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-rpc = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-rpc-api = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-service = {features = ['wasmtime'], version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-telemetry = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sc-transaction-pool = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-api = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-block-builder = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-blockchain = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-consensus = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-consensus-aura = {version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-core = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-finality-grandpa = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-inherents = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-runtime = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-transaction-pool = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -substrate-frame-rpc-system = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} - -# local dependencies node-template-runtime = {version = '3.0.0', path = '../runtime'} pallet-utxo-rpc = { path = "../pallets/utxo/rpc" } pallet-utxo-rpc-runtime-api = { path = "../pallets/utxo/rpc/runtime-api" } -#bls_sigs_ref = {version = '0.3.0', path = '../../BLS'} + +[dependencies.frame-benchmarking] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-benchmarking-cli] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-transaction-payment-rpc] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sc-basic-authorship] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-cli] +features = ['wasmtime'] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-client-api] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sc-consensus] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-consensus-aura] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-executor] +features = ['wasmtime'] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-finality-grandpa] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-keystore] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sc-rpc] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sc-rpc-api] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-service] +features = ['wasmtime'] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sc-telemetry] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sc-transaction-pool] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sc-transaction-pool-api] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-api] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-block-builder] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-blockchain] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-consensus] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sp-consensus-aura] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sp-core] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-finality-grandpa] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-inherents] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-runtime] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-timestamp] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.substrate-frame-rpc-system] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +# local dependencies +# bls_sigs_ref = {version = '0.3.0', path = '../../BLS'} [features] default = [] diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index b32e6e9..4a160ae 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -155,30 +155,30 @@ fn testnet_genesis( }).unwrap(); GenesisConfig { - frame_system: SystemConfig { + system: SystemConfig { // Add Wasm runtime to storage. code: wasm_binary.to_vec(), changes_trie_config: Default::default(), }, - pallet_balances: BalancesConfig { + balances: BalancesConfig { // Configure endowed accounts with initial balance of 1 << 60. balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(), }, - pallet_aura: AuraConfig { + aura: AuraConfig { authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), }, - pallet_grandpa: GrandpaConfig { + grandpa: GrandpaConfig { authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), }, - pallet_sudo: SudoConfig { + sudo: SudoConfig { // Assign network admin rights. key: root_key, }, - pallet_utxo: UtxoConfig { + utxo: UtxoConfig { genesis_utxos: vec![genesis], _marker: Default::default() }, - pallet_pp: PpConfig { + pp: PpConfig { _marker: Default::default() } } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 753b913..48be878 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -12,8 +12,7 @@ use sp_api::ProvideRuntimeApi; use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend}; use sp_block_builder::BlockBuilder; pub use sc_rpc_api::DenyUnsafe; -use sp_transaction_pool::TransactionPool; - +use sc_transaction_pool_api::TransactionPool; /// Full client dependencies. pub struct FullDeps { diff --git a/node/src/service.rs b/node/src/service.rs index 197a495..dbdb307 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,18 +1,17 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. -use std::sync::Arc; -use std::time::Duration; -use sc_client_api::{ExecutorProvider, RemoteBackend}; use node_template_runtime::{self, opaque::Block, RuntimeApi}; -use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; -use sp_inherents::InherentDataProviders; +use sc_client_api::{ExecutorProvider, RemoteBackend}; +use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; use sc_executor::native_executor_instance; pub use sc_executor::NativeExecutor; -use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; -use sc_consensus_aura::{ImportQueueParams, StartAuraParams, SlotProportion}; use sc_finality_grandpa::SharedVoterState; use sc_keystore::LocalKeystore; +use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; +use sp_consensus::SlotData; +use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; +use std::{sync::Arc, time::Duration}; // Our native executor instance. native_executor_instance!( @@ -26,28 +25,35 @@ type FullClient = sc_service::TFullClient; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; -pub fn new_partial(config: &Configuration) -> Result, - sc_transaction_pool::FullPool, - ( - sc_consensus_aura::AuraBlockImport< - Block, - FullClient, - sc_finality_grandpa::GrandpaBlockImport, - AuraPair - >, - sc_finality_grandpa::LinkHalf, - Option, - ) ->, ServiceError> { +pub fn new_partial( + config: &Configuration, +) -> Result< + sc_service::PartialComponents< + FullClient, + FullBackend, + FullSelectChain, + sc_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool, + ( + sc_finality_grandpa::GrandpaBlockImport< + FullBackend, + Block, + FullClient, + FullSelectChain, + >, + sc_finality_grandpa::LinkHalf, + Option, + ), + >, + ServiceError, +> { if config.keystore_remote.is_some() { - return Err(ServiceError::Other( - format!("Remote Keystores are not supported."))) + return Err(ServiceError::Other(format!("Remote Keystores are not supported."))) } - let inherent_data_providers = InherentDataProviders::new(); - let telemetry = config.telemetry_endpoints.clone() + let telemetry = config + .telemetry_endpoints + .clone() .filter(|x| !x.is_empty()) .map(|endpoints| -> Result<_, sc_telemetry::Error> { let worker = TelemetryWorker::new(16)?; @@ -63,11 +69,10 @@ pub fn new_partial(config: &Configuration) -> Result Result Result::new( - grandpa_block_import.clone(), client.clone(), - ); + let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration(); - let import_queue = sc_consensus_aura::import_queue::( - ImportQueueParams { - block_import: aura_block_import.clone(), + let import_queue = + sc_consensus_aura::import_queue::(ImportQueueParams { + block_import: grandpa_block_import.clone(), justification_import: Some(Box::new(grandpa_block_import.clone())), client: client.clone(), - inherent_data_providers: inherent_data_providers.clone(), + create_inherent_data_providers: move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + slot_duration, + ); + + Ok((timestamp, slot)) + }, spawner: &task_manager.spawn_essential_handle(), - can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()), - slot_duration: sc_consensus_aura::slot_duration(&*client)?, + can_author_with: sp_consensus::CanAuthorWithNativeVersion::new( + client.executor().clone(), + ), registry: config.prometheus_registry(), check_for_equivocation: Default::default(), telemetry: telemetry.as_ref().map(|x| x.handle()), - }, - )?; + })?; Ok(sc_service::PartialComponents { client, @@ -113,8 +126,7 @@ pub fn new_partial(config: &Configuration) -> Result Result mut keystore_container, select_chain, transaction_pool, - inherent_data_providers, other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; if let Some(url) = &config.keystore_remote { match remote_keystore(url) { Ok(k) => keystore_container.set_remote_keystore(k), - Err(e) => { - return Err(ServiceError::Other( - format!("Error hooking up remote keystore for {}: {}", url, e))) - } + Err(e) => + return Err(ServiceError::Other(format!( + "Error hooking up remote keystore for {}: {}", + url, e + ))), }; } config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); - let (network, network_status_sinks, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -164,7 +176,10 @@ pub fn new_full(mut config: Configuration) -> Result if config.offchain_worker.enabled { sc_service::build_offchain_workers( - &config, task_manager.spawn_handle(), client.clone(), network.clone(), + &config, + task_manager.spawn_handle(), + client.clone(), + network.clone(), ); } @@ -180,33 +195,27 @@ pub fn new_full(mut config: Configuration) -> Result let pool = transaction_pool.clone(); Box::new(move |deny_unsafe, _| { - let deps = crate::rpc::FullDeps { - client: client.clone(), - pool: pool.clone(), - deny_unsafe, - }; + let deps = + crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe }; crate::rpc::create_full(deps) }) }; - let _rpc_handlers = sc_service::spawn_tasks( - sc_service::SpawnTasksParams { - network: network.clone(), - client: client.clone(), - keystore: keystore_container.sync_keystore(), - task_manager: &mut task_manager, - transaction_pool: transaction_pool.clone(), - rpc_extensions_builder, - on_demand: None, - remote_blockchain: None, - backend, - network_status_sinks, - system_rpc_tx, - config, - telemetry: telemetry.as_mut(), - }, - )?; + let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { + network: network.clone(), + client: client.clone(), + keystore: keystore_container.sync_keystore(), + task_manager: &mut task_manager, + transaction_pool: transaction_pool.clone(), + rpc_extensions_builder, + on_demand: None, + remote_blockchain: None, + backend, + system_rpc_tx, + config, + telemetry: telemetry.as_mut(), + })?; if role.is_authority() { let proposer_factory = sc_basic_authorship::ProposerFactory::new( @@ -220,20 +229,35 @@ pub fn new_full(mut config: Configuration) -> Result let can_author_with = sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()); - let aura = sc_consensus_aura::start_aura::( + let slot_duration = sc_consensus_aura::slot_duration(&*client)?; + let raw_slot_duration = slot_duration.slot_duration(); + + let aura = sc_consensus_aura::start_aura::( StartAuraParams { - slot_duration: sc_consensus_aura::slot_duration(&*client)?, + slot_duration, client: client.clone(), select_chain, block_import, proposer_factory, - inherent_data_providers: inherent_data_providers.clone(), + create_inherent_data_providers: move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + raw_slot_duration, + ); + + Ok((timestamp, slot)) + }, force_authoring, backoff_authoring_blocks, keystore: keystore_container.sync_keystore(), can_author_with, sync_oracle: network.clone(), + justification_sync_link: network.clone(), block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32), + max_block_proposal_slot_portion: None, telemetry: telemetry.as_ref().map(|x| x.handle()), }, )?; @@ -245,11 +269,8 @@ pub fn new_full(mut config: Configuration) -> Result // if the node isn't actively participating in consensus then it doesn't // need a keystore, regardless of which protocol we use below. - let keystore = if role.is_authority() { - Some(keystore_container.sync_keystore()) - } else { - None - }; + let keystore = + if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; let grandpa_config = sc_finality_grandpa::Config { // FIXME #1578 make this available through chainspec @@ -258,7 +279,7 @@ pub fn new_full(mut config: Configuration) -> Result name: Some(name), observer_enabled: false, keystore, - is_authority: role.is_authority(), + local_role: role, telemetry: telemetry.as_ref().map(|x| x.handle()), }; @@ -283,7 +304,7 @@ pub fn new_full(mut config: Configuration) -> Result // if it fails we take down the service with it. task_manager.spawn_essential_handle().spawn_blocking( "grandpa-voter", - sc_finality_grandpa::run_grandpa_voter(grandpa_config)? + sc_finality_grandpa::run_grandpa_voter(grandpa_config)?, ); } @@ -293,7 +314,9 @@ pub fn new_full(mut config: Configuration) -> Result /// Builds a new service for a light client. pub fn new_light(mut config: Configuration) -> Result { - let telemetry = config.telemetry_endpoints.clone() + let telemetry = config + .telemetry_endpoints + .clone() .filter(|x| !x.is_empty()) .map(|endpoints| -> Result<_, sc_telemetry::Error> { let worker = TelemetryWorker::new(16)?; @@ -308,11 +331,10 @@ pub fn new_light(mut config: Configuration) -> Result telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), )?; - let mut telemetry = telemetry - .map(|(worker, telemetry)| { - task_manager.spawn_handle().spawn("telemetry", worker.run()); - telemetry - }); + let mut telemetry = telemetry.map(|(worker, telemetry)| { + task_manager.spawn_handle().spawn("telemetry", worker.run()); + telemetry + }); config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); @@ -321,39 +343,44 @@ pub fn new_light(mut config: Configuration) -> Result let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light( config.transaction_pool.clone(), config.prometheus_registry(), - task_manager.spawn_handle(), + task_manager.spawn_essential_handle(), client.clone(), on_demand.clone(), )); - let (grandpa_block_import, _) = sc_finality_grandpa::block_import( + let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import( client.clone(), &(client.clone() as Arc<_>), select_chain.clone(), telemetry.as_ref().map(|x| x.handle()), )?; - let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new( - grandpa_block_import.clone(), - client.clone(), - ); + let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration(); - let import_queue = sc_consensus_aura::import_queue::( - ImportQueueParams { - block_import: aura_block_import.clone(), + let import_queue = + sc_consensus_aura::import_queue::(ImportQueueParams { + block_import: grandpa_block_import.clone(), justification_import: Some(Box::new(grandpa_block_import.clone())), client: client.clone(), - inherent_data_providers: InherentDataProviders::new(), + create_inherent_data_providers: move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( + *timestamp, + slot_duration, + ); + + Ok((timestamp, slot)) + }, spawner: &task_manager.spawn_essential_handle(), can_author_with: sp_consensus::NeverCanAuthor, - slot_duration: sc_consensus_aura::slot_duration(&*client)?, registry: config.prometheus_registry(), check_for_equivocation: Default::default(), telemetry: telemetry.as_ref().map(|x| x.handle()), - }, - )?; + })?; - let (network, network_status_sinks, system_rpc_tx, network_starter) = + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -366,7 +393,30 @@ pub fn new_light(mut config: Configuration) -> Result if config.offchain_worker.enabled { sc_service::build_offchain_workers( - &config, task_manager.spawn_handle(), client.clone(), network.clone(), + &config, + task_manager.spawn_handle(), + client.clone(), + network.clone(), + ); + } + + let enable_grandpa = !config.disable_grandpa; + if enable_grandpa { + let name = config.network.node_name.clone(); + + let config = sc_finality_grandpa::Config { + gossip_duration: std::time::Duration::from_millis(333), + justification_period: 512, + name: Some(name), + observer_enabled: false, + keystore: None, + local_role: config.role.clone(), + telemetry: telemetry.as_ref().map(|x| x.handle()), + }; + + task_manager.spawn_handle().spawn_blocking( + "grandpa-observer", + sc_finality_grandpa::run_grandpa_observer(config, grandpa_link, network.clone())?, ); } @@ -381,12 +431,10 @@ pub fn new_light(mut config: Configuration) -> Result keystore: keystore_container.sync_keystore(), backend, network, - network_status_sinks, system_rpc_tx, telemetry: telemetry.as_mut(), })?; network_starter.start_network(); - Ok(task_manager) } diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml index c87d1be..aadb948 100644 --- a/pallets/pp/Cargo.toml +++ b/pallets/pp/Cargo.toml @@ -10,21 +10,55 @@ version = '3.0.0' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] -[dependencies] -# external dependencies -codec = {default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0'} - -# Substrate dependencies -frame-benchmarking = {default-features = false, optional = true, version = '3.1.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-support = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-system = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -contract-provider = { default-features = false, path = "../../traits/contract-provider/" } - -[dev-dependencies] -serde = '1.0.119' -sp-core = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-io = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-runtime = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies.contract-provider] +default-features = false +path = "../../traits/contract-provider/" + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.serde] +version = '1.0.126' + +[dev-dependencies.sp-io] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' [features] default = ['std'] diff --git a/pallets/pp/src/mock.rs b/pallets/pp/src/mock.rs index b9d81af..4ba53ea 100644 --- a/pallets/pp/src/mock.rs +++ b/pallets/pp/src/mock.rs @@ -43,7 +43,7 @@ parameter_types! { } impl system::Config for Test { - type BaseCallFilter = (); + type BaseCallFilter = frame_support::traits::AllowAll; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/pallets/template/Cargo.toml b/pallets/template/Cargo.toml index 688415c..4b3a7ad 100644 --- a/pallets/template/Cargo.toml +++ b/pallets/template/Cargo.toml @@ -12,20 +12,51 @@ version = '3.0.0' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] -[dependencies] -# external dependencies -codec = {default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0'} - -# Substrate dependencies -frame-benchmarking = {default-features = false, optional = true, version = '3.1.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-support = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-system = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} - -[dev-dependencies] -serde = '1.0.119' -sp-core = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-io = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-runtime = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.serde] +version = '1.0.126' + +[dev-dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.sp-io] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' [features] default = ['std'] diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs index 8719bcb..9bea61d 100644 --- a/pallets/template/src/mock.rs +++ b/pallets/template/src/mock.rs @@ -27,7 +27,7 @@ parameter_types! { } impl system::Config for Test { - type BaseCallFilter = (); + type BaseCallFilter = frame_support::traits::AllowAll; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/pallets/utxo/Cargo.toml b/pallets/utxo/Cargo.toml index 497d76e..a0ce275 100644 --- a/pallets/utxo/Cargo.toml +++ b/pallets/utxo/Cargo.toml @@ -15,22 +15,65 @@ std = [ 'sp-core/std' ] - [dependencies] -codec = {default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0'} hex-literal = "0.2.1" log = "0.4.8" serde = '1.0.119' -# Substrate dependencies -frame-benchmarking = { default-features = false, version = '3.1.0', optional = true, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-system = { default-features = false, version ='3.0.0' ,git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-core = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -contract-provider = { default-features = false, path = "../../traits/contract-provider/" } - -[dev-dependencies] -sp-consensus-aura = { version = "0.9.0", git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-keystore = { version = "0.9.0", git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-aura = { version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-timestamp = { version = "3.0.0", git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies.contract-provider] +default-features = false +path = "../../traits/contract-provider/" + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.sp-keystore] +version = "0.10.0-dev" +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' + +[dev-dependencies.pallet-aura] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dev-dependencies.sp-consensus-aura] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dev-dependencies.pallet-timestamp] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' diff --git a/pallets/utxo/rpc/Cargo.toml b/pallets/utxo/rpc/Cargo.toml index 6e40c75..ae2b7d5 100644 --- a/pallets/utxo/rpc/Cargo.toml +++ b/pallets/utxo/rpc/Cargo.toml @@ -6,16 +6,40 @@ edition = "2018" [dependencies] pallet-utxo-rpc-runtime-api = { path = "./runtime-api" } - -# General -serde = { version = "1.0.104", features = ["derive"] } jsonrpc-core = "15.0.0" jsonrpc-core-client = "15.0.0" jsonrpc-derive = "15.0.0" -sp-blockchain = { version = "3.0.0", default_features = false, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } -sp-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-runtime = { version = "3.0.0", default_features = false, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05' } -frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +[dependencies.serde] +version = "1.0.104" +features = ["derive"] + +[dependencies.sp-blockchain] +default_features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.codec] +package = "parity-scale-codec" +version = "2.0.0" +default-features = false +features = ["derive"] + +[dependencies.sp-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' diff --git a/pallets/utxo/rpc/runtime-api/Cargo.toml b/pallets/utxo/rpc/runtime-api/Cargo.toml index 50fb6fa..067951e 100644 --- a/pallets/utxo/rpc/runtime-api/Cargo.toml +++ b/pallets/utxo/rpc/runtime-api/Cargo.toml @@ -4,12 +4,34 @@ version = "0.1.0" authors = ["Mintlayer"] edition = "2018" -[dependencies] -serde = { version = "1.0.104", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } -sp-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-runtime = { version = "3.0.0", default_features = false, git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05' } -frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +[dependencies.serde] +version = "1.0.104" +optional = true +features = ["derive"] + +[dependencies.codec] +package = "parity-scale-codec" +version = "2.0.0" +default-features = false +features = ["derive"] + +[dependencies.sp-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' [dev-dependencies] serde_json = "1.0.48" diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index 7d497d7..d76c9d8 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -63,7 +63,7 @@ frame_support::construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Utxo: pallet_utxo::{Pallet, Call, Config, Storage, Event}, - Aura: pallet_aura::{Pallet, Call, Config, Storage}, + Aura: pallet_aura::{Pallet, Config, Storage}, } ); @@ -78,7 +78,7 @@ parameter_types! { } impl frame_system::Config for Test { - type BaseCallFilter = (); + type BaseCallFilter = frame_support::traits::AllowAll; type BlockWeights = (); type BlockLength = (); type Origin = Origin; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index c0a36bd..0cf38e8 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -10,46 +10,190 @@ version = '3.0.0' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] -[build-dependencies] -substrate-wasm-builder={version = '4.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} - -[dependencies] -# external dependencies -codec = {default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '2.0.0'} -hex-literal= {optional = true, version = '0.3.1'} - -# Substrate dependencies -frame-benchmarking = {default-features = false, optional = true, version = '3.1.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-executive = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-support = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-system = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-system-benchmarking = {default-features = false, optional = true, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -frame-system-rpc-runtime-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-aura = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-balances = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-grandpa = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-randomness-collective-flip = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-sudo = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-timestamp = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-transaction-payment = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -pallet-transaction-payment-rpc-runtime-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-api = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-block-builder = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-consensus-aura = {default-features = false, version = '0.9.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-core = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-inherents = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-offchain = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-runtime = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-session = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-std = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-transaction-pool = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} -sp-version = {default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} - -# local dependencies -pallet-template = {default-features = false, version = '3.0.0', path = '../pallets/template'} -pallet-utxo = {default-features = false, path = "../pallets/utxo" } -pallet-utxo-rpc-runtime-api = {default-features = false, path = "../pallets/utxo/rpc/runtime-api" } -pallet-pp = {default-features = false, path = "../pallets/pp" } +[build-dependencies.substrate-wasm-builder] +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '5.0.0-dev' + +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-executive] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system-rpc-runtime-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.hex-literal] +optional = true +version = '0.3.1' + +[dependencies.pallet-aura] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-balances] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-grandpa] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-randomness-collective-flip] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-sudo] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-timestamp] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-transaction-payment] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-transaction-payment-rpc-runtime-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-block-builder] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-consensus-aura] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '0.10.0-dev' + +[dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-inherents] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-offchain] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-session] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-transaction-pool] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-version] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +# Local dependencies +[dependencies.pallet-template] +default-features = false +version = '3.0.0' +path = '../pallets/template' + +[dependencies.pallet-utxo] +default-features = false +path = "../pallets/utxo" + +[dependencies.pallet-utxo-rpc-runtime-api] +default-features = false +path = "../pallets/utxo/rpc/runtime-api" + +[dependencies.pallet-pp] +default-features = false +path = "../pallets/pp" [features] default = ['std'] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 88543e3..09f37f6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -153,7 +153,7 @@ parameter_types! { impl frame_system::Config for Runtime { /// The basic call filter to use in dispatchable. - type BaseCallFilter = (); + type BaseCallFilter = frame_support::traits::AllowAll; /// Block & extrinsics weights: base values and limits. type BlockWeights = BlockWeights; /// The maximum length of a block (in bytes). @@ -252,6 +252,8 @@ impl pallet_balances::Config for Runtime { type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; } parameter_types! { @@ -296,6 +298,8 @@ impl pallet_pp::Config for Runtime { type Event = Event; } +impl pallet_randomness_collective_flip::Config for Runtime {} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -304,7 +308,7 @@ construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: frame_system::{Pallet, Call, Config, Storage, Event}, - RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Aura: pallet_aura::{Pallet, Config}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, @@ -391,16 +395,13 @@ impl_runtime_apis! { ) -> sp_inherents::CheckInherentsResult { data.check_extrinsics(&block) } - - fn random_seed() -> ::Hash { - RandomnessCollectiveFlip::random_seed().0 - } } impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { fn validate_transaction( source: TransactionSource, tx: ::Extrinsic, + block_hash: ::Hash, ) -> TransactionValidity { if let Some(pallet_utxo::Call::spend(ref tx)) = IsSubType::>::is_sub_type(&tx.function) { @@ -412,7 +413,7 @@ impl_runtime_apis! { } } - Executive::validate_transaction(source, tx) + Executive::validate_transaction(source, tx, block_hash) } } diff --git a/traits/contract-provider/Cargo.toml b/traits/contract-provider/Cargo.toml index e433d85..16188f6 100644 --- a/traits/contract-provider/Cargo.toml +++ b/traits/contract-provider/Cargo.toml @@ -6,13 +6,21 @@ authors = ['Mintlayer'] description = "Contract provider trait filled by programmable pools" license = "MIT" +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + [features] default = ['std'] std = [ 'frame-support/std', 'sp-std/std', ] - -[dependencies] -sp-std = { version = '3.0', default-features = false } -frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} From 29d9786c163d6dd17473d5df6b0bdb9cfb20da94 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Wed, 18 Aug 2021 16:45:22 +0300 Subject: [PATCH 06/12] Add Contracts pallet to core --- node/Cargo.toml | 12 +++++ node/src/rpc.rs | 5 +- pallets/pp/Cargo.toml | 20 ++++++++ runtime/Cargo.toml | 20 ++++++++ runtime/src/lib.rs | 113 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 168 insertions(+), 2 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index ef9178c..f7208f7 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -168,6 +168,18 @@ git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '4.0.0-dev' +[dependencies.pallet-contracts] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-contracts-rpc] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + # local dependencies # bls_sigs_ref = {version = '0.3.0', path = '../../BLS'} diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 48be878..119a3bd 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -7,7 +7,7 @@ use std::sync::Arc; -use node_template_runtime::{opaque::Block, AccountId, Balance, Index}; +use node_template_runtime::{opaque::Block, AccountId, Balance, Index, BlockNumber, Hash}; use sp_api::ProvideRuntimeApi; use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend}; use sp_block_builder::BlockBuilder; @@ -34,12 +34,14 @@ pub fn create_full( C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: pallet_utxo_rpc::UtxoRuntimeApi, + C::Api: pallet_contracts_rpc::ContractsRuntimeApi, C::Api: BlockBuilder, P: TransactionPool + 'static, { use substrate_frame_rpc_system::{FullSystem, SystemApi}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; use pallet_utxo_rpc::{Utxo, UtxoApi}; + use pallet_contracts_rpc::{Contracts, ContractsApi}; let mut io = jsonrpc_core::IoHandler::default(); let FullDeps { @@ -57,6 +59,7 @@ pub fn create_full( ); io.extend_with(UtxoApi::to_delegate(Utxo::new(client.clone()))); + io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone()))); // Extend this RPC with a custom API by using the following syntax. // `YourRpcStruct` should have a reference to a client, which is needed diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml index aadb948..5de48ed 100644 --- a/pallets/pp/Cargo.toml +++ b/pallets/pp/Cargo.toml @@ -39,6 +39,24 @@ git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '4.0.0-dev' +[dependencies.pallet-contracts] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-contracts-primitives] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + [dev-dependencies.serde] version = '1.0.126' @@ -68,5 +86,7 @@ std = [ 'frame-support/std', 'frame-system/std', 'frame-benchmarking/std', + 'pallet-contracts/std', + 'pallet-contracts-primitives/std', ] try-runtime = ['frame-support/try-runtime'] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 0cf38e8..d383f11 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -178,6 +178,24 @@ tag = 'monthly-2021-08' version = '4.0.0-dev' # Local dependencies +[dependencies.pallet-contracts] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-contracts-primitives] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.pallet-contracts-rpc-runtime-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + [dependencies.pallet-template] default-features = false version = '3.0.0' @@ -226,6 +244,8 @@ std = [ 'pallet-transaction-payment/std', 'pallet-utxo-rpc-runtime-api/std', 'pallet-utxo/std', + 'pallet-contracts/std', + 'pallet-contracts-primitives/std', 'sp-api/std', 'sp-block-builder/std', 'sp-consensus-aura/std', diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 09f37f6..f03da02 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -31,13 +31,14 @@ pub use pallet_balances::Call as BalancesCall; pub use sp_runtime::{Permill, Perbill}; pub use frame_support::{ construct_runtime, parameter_types, StorageValue, - traits::{KeyOwnerProofSystem, Randomness, IsSubType}, + traits::{KeyOwnerProofSystem, Randomness, IsSubType, DenyAll}, weights::{ Weight, IdentityFee, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, }, }; use pallet_transaction_payment::CurrencyAdapter; +use pallet_contracts::weights::WeightInfo; /// Import the template pallet. pub use pallet_template; @@ -127,6 +128,18 @@ pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; +pub const MILLICENTS: Balance = 1_000_000_000; +pub const CENTS: Balance = 1_000 * MILLICENTS; +pub const DOLLARS: Balance = 100 * CENTS; + +const fn deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS +} + +/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers. +/// This is used to limit the maximal weight of a single extrinsic. +const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); + /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { @@ -300,6 +313,61 @@ impl pallet_pp::Config for Runtime { impl pallet_randomness_collective_flip::Config for Runtime {} +parameter_types! { + pub TombstoneDeposit: Balance = deposit( + 1, + >::contract_info_size() + ); + pub DepositPerContract: Balance = TombstoneDeposit::get(); + pub const DepositPerStorageByte: Balance = deposit(0, 1); + pub const DepositPerStorageItem: Balance = deposit(1, 0); + pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS); + pub const SurchargeReward: Balance = 150 * MILLICENTS; + pub const SignedClaimHandicap: u32 = 2; + pub const MaxValueSize: u32 = 16 * 1024; + // The lazy deletion runs inside on_initialize. + pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * + BlockWeights::get().max_block; + // The weight needed for decoding the queue should be less or equal than a fifth + // of the overall weight dedicated to the lazy deletion. + pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( + ::WeightInfo::on_initialize_per_queue_item(1) - + ::WeightInfo::on_initialize_per_queue_item(0) + )) / 5) as u32; + + pub Schedule: pallet_contracts::Schedule = Default::default(); +} + +impl pallet_contracts::Config for Runtime { + type Time = Timestamp; + type Randomness = RandomnessCollectiveFlip; + type Currency = Balances; + type Event = Event; + type RentPayment = (); + type SignedClaimHandicap = SignedClaimHandicap; + type TombstoneDeposit = TombstoneDeposit; + type DepositPerContract = DepositPerContract; + type DepositPerStorageByte = DepositPerStorageByte; + type DepositPerStorageItem = DepositPerStorageItem; + type RentFraction = RentFraction; + type SurchargeReward = SurchargeReward; + type WeightPrice = pallet_transaction_payment::Pallet; + type WeightInfo = pallet_contracts::weights::SubstrateWeight; + type ChainExtension = (); + type DeletionQueueDepth = DeletionQueueDepth; + type DeletionWeightLimit = DeletionWeightLimit; + type Call = Call; + /// The safest default is to allow no calls at all. + /// + /// Runtimes should whitelist dispatchables that are allowed to be called from contracts + /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to + /// change because that would break already deployed contracts. The `Call` structure itself + /// is not allowed to change the indices of existing pallets, too. + type CallFilter = DenyAll; + type Schedule = Schedule; + type CallStack = [pallet_contracts::Frame; 31]; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -319,6 +387,7 @@ construct_runtime!( TemplateModule: pallet_template::{Pallet, Call, Storage, Event}, Utxo: pallet_utxo::{Pallet, Call, Config, Storage, Event}, Pp: pallet_pp::{Pallet, Call, Config, Storage, Event}, + Contracts: pallet_contracts::{Pallet, Call, Storage, Event}, } ); @@ -498,6 +567,48 @@ impl_runtime_apis! { } } + impl pallet_contracts_rpc_runtime_api::ContractsApi< + Block, AccountId, Balance, BlockNumber, Hash + > for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: u64, + input_data: Vec, + ) -> pallet_contracts_primitives::ContractExecResult { + let debug = true; + Contracts::bare_call(origin, dest, value, gas_limit, input_data, debug) + } + + fn instantiate( + origin: AccountId, + endowment: Balance, + gas_limit: u64, + code: pallet_contracts_primitives::Code, + data: Vec, + salt: Vec, + ) -> pallet_contracts_primitives::ContractInstantiateResult { + let compute_rent_projection = true; + let debug = true; + Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, compute_rent_projection, debug) + } + + fn get_storage( + address: AccountId, + key: [u8; 32], + ) -> pallet_contracts_primitives::GetStorageResult { + Contracts::get_storage(address, key) + } + + fn rent_projection( + address: AccountId, + ) -> pallet_contracts_primitives::RentProjectionResult { + Contracts::rent_projection(address) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn dispatch_benchmark( From 95ec7f3fd0018c73338162c6f4eb74dc4db8f31b Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Wed, 18 Aug 2021 16:21:21 +0300 Subject: [PATCH 07/12] Implement OP_CREATE and OP_CALL opcodes --- pallets/pp/Cargo.toml | 3 + pallets/pp/src/lib.rs | 55 ++- pallets/pp/src/mock.rs | 169 ++++++--- pallets/pp/src/tests.rs | 42 +-- pallets/utxo/Cargo.toml | 6 + pallets/utxo/src/lib.rs | 524 +++++++++++++++------------- pallets/utxo/src/mock.rs | 18 +- pallets/utxo/src/script.rs | 5 +- traits/contract-provider/Cargo.toml | 12 + traits/contract-provider/src/lib.rs | 17 +- 10 files changed, 525 insertions(+), 326 deletions(-) diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml index 5de48ed..2181c00 100644 --- a/pallets/pp/Cargo.toml +++ b/pallets/pp/Cargo.toml @@ -10,6 +10,9 @@ version = '3.0.0' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] +[dependencies] +log = "0.4.8" + [dependencies.codec] default-features = false features = ['derive'] diff --git a/pallets/pp/src/lib.rs b/pallets/pp/src/lib.rs index d18cd14..535623d 100644 --- a/pallets/pp/src/lib.rs +++ b/pallets/pp/src/lib.rs @@ -31,8 +31,12 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; -use frame_support::dispatch::Vec; +use frame_support::{ + dispatch::Vec, + weights::Weight, +}; use contract_provider::ContractProvider; +use sp_core::{crypto::UncheckedFrom, Bytes}; #[frame_support::pallet] pub mod pallet { @@ -41,7 +45,7 @@ pub mod pallet { /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: frame_system::Config { + pub trait Config: frame_system::Config + pallet_contracts::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type Event: From> + IsType<::Event>; } @@ -142,8 +146,51 @@ pub mod pallet { } } -impl ContractProvider for Pallet { - fn create(_code: &Vec) -> Result<(), &'static str> { +impl ContractProvider for Pallet +where + T::AccountId: UncheckedFrom + AsRef<[u8]>, +{ + type AccountId = T::AccountId; + + fn create( + caller: &T::AccountId, + gas_limit: Weight, + code: &Vec + ) -> Result<(), &'static str> { + let code = pallet_contracts_primitives::Code::Upload(Bytes(code.to_vec())); + let endowment = pallet_contracts::Pallet::::subsistence_threshold(); + + let _ = pallet_contracts::Pallet::::bare_instantiate( + caller.clone(), + endowment * 100_u32.into(), // TODO + gas_limit, + code, + Vec::new(), + Vec::new(), + false, + true, + ); + + Ok(()) + } + + fn call( + caller: &T::AccountId, + dest: &T::AccountId, + gas_limit: Weight, + input_data: &Vec, + ) -> Result<(), &'static str> { + let value = pallet_contracts::Pallet::::subsistence_threshold(); + + let _ = pallet_contracts::Pallet::::bare_call( + caller.clone(), + dest.clone(), + value, // TODO + gas_limit, + input_data.to_vec(), + true, + ); + Ok(()) } } diff --git a/pallets/pp/src/mock.rs b/pallets/pp/src/mock.rs index 4ba53ea..7d16fad 100644 --- a/pallets/pp/src/mock.rs +++ b/pallets/pp/src/mock.rs @@ -14,65 +14,122 @@ // limitations under the License. // // Author(s): A. Altonen -use crate as pallet_pp; -use sp_core::H256; -use frame_support::parameter_types; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, testing::Header, -}; -use frame_system as system; +// use crate as pallet_pp; +// use sp_core::H256; +// use frame_support::parameter_types; +// use sp_runtime::{ +// traits::{BlakeTwo256, IdentityLookup}, testing::Header, +// }; +// use frame_system as system; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; +// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +// type Block = frame_system::mocking::MockBlock; -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - PpModule: pallet_pp::{Pallet, Call, Storage, Event}, - } -); +// // Configure a mock runtime to test the pallet. +// frame_support::construct_runtime!( +// pub enum Test where +// Block = Block, +// NodeBlock = Block, +// UncheckedExtrinsic = UncheckedExtrinsic, +// { +// System: frame_system::{Pallet, Call, Config, Storage, Event}, +// PpModule: pallet_pp::{Pallet, Call, Storage, Event}, +// } +// ); -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; -} +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// pub const SS58Prefix: u8 = 42; +// } -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::AllowAll; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Call = Call; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); -} +// impl system::Config for Test { +// type BaseCallFilter = frame_support::traits::AllowAll; +// type BlockWeights = (); +// type BlockLength = (); +// type DbWeight = (); +// type Origin = Origin; +// type Call = Call; +// type Index = u64; +// type BlockNumber = u64; +// type Hash = H256; +// type Hashing = BlakeTwo256; +// type AccountId = u64; +// type Lookup = IdentityLookup; +// type Header = Header; +// type Event = Event; +// type BlockHashCount = BlockHashCount; +// type Version = (); +// type PalletInfo = PalletInfo; +// type AccountData = (); +// type OnNewAccount = (); +// type OnKilledAccount = (); +// type SystemWeightInfo = (); +// type SS58Prefix = SS58Prefix; +// type OnSetCode = (); +// } -impl pallet_pp::Config for Test { - type Event = Event; -} +// impl pallet_pp::Config for Test { +// type Event = Event; +// } -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default().build_storage::().unwrap().into() -} +// parameter_types! { +// pub TombstoneDeposit: Balance = deposit( +// 1, +// >::contract_info_size() +// ); +// pub DepositPerContract: Balance = TombstoneDeposit::get(); +// pub const DepositPerStorageByte: Balance = deposit(0, 1); +// pub const DepositPerStorageItem: Balance = deposit(1, 0); +// pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS); +// pub const SurchargeReward: Balance = 150 * MILLICENTS; +// pub const SignedClaimHandicap: u32 = 2; +// pub const MaxValueSize: u32 = 16 * 1024; + +// // The lazy deletion runs inside on_initialize. +// pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * +// BlockWeights::get().max_block; + +// // The weight needed for decoding the queue should be less or equal than a fifth +// // of the overall weight dedicated to the lazy deletion. +// pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( +// ::WeightInfo::on_initialize_per_queue_item(1) - +// ::WeightInfo::on_initialize_per_queue_item(0) +// )) / 5) as u32; + +// pub Schedule: pallet_contracts::Schedule = Default::default(); +// } + +// impl pallet_contracts::Config for Runtime { +// type Time = Timestamp; +// type Randomness = RandomnessCollectiveFlip; +// type Currency = Balances; +// type Event = Event; +// type RentPayment = (); +// type SignedClaimHandicap = SignedClaimHandicap; +// type TombstoneDeposit = TombstoneDeposit; +// type DepositPerContract = DepositPerContract; +// type DepositPerStorageByte = DepositPerStorageByte; +// type DepositPerStorageItem = DepositPerStorageItem; +// type RentFraction = RentFraction; +// type SurchargeReward = SurchargeReward; +// type WeightPrice = pallet_transaction_payment::Pallet; +// type WeightInfo = pallet_contracts::weights::SubstrateWeight; +// type ChainExtension = (); +// type DeletionQueueDepth = DeletionQueueDepth; +// type DeletionWeightLimit = DeletionWeightLimit; +// type Call = Call; +// /// The safest default is to allow no calls at all. +// /// +// /// Runtimes should whitelist dispatchables that are allowed to be called from contracts +// /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to +// /// change because that would break already deployed contracts. The `Call` structure itself +// /// is not allowed to change the indices of existing pallets, too. +// type CallFilter = DenyAll; +// type Schedule = Schedule; +// type CallStack = [pallet_contracts::Frame; 31]; +// } + +// // Build genesis storage according to the mock runtime. +// pub fn new_test_ext() -> sp_io::TestExternalities { +// system::GenesisConfig::default().build_storage::().unwrap().into() +// } diff --git a/pallets/pp/src/tests.rs b/pallets/pp/src/tests.rs index 75f3a7a..bb9a0b3 100644 --- a/pallets/pp/src/tests.rs +++ b/pallets/pp/src/tests.rs @@ -14,26 +14,26 @@ // limitations under the License. // // Author(s): A. Altonen -use crate::{Error, mock::*}; -use frame_support::{assert_ok, assert_noop}; +// use crate::{Error, mock::*}; +// use frame_support::{assert_ok, assert_noop}; -#[test] -fn it_works_for_default_value() { - new_test_ext().execute_with(|| { - // Dispatch a signed extrinsic. - assert_ok!(PpModule::do_something(Origin::signed(1), 42)); - // Read pallet storage and assert an expected result. - assert_eq!(PpModule::something(), Some(42)); - }); -} +// #[test] +// fn it_works_for_default_value() { +// new_test_ext().execute_with(|| { +// // Dispatch a signed extrinsic. +// assert_ok!(PpModule::do_something(Origin::signed(1), 42)); +// // Read pallet storage and assert an expected result. +// assert_eq!(PpModule::something(), Some(42)); +// }); +// } -#[test] -fn correct_error_for_none_value() { - new_test_ext().execute_with(|| { - // Ensure the expected error is thrown when no value is present. - assert_noop!( - PpModule::cause_error(Origin::signed(1)), - Error::::NoneValue - ); - }); -} +// #[test] +// fn correct_error_for_none_value() { +// new_test_ext().execute_with(|| { +// // Ensure the expected error is thrown when no value is present. +// assert_noop!( +// PpModule::cause_error(Origin::signed(1)), +// Error::::NoneValue +// ); +// }); +// } diff --git a/pallets/utxo/Cargo.toml b/pallets/utxo/Cargo.toml index a0ce275..fff917e 100644 --- a/pallets/utxo/Cargo.toml +++ b/pallets/utxo/Cargo.toml @@ -55,6 +55,12 @@ git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '4.0.0-dev' +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + [dev-dependencies.sp-keystore] version = "0.10.0-dev" git = 'https://github.com/paritytech/substrate.git' diff --git a/pallets/utxo/src/lib.rs b/pallets/utxo/src/lib.rs index c75ec99..291a1ed 100644 --- a/pallets/utxo/src/lib.rs +++ b/pallets/utxo/src/lib.rs @@ -36,273 +36,286 @@ pub mod weights; #[frame_support::pallet] pub mod pallet { - use core::marker::PhantomData; - #[cfg(feature = "std")] - use serde::{Deserialize, Serialize}; - - use crate::{validate_header, SignatureMethod, TXOutputHeader, TXOutputHeaderImpls, TokenType}; - use crate::ScriptPubKey; - use contract_provider::ContractProvider; - use codec::{Decode, Encode}; - use frame_support::{ - dispatch::{DispatchResultWithPostInfo, Vec}, - pallet_prelude::*, - sp_io::crypto, - sp_runtime::traits::{BlakeTwo256, Dispatchable, Hash, SaturatedConversion}, - traits::IsSubType, - }; - use frame_system::pallet_prelude::*; - use sp_core::{ - sp_std::collections::btree_map::BTreeMap, - sr25519::{Public as SR25Pub, Signature as SR25Sig}, - H256, H512, - }; - - pub type Value = u128; - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(PhantomData); - - /// runtime configuration - #[pallet::config] - pub trait Config: frame_system::Config { - type Event: From> + IsType<::Event>; - - /// The overarching call type. - type Call: Dispatchable + From> + IsSubType> + Clone; - - type WeightInfo: WeightInfo; - - type ProgrammablePool: ContractProvider; - - fn authorities() -> Vec; - } +use core::marker::PhantomData; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + +use crate::{validate_header, SignatureMethod, TXOutputHeader, TXOutputHeaderImpls, TokenType}; +use crate::{ScriptPubKey, ScriptType}; +use contract_provider::ContractProvider; +use codec::{Decode, Encode}; +use frame_support::{ + dispatch::{DispatchResultWithPostInfo, Vec}, + pallet_prelude::*, + sp_io::crypto, + sp_runtime::traits::{BlakeTwo256, Dispatchable, Hash, SaturatedConversion}, + traits::IsSubType, +}; +use frame_system::pallet_prelude::*; +use sp_core::{ + sp_std::collections::btree_map::BTreeMap, + sr25519::{Public as SR25Pub, Signature as SR25Sig}, + H256, H512, +}; + +pub type Value = u128; + +#[pallet::pallet] +#[pallet::generate_store(pub(super) trait Store)] +pub struct Pallet(PhantomData); + +/// runtime configuration +#[pallet::config] +pub trait Config: frame_system::Config { + type Event: From> + IsType<::Event>; + + /// The overarching call type. + type Call: Dispatchable + From> + IsSubType> + Clone; + + type WeightInfo: WeightInfo; + + type ProgrammablePool: ContractProvider; + + fn authorities() -> Vec; +} - pub trait WeightInfo { - fn spend(u: u32) -> Weight; - } +pub trait WeightInfo { + fn spend(u: u32) -> Weight; +} - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive( - Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, RuntimeDebug, Hash, Default, - )] - pub struct TransactionInput { - pub(crate) outpoint: H256, - pub(crate) sig_script: H512, - } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive( + Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, RuntimeDebug, Hash, Default, +)] +pub struct TransactionInput { + pub(crate) outpoint: H256, + pub(crate) sig_script: H512, +} - impl TransactionInput { - pub fn new(outpoint: H256, sig_script: H512) -> Self { - Self { - outpoint, - sig_script, - } +impl TransactionInput { + pub fn new(outpoint: H256, sig_script: H512) -> Self { + Self { + outpoint, + sig_script, } } +} - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive( - Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, RuntimeDebug, Hash, Default, - )] - pub struct TransactionOutput { - pub(crate) value: Value, - pub(crate) pub_key: H256, - pub(crate) header: TXOutputHeader, - pub(crate) script: ScriptPubKey, - } +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive( + Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, RuntimeDebug, Hash, Default, +)] +pub struct TransactionOutput { + pub(crate) value: Value, + pub(crate) pub_key: H256, + pub(crate) header: TXOutputHeader, + pub(crate) script: ScriptPubKey, +} - impl TransactionOutput { - /// By default the header is 0: - /// token type for both the value and fee is MLT, - /// and the signature method is BLS. - /// functions are available in TXOutputHeaderImpls to update the header. - pub fn new(value: Value, pub_key: H256) -> Self { - Self { - value, - pub_key, - header: 0, - script: ScriptPubKey::new(), - } +impl TransactionOutput { + /// By default the header is 0: + /// token type for both the value and fee is MLT, + /// and the signature method is BLS. + /// functions are available in TXOutputHeaderImpls to update the header. + pub fn new(value: Value, pub_key: H256) -> Self { + Self { + value, + pub_key, + header: 0, + script: ScriptPubKey::new(), } } +} - impl TXOutputHeaderImpls for TransactionOutput { - fn set_token_type(&mut self, value_token_type: TokenType) { - TokenType::insert(&mut self.header, value_token_type); - } - - fn set_signature_method(&mut self, signature_method: SignatureMethod) { - SignatureMethod::insert(&mut self.header, signature_method); - } +impl TXOutputHeaderImpls for TransactionOutput { + fn set_token_type(&mut self, value_token_type: TokenType) { + TokenType::insert(&mut self.header, value_token_type); + } - fn get_token_type(&self) -> Result { - TokenType::extract(self.header) - } + fn set_signature_method(&mut self, signature_method: SignatureMethod) { + SignatureMethod::insert(&mut self.header, signature_method); + } - fn get_signature_method(&self) -> Result { - SignatureMethod::extract(self.header) - } + fn get_token_type(&self) -> Result { + TokenType::extract(self.header) + } - fn validate_header(&self) -> Result<(), &'static str> { - validate_header(self.header) - } + fn get_signature_method(&self) -> Result { + SignatureMethod::extract(self.header) } - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Hash, Default)] - pub struct Transaction { - pub(crate) inputs: Vec, - pub(crate) outputs: Vec, + fn validate_header(&self) -> Result<(), &'static str> { + validate_header(self.header) } +} - #[pallet::storage] - #[pallet::getter(fn reward_total)] - pub(super) type RewardTotal = StorageValue<_, Value, ValueQuery>; +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Hash, Default)] +pub struct Transaction { + pub(crate) inputs: Vec, + pub(crate) outputs: Vec, +} - #[pallet::storage] - #[pallet::getter(fn utxo_store)] - pub(super) type UtxoStore = - StorageMap<_, Blake2_256, H256, Option, ValueQuery>; +#[pallet::storage] +#[pallet::getter(fn reward_total)] +pub(super) type RewardTotal = StorageValue<_, Value, ValueQuery>; + +#[pallet::storage] +#[pallet::getter(fn utxo_store)] +pub(super) type UtxoStore = + StorageMap<_, Blake2_256, H256, Option, ValueQuery>; + +#[pallet::event] +#[pallet::generate_deposit(pub(super) fn deposit_event)] +pub enum Event { + TransactionSuccess(Transaction), +} - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - TransactionSuccess(Transaction), +#[pallet::hooks] +impl Hooks> for Pallet { + fn on_finalize(block_num: T::BlockNumber) { + disperse_reward::(&T::authorities(), block_num) } +} - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_finalize(block_num: T::BlockNumber) { - disperse_reward::(&T::authorities(), block_num) - } +// Strips a transaction of its Signature fields by replacing value with ZERO-initialized fixed hash. +pub fn get_simple_transaction(tx: &Transaction) -> Vec { + let mut trx = tx.clone(); + for input in trx.inputs.iter_mut() { + input.sig_script = H512::zero(); } - // Strips a transaction of its Signature fields by replacing value with ZERO-initialized fixed hash. - pub fn get_simple_transaction(tx: &Transaction) -> Vec { - let mut trx = tx.clone(); - for input in trx.inputs.iter_mut() { - input.sig_script = H512::zero(); - } + trx.encode() +} - trx.encode() +fn disperse_reward(auths: &[H256], block_number: T::BlockNumber) { + let reward = >::take(); + let share_value: Value = reward + .checked_div(auths.len() as Value) + .ok_or("No authorities") + .unwrap(); + if share_value == 0 { + //put reward back if it can't be split nicely + >::put(reward as Value); + return; } - fn disperse_reward(auths: &[H256], block_number: T::BlockNumber) { - let reward = >::take(); - let share_value: Value = reward - .checked_div(auths.len() as Value) - .ok_or("No authorities") - .unwrap(); - if share_value == 0 { - //put reward back if it can't be split nicely - >::put(reward as Value); - return; + let remainder = reward + .checked_sub(share_value * auths.len() as Value) + .ok_or("Sub underflow") + .unwrap(); + + log::debug!("disperse_reward:: reward total: {:?}", remainder); + >::put(remainder as Value); + + for authority in auths { + // TODO: where do we get the header info? + // TODO: are the rewards always of MLT token type? + let utxo = TransactionOutput::new(share_value, *authority); + + let hash = { + let b_num = block_number.saturated_into::(); + BlakeTwo256::hash_of(&(&utxo, b_num)) + }; + + if !>::contains_key(hash) { + >::insert(hash, Some(utxo)); } + } +} - let remainder = reward - .checked_sub(share_value * auths.len() as Value) - .ok_or("Sub underflow") - .unwrap(); +pub fn create(caller: &T::AccountId, code: &Vec) { + let weight: Weight = 6000000000; - log::debug!("disperse_reward:: reward total: {:?}", remainder); - >::put(remainder as Value); + match T::ProgrammablePool::create(caller, weight, code) { + Ok(_) => log::info!("success!"), + Err(e) => log::error!("failure: {:#?}", e), + } +} - for authority in auths { - // TODO: where do we get the header info? - // TODO: are the rewards always of MLT token type? - let utxo = TransactionOutput::new(share_value, *authority); +pub fn call(caller: &T::AccountId, dest: &T::AccountId, code: &Vec) { + let weight: Weight = 6000000000; - let hash = { - let b_num = block_number.saturated_into::(); - BlakeTwo256::hash_of(&(&utxo, b_num)) - }; + match T::ProgrammablePool::call(caller, dest, weight, code) { + Ok(_) => log::info!("success!"), + Err(e) => log::error!("failure: {:#?}", e), + } +} - if !>::contains_key(hash) { - >::insert(hash, Some(utxo)); - } - } +pub fn validate_transaction( + tx: &Transaction, +) -> Result { + //ensure rather than assert to avoid panic + //both inputs and outputs should contain at least 1 utxo + ensure!(!tx.inputs.is_empty(), "no inputs"); + ensure!(!tx.outputs.is_empty(), "no outputs"); + + //ensure each input is used only a single time + //maps each input into btree + //if map.len() > num of inputs then fail + //https://doc.rust-lang.org/std/collections/struct.BTreeMap.html + //WARNING workshop code has a bug here + //https://github.com/substrate-developer-hub/utxo-workshop/blob/workshop/runtime/src/utxo.rs + //input_map.len() > transaction.inputs.len() //THIS IS WRONG + { + let input_map: BTreeMap<_, ()> = tx.inputs.iter().map(|input| (input, ())).collect(); + //we want map size and input size to be equal to ensure each is used only once + ensure!( + input_map.len() == tx.inputs.len(), + "each input should be used only once" + ); + } + //ensure each output is unique + //map each output to btree to count unique elements + //WARNING example code has a bug here + //out_map.len() != transaction.outputs.len() //THIS IS WRONG + { + let out_map: BTreeMap<_, ()> = tx.outputs.iter().map(|output| (output, ())).collect(); + //check each output is defined only once + ensure!( + out_map.len() == tx.outputs.len(), + "each output should be used once" + ); } - pub fn validate_transaction( - tx: &Transaction, - ) -> Result { - //ensure rather than assert to avoid panic - //both inputs and outputs should contain at least 1 utxo - ensure!(!tx.inputs.is_empty(), "no inputs"); - ensure!(!tx.outputs.is_empty(), "no outputs"); - - //ensure each input is used only a single time - //maps each input into btree - //if map.len() > num of inputs then fail - //https://doc.rust-lang.org/std/collections/struct.BTreeMap.html - //WARNING workshop code has a bug here - //https://github.com/substrate-developer-hub/utxo-workshop/blob/workshop/runtime/src/utxo.rs - //input_map.len() > transaction.inputs.len() //THIS IS WRONG - { - let input_map: BTreeMap<_, ()> = tx.inputs.iter().map(|input| (input, ())).collect(); - //we want map size and input size to be equal to ensure each is used only once + let mut total_input: Value = 0; + let mut total_output: Value = 0; + let mut output_index: u64 = 0; + let simple_tx = get_simple_transaction(tx); + + // In order to avoid race condition in network we maintain a list of required utxos for a tx + // Example of race condition: + // Assume both alice and bob have 10 coins each and bob owes charlie 20 coins + // In order to pay charlie alice must first send 10 coins to bob which creates a new utxo + // If bob uses the new utxo to try and send the coins to charlie before charlie receives the alice to bob 10 coins utxo + // then the tx from bob to charlie is invalid. By maintaining a list of required utxos we can ensure the tx can happen as and + // when the utxo is available. We use max longevity at the moment. That should be fixed. + + let mut missing_utxos = Vec::new(); + let mut new_utxos = Vec::new(); + let mut reward = 0; + + // Check that inputs are valid + for input in tx.inputs.iter() { + if let Some(input_utxo) = >::get(&input.outpoint) { ensure!( - input_map.len() == tx.inputs.len(), - "each input should be used only once" + crypto::sr25519_verify( + &SR25Sig::from_raw(*input.sig_script.as_fixed_bytes()), + &simple_tx, + &SR25Pub::from_h256(input_utxo.pub_key) + ), + "signature must be valid" ); + total_input = total_input + .checked_add(input_utxo.value) + .ok_or("input value overflow")?; + } else { + missing_utxos.push(input.outpoint.clone().as_fixed_bytes().to_vec()); } - //ensure each output is unique - //map each output to btree to count unique elements - //WARNING example code has a bug here - //out_map.len() != transaction.outputs.len() //THIS IS WRONG - { - let out_map: BTreeMap<_, ()> = tx.outputs.iter().map(|output| (output, ())).collect(); - //check each output is defined only once - ensure!( - out_map.len() == tx.outputs.len(), - "each output should be used once" - ); - } - - let mut total_input: Value = 0; - let mut total_output: Value = 0; - let mut output_index: u64 = 0; - let simple_tx = get_simple_transaction(tx); - - // In order to avoid race condition in network we maintain a list of required utxos for a tx - // Example of race condition: - // Assume both alice and bob have 10 coins each and bob owes charlie 20 coins - // In order to pay charlie alice must first send 10 coins to bob which creates a new utxo - // If bob uses the new utxo to try and send the coins to charlie before charlie receives the alice to bob 10 coins utxo - // then the tx from bob to charlie is invalid. By maintaining a list of required utxos we can ensure the tx can happen as and - // when the utxo is available. We use max longevity at the moment. That should be fixed. - - let mut missing_utxos = Vec::new(); - let mut new_utxos = Vec::new(); - let mut reward = 0; - - // Check that inputs are valid - for input in tx.inputs.iter() { - if let Some(input_utxo) = >::get(&input.outpoint) { - ensure!( - crypto::sr25519_verify( - &SR25Sig::from_raw(*input.sig_script.as_fixed_bytes()), - &simple_tx, - &SR25Pub::from_h256(input_utxo.pub_key) - ), - "signature must be valid" - ); - total_input = total_input - .checked_add(input_utxo.value) - .ok_or("input value overflow")?; - } else { - missing_utxos.push(input.outpoint.clone().as_fixed_bytes().to_vec()); - } - } - - // Check that outputs are valid - for output in tx.outputs.iter() { - ensure!(output.value > 0, "output value must be nonzero"); - let hash = BlakeTwo256::hash_of(&(&tx, output_index)); - output_index = output_index.checked_add(1).ok_or("output index overflow")?; - ensure!(!>::contains_key(hash), "output already exists"); + } + // Check that outputs are valid + for output in tx.outputs.iter() { // Check the header is valid let res = output.validate_header(); if let Err(e) = res { @@ -310,11 +323,26 @@ pub mod pallet { } ensure!(res.is_ok(), "header error. Please check the logs."); - // checked add bug in example cod where it uses checked_sub - total_output = total_output - .checked_add(output.value) - .ok_or("output value overflow")?; - new_utxos.push(hash.as_fixed_bytes().to_vec()); + match output.script.stype { + ScriptType::P2pkh => { + ensure!(output.value > 0, "output value must be nonzero"); + let hash = BlakeTwo256::hash_of(&(&tx, output_index)); + output_index = output_index.checked_add(1).ok_or("output index overflow")?; + ensure!(!>::contains_key(hash), "output already exists"); + + // checked add bug in example cod where it uses checked_sub + total_output = total_output + .checked_add(output.value) + .ok_or("output value overflow")?; + new_utxos.push(hash.as_fixed_bytes().to_vec()); + }, + ScriptType::OpCreate => { + log::info!("TODO validate OP_CREATE"); + }, + ScriptType::OpCall => { + log::info!("TODO validate OP_CALL"); + } + } } // if no race condition, check the math @@ -340,6 +368,7 @@ pub mod pallet { /// Update storage to reflect changes made by transaction /// Where each utxo key is a hash of the entire transaction and its order in the TransactionOutputs vector pub fn update_storage( + caller: &T::AccountId, tx: &Transaction, reward: Value, ) -> DispatchResultWithPostInfo { @@ -359,10 +388,23 @@ pub mod pallet { let mut index: u64 = 0; for output in &tx.outputs { - let hash = BlakeTwo256::hash_of(&(&tx, index)); - index = index.checked_add(1).ok_or("output index overflow")?; - log::debug!("inserting to UtxoStore {:?} as key {:?}", output, hash); - >::insert(hash, Some(output)); + match output.script.stype { + ScriptType::P2pkh => { + let hash = BlakeTwo256::hash_of(&(&tx, index)); + index = index.checked_add(1).ok_or("output index overflow")?; + log::debug!("inserting to UtxoStore {:?} as key {:?}", output, hash); + >::insert(hash, Some(output)); + }, + ScriptType::OpCreate => { + create::(caller, &output.script.script); + }, + ScriptType::OpCall => { + // TODO convert pubkey of tx to the destination (contract transaction), fix this + let mut tmp = output.pub_key.as_bytes().clone(); + let id = T::AccountId::decode(&mut tmp).unwrap(); + call::(caller, &id, &output.script.script); + }, + } } Ok(().into()) @@ -371,11 +413,11 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::weight(T::WeightInfo::spend(tx.inputs.len().saturating_add(tx.outputs.len()) as u32))] - pub fn spend(_origin: OriginFor, tx: Transaction) -> DispatchResultWithPostInfo { + pub fn spend(origin: OriginFor, tx: Transaction) -> DispatchResultWithPostInfo { + let caller = ensure_signed(origin)?; let tx_validity = validate_transaction::(&tx)?; ensure!(tx_validity.requires.is_empty(), "missing inputs"); - - update_storage::(&tx, tx_validity.priority as Value)?; + update_storage::(&caller, &tx, tx_validity.priority as Value)?; Self::deposit_event(Event::::TransactionSuccess(tx)); Ok(().into()) diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index d76c9d8..7e2d9e7 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -30,6 +30,7 @@ use frame_support::{ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sp_std::{vec, marker::PhantomData}, sr25519::Public, testing::SR25519, H256}; use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore}; +use frame_support::{dispatch::Vec, weights::Weight}; // need to manually import this crate since its no include by default use hex_literal::hex; @@ -48,7 +49,22 @@ pub const GENESIS_UTXO: [u8; 32] = pub struct MockPool(PhantomData); impl ContractProvider for MockPool { - fn create(_code: &Vec) -> Result<(), &'static str> { + type AccountId = u64; + + fn create( + _origin: &Self::AccountId, + _weight: Weight, + _code: &Vec + ) -> Result<(), &'static str> { + Ok(()) + } + + fn call( + _caller: &Self::AccountId, + _dest: &Self::AccountId, + _gas_limit: Weight, + _input_data: &Vec, + ) -> Result<(), &'static str> { Ok(()) } } diff --git a/pallets/utxo/src/script.rs b/pallets/utxo/src/script.rs index 52f1f29..c33be75 100644 --- a/pallets/utxo/src/script.rs +++ b/pallets/utxo/src/script.rs @@ -24,8 +24,11 @@ const SCRIPT_MAX_SIZE: u16 = 10_000; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, Hash, Debug)] +#[repr(u8)] pub enum ScriptType { - P2pkh = 0, + P2pkh = 1, + OpCreate = 2, + OpCall = 3, } impl Default for ScriptType { diff --git a/traits/contract-provider/Cargo.toml b/traits/contract-provider/Cargo.toml index 16188f6..24c1900 100644 --- a/traits/contract-provider/Cargo.toml +++ b/traits/contract-provider/Cargo.toml @@ -18,6 +18,18 @@ git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '4.0.0-dev' +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +tag = 'monthly-2021-08' +version = '4.0.0-dev' + [features] default = ['std'] std = [ diff --git a/traits/contract-provider/src/lib.rs b/traits/contract-provider/src/lib.rs index 5a5e2df..af93cb6 100644 --- a/traits/contract-provider/src/lib.rs +++ b/traits/contract-provider/src/lib.rs @@ -1,7 +1,20 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::dispatch::Vec; +use frame_support::{dispatch::Vec, weights::Weight}; pub trait ContractProvider { - fn create(code: &Vec) -> Result<(), &'static str>; + type AccountId; + + fn create( + origin: &Self::AccountId, + gas: Weight, + code: &Vec + ) -> Result<(), &'static str>; + + fn call( + caller: &Self::AccountId, + dest: &Self::AccountId, + gas_limit: Weight, + input_data: &Vec, + ) -> Result<(), &'static str>; } From 4b67b841c80f8bf9c0dea91600d56bec76c43b88 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Fri, 20 Aug 2021 09:53:38 +0300 Subject: [PATCH 08/12] Fix pallet-utxo unit tests --- pallets/utxo/Cargo.toml | 3 --- pallets/utxo/src/mock.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/utxo/Cargo.toml b/pallets/utxo/Cargo.toml index fff917e..56d9a1d 100644 --- a/pallets/utxo/Cargo.toml +++ b/pallets/utxo/Cargo.toml @@ -67,19 +67,16 @@ git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' [dev-dependencies.pallet-aura] -default-features = false git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '4.0.0-dev' [dev-dependencies.sp-consensus-aura] -default-features = false git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '0.10.0-dev' [dev-dependencies.pallet-timestamp] -default-features = false git = 'https://github.com/paritytech/substrate.git' tag = 'monthly-2021-08' version = '4.0.0-dev' diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index 7e2d9e7..8f3cc4a 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -43,7 +43,7 @@ pub const ALICE_PHRASE: &str = // BlakeHash of TransactionOutput::new(100, H256::from(alice_pub_key)) in fn new_test_ext() pub const GENESIS_UTXO: [u8; 32] = - hex!("01a9fbfde6f0584e88dcff57b5cf4fc9d538bca4e91b1945437b325af7860b3a"); + hex!("538563107b8a5079a84a8177d298725886e6e4d45a4eaef370849c532a4545c5"); // Dummy programmable pool for testing pub struct MockPool(PhantomData); From 70ca2625b5414f77979fb355de8063d698afc1c4 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Fri, 20 Aug 2021 16:38:48 +0300 Subject: [PATCH 09/12] Address PR #23 comments * Replace Mintlayer with RBB Lab * cargo-fmt source code and fix indentation * Remove unused code from pallet-pp --- pallets/pp/Cargo.toml | 2 +- pallets/pp/README.md | 2 +- pallets/pp/src/benchmarking.rs | 26 ++--- pallets/pp/src/lib.rs | 147 ++++++------------------ pallets/utxo/rpc/Cargo.toml | 2 +- pallets/utxo/rpc/runtime-api/Cargo.toml | 2 +- pallets/utxo/rpc/src/lib.rs | 7 +- traits/contract-provider/Cargo.toml | 2 +- traits/contract-provider/src/lib.rs | 10 +- 9 files changed, 59 insertions(+), 141 deletions(-) diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml index 2181c00..f2ccb4f 100644 --- a/pallets/pp/Cargo.toml +++ b/pallets/pp/Cargo.toml @@ -1,5 +1,5 @@ [package] -authors = ['Mintlayer'] +authors = ["RBB Lab"] description = 'Programmable pools pallet' edition = '2018' license = 'MIT' diff --git a/pallets/pp/README.md b/pallets/pp/README.md index 8d751a4..2fdf7c7 100644 --- a/pallets/pp/README.md +++ b/pallets/pp/README.md @@ -1 +1 @@ -License: Unlicense \ No newline at end of file +License: MIT \ No newline at end of file diff --git a/pallets/pp/src/benchmarking.rs b/pallets/pp/src/benchmarking.rs index 426941d..d6326ab 100644 --- a/pallets/pp/src/benchmarking.rs +++ b/pallets/pp/src/benchmarking.rs @@ -5,7 +5,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://spdx.org/licenses/MIT +// http://spdx.org/licenses/MIT // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -18,23 +18,19 @@ use super::*; -use frame_system::RawOrigin; -use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite}; #[allow(unused)] use crate::Pallet as PP; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_system::RawOrigin; benchmarks! { - do_something { - let s in 0 .. 100; - let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller), s) - verify { - assert_eq!(Something::::get(), Some(s)); - } + do_something { + let s in 0 .. 100; + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller), s) + verify { + assert_eq!(Something::::get(), Some(s)); + } } -impl_benchmark_test_suite!( - PP, - crate::mock::new_test_ext(), - crate::mock::Test, -); +impl_benchmark_test_suite!(PP, crate::mock::new_test_ext(), crate::mock::Test,); diff --git a/pallets/pp/src/lib.rs b/pallets/pp/src/lib.rs index 535623d..1a643f7 100644 --- a/pallets/pp/src/lib.rs +++ b/pallets/pp/src/lib.rs @@ -5,7 +5,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://spdx.org/licenses/MIT +// http://spdx.org/licenses/MIT // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,6 @@ // Author(s): A. Altonen #![cfg_attr(not(feature = "std"), no_std)] -/// Edit this file to define custom logic or remove it if it is not needed. -/// Learn more about FRAME and the core library of Substrate FRAME pallets: -/// - pub use pallet::*; #[cfg(test)] @@ -31,112 +27,45 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; -use frame_support::{ - dispatch::Vec, - weights::Weight, -}; use contract_provider::ContractProvider; +use frame_support::{dispatch::Vec, weights::Weight}; use sp_core::{crypto::UncheckedFrom, Bytes}; #[frame_support::pallet] pub mod pallet { - use frame_support::{dispatch::{DispatchResult}, pallet_prelude::*}; - use frame_system::pallet_prelude::*; - - /// Configure the pallet by specifying the parameters and types on which it depends. - #[pallet::config] - pub trait Config: frame_system::Config + pallet_contracts::Config { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - type Event: From> + IsType<::Event>; - } - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); - - // The pallet's runtime storage items. - // https://substrate.dev/docs/en/knowledgebase/runtime/storage - #[pallet::storage] - #[pallet::getter(fn something)] - // Learn more about declaring storage items: - // https://substrate.dev/docs/en/knowledgebase/runtime/storage#declaring-storage-items - pub type Something = StorageValue<_, u32>; - - // Pallets use events to inform users when important changes are made. - // https://substrate.dev/docs/en/knowledgebase/runtime/events - #[pallet::event] - #[pallet::metadata(T::AccountId = "AccountId")] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Event documentation should end with an array that provides descriptive names for event - /// parameters. [something, who] - SomethingStored(u32, T::AccountId), - } - - // Errors inform users that something went wrong. - #[pallet::error] - pub enum Error { - /// Error names should be descriptive. - NoneValue, - /// Errors should have helpful documentation associated with them. - StorageOverflow, - } - - #[pallet::hooks] - impl Hooks> for Pallet {} - - // Dispatchable functions allows users to interact with the pallet and invoke state changes. - // These functions materialize as "extrinsics", which are often compared to transactions. - // Dispatchable functions must be annotated with a weight and must return a DispatchResult. - #[pallet::call] - impl Pallet { - /// An example dispatchable that takes a singles value as a parameter, writes the value to - /// storage and emits an event. This function must be dispatched by a signed extrinsic. - #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] - pub fn do_something(origin: OriginFor, something: u32) -> DispatchResult { - // Check that the extrinsic was signed and get the signer. - // This function will return an error if the extrinsic is not signed. - // https://substrate.dev/docs/en/knowledgebase/runtime/origin - let who = ensure_signed(origin)?; - - // Update storage. - >::put(something); - - // Emit an event. - Self::deposit_event(Event::SomethingStored(something, who)); - // Return a successful DispatchResultWithPostInfo - Ok(()) - } - - /// An example dispatchable that may throw a custom error. - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] - pub fn cause_error(origin: OriginFor) -> DispatchResult { - let _who = ensure_signed(origin)?; - - // Read a value from storage. - match >::get() { - // Return an error if the value has not been set. - None => Err(Error::::NoneValue)?, - Some(old) => { - // Increment the value read from storage; will error in the event of overflow. - let new = old.checked_add(1).ok_or(Error::::StorageOverflow)?; - // Update the value in storage with the incremented result. - >::put(new); - Ok(()) - }, - } - } - } + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config + pallet_contracts::Config { + type Event: From> + IsType<::Event>; + } + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::event] + #[pallet::metadata(T::AccountId = "AccountId")] + pub enum Event {} + + #[pallet::hooks] + impl Hooks> for Pallet {} + + #[pallet::call] + impl Pallet {} #[pallet::genesis_config] - pub struct GenesisConfig { - pub _marker: PhantomData - } + pub struct GenesisConfig { + pub _marker: PhantomData, + } - #[cfg(feature = "std")] + #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - Self { _marker: Default::default() } + Self { + _marker: Default::default(), + } } } @@ -148,16 +77,16 @@ pub mod pallet { impl ContractProvider for Pallet where - T::AccountId: UncheckedFrom + AsRef<[u8]>, + T::AccountId: UncheckedFrom + AsRef<[u8]>, { type AccountId = T::AccountId; fn create( caller: &T::AccountId, gas_limit: Weight, - code: &Vec + code: &Vec, ) -> Result<(), &'static str> { - let code = pallet_contracts_primitives::Code::Upload(Bytes(code.to_vec())); + let code = pallet_contracts_primitives::Code::Upload(Bytes(code.to_vec())); let endowment = pallet_contracts::Pallet::::subsistence_threshold(); let _ = pallet_contracts::Pallet::::bare_instantiate( @@ -167,8 +96,8 @@ where code, Vec::new(), Vec::new(), - false, - true, + false, // calculate rent projection + true, // enable debugging ); Ok(()) @@ -177,8 +106,8 @@ where fn call( caller: &T::AccountId, dest: &T::AccountId, - gas_limit: Weight, - input_data: &Vec, + gas_limit: Weight, + input_data: &Vec, ) -> Result<(), &'static str> { let value = pallet_contracts::Pallet::::subsistence_threshold(); @@ -188,7 +117,7 @@ where value, // TODO gas_limit, input_data.to_vec(), - true, + true, // enable debugging ); Ok(()) diff --git a/pallets/utxo/rpc/Cargo.toml b/pallets/utxo/rpc/Cargo.toml index ae2b7d5..9372a4e 100644 --- a/pallets/utxo/rpc/Cargo.toml +++ b/pallets/utxo/rpc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pallet-utxo-rpc" version = "0.1.0" -authors = ["Mintlayer"] +authors = ["RBB Lab"] edition = "2018" [dependencies] diff --git a/pallets/utxo/rpc/runtime-api/Cargo.toml b/pallets/utxo/rpc/runtime-api/Cargo.toml index 067951e..f280082 100644 --- a/pallets/utxo/rpc/runtime-api/Cargo.toml +++ b/pallets/utxo/rpc/runtime-api/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pallet-utxo-rpc-runtime-api" version = "0.1.0" -authors = ["Mintlayer"] +authors = ["RBB Lab"] edition = "2018" [dependencies.serde] diff --git a/pallets/utxo/rpc/src/lib.rs b/pallets/utxo/rpc/src/lib.rs index 9599a7b..10d00ab 100644 --- a/pallets/utxo/rpc/src/lib.rs +++ b/pallets/utxo/rpc/src/lib.rs @@ -16,7 +16,7 @@ // Author(s): A. Altonen use jsonrpc_core::{Error as RpcError, ErrorCode, Result}; use jsonrpc_derive::rpc; -pub use pallet_utxo_rpc_runtime_api::{UtxoApi as UtxoRuntimeApi}; +pub use pallet_utxo_rpc_runtime_api::UtxoApi as UtxoRuntimeApi; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::{generic::BlockId, traits::Block as BlockT}; @@ -60,10 +60,7 @@ where C: HeaderBackend, C::Api: UtxoRuntimeApi, { - fn send( - &self, - at: Option<::Hash>, - ) -> Result { + fn send(&self, at: Option<::Hash>) -> Result { let api = self.client.runtime_api(); let at = BlockId::hash(at.unwrap_or_else(|| // If the block hash is not supplied assume the best block. diff --git a/traits/contract-provider/Cargo.toml b/traits/contract-provider/Cargo.toml index 24c1900..cd180b9 100644 --- a/traits/contract-provider/Cargo.toml +++ b/traits/contract-provider/Cargo.toml @@ -2,7 +2,7 @@ name = "contract-provider" version = "3.0.0" edition = "2018" -authors = ['Mintlayer'] +authors = ["RBB Lab"] description = "Contract provider trait filled by programmable pools" license = "MIT" diff --git a/traits/contract-provider/src/lib.rs b/traits/contract-provider/src/lib.rs index af93cb6..c016835 100644 --- a/traits/contract-provider/src/lib.rs +++ b/traits/contract-provider/src/lib.rs @@ -5,16 +5,12 @@ use frame_support::{dispatch::Vec, weights::Weight}; pub trait ContractProvider { type AccountId; - fn create( - origin: &Self::AccountId, - gas: Weight, - code: &Vec - ) -> Result<(), &'static str>; + fn create(origin: &Self::AccountId, gas: Weight, code: &Vec) -> Result<(), &'static str>; fn call( caller: &Self::AccountId, dest: &Self::AccountId, - gas_limit: Weight, - input_data: &Vec, + gas_limit: Weight, + input_data: &Vec, ) -> Result<(), &'static str>; } From cbf4f9c74645df74c3bcab3f6bf63862a3c9e31f Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Thu, 26 Aug 2021 12:01:56 +0300 Subject: [PATCH 10/12] Add data field to ScriptPubKey Some ink! smart contracts may require additional data passed in when they are instantiated such as the selector for the constructor. While there, remove size field from ScriptPubKey as it had no purpose --- pallets/pp/src/lib.rs | 3 ++- pallets/utxo/src/lib.rs | 12 ++++++------ pallets/utxo/src/mock.rs | 5 +++-- pallets/utxo/src/script.rs | 11 +++++++---- traits/contract-provider/src/lib.rs | 7 ++++++- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/pallets/pp/src/lib.rs b/pallets/pp/src/lib.rs index 1a643f7..064b954 100644 --- a/pallets/pp/src/lib.rs +++ b/pallets/pp/src/lib.rs @@ -85,6 +85,7 @@ where caller: &T::AccountId, gas_limit: Weight, code: &Vec, + data: &Vec, ) -> Result<(), &'static str> { let code = pallet_contracts_primitives::Code::Upload(Bytes(code.to_vec())); let endowment = pallet_contracts::Pallet::::subsistence_threshold(); @@ -94,7 +95,7 @@ where endowment * 100_u32.into(), // TODO gas_limit, code, - Vec::new(), + data.to_vec(), Vec::new(), false, // calculate rent projection true, // enable debugging diff --git a/pallets/utxo/src/lib.rs b/pallets/utxo/src/lib.rs index 291a1ed..5571d5d 100644 --- a/pallets/utxo/src/lib.rs +++ b/pallets/utxo/src/lib.rs @@ -224,19 +224,19 @@ fn disperse_reward(auths: &[H256], block_number: T::BlockNumber) { } } -pub fn create(caller: &T::AccountId, code: &Vec) { +pub fn create(caller: &T::AccountId, code: &Vec, data: &Vec) { let weight: Weight = 6000000000; - match T::ProgrammablePool::create(caller, weight, code) { + match T::ProgrammablePool::create(caller, weight, code, data) { Ok(_) => log::info!("success!"), Err(e) => log::error!("failure: {:#?}", e), } } -pub fn call(caller: &T::AccountId, dest: &T::AccountId, code: &Vec) { +pub fn call(caller: &T::AccountId, dest: &T::AccountId, data: &Vec) { let weight: Weight = 6000000000; - match T::ProgrammablePool::call(caller, dest, weight, code) { + match T::ProgrammablePool::call(caller, dest, weight, data) { Ok(_) => log::info!("success!"), Err(e) => log::error!("failure: {:#?}", e), } @@ -396,13 +396,13 @@ pub fn validate_transaction( >::insert(hash, Some(output)); }, ScriptType::OpCreate => { - create::(caller, &output.script.script); + create::(caller, &output.script.script, &output.script.data); }, ScriptType::OpCall => { // TODO convert pubkey of tx to the destination (contract transaction), fix this let mut tmp = output.pub_key.as_bytes().clone(); let id = T::AccountId::decode(&mut tmp).unwrap(); - call::(caller, &id, &output.script.script); + call::(caller, &id, &output.script.data); }, } } diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index 8f3cc4a..339363e 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -43,7 +43,7 @@ pub const ALICE_PHRASE: &str = // BlakeHash of TransactionOutput::new(100, H256::from(alice_pub_key)) in fn new_test_ext() pub const GENESIS_UTXO: [u8; 32] = - hex!("538563107b8a5079a84a8177d298725886e6e4d45a4eaef370849c532a4545c5"); + hex!("0a08a0ef477ab5416c15bda44ff1938279e1677569b0cccaf73f0d30f4e935cb"); // Dummy programmable pool for testing pub struct MockPool(PhantomData); @@ -54,7 +54,8 @@ impl ContractProvider for MockPool { fn create( _origin: &Self::AccountId, _weight: Weight, - _code: &Vec + _code: &Vec, + _data: &Vec, ) -> Result<(), &'static str> { Ok(()) } diff --git a/pallets/utxo/src/script.rs b/pallets/utxo/src/script.rs index c33be75..8d85443 100644 --- a/pallets/utxo/src/script.rs +++ b/pallets/utxo/src/script.rs @@ -41,8 +41,8 @@ impl Default for ScriptType { #[derive(Clone, Encode, Decode, Eq, PartialEq, PartialOrd, Ord, Debug, Hash, Default)] pub struct ScriptPubKey { pub(crate) stype: ScriptType, - pub(crate) size: u16, pub(crate) script: Vec, + pub(crate) data: Vec, } impl ScriptPubKey { @@ -50,8 +50,8 @@ impl ScriptPubKey { pub fn new() -> Self { Self { stype: ScriptType::default(), - size: 0, script: Vec::new(), + data: Vec::new(), } } @@ -63,9 +63,12 @@ impl ScriptPubKey { self.stype = stype; self.script = script.clone(); - self.size = self.script.len() as u16; Ok(()) } + + pub fn set_data(&mut self, data: &Vec) { + self.data = data.clone() + } } #[cfg(test)] @@ -77,8 +80,8 @@ mod tests { fn new_script() { let script = ScriptPubKey::new(); assert_eq!(script.stype, ScriptType::P2pkh); - assert_eq!(script.size, 0); assert_eq!(script.script.len(), 0); + assert_eq!(script.data.len(), 0); } #[test] diff --git a/traits/contract-provider/src/lib.rs b/traits/contract-provider/src/lib.rs index c016835..4cf7803 100644 --- a/traits/contract-provider/src/lib.rs +++ b/traits/contract-provider/src/lib.rs @@ -5,7 +5,12 @@ use frame_support::{dispatch::Vec, weights::Weight}; pub trait ContractProvider { type AccountId; - fn create(origin: &Self::AccountId, gas: Weight, code: &Vec) -> Result<(), &'static str>; + fn create( + origin: &Self::AccountId, + gas: Weight, + code: &Vec, + data: &Vec, + ) -> Result<(), &'static str>; fn call( caller: &Self::AccountId, From d7493f34df5c1d5e4db63955273f5fccf8f14943 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Thu, 26 Aug 2021 12:38:09 +0300 Subject: [PATCH 11/12] Pass zero as value to contracts::bare_call() For some reason, calling ink! smart contracts with non-zero value resulted in ContractTrapped error. This does not happen with Subtrate's example smart contracts where it seems that any value can be given. --- pallets/pp/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/pp/src/lib.rs b/pallets/pp/src/lib.rs index 064b954..80fb386 100644 --- a/pallets/pp/src/lib.rs +++ b/pallets/pp/src/lib.rs @@ -115,7 +115,7 @@ where let _ = pallet_contracts::Pallet::::bare_call( caller.clone(), dest.clone(), - value, // TODO + value * 0u32.into(), gas_limit, input_data.to_vec(), true, // enable debugging From e9b05fca7a1526508ed849dd46ad548e577b03d8 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Fri, 27 Aug 2021 13:22:56 +0300 Subject: [PATCH 12/12] Update node to the latest version Update node from tag v3.0.0+monthly-2021-05 to track origin/master. --- node/Cargo.toml | 94 ++++++++++++++++--------- node/src/command.rs | 2 +- node/src/service.rs | 62 +++++++++++----- pallets/pp/Cargo.toml | 18 ++--- pallets/template/Cargo.toml | 12 ++-- pallets/template/src/mock.rs | 2 +- pallets/utxo/Cargo.toml | 18 ++--- pallets/utxo/rpc/Cargo.toml | 14 ++-- pallets/utxo/rpc/runtime-api/Cargo.toml | 6 +- pallets/utxo/src/mock.rs | 3 +- runtime/Cargo.toml | 58 +++++++-------- runtime/src/lib.rs | 11 ++- traits/contract-provider/Cargo.toml | 8 +-- 13 files changed, 187 insertions(+), 121 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index f7208f7..42e22fb 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -16,10 +16,10 @@ name = 'node-template' targets = ['x86_64-unknown-linux-gnu'] [build-dependencies] -substrate-build-script-utils = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', tag = 'monthly-2021-05'} +substrate-build-script-utils = {version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = "master" } [dependencies] -jsonrpc-core = '15.1.0' +jsonrpc-core = '18.0.0' structopt = '0.3.8' node-template-runtime = {version = '3.0.0', path = '../runtime'} pallet-utxo-rpc = { path = "../pallets/utxo/rpc" } @@ -27,158 +27,188 @@ pallet-utxo-rpc-runtime-api = { path = "../pallets/utxo/rpc/runtime-api" } [dependencies.frame-benchmarking] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-benchmarking-cli] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-transaction-payment-rpc] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sc-basic-authorship] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-cli] features = ['wasmtime'] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-client-api] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sc-consensus] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-consensus-aura] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-executor] features = ['wasmtime'] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-finality-grandpa] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" + +[dependencies.sc-finality-grandpa-rpc] +git = 'https://github.com/paritytech/substrate.git' +version = '0.10.0-dev' +branch = "master" + +[dependencies.sc-network] +git = 'https://github.com/paritytech/substrate.git' +version = "0.10.0-dev" +branch = "master" + +[dependencies.sc-consensus-babe] +git = 'https://github.com/paritytech/substrate.git' +version = "0.10.0-dev" +branch = "master" + +[dependencies.sc-consensus-babe-rpc] +git = 'https://github.com/paritytech/substrate.git' +version = "0.10.0-dev" +branch = "master" [dependencies.sc-keystore] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sc-rpc] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sc-rpc-api] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-service] features = ['wasmtime'] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sc-telemetry] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sc-transaction-pool] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sc-transaction-pool-api] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-api] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-block-builder] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-blockchain] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-consensus] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sp-consensus-aura] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sp-core] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-finality-grandpa] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-inherents] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-runtime] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-timestamp] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.substrate-frame-rpc-system] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-contracts] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-contracts-rpc] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" + +[dependencies.sp-authorship] +git = 'https://github.com/paritytech/substrate.git' +version = "4.0.0-dev" +branch = "master" + +[dependencies.sc-authority-discovery] +git = 'https://github.com/paritytech/substrate.git' +version = "0.10.0-dev" +branch = "master" # local dependencies # bls_sigs_ref = {version = '0.3.0', path = '../../BLS'} diff --git a/node/src/command.rs b/node/src/command.rs index fefb8a0..d1ee79a 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -119,7 +119,7 @@ pub fn run() -> sc_cli::Result<()> { if cfg!(feature = "runtime-benchmarks") { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run::(config)) } else { Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`.".into()) diff --git a/node/src/service.rs b/node/src/service.rs index dbdb307..a625855 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,10 +1,7 @@ -//! Service and ServiceFactory implementation. Specialized wrapper over substrate service. - use node_template_runtime::{self, opaque::Block, RuntimeApi}; use sc_client_api::{ExecutorProvider, RemoteBackend}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; -use sc_executor::native_executor_instance; -pub use sc_executor::NativeExecutor; +pub use sc_executor::NativeElseWasmExecutor; use sc_finality_grandpa::SharedVoterState; use sc_keystore::LocalKeystore; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; @@ -14,14 +11,22 @@ use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use std::{sync::Arc, time::Duration}; // Our native executor instance. -native_executor_instance!( - pub Executor, - node_template_runtime::api::dispatch, - node_template_runtime::native_version, - frame_benchmarking::benchmarking::HostFunctions, -); - -type FullClient = sc_service::TFullClient; +pub struct ExecutorDispatch; + +impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { + type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; + + fn dispatch(method: &str, data: &[u8]) -> Option> { + node_template_runtime::api::dispatch(method, data) + } + + fn native_version() -> sc_executor::NativeVersion { + node_template_runtime::native_version() + } +} + +type FullClient = + sc_service::TFullClient>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; @@ -62,10 +67,17 @@ pub fn new_partial( }) .transpose()?; + let executor = NativeElseWasmExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( + sc_service::new_full_parts::( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, )?; let client = Arc::new(client); @@ -162,6 +174,10 @@ pub fn new_full(mut config: Configuration) -> Result } config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); + let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( + backend.clone(), + grandpa_link.shared_authority_set().clone(), + )); let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { @@ -172,6 +188,7 @@ pub fn new_full(mut config: Configuration) -> Result import_queue, on_demand: None, block_announce_validator_builder: None, + warp_sync: Some(warp_sync), })?; if config.offchain_worker.enabled { @@ -198,7 +215,7 @@ pub fn new_full(mut config: Configuration) -> Result let deps = crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe }; - crate::rpc::create_full(deps) + Ok(crate::rpc::create_full(deps)) }) }; @@ -325,10 +342,17 @@ pub fn new_light(mut config: Configuration) -> Result }) .transpose()?; + let executor = NativeElseWasmExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore_container, mut task_manager, on_demand) = - sc_service::new_light_parts::( + sc_service::new_light_parts::( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, )?; let mut telemetry = telemetry.map(|(worker, telemetry)| { @@ -380,6 +404,11 @@ pub fn new_light(mut config: Configuration) -> Result telemetry: telemetry.as_ref().map(|x| x.handle()), })?; + let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( + backend.clone(), + grandpa_link.shared_authority_set().clone(), + )); + let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, @@ -389,6 +418,7 @@ pub fn new_light(mut config: Configuration) -> Result import_queue, on_demand: Some(on_demand.clone()), block_announce_validator_builder: None, + warp_sync: Some(warp_sync), })?; if config.offchain_worker.enabled { @@ -425,7 +455,7 @@ pub fn new_light(mut config: Configuration) -> Result transaction_pool, task_manager: &mut task_manager, on_demand: Some(on_demand), - rpc_extensions_builder: Box::new(|_, _| ()), + rpc_extensions_builder: Box::new(|_, _| Ok(())), config, client, keystore: keystore_container.sync_keystore(), diff --git a/pallets/pp/Cargo.toml b/pallets/pp/Cargo.toml index f2ccb4f..c989966 100644 --- a/pallets/pp/Cargo.toml +++ b/pallets/pp/Cargo.toml @@ -27,38 +27,38 @@ path = "../../traits/contract-provider/" default-features = false git = 'https://github.com/paritytech/substrate.git' optional = true -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-system] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-contracts] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-contracts-primitives] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-core] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.serde] version = '1.0.126' @@ -66,20 +66,20 @@ version = '1.0.126' [dev-dependencies.sp-io] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.sp-core] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [features] default = ['std'] diff --git a/pallets/template/Cargo.toml b/pallets/template/Cargo.toml index 4b3a7ad..971f543 100644 --- a/pallets/template/Cargo.toml +++ b/pallets/template/Cargo.toml @@ -21,21 +21,21 @@ version = '2.0.0' [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-system] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-benchmarking] default-features = false git = 'https://github.com/paritytech/substrate.git' optional = true -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.serde] version = '1.0.126' @@ -43,20 +43,20 @@ version = '1.0.126' [dev-dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.sp-core] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.sp-io] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [features] default = ['std'] diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs index 9bea61d..e10f10a 100644 --- a/pallets/template/src/mock.rs +++ b/pallets/template/src/mock.rs @@ -27,7 +27,7 @@ parameter_types! { } impl system::Config for Test { - type BaseCallFilter = frame_support::traits::AllowAll; + type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); type BlockLength = (); type DbWeight = (); diff --git a/pallets/utxo/Cargo.toml b/pallets/utxo/Cargo.toml index 56d9a1d..e0dc924 100644 --- a/pallets/utxo/Cargo.toml +++ b/pallets/utxo/Cargo.toml @@ -34,49 +34,49 @@ path = "../../traits/contract-provider/" default-features = false git = 'https://github.com/paritytech/substrate.git' optional = true -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-system] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-core] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.sp-keystore] version = "0.10.0-dev" git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' +branch = "master" [dev-dependencies.pallet-aura] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies.sp-consensus-aura] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dev-dependencies.pallet-timestamp] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' +branch = "master" version = '4.0.0-dev' diff --git a/pallets/utxo/rpc/Cargo.toml b/pallets/utxo/rpc/Cargo.toml index 9372a4e..6b90d18 100644 --- a/pallets/utxo/rpc/Cargo.toml +++ b/pallets/utxo/rpc/Cargo.toml @@ -6,9 +6,9 @@ edition = "2018" [dependencies] pallet-utxo-rpc-runtime-api = { path = "./runtime-api" } -jsonrpc-core = "15.0.0" -jsonrpc-core-client = "15.0.0" -jsonrpc-derive = "15.0.0" +jsonrpc-core = "18.0.0" +jsonrpc-core-client = "18.0.0" +jsonrpc-derive = "18.0.0" [dependencies.serde] version = "1.0.104" @@ -17,8 +17,8 @@ features = ["derive"] [dependencies.sp-blockchain] default_features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.codec] package = "parity-scale-codec" @@ -29,17 +29,17 @@ features = ["derive"] [dependencies.sp-api] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" diff --git a/pallets/utxo/rpc/runtime-api/Cargo.toml b/pallets/utxo/rpc/runtime-api/Cargo.toml index f280082..86e5156 100644 --- a/pallets/utxo/rpc/runtime-api/Cargo.toml +++ b/pallets/utxo/rpc/runtime-api/Cargo.toml @@ -18,20 +18,20 @@ features = ["derive"] [dependencies.sp-api] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dev-dependencies] serde_json = "1.0.48" diff --git a/pallets/utxo/src/mock.rs b/pallets/utxo/src/mock.rs index 339363e..8618c42 100644 --- a/pallets/utxo/src/mock.rs +++ b/pallets/utxo/src/mock.rs @@ -95,7 +95,7 @@ parameter_types! { } impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::AllowAll; + type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); type BlockLength = (); type Origin = Origin; @@ -130,6 +130,7 @@ impl pallet_timestamp::Config for Test { impl pallet_aura::Config for Test { type AuthorityId = AuraId; + type DisabledValidators = (); } impl pallet_utxo::Config for Test { diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d383f11..5e7a413 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -12,8 +12,8 @@ targets = ['x86_64-unknown-linux-gnu'] [build-dependencies.substrate-wasm-builder] git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '5.0.0-dev' +branch = "master" [dependencies.codec] default-features = false @@ -25,39 +25,39 @@ version = '2.0.0' default-features = false git = 'https://github.com/paritytech/substrate.git' optional = true -tag = 'monthly-2021-08' +branch = "master" version = '4.0.0-dev' [dependencies.frame-executive] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' +branch = "master" version = '4.0.0-dev' [dependencies.frame-system] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-system-benchmarking] default-features = false git = 'https://github.com/paritytech/substrate.git' optional = true -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-system-rpc-runtime-api] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.hex-literal] optional = true @@ -66,135 +66,135 @@ version = '0.3.1' [dependencies.pallet-aura] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-balances] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-grandpa] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-randomness-collective-flip] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-sudo] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-timestamp] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-transaction-payment] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-transaction-payment-rpc-runtime-api] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-api] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-block-builder] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-consensus-aura] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '0.10.0-dev' +branch = "master" [dependencies.sp-core] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-inherents] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-offchain] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' +branch = "master" version = '4.0.0-dev' [dependencies.sp-session] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-std] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-transaction-pool] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' +branch = "master" version = '4.0.0-dev' [dependencies.sp-version] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" # Local dependencies [dependencies.pallet-contracts] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-contracts-primitives] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-contracts-rpc-runtime-api] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.pallet-template] default-features = false diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index f03da02..f8958a4 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -31,7 +31,7 @@ pub use pallet_balances::Call as BalancesCall; pub use sp_runtime::{Permill, Perbill}; pub use frame_support::{ construct_runtime, parameter_types, StorageValue, - traits::{KeyOwnerProofSystem, Randomness, IsSubType, DenyAll}, + traits::{KeyOwnerProofSystem, Randomness, IsSubType, Nothing, Everything}, weights::{ Weight, IdentityFee, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, @@ -166,7 +166,7 @@ parameter_types! { impl frame_system::Config for Runtime { /// The basic call filter to use in dispatchable. - type BaseCallFilter = frame_support::traits::AllowAll; + type BaseCallFilter = Everything; /// Block & extrinsics weights: base values and limits. type BlockWeights = BlockWeights; /// The maximum length of a block (in bytes). @@ -217,6 +217,7 @@ impl frame_system::Config for Runtime { impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; + type DisabledValidators = (); } impl pallet_grandpa::Config for Runtime { @@ -363,7 +364,7 @@ impl pallet_contracts::Config for Runtime { /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to /// change because that would break already deployed contracts. The `Call` structure itself /// is not allowed to change the indices of existing pallets, too. - type CallFilter = DenyAll; + type CallFilter = Nothing; type Schedule = Schedule; type CallStack = [pallet_contracts::Frame; 31]; } @@ -519,6 +520,10 @@ impl_runtime_apis! { Grandpa::grandpa_authorities() } + fn current_set_id() -> fg_primitives::SetId { + Grandpa::current_set_id() + } + fn submit_report_equivocation_unsigned_extrinsic( _equivocation_proof: fg_primitives::EquivocationProof< ::Hash, diff --git a/traits/contract-provider/Cargo.toml b/traits/contract-provider/Cargo.toml index cd180b9..dce84b6 100644 --- a/traits/contract-provider/Cargo.toml +++ b/traits/contract-provider/Cargo.toml @@ -9,26 +9,26 @@ license = "MIT" [dependencies.frame-support] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-std] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.sp-runtime] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [dependencies.frame-system] default-features = false git = 'https://github.com/paritytech/substrate.git' -tag = 'monthly-2021-08' version = '4.0.0-dev' +branch = "master" [features] default = ['std']