Skip to content

Commit

Permalink
inline documentations for each pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyTimes committed Mar 30, 2022
1 parent d6f3c06 commit f7ec64a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 72 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
# blockchain
'crates/skw-blockchain-node',
'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 Expand Up @@ -39,6 +38,8 @@ exclude = [
'enclave/skw-sgx-enclave',

"crates/near-contract-standards",
'crates/skw-blockchain-pallets-unused/pallet-naming',

]
[profile.release]
panic = 'unwind'
14 changes: 12 additions & 2 deletions crates/skw-blockchain-pallets/pallet-parentchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,50 @@ pub mod pallet {
pub trait Config: frame_system::Config + pallet_registry::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

type WeightInfo: WeightInfo;

/// Maximum delay between receiving a call and submitting result for it
#[pallet::constant]
type DeplayThreshold: Get<<Self as frame_system::Config>::BlockNumber>;

/// Maximum number of outcomes allowed per submission
#[pallet::constant]
type MaxOutcomePerSubmission: Get<u64>;

/// Maximum length of sizze for each outcome submitted
#[pallet::constant]
type MaxSizePerOutcome: Get<u64>;

type WeightInfo: WeightInfo;
}

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

/// Threshold of outcome submission from SecretKeepers needed to confirm a block
#[pallet::storage]
#[pallet::getter(fn shard_confirmation_threshold)]
pub(super) type ShardConfirmationThreshold<T: Config> = StorageMap<_, Twox64Concat,
ShardId, u64>;

/// state_root of offchain runtime
#[pallet::storage]
#[pallet::getter(fn state_root_at)]
pub(super) type StateRoot<T: Config> = StorageDoubleMap<_, Twox64Concat, ShardId,
Twox64Concat, T::BlockNumber, [u8; 32]>;

/// state dump file checksum of offchain runtime
#[pallet::storage]
#[pallet::getter(fn state_file_hash_at)]
pub(super) type StateFileHash<T: Config> = StorageDoubleMap<_, Twox64Concat, ShardId,
Twox64Concat, T::BlockNumber, [u8; 32]>;

/// confirmations received for offchain runtime for blocks
#[pallet::storage]
#[pallet::getter(fn confirmation_of)]
pub(super) type Confirmation<T: Config> = StorageDoubleMap<_, Twox64Concat, ShardId,
Twox64Concat, T::BlockNumber, u64>;

/// outcome received each call
#[pallet::storage]
#[pallet::getter(fn outcome_of)]
pub(super) type Outcome<T: Config> = StorageMap<_, Twox64Concat,
Expand All @@ -88,6 +96,7 @@ pub mod pallet {
#[pallet::call]
impl<T:Config> Pallet<T> {

/// (ROOT ONLY) set the confirmation threshold for a shard
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_shard_confirmation_threshold())]
pub fn set_shard_confirmation_threshold(
origin: OriginFor<T>,
Expand All @@ -101,6 +110,7 @@ pub mod pallet {
Ok(())
}

/// submit a batch of outcomes for a block
#[pallet::weight(<T as pallet::Config>::WeightInfo::submit_outcome(outcome_call_index.len() as u32))]
pub fn submit_outcome(
origin: OriginFor<T>,
Expand Down
19 changes: 17 additions & 2 deletions crates/skw-blockchain-pallets/pallet-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,55 @@ pub mod pallet {
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

type WeightInfo: WeightInfo;

/// duration of the validity of registrations
#[pallet::constant]
type RegistrationDuration: Get<u32>;

/// maximum number of shards allowed
#[pallet::constant]
type MaxActiveShards: Get<u64>;

type WeightInfo: WeightInfo;
// type ForceOrigin: EnsureOrigin<Self::Origin>;
}

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

/// a list of all active secret keepers
#[pallet::storage]
#[pallet::getter(fn secret_keepers)]
pub(super) type SecretKeepers<T: Config> = StorageValue<_,
Vec< T::AccountId >, OptionQuery >;

/// registration expiration block number for each secret keepers
#[pallet::storage]
#[pallet::getter(fn expiration_of)]
pub(super) type Expiration<T: Config> = StorageMap<_, Twox64Concat,
T::AccountId, T::BlockNumber>;

/// identity publlic key of each secret keepers, used to receive the secret
#[pallet::storage]
#[pallet::getter(fn public_key_of)]
pub(super) type PublicKey<T: Config> = StorageMap<_, Twox64Concat,
T::AccountId, Vec<u8>>;

/// members of each shard
#[pallet::storage]
#[pallet::getter(fn shard_members_of)]
pub(super) type ShardMembers<T: Config> = StorageMap<_, Twox64Concat, ShardId, Vec<T::AccountId>>;


// Beacons are identifier of when a secret keeper is supposed to submit a outcome

/// beacon index of each secret keeper, first come first serve
#[pallet::storage]
#[pallet::getter(fn beacon_index_of)]
pub(super) type BeaconIndex<T: Config> = StorageDoubleMap<_, Twox64Concat, ShardId,
Twox64Concat, T::AccountId, u64>;

/// total number of members in a shard - numbers of nodes playing the beacon game
#[pallet::storage]
#[pallet::getter(fn beacon_count_of)]
pub(super) type BeaconCount<T: Config> = StorageMap<_, Twox64Concat, ShardId, u64>;
Expand All @@ -90,6 +101,7 @@ pub mod pallet {
#[pallet::call]
impl<T:Config> Pallet<T> {

/// register a secret keeper
#[pallet::weight(<T as pallet::Config>::WeightInfo::register_secret_keeper())]
pub fn register_secret_keeper(
origin: OriginFor<T>,
Expand Down Expand Up @@ -118,6 +130,7 @@ pub mod pallet {
Ok(())
}

/// renew registration by submitting a new signature and public key
#[pallet::weight(<T as pallet::Config>::WeightInfo::renew_registration())]
pub fn renew_registration(
origin: OriginFor<T>,
Expand All @@ -142,6 +155,7 @@ pub mod pallet {
Ok(())
}

/// remove ones own registration record
#[pallet::weight(<T as pallet::Config>::WeightInfo::remove_registration())]
pub fn remove_registration(
origin: OriginFor<T>,
Expand All @@ -159,6 +173,7 @@ pub mod pallet {
}
}

/// register all active shards one is running
#[pallet::weight(<T as pallet::Config>::WeightInfo::register_running_shard())]
pub fn register_running_shard(
origin: OriginFor<T>,
Expand Down
22 changes: 18 additions & 4 deletions crates/skw-blockchain-pallets/pallet-s-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub type CallIndex = u64;
pub type EncodedCall = Vec<u8>;
pub type ShardId = u64;
pub type PublicKey = [u8; 32];
pub type ContractName = Vec<u8>;

#[frame_support::pallet]
pub mod pallet {
Expand All @@ -37,15 +38,15 @@ pub mod pallet {

type WeightInfo: WeightInfo;

/// maximum length of encoded calls allowed
#[pallet::constant]
type MaxCallLength: Get<u32>;

#[pallet::constant]
type MaxOutputLength: Get<u32>;

/// minimum length of a contract name
#[pallet::constant]
type MinContractNameLength: Get<u32>;

/// maximum length of a contract name
#[pallet::constant]
type MaxContractNameLength: Get<u32>;
}
Expand All @@ -54,41 +55,49 @@ pub mod pallet {
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

/// wasm_blob of a deployed contracts
#[pallet::storage]
#[pallet::getter(fn wasm_blob_cid_of)]
pub(super) type WasmBlobCID<T: Config> = StorageDoubleMap<_, Twox64Concat,
ShardId, Blake2_128Concat, Vec<u8>, Vec<u8> >;
ShardId, Blake2_128Concat, ContractName, Vec<u8> >;

/// call history of a block (ShardId, BlockNumber) -> Vec<CallIndex>
#[pallet::storage]
#[pallet::getter(fn call_history_of)]
pub(super) type CallHistory<T: Config> = StorageDoubleMap<_, Twox64Concat,
ShardId, Twox64Concat, T::BlockNumber, Vec<CallIndex> >;

/// call content of a call (ShardId, CallIndex) -> EncodedCall
#[pallet::storage]
#[pallet::getter(fn call_record_of)]
pub(super) type CallRecord<T: Config> = StorageDoubleMap<_, Twox64Concat,
ShardId, Twox64Concat, CallIndex, (EncodedCall, T::AccountId) >;

/// the callIndex that will be assigned to the next calls
#[pallet::storage]
#[pallet::getter(fn current_call_index_of)]
pub(super) type CurrentCallIndex<T: Config> = StorageMap<_, Twox64Concat,
ShardId, CallIndex >;

/// the secret id of the shard state file on pallet-secrets
#[pallet::storage]
#[pallet::getter(fn shard_secret_id)]
pub(super) type ShardSecretIndex<T: Config> = StorageMap<_, Twox64Concat,
ShardId, SecretId >;

/// the public key of the shard, used for sending encrypted encoded calls
#[pallet::storage]
#[pallet::getter(fn shard_public_key)]
pub(super) type ShardPublicKey<T: Config> = StorageMap<_, Twox64Concat,
ShardId, PublicKey>;

/// the highest call index of a shard as of the latest state rollup
#[pallet::storage]
#[pallet::getter(fn shard_high_call_index)]
pub(super) type ShardHighCallIndex<T: Config> = StorageMap<_, Twox64Concat,
ShardId, CallIndex>;

/// authorized members who can access the shard
#[pallet::storage]
#[pallet::getter(fn shard_operator)]
pub(super) type ShardOperator<T: Config> = StorageDoubleMap<_, Twox64Concat,
Expand Down Expand Up @@ -119,6 +128,7 @@ pub mod pallet {
#[pallet::call]
impl<T:Config> Pallet<T> {

/// register a contract with a deployment encoded call
#[pallet::weight(<T as pallet::Config>::WeightInfo::register_contract())]
pub fn register_contract(
origin: OriginFor<T>,
Expand Down Expand Up @@ -165,6 +175,7 @@ pub mod pallet {
Ok(())
}

/// push a batch of calls for a shard
#[pallet::weight(<T as pallet::Config>::WeightInfo::push_call())]
pub fn push_call(
origin: OriginFor<T>,
Expand Down Expand Up @@ -193,6 +204,7 @@ pub mod pallet {
Ok(())
}

/// (SHARD OPERATOR ONLY) initialize a shard with initial state file and initial calls
#[pallet::weight(<T as pallet::Config>::WeightInfo::initialize_shard())]
pub fn initialize_shard(
origin: OriginFor<T>,
Expand Down Expand Up @@ -230,6 +242,7 @@ pub mod pallet {
}
}

/// (SHARD OPERATOR ONLY) rollup a shard for key rotations
#[pallet::weight(<T as pallet::Config>::WeightInfo::shard_rollup())]
pub fn shard_rollup(
origin: OriginFor<T>,
Expand All @@ -254,6 +267,7 @@ pub mod pallet {
}
}

/// (ROOT ONLY) nominate a shard operator
#[pallet::weight(<T as pallet::Config>::WeightInfo::add_authorized_shard_operator())]
pub fn add_authorized_shard_operator(
origin: OriginFor<T>,
Expand Down
3 changes: 0 additions & 3 deletions crates/skw-blockchain-pallets/pallet-s-contract/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ impl pallet_secrets::Config for Test {
type WeightInfo = ();
type Event = Event;
type IPFSCIDLength = IPFSCIDLength;
type MaxActiveShards = MaxActiveShards;
}

parameter_types! {
pub const MaxCallLength: u32 = 512;
pub const MaxOutputLength: u32 = 1024;
pub const MinContractNameLength: u32 = 1;
pub const MaxContractNameLength: u32 = 32;
}
Expand All @@ -80,7 +78,6 @@ impl pallet_s_contract::Config for Test {
type WeightInfo = ();
type Event = Event;
type MaxCallLength = MaxCallLength;
type MaxOutputLength = MaxOutputLength;
type MinContractNameLength = MinContractNameLength;
type MaxContractNameLength = MaxContractNameLength;
}
Expand Down
Loading

0 comments on commit f7ec64a

Please sign in to comment.