Skip to content

Commit

Permalink
move unused pallets & cos
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyTimes committed Mar 28, 2022
1 parent 8d8fba5 commit e1b2794
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 182 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
# blockchain
'crates/skw-blockchain-node',
'crates/skw-blockchain-pallets/pallet-naming',
'crates/skw-blockchain-pallets-unused/pallet-naming',
'crates/skw-blockchain-pallets/pallet-secrets',
'crates/skw-blockchain-pallets/pallet-s-contract',
'crates/skw-blockchain-pallets/pallet-registry',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,3 @@ pub mod pallet {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub mod pallet {
// by default - confirmation at 1
let threshold = Self::shard_confirmation_threshold(shard_id).unwrap_or(1);

// TODO: maybe we should allow any submission and let clients handle the rest
ensure!(pallet_registry::Pallet::<T>::is_beacon_turn(block_number, &who, shard_id, threshold), Error::<T>::Unauthorized);
ensure!(outcome_call_index.len() == outcome.len(), Error::<T>::InvalidOutcome);
ensure!(outcome_call_index.len() < T::MaxOutcomePerSubmission::get() as usize, Error::<T>::InvalidOutcome);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! Benchmarking setup for pallet-template
use super::*;

use frame_system::RawOrigin;
Expand Down
13 changes: 10 additions & 3 deletions crates/skw-blockchain-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ version = '3.0.0'
targets = ['x86_64-unknown-linux-gnu']

[dependencies]
pallet-naming = { default-features = false, path = '../skw-blockchain-pallets/pallet-naming', version = '3.0.0' }
pallet-secrets = { default-features = false, path = '../skw-blockchain-pallets/pallet-secrets', version = '3.0.0' }
pallet-s-contract = { default-features = false, path = '../skw-blockchain-pallets/pallet-s-contract', version = '3.0.0' }
pallet-registry = { default-features = false, path = '../skw-blockchain-pallets/pallet-registry', version = '3.0.0' }
Expand Down Expand Up @@ -63,11 +62,16 @@ runtime-benchmarks = [
'frame-system/runtime-benchmarks',
'hex-literal',
'pallet-balances/runtime-benchmarks',

'pallet-secrets/runtime-benchmarks',
'pallet-naming/runtime-benchmarks',
'pallet-s-contract/runtime-benchmarks',
'pallet-registry/runtime-benchmarks',
'pallet-parentchain/runtime-benchmarks',

'pallet-timestamp/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]

std = [
'codec/std',
'scale-info/std',
Expand All @@ -81,7 +85,10 @@ std = [
'pallet-randomness-collective-flip/std',
'pallet-sudo/std',
'pallet-secrets/std',
'pallet-naming/std',
'pallet-s-contract/std',
'pallet-registry/std',
'pallet-parentchain/std',

'pallet-timestamp/std',
'pallet-transaction-payment-rpc-runtime-api/std',
'pallet-transaction-payment/std',
Expand Down
24 changes: 1 addition & 23 deletions crates/skw-blockchain-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ pub use frame_support::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
},
};
use frame_system::EnsureRoot;
use pallet_transaction_payment::CurrencyAdapter;

pub use pallet_naming;
pub use pallet_secrets;
pub use pallet_s_contract;
pub use pallet_registry;
Expand Down Expand Up @@ -287,25 +285,6 @@ impl pallet_utility::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
pub const ReservationFee: u128 = 10_000_000_000_000;
// pub const Day: BlockNumber = DAYS;
pub const BlockPerPeriod: BlockNumber = 5;

// reserve a slot no more than 5 years.
pub const MaxPeriod: u32 = 1825;
}

impl pallet_naming::Config for Runtime {
type ReservationFee = ReservationFee;
type BlockPerPeriod = BlockPerPeriod;
type MaxPeriod = MaxPeriod;

type ForceOrigin = EnsureRoot<AccountId>;
type Event = Event;
type Currency = Balances;
}

parameter_types! {
pub const IPFSCIDLength: u32 = 46;
pub const MaxActiveShards: u64 = 0;
Expand Down Expand Up @@ -344,7 +323,7 @@ impl pallet_registry::Config for Runtime {


parameter_types! {
pub const DeplayThreshold: u32 = 20;
pub const DeplayThreshold: u32 = 5_000;
pub const MaxOutcomePerSubmission: u64 = 10_000;
pub const MaxSizePerOutcome: u64 = 500_000;
}
Expand Down Expand Up @@ -373,7 +352,6 @@ construct_runtime!(
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
Utility: pallet_utility::{Pallet, Call, Event},

Naming: pallet_naming::{Pallet, Call, Storage, Event<T>},
Secrets: pallet_secrets::{Pallet, Call, Storage, Event<T>},
SContract: pallet_s_contract::{Pallet, Call, Storage, Event<T>},
Registry: pallet_registry::{Pallet, Call, Storage, Event<T>},
Expand Down
2 changes: 1 addition & 1 deletion crates/skw-vm-primitives/src/account_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl AccountId {
for (i, c) in account_id.chars().enumerate() {
this.replace((i, c));
let current_char_is_separator = match c {
'a'..='z' | 'A'..='Z' | '0'..='9' => false,
'a'..='z' | '0'..='9' => false,
'-' | '_' | '.' => true,
_ => {
return Err(ParseAccountError {
Expand Down
18 changes: 15 additions & 3 deletions mock-enclave/src/host/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'fs';
import {IPFS} from '@skyekiwi/ipfs'
import { Calls, Call, Outcomes } from '@skyekiwi/s-contract';
import { hexToU8a } from '@polkadot/util';

import { getLogger } from '@skyekiwi/util';
import { Storage } from './storage';
import {Indexer} from './indexer'

Expand All @@ -25,6 +25,7 @@ export class Dispatcher {
contractName: string, stateRoot: Uint8Array,
executor: (calls: Calls, stateRoot: Uint8Array) => Outcomes
): Promise<Uint8Array> {
const logger = getLogger('dispatcher.dispatchNewContract');

const wasmPath = path.join(__dirname, "../../wasm/", contractName + '.wasm');
const contract = await Storage.getContractRecord(db, contractName);
Expand All @@ -34,6 +35,7 @@ export class Dispatcher {

// can this be exploited?
fs.writeFileSync(wasmPath, hexToU8a(content));
logger.info(`wasm blobk downloaded to ${wasmPath}`);

// now we deal with the calls
let rawOps = contract.deployment_call.ops;
Expand Down Expand Up @@ -67,8 +69,11 @@ export class Dispatcher {
}

const c = new Calls({ "ops": verifiedOps});
logger.info(`calls validated for ${contractName}, sending to executor`);

const o = executor(c, stateRoot)

logger.info(`outcome received for contract deployment of ${contractName}, writing to DB`);
indexer.writeOutcomes(0, contract.deployment_call_index, o);
return o.state_root;
}
Expand All @@ -78,16 +83,23 @@ export class Dispatcher {
callsIndex: number, stateRoot: Uint8Array,
executor: (calls: Calls, stateRoot: Uint8Array) => Outcomes
): Promise<Uint8Array> {

const logger = getLogger('dispatcher.dispatchCalls');

const c = await Storage.getCallsRecord(db, 0, callsIndex)
// const ops = c.ops.filter(op => op.transaction_action !== "deploy");
const ops = c.ops;
const ops = c.ops.filter(op => op.transaction_action !== "deploy");

// const ops = c.ops;
ops.map(it => {
it.origin = it.origin.toLowerCase();
it.receiver = it.receiver.toLowerCase();
})

logger.info(`call validated for ${callsIndex}, sending to executor`)
const o = executor(new Calls({ ops: ops }), stateRoot);

indexer.writeOutcomes(0, callsIndex, o);
logger.info(`outcome received for ${callsIndex}, writing to DB`);

return o.state_root;
}
Expand Down
9 changes: 8 additions & 1 deletion mock-enclave/src/host/shard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Keyring } from '@polkadot/keyring'

import { AsymmetricEncryption } from '@skyekiwi/crypto';
import { ShardMetadata, buildOutcomes } from '@skyekiwi/s-contract/borsh';
import { sendTx, u8aToHex } from '@skyekiwi/util';
import { getLogger, sendTx, u8aToHex } from '@skyekiwi/util';

import {Storage} from './storage'

Expand All @@ -38,12 +38,15 @@ export class ShardManager {
}

public async maybeRegisterSecretKeeper (api: ApiPromise, blockNumber: number): Promise<void> {
const logger = getLogger(`shardManager.maybeRegisterSecretKeeper`);
const allExtrinsics = [];

const maybeExpiration = await api.query.registry.expiration(this.#keyring.address);
const expiration = Number(maybeExpiration.toString());

if (isNaN(expiration) || expiration - 10 < blockNumber) {
logger.info(`registering secret keeper at blockNumber ${blockNumber}`);

// not previously registered
allExtrinsics.push(api.tx.registry.registerSecretKeeper(
u8aToHex(AsymmetricEncryption.getPublicKey(this.#key)),
Expand All @@ -61,11 +64,15 @@ export class ShardManager {
}

public async maybeSubmitExecutionReport (api: ApiPromise, db: Level.LevelDB, blockNumber: number) {
const logger = getLogger(`shardManager.maybeRegisterSecretKeeper`);

for (const shard of this.#shards) {

const shardMetadata = await Storage.getShardMetadataRecord(db, shard);
if (this.beaconIsTurn(blockNumber, shardMetadata)) {

logger.info(`in turn and submitting executing report for blockNumber ${blockNumber}`);

const block = await Storage.getBlockRecord(db, shard, blockNumber);

if (!block.calls || !block.contracts) {
Expand Down
24 changes: 13 additions & 11 deletions mock-enclave/src/host/subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright 2021-2022 @skyekiwi/s-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ApiPromise } from '@polkadot/api';

import { getLogger } from '@skyekiwi/util';

/* eslint-disable sort-keys, camelcase, @typescript-eslint/ban-ts-comment */
export class Subscriber {
public async subscribeNewBlock (
api: ApiPromise,
newBlockHook: (blockNumber: number) => Promise<void>,
): Promise<void> {
await api.rpc.chain.subscribeNewHeads(async (latestHeader) => {
await newBlockHook(latestHeader.number.toNumber());
});
}
public async subscribeNewBlock (
api: ApiPromise,
newBlockHook: (blockNumber: number) => Promise<void>,
): Promise<void> {
const logger = getLogger('subscriber');
logger.info("Subscribing to new blocks");
await api.rpc.chain.subscribeNewHeads(async (latestHeader) => {
logger.info(`new block received ${latestHeader.number.toNumber()}`);
await newBlockHook(latestHeader.number.toNumber());
});
}
}
34 changes: 23 additions & 11 deletions mock-enclave/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
import level from 'level'

import {Calls, Block, Outcomes} from '@skyekiwi/s-contract/borsh';
import {u8aToString, u8aToHex} from '@skyekiwi/util';
import {u8aToString, u8aToHex, getLogger} from '@skyekiwi/util';

import { Indexer } from './host/indexer';
import { Storage } from './host/storage'
Expand Down Expand Up @@ -50,14 +50,15 @@ const processCalls = (calls: Calls, stateRoot: Uint8Array) => {

const main = async () => {

// callStatus(true)
const logger = getLogger("mock-enclave")

const subscriber = new Subscriber();
const indexer = new Indexer();
const shard = new ShardManager([0]);
await shard.init();
const dispatcher = new Dispatcher();

await shard.init();

const provider = new WsProvider('ws://localhost:9944');
const api = await ApiPromise.create({ provider: provider });
const db = level('local');
Expand All @@ -68,7 +69,7 @@ const main = async () => {
await indexer.fetchOnce(api, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
await indexer.fetchAll(api);
await indexer.writeAll();
console.log(`pre-launching indexing done`)
logger.info("pre-launching indexing done, sending to executor")

let executionSummary = await Storage.getExecutionSummary(db);
let localMetadata = await Storage.getMetadata(db);
Expand Down Expand Up @@ -101,8 +102,7 @@ const main = async () => {

console.log(`execution summary: ${executionSummary.high_local_execution_block}`)
}

await indexer.writeAll()
await indexer.writeAll();

const conf = (await api.query.parentchain.confirmation(0, block.block_number)).toJSON();
if (
Expand All @@ -118,10 +118,11 @@ const main = async () => {
}
)

logger.info("subscribe to new blocks");
await subscriber.subscribeNewBlock(api, async (blockNumber: number) => {

console.log(`New block: ${blockNumber}`);
if (blockNumber % 20 === 0) {
logger.info(`New block: ${blockNumber}`);
if (blockNumber % 20 === 0) {
await shard.maybeRegisterSecretKeeper(api, blockNumber);
await shard.maybeSubmitExecutionReport(api, db, blockNumber);
}
Expand Down Expand Up @@ -153,9 +154,20 @@ const main = async () => {
Storage.writeMetadata(localMetadata),
];
await Storage.writeAll(db, op);

console.log(`execution summary: ${executionSummary.high_local_execution_block}`)
await indexer.writeAll()
await indexer.writeAll();

logger.info(`execution summary: ${executionSummary.high_local_execution_block}`)
const conf = (await api.query.parentchain.confirmation(0, block.block_number)).toJSON();
if (
// no reports has been submitted yet || confirmation is below the threshold?
(conf === null) && (
(block.calls && block.calls.length !== 0) ||
(block.contracts && block.contracts.length !== 0)
) && dispatcher.isDispatchable(db, block.block_number)
) {
logger.info("submitting report for ", block.block_number)
await shard.maybeSubmitExecutionReport(api, db, block.block_number);
}
}
)
})
Expand Down
Loading

0 comments on commit e1b2794

Please sign in to comment.