Skip to content

Commit

Permalink
pallet-contracts bringup (#306)
Browse files Browse the repository at this point in the history
* pallet-contract bringup

* pallet-contract bringup rpc call works

* pallet-contract bringup revert ENDOWMENT

* pallet-contract bringup formatt corrections

* cargo fmt --all

* fix pallet contracts benchmarks

Co-authored-by: Eliott Teissonniere <[email protected]>
  • Loading branch information
shamb0 and ETeissonniere authored Mar 23, 2021
1 parent 5ceae46 commit 5ca7c65
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 6 deletions.
89 changes: 88 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ sp-runtime = "2.0.0"
sp-transaction-pool = "2.0.0"
structopt = "0.3.14"
substrate-frame-rpc-system = "2.0.0"
pallet-contracts = "2.0.0"
pallet-contracts-rpc = "0.8.0"

[build-dependencies]
vergen = "3.0.4"
Expand Down
14 changes: 9 additions & 5 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

use nodle_chain_primitives::{AccountId, Balance, BlockNumber, Signature};
use nodle_chain_runtime::{
constants::*, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, FinancialMembershipConfig,
GenesisConfig, GrandpaConfig, GrantsConfig, ImOnlineConfig, IndicesConfig,
RootMembershipConfig, SessionConfig, SessionKeys, SystemConfig, TechnicalMembershipConfig,
ValidatorsSetConfig, WASM_BINARY,
constants::*, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig,
FinancialMembershipConfig, GenesisConfig, GrandpaConfig, GrantsConfig, ImOnlineConfig,
IndicesConfig, RootMembershipConfig, SessionConfig, SessionKeys, SystemConfig,
TechnicalMembershipConfig, ValidatorsSetConfig, WASM_BINARY,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::ChainType;
Expand Down Expand Up @@ -148,7 +148,11 @@ pub fn testnet_genesis(
pallet_grants: Some(GrantsConfig {
vesting: vested_grants,
}),

pallet_contracts: Some(ContractsConfig {
current_schedule: pallet_contracts::Schedule {
..Default::default()
},
}),
// Consensus
pallet_session: Some(SessionConfig {
keys: initial_authorities
Expand Down
8 changes: 8 additions & 0 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ where
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,
C::Api: RootOfTrustRuntimeApi<Block, CertificateId>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
Expand All @@ -111,6 +112,7 @@ where
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use pallet_contracts_rpc::{Contracts, ContractsApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use substrate_frame_rpc_system::{FullSystem, SystemApi};

Expand Down Expand Up @@ -142,6 +144,12 @@ where
pool,
deny_unsafe,
)));

// Making synchronous calls in light client freezes the browser currently,
// more context: https://github.com/paritytech/substrate/pull/3480
// These RPCs should use an asynchronous caller instead.
io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));

io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(
client.clone(),
)));
Expand Down
7 changes: 7 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ std = [
"pallet-babe/std",
"pallet-balances/std",
"pallet-collective/std",
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-contracts-rpc-runtime-api/std",
"pallet-emergency-shutdown/std",
"pallet-finality-tracker/std",
"pallet-grandpa/std",
Expand Down Expand Up @@ -72,6 +75,7 @@ runtime-benchmarks = [
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-emergency-shutdown/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-grants/runtime-benchmarks",
Expand Down Expand Up @@ -106,6 +110,9 @@ pallet-authorship = { version = "2.0.0", default-features = false }
pallet-babe = { version = "2.0.0", default-features = false }
pallet-balances = { version = "2.0.0", default-features = false }
pallet-collective = { version = "2.0.0", default-features = false }
pallet-contracts = { version = "2.0.0", default-features = false }
pallet-contracts-primitives = { version = "2.0.0", default-features = false }
pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false }
pallet-emergency-shutdown = { version = "2.0.0", default-features = false, path = "../pallets/emergency-shutdown" }
pallet-finality-tracker = { version = "2.0.0", default-features = false }
pallet-grandpa = { version = "2.0.0", default-features = false }
Expand Down
65 changes: 65 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use frame_support::{
use nodle_chain_primitives::{
AccountId, AccountIndex, Balance, BlockNumber, CertificateId, Hash, Index, Moment, Signature,
};
use pallet_contracts_rpc_runtime_api::ContractExecResult;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
Expand Down Expand Up @@ -780,6 +781,32 @@ impl pallet_membership::Trait<pallet_membership::Instance5> for Runtime {
type MembershipChanged = Allocations;
}

parameter_types! {
pub const TombstoneDeposit: Balance = 16 * constants::MILLICENTS;
pub const RentByteFee: Balance = 4 * constants::MILLICENTS;
pub const RentDepositOffset: Balance = 1000 * constants::MILLICENTS;
pub const SurchargeReward: Balance = 150 * constants::MILLICENTS;
}

impl pallet_contracts::Trait for Runtime {
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Currency = Balances;
type Event = Event;
type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;
type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;
type RentPayment = ();
type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;
type RentByteFee = RentByteFee;
type RentDepositOffset = RentDepositOffset;
type SurchargeReward = SurchargeReward;
type MaxDepth = pallet_contracts::DefaultMaxDepth;
type MaxValueSize = pallet_contracts::DefaultMaxValueSize;
type WeightPrice = pallet_transaction_payment::Module<Self>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand All @@ -798,6 +825,7 @@ construct_runtime!(
// Consensus
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent, ValidateUnsigned},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned},
Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
Offences: pallet_offences::{Module, Call, Storage, Event},
Expand Down Expand Up @@ -1031,6 +1059,42 @@ sp_api::impl_runtime_apis! {
}
}

impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>
for Runtime
{
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: u64,
input_data: Vec<u8>,
) -> ContractExecResult {
let (exec_result, gas_consumed) =
Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);
match exec_result {
Ok(v) => ContractExecResult::Success {
flags: v.flags.bits(),
data: v.data,
gas_consumed: gas_consumed,
},
Err(_) => ContractExecResult::Error,
}
}

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<BlockNumber> {
Contracts::rent_projection(address)
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Block,
Balance,
Expand Down Expand Up @@ -1079,6 +1143,7 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, pallet_babe, Babe);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_collective, TechnicalCommittee);
add_benchmark!(params, batches, pallet_contracts, Contracts);
add_benchmark!(params, batches, pallet_emergency_shutdown, EmergencyShutdown);
add_benchmark!(params, batches, pallet_grandpa, Grandpa);
add_benchmark!(params, batches, pallet_grants, Grants);
Expand Down

0 comments on commit 5ca7c65

Please sign in to comment.