Skip to content
  1. May 03, 2021
    • Peter Goodspeed-Niklaus's avatar
      Refactor election solution trimming for efficiency (#8614) · c786fb21
      Peter Goodspeed-Niklaus authored
      * Refactor election solution trimming for efficiency
      
      The previous version always trimmed the `CompactOf<T>` instance,
      which was intrinsically inefficient: that's a packed data structure,
      which is naturally expensive to edit. It's much easier to edit
      the unpacked data structures: the `voters` and `assignments` lists.
      
      * rework length-trim tests to work with the new interface
      
      Test suite now compiles. Tests still don't pass because the macro
      generating the compact structure still generates `unimplemented!()`
      for the actual `compact_length_of` implementation.
      
      * simplify
      
      * add a fuzzer which can validate `Compact::encoded_size_for`
      
      The `Compact` solution type is generated distinctly for each runtime,
      and has both three type parameters and a built-in limit to the number
      of candidates that each voter can vote for. Finally, they have an
      optional `#[compact]` attribute which changes the encoding behavior.
      
      The assignment truncation algorithm we're using depends on the ability
      to efficiently and accurately determine how much space a `Compact`
      solution will take once encoded.
      
      Together, these two facts imply that simple unit tests are not
      sufficient to validate the behavior of `Compact::encoded_size_for`.
      This commit adds such a fuzzer. It is designed such that it is possible
      to add a new fuzzer to the family by simply adjusting the
      `generate_solution_type` macro invocation as desired, and making a
      few minor documentation edits.
      
      Of course, the fuzzer still fails for now: the generated implementation
      for `encoded_size_for` is still `unimplemented!()`. However, once
      the macro is updated appropriately, this fuzzer family should allow
      us to gain confidence in the correctness of the generated code.
      
      * Revert "add a fuzzer which can validate `Compact::encoded_size_for`"
      
      This reverts commit 916038790887e64217c6a46e9a6d281386762bfb.
      
      The design of `Compact::encoded_size_for` is flawed. When `#[compact]`
      mode is enabled, every integer in the dataset is encoded using run-
      length encoding. This means that it is impossible to compute the final
      length faster than actually encoding the data structure, because the
      encoded length of every field varies with the actual value stored.
      
      Given that we won't be adding that method to the trait, we won't be
      needing a fuzzer to validate its performance.
      
      * revert changes to `trait CompactSolution`
      
      If `CompactSolution::encoded_size_for` can't be implemented in the
      way that we wanted, there's no point in adding it.
      
      * WIP: restructure trim_assignments_length by actually encoding
      
      This is not as efficient as what we'd hoped for, but it should still
      be better than what it's replacing. Overall efficiency of
      `fn trim_assignments_length` is now `O(edges * lg assignments.len())`.
      
      * fix compiler errors
      
      * don't sort voters, just assignments
      
      Sorting the `voters` list causes lots of problems; an invariant that
      we need to maintain is that an index into the voters list has a stable
      meaning.
      
      Luckily, it turns out that there is no need for the assignments list
      to correspond to the voters list. That isn't an invariant, though previously
      I'd thought that it was.
      
      This simplifies things; we can just leave the voters list alone,
      and sort the assignments list the way that is convenient.
      
      * WIP: add `IndexAssignment` type to speed up repeatedly creating `Compact`
      
      Next up: `impl<'a, T> From<&'a [IndexAssignmentOf<T>]> for Compact`,
      in the proc-macro which makes `Compact`. Should be a pretty straightforward
      adaptation of `from_assignment`.
      
      * Add IndexAssignment and conversion method to CompactSolution
      
      This involves a bit of duplication of types from
      `election-provider-multi-phase`; we'll clean those up shortly.
      
      I'm not entirely happy that we had to add a `from_index_assignments`
      method to `CompactSolution`, but we couldn't define
      `trait CompactSolution: TryFrom<&'a [Self::IndexAssignment]` because
      that made trait lookup recursive, and I didn't want to propagate
      `CompactSolutionOf<T> + TryFrom<&[IndexAssignmentOf<T>]>` everywhere
      that compact solutions are specified.
      
      * use `CompactSolution::from_index_assignment` and clean up dead code
      
      * get rid of `from_index_assignments` in favor of `TryFrom`
      
      * cause `pallet-election-provider-multi-phase` tests to compile successfully
      
      Mostly that's just updating the various test functions to keep track of
      refactorings elsewhere, though in a few places we needed to refactor some
      test-only helpers as well.
      
      * fix infinite binary search loop
      
      Turns out that moving `low` and `high` into an averager function is a
      bad idea, because the averager gets copies of those values, which
      of course are never updated. Can't use mutable references, because
      we want to read them elsewhere in the code. Just compute the average
      directly; life is better that way.
      
      * fix a test failure
      
      * fix the rest of test failures
      
      * remove unguarded subtraction
      
      * fix npos-elections tests compilation
      
      * ensure we use sp_std::vec::Vec in assignments
      
      * add IndexAssignmentOf to sp_npos_elections
      
      * move miner types to `unsigned`
      
      * use stable sort
      
      * rewrap some long comments
      
      * use existing cache instead of building a dedicated stake map
      
      * generalize the TryFrom bound on CompactSolution
      
      * undo adding sp-core dependency
      
      * consume assignments to produce index_assignments
      
      * Add a test of Assignment -> IndexAssignment -> Compact
      
      * fix `IndexAssignmentOf` doc
      
      * move compact test from sp-npos-elections-compact to sp-npos-elections
      
      This means that we can put the mocking parts of that into a proper
      mock package, put the test into a test package among other tests.
      
      Having the mocking parts in a mock package enables us to create a
      benchmark (which is treated as a separate crate) import them.
      
      * rename assignments -> sorted_assignments
      
      * sort after reducing to avoid potential re-sort issues
      
      * add runtime benchmark, fix critical binary search error
      
      "Why don't you add a benchmark?", he said. "It'll be good practice,
      and can help demonstrate that this isn't blowing up the runtime."
      
      He was absolutely right.
      
      The biggest discovery is that adding a parametric benchmark means that
      you get a bunch of new test cases, for free. This is excellent, because
      those test cases uncovered a binary search bug. Fixing that simplified
      that part of the code nicely.
      
      The other nice thing you get from a parametric benchmark is data about
      what each parameter does. In this case, `f` is the size factor: what
      percent of the votes (by size) should be removed. 0 means that we should
      keep everything, 95 means that we should trim down to 5% of original size
      or less.
      
      ```
      Median Slopes Analysis
      ========
      -- Extrinsic Time --
      
      Model:
      Time ~=     3846
          + v    0.015
          + t        0
          + a    0.192
          + d        0
          + f        0
                    µs
      
      Min Squares Analysis
      ========
      -- Extrinsic Time --
      
      Data points distribution:
          v     t     a     d     f   mean µs  sigma µs       %
      <snip>
       6000  1600  3000   800     0      4385     75.87    1.7%
       6000  1600  3000   800     9      4089     46.28    1.1%
       6000  1600  3000   800    18      3793     36.45    0.9%
       6000  1600  3000   800    27      3365     41.13    1.2%
       6000  1600  3000   800    36      3096     7.498    0.2%
       6000  1600  3000   800    45      2774     17.96    0.6%
       6000  1600  3000   800    54      2057     37.94    1.8%
       6000  1600  3000   800    63      1885     2.515    0.1%
       6000  1600  3000   800    72      1591     3.203    0.2%
       6000  1600  3000   800    81      1219     25.72    2.1%
       6000  1600  3000   800    90       859     5.295    0.6%
       6000  1600  3000   800    95     684.6     2.969    0.4%
      
      Quality and confidence:
      param     error
      v         0.008
      t         0.029
      a         0.008
      d         0.044
      f         0.185
      
      Model:
      Time ~=     3957
          + v    0.009
          + t        0
          + a    0.185
          + d        0
          + f        0
                    µs
      ```
      
      What's nice about this is the clear negative correlation between
      amount removed and total time. The more we remove, the less total
      time things take.
      c786fb21
  2. Apr 23, 2021
  3. Apr 22, 2021
  4. Apr 18, 2021
  5. Apr 17, 2021
  6. Apr 16, 2021
    • Bastian Köcher's avatar
      Remove `serde` requirement from FRAME macros (#8628) · c8136bd1
      Bastian Köcher authored
      
      
      * Remove `serde` requirement from FRAME macros
      
      Currently there is some implicit requirement on `serde` being present in
      the `Cargo.toml` of a pallet when `GenesisConfig` is used. This pr
      removes this requirement by using the serde attribute `serde(crate = "..")`.
      
      * build a unique reexport of serde in impl_opaque_keys, by abusing paste doc concatenation
      
      * Optimize
      
      Co-authored-by: default avatarthiolliere <[email protected]>
      c8136bd1
  7. Apr 14, 2021
  8. Apr 13, 2021
  9. Apr 09, 2021
  10. Apr 08, 2021
  11. Apr 07, 2021
  12. Apr 05, 2021
  13. Apr 04, 2021
  14. Mar 30, 2021
  15. Mar 29, 2021
  16. Mar 28, 2021
    • Peter Goodspeed-Niklaus's avatar
      make types within `generate_solution_type` macro explicit (#8447) · c2dd5e21
      Peter Goodspeed-Niklaus authored
      * make types within `generate_solution_type` macro explicit
      
      Closes #8444.
      
      Just changes the parsing logic for that macro; does not change any
      emitted code. The associated types associated with the macro now
      require explicit, keyword-style declaration.
      
      **Old**:
      
      ```rust
      sp_npos_elections::generate_solution_type!(
      	#[compact]
      	pub struct TestCompact::<VoterIndex, TargetIndex, PerU16>(16)
      );
      ```
      
      **New**:
      
      ```rust
      sp_npos_elections::generate_solution_type!(
      	#[compact]
      	pub struct TestCompact::<VoterIndex = VoterIndex, CandidateIndex = TargetIndex, Accuracy = PerU16>(16)
      );
      ```
      
      * un-ignore doc-tests
      
      * use new form in bin/node/runtime/
      
      * rename CandidateIndex -> TargetIndex
      
      * add tests demonstrating some potential compile failures
      c2dd5e21
  17. Mar 27, 2021
    • Gavin Wood's avatar
      Repot frame_support::traits; introduce some new currency stuff (#8435) · ff5765ea
      Gavin Wood authored
      
      
      * Reservable, Transferrable Fungible(s), plus adapters.
      
      * Repot into new dir
      
      * Imbalances for Fungibles
      
      * Repot and balanced fungible.
      
      * Clean up names and bridge-over Imbalanced.
      
      * Repot frame_support::trait. Finally.
      
      * Make build.
      
      * Docs
      
      * Good errors
      
      * Fix tests. Implement fungible::Inspect for Balances.
      
      * Implement additional traits for Balances.
      
      * Revert UI test "fixes"
      
      * Fix UI error
      
      * Fix UI test
      
      * Fixes
      
      * Update lock
      
      * Grumbles
      
      * Grumbles
      
      * Fixes
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      ff5765ea
  18. Mar 24, 2021
  19. Mar 21, 2021
  20. Mar 18, 2021
  21. Mar 17, 2021
    • Bastian Köcher's avatar
      Aura and Slots refactoring (#8386) · 15e15e7d
      Bastian Köcher authored
      * Make slot duration being exposed as `Duration` to the outside
      
      * Some slot info love
      
      * Add `build_aura_worker` utility function
      
      * Copy copy copy
      15e15e7d
    • Jon Häggblad's avatar
      Storing multiple Justifications per block (#7640) · 0d6884b9
      Jon Häggblad authored
      
      
      * primitives/runtime: initial changes on supporting multiple Justifications
      
      * primitives/runtime: make Justifications strongly typed
      
      * Encode/decode Justifications
      
      * primitives/runtime: add Justification type
      
      * backend: apply_finality and finalize_block takes a single Justification
      
      * manual-seal: create engine id and let rpc take encoded justification
      
      * backend: skeleton functions for appending justifications
      
      * backend: initial implementation append_justification
      
      Initial implementation of append_justification on the Backend trait, and also remove unused skeleton
      functions for append_justificaton on Finaziler trait.
      k
      
      * backend: guard against duplicate consensus engine id
      
      * client/db: add check for block finality
      
      * client/api: add append_justification to in_mem db
      
      * client/light: add no-op append_justification
      
      * network: fix decode call for Justification
      
      * network: only send a single Justification in BlockData
      
      * network: minor comment update
      
      * protocol: update field names to distinguish single justification
      
      * client: further field renames to plural
      
      * client: update function names to plural justifications
      
      * client/db: upgrade existing database for new format
      
      * network: remove dependency on grandpa crate
      
      * db: fix check for finalized block
      
      * grandpa: check for multiple grandpa justifications hwne importing
      
      * backend: update Finalizer trait to take multiple Justifications
      
      * db: remove debugging statements in migration code
      
      * manual-seal: update note about engine id
      
      * db: fix check for finalized block
      
      * client: update variable name to reflect it is now plural
      
      * grandpa: fix incorrect empty Justications in test
      
      * primitives: make Justifications opaque to avoid being empty
      
      * network: fix detecting empty Justification
      
      * runtime: doc strings for Justifications functions
      
      * runtime: add into_justifications
      
      * primitives: check for duplicates in when adding to Justifications
      
      * network/test: use real grandpa engine id in test
      
      * client: fix reviewer comments
      
      * primitives: rename Justifications::push to append
      
      * backend: revert changes to Finalizer trait
      
      * backend: revert mark_finalized
      
      * backend: revert changes to finalize_block
      
      * backend: revert finalized_blocks
      
      * db: add a quick early return for performance
      
      * client: minor reviewer comments
      
      * service/test: use local ConsensusEngineId
      
      * network: add link to issue for sending multiple Justifications
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarPierre Krieger <[email protected]>
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarPierre Krieger <[email protected]>
      
      * network: tweaks to review suggestions
      
      * network: revert change to BlockData for backwards compatibility
      
      * Apply suggestion from code review
      
      Co-authored-by: default avatarPierre Krieger <[email protected]>
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarAndré Silva <[email protected]>
      
      * primitives: update doc comment for Justifications
      
      * client/db/upgrade: avoid grandpa crate dependency
      
      * consensus: revert to single Justification for import_justification
      
      * primitives: improve justifications docs
      
      * style cleanups
      
      * use and_then
      
      * client: rename JUSTIFICATIONS db column
      
      * network: revert to using FRNK in network-test
      
      Co-authored-by: default avatarPierre Krieger <[email protected]>
      Co-authored-by: default avatarAndré Silva <[email protected]>
      Co-authored-by: default avatarAndré Silva <[email protected]>
      0d6884b9
    • Peter Goodspeed-Niklaus's avatar
      Improve complexity of CompactAssignments::unique_targets (#8314) · 23b32e75
      Peter Goodspeed-Niklaus authored
      * Improve complexity of CompactAssignments::unique_targets
      
      Original implementation was O(n**2). Current impl is O(n log n).
      
      Avoided the original proposed mitigation because it does not retain
      the de-duplicating property present in the original implementation.
      This implementation does a little more work, but retains that property.
      
      * Explicitly choose sp_std Vec and BTreeSet
      
      Ensures that the macro still works if someone uses it in a context
      in which sp_std is not imported or is renamed.
      
      * explicitly use sp_std vectors throughout compact macro
      23b32e75
  22. Mar 16, 2021
    • Gavin Wood's avatar
      staking: Flexible generation of reward curve and associated tweaks (#8327) · 363db4f0
      Gavin Wood authored
      
      
      * Initial abstraction
      
      * Alter rest of APIs
      
      * Fixes
      
      * Some extra getters in Gilt pallet.
      
      * Refactor Gilt to avoid u128 conversions
      
      * Simplify and improve pow in per_things
      
      * Add scalar division to per_things
      
      * Renaming from_fraction -> from_float, drop _approximation
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Make stuff build
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Update .gitignore
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Update frame/gilt/src/lib.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Update frame/gilt/src/mock.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      Co-authored-by: default avatarShawn Tabrizi <[email protected]>
      Co-authored-by: default avatarKian Paimani <[email protected]>
      363db4f0
    • Kian Paimani's avatar
      Audit fixes for election/staking decoupling part 2 (#8167) · b6c62639
      Kian Paimani authored
      
      
      * Base features and traits.
      
      * pallet and unsigned phase
      
      * Undo bad formattings.
      
      * some formatting cleanup.
      
      * Small self-cleanup.
      
      * Make it all build
      
      * self-review
      
      * Some doc tests.
      
      * Some changes from other PR
      
      * Fix session test
      
      * Update Cargo.lock
      
      * Update frame/election-provider-multi-phase/src/lib.rs
      
      Co-authored-by: default avatarGuillaume Thiolliere <[email protected]>
      
      * Some review comments
      
      * Rename + make encode/decode
      
      * Do an assert as well, just in case.
      
      * Fix build
      
      * Update frame/election-provider-multi-phase/src/unsigned.rs
      
      Co-authored-by: default avatarGuillaume Thiolliere <[email protected]>
      
      * Las comment
      
      * fix staking fuzzer.
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * Add one last layer of feasibility check as well.
      
      * Last fixes to benchmarks
      
      * Some more docs.
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * Some nits
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * Fix doc
      
      * Mkae ci green
      
      * Audit fixes for election-provider: part 2 signed phase.
      
      * Fix weight
      
      * Some grumbles.
      
      * Try and weigh to get_npos_voters
      
      * Fix build
      
      * Fix line width
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * Fix tests.
      
      * Fix build
      
      * Reorg some stuff
      
      * More reorg.
      
      * Reorg done.
      
      * Fix build
      
      * Another rename
      
      * Fix build
      
      * Update frame/election-provider-multi-phase/src/mock.rs
      
      Co-authored-by: default avatarPeter Goodspeed-Niklaus <[email protected]>
      
      * nit
      
      * better doc
      
      * Line width
      
      * Fix build
      
      * Self-review
      
      * Self-review
      
      * Fix wan
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs
      
      * fix build and review comments.
      
      * Update frame/election-provider-multi-phase/src/lib.rs
      
      Co-authored-by: default avatarShawn Tabrizi <[email protected]>
      
      * add comment
      
      Co-authored-by: default avatarShawn Tabrizi <[email protected]>
      Co-authored-by: default avatarGuillaume Thiolliere <[email protected]>
      Co-authored-by: default avatarParity Benchmarking Bot <[email protected]>
      Co-authored-by: default avatarPeter Goodspeed-Niklaus <[email protected]>
      b6c62639
    • Peter Goodspeed-Niklaus's avatar
      NPoS Challenge Mode (#8236) · 49be0579
      Peter Goodspeed-Niklaus authored
      
      
      * Add PJR challenge functions
      
      - Updates the PJR check to return a counterexample if one exists
      - Adds functions to cheaply check counterexamples
      
      This is in support of off-chain PJR challenges: if a miner discovers
      that an accepted election solution does not satisfy PJR, it will be
      eligible for substantial rewards. This helps ensure that validator
      elections have an absolute quality floor, so even if someone manages
      to censor well-behaved solutions to give themselves unfair representation,
      we can catch them in the act and penalize them.
      
      * counterexample -> counter_example
      
      * reorganize: high -> low abstraction
      
      * reorganize challenges high -> low abstraction
      
      * add note justifying linear search
      
      * Simplify max_pre_score validation
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * add minor test of pjr challenge validation
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      49be0579
  23. Mar 15, 2021
  24. Mar 11, 2021
    • Bastian Köcher's avatar
      Convert timestamp to unit type wrapper (#8333) · 5d73e960
      Bastian Köcher authored
      The timestamp inherent type was up to now just a simple `u64`. This
      worked, but doesn't give you that much guarantees at compile time about
      the type. This pr changes that by converting this type to a unit type
      wrapper, similar to what we have done for `Slot`.
      
      This is required for some future pr that touches quite a lot of the
      inherents stuff :)
      
      Besides this unit wrapper type, this pr also moves the `OnTimestampSet`
      trait to `frame_support::traits`.
      5d73e960
    • dependabot[bot]'s avatar
    • Peter Goodspeed-Niklaus's avatar
      Implement PJR checker (#8160) · 781f9087
      Peter Goodspeed-Niklaus authored
      
      
      * Apply.
      
      * get rid of glob import
      
      * use meaningful generic type name
      
      * pjr_check operates on `Supports` struct used elsewhere
      
      * improve algorithmic complexity of `prepare_pjr_input`
      
      * fix rustdoc warnings
      
      * improve module docs
      
      * typo
      
      * simplify debug assertion
      
      * add test finding the phase-change threshold value for a constructed scenario
      
      * add more threshold scenarios to disambiguate plausible interpretations
      
      * add link to npos paper reference
      
      * docs: staked_assignment -> supports
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * add utility method for generating npos inputs
      
      * add a fuzzer which asserts that all unbalanced seq_phragmen are PJR
      
      Note that this currently fails. I hope that this can be rectified
      by calculating the threshold instead of choosing some arbitrary number.
      
      * assert in all cases, not just debug
      
      * leverage a native solution to choose candidates
      
      * use existing helper methods
      
      * add pjr-check and incorporate into the fuzzer
      
      We should probably have one of the W3F people look at this to ensure
      we're not misconstruing any definitions, but this seems like a
      fairly straightforward implementation.
      
      * fix compilation errors
      
      * Enable manually setting iteration parameters in single run.
      
      This gives us the ability to reproducably extract cases where
      honggfuzz has discovered a panic. For example:
      
      $ cargo run --release --bin phragmen_pjr -- --candidates 569 --voters 100
      Tue 23 Feb 2021 11:23:39 AM CET
         Compiling bitflags v1.2.1
         Compiling unicode-width v0.1.8
         Compiling unicode-segmentation v1.7.1
         Compiling ansi_term v0.11.0
         Compiling strsim v0.8.0
         Compiling vec_map v0.8.2
         Compiling proc-macro-error-attr v1.0.4
         Compiling proc-macro-error v1.0.4
         Compiling textwrap v0.11.0
         Compiling atty v0.2.14
         Compiling heck v0.3.2
         Compiling clap v2.33.3
         Compiling structopt-derive v0.4.14
         Compiling structopt v0.3.21
         Compiling sp-npos-elections-fuzzer v2.0.0-alpha.5 (/home/coriolinus/Documents/Projects/paritytech/substrate/primitives/npos-elections/fuzzer)
          Finished release [optimized] target(s) in 6.15s
           Running `/home/coriolinus/Documents/Projects/paritytech/substrate/target/release/phragmen_pjr -c 569 -v 100`
      thread 'main' panicked at 'unbalanced sequential phragmen must satisfy PJR', primitives/npos-elections/fuzzer/src/phragmen_pjr.rs:133:5
      note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
      
      This is still not adequate proof that seq_phragmen is broken; it could
      very well be that our PJR checker is doing the wrong thing, or we've
      somehow missed a parameter of interest. Still, it's concerning.
      
      * update comment verbiage for accuracy
      
      * it is valid in PJR for an elected candidate to have 0 support
      
      * Fix phragmen_pjr fuzzer
      
      It turns out that the fundamental problem causing previous implementations
      of the fuzzer to fail wasn't in `seq_phragmen` _or_ in `pjr_check`: it was
      in the rounding errors introduced in the various conversions between the
      internal data representation and the external one.
      
      Fixing the fuzzer is then simply an issue of using the internal representation
      and staying in that representation. However, that leaves the issue that
      `seq_phragmen` occasionally produces an output which is technically not
      PJR due to rounding errors. In the future we will need to add some kind of
      "close-enough" threshold. However, that is explicitly out of scope of
      this PR.
      
      * restart ci; it appears to be stalled
      
      * use necessary import for no-std
      
      * use a more realistic distribution of voters and candidates
      
      This isn't ideal; more realistic numbers would be about twice these.
      However, either case generation or voting has nonlinear execution
      time, and doubling these values brings iteration time from ~20s to
      ~180s. Fuzzing 6x as fast should make up for fuzzing cases half the size.
      
      * identify specifically which PJR check may fail
      
      * move candidate collection comment into correct place
      
      * standard_threshold: use a calculation method which cannot overflow
      
      * Apply suggestions from code review (update comments)
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * clarify the effectiveness bounds for t-pjr check
      
      * how to spell "committee"
      
      * reorganize: high -> low abstraction
      
      * ensure standard threshold calc cannot panic
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarShawn Tabrizi <[email protected]>
      
      Co-authored-by: default avatarkianenigma <[email protected]>
      Co-authored-by: default avatarKian Paimani <[email protected]>
      Co-authored-by: default avatarShawn Tabrizi <[email protected]>
      781f9087
  25. Mar 10, 2021
    • Tomasz Drwięga's avatar
      Custom RPC for Merkle Mountain Range pallet (#8137) · f3d4355a
      Tomasz Drwięga authored
      * Add MMR custom RPC.
      
      * Change RuntimeApi to avoid hardcoding leaf type.
      
      * Properly implement the new RuntimeAPI and wire up RPC.
      
      * Extract Offchain DB as separate execution extension.
      
      * Enable offchain DB access for offchain calls.
      
      * Fix offchain_election tests.
      
      * Skip block initialisation for proof generation.
      
      * Fix integration test setup.
      
      * Fix offchain tests. Not sure how I missed them earlier 🤷.
      
      * Fix long line.
      
      * One more test missing.
      
      * Update mock for multi-phase.
      
      * Address review grumbbles.
      
      * Address review grumbles.
      
      * Fix line width of a comment
      f3d4355a
    • Ashley's avatar
      Return babe configuration information in the babe api epoch functions (#8072) · 7ace5e21
      Ashley authored
      
      
      * Make changes
      
      * Add serialize/deserialize, copy babe epoch config defaults from node runtime
      
      * Fix line widths and turn default features off for serde
      
      * Remove ser/deser from Epoch, fix node-cli
      
      * Apply suggestions
      
      * Add comment to BABE_GENESIS_EPOCH_CONFIG in bin
      
      * Apply suggestions
      
      * Add a sketchy migration function
      
      * Add a migration test
      
      * Check for PendingEpochConfigChange as well
      
      * Make epoch_config in node-cli
      
      * Move updating EpochConfig out of the if
      
      * Fix executor tests
      
      * Calculate weight for add_epoch_configurations
      
      * Fix babe test
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarAndré Silva <[email protected]>
      
      * Add more asserts to tests, remove unused changes to primitives/slots
      
      * Allow setting the migration pallet prefix
      
      * Rename to BabePalletPrefix
      
      Co-authored-by: default avatarAndré Silva <[email protected]>
      7ace5e21
  26. Mar 09, 2021
  27. Mar 08, 2021
    • honeywest's avatar
      Clippy arithmetic new (#8282) · b3f8e064
      honeywest authored
      * optimize code
      
      * fix clippy replace = with += or %=
      
      * fix redundant closure found warning
      
      * redundant field names in struct initialization
      
      * fix clippy warning and optimize code
      
      * fix clippy warning
      
      * fix clippy warning
      
      * fix test error
      b3f8e064
  28. Mar 05, 2021