Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[MPoW] New MPoW #261

Merged
merged 18 commits into from
Sep 29, 2020
Merged

[MPoW] New MPoW #261

merged 18 commits into from
Sep 29, 2020

Conversation

badkk
Copy link
Member

@badkk badkk commented Sep 27, 2020

New MPoW Spec

Under the performance test restriction(reported files size) and other requirements, the whole MPoW re-designed with Incremental Reporting, New A/B Upgrade and Start Network.

Resolved #229
Resolved #215
Resolved #214
New open #259 #260 #262

Mechanism

⚡️ WR Reporting

  1. WR reporting including added and deleted, the data structure shows below
pub struct WorkReport {
    pub block_number: u64,
    pub block_hash: BlockHash,
    pub files_size: u64,
    pub reserved: u64,
    pub deleted_files: Vec<(MerkleRoot, u64)>,
    pub added_files: Vec<(MerkleRoot, u64)>,
    pub reserved_root: MerkleRoot,
    pub files_root: MerkleRoot,
    pub pub_key: SworkerPubKey,
    pub old_pub_key: SworkerPubKey,
    pub sig: SworkerSig,
}
  1. Validation process: (READ ONLY)

    • identity check;
      • Registed?
      • Valid sWorker code(or not expired)
    • A/B upgrade check: added and deleted should be empty, files root and srd root MUST match
    • Timing check;
      • Block Number matches Block Hash
      • Block number matches current_report_slot
    • sig check
    • files transition check, compare old_file_size matches the new_files_size change
  2. merge work report: (WRITE)

    • Judge if it is resuming reporting(has report slot gap),resuming report needs to set all sOrder status to success
    • added files(Pending -> Success) -> set sOrder status to success and update order's expired;
    • added files(Failed -> Success) -> set sOrder status to success;
    • deleted files -> set sOrder status to failed;
    • Update ReportInSlot
    • Update total free and used
    • If it is A/B upgrade report, chill A;

Update Identities

  1. Loop all IdBonds,sum up all work reports(mapping to identities) and update stake limit(staking module);
  2. As for the outdated work report,set stake_limit to 0 and set all corresponding sOrder status to failed(Only set once, aka. 1st failed),but WITHOUT deleting work report;

Data structure

With pub_key as index,all data surrounded with this, account will define with IdBonds.

  1. Identities
Map<PubKey, SworkerCode>;
  1. IdBonds
Map<AccountId, PubKeys>
  1. WorkReports
Map<PubKey, WorkReport>
  1. ReportInSlot
DoubleMap<PubKey, ReportSlot, bool>
  1. CurrentReportSlot
Option<ReportSlot>
  1. Code
Option<SworkerCode>
  1. ABExpire
Option<BlockNumber>

Calls

  1. register
  2. report works(follow WR Reporting)
  3. update identities(follow Update Identities)

Test breaking

Change all swork module test cases

Other modules's affects

  1. check_works in market module

@badkk badkk added A0-breakconsensus PR which break the consensus, make blocking error P0-dropeverything🔔 Fix first A3-breaktest PR which break current test case M0-protocol Mechanism related, break the protocol-self labels Sep 27, 2020
@badkk badkk added this to the Maxwell M2 milestone Sep 27, 2020
@badkk badkk marked this pull request as ready for review September 28, 2020 15:51
Copy link
Member

@mmyyrroonn mmyyrroonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!! 👍

@@ -645,7 +645,7 @@ construct_runtime! {
Identity: pallet_identity::{Module, Call, Storage, Event<T>},

// Crust modules
Swork: swork::{Module, Call, Storage, Event<T>, Config<T>},
Swork: swork::{Module, Call, Storage, Event<T>, Config},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious about the difference between Config and Config<T>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have storage with generic type to initialize(config), we need this <T>

@badkk badkk merged commit db38b87 into master Sep 29, 2020
@badkk badkk deleted the zikun/new-mpow branch September 29, 2020 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-breakconsensus PR which break the consensus, make blocking error A3-breaktest PR which break current test case M0-protocol Mechanism related, break the protocol-self P0-dropeverything🔔 Fix first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MPoW] New A/B Upgrade Mechanism [MPoW] Multiple enclave pub keys bond [MPoW] Realtime file report
3 participants