Skip to content

Commit

Permalink
feat: ✨ Add stop time functionality to Proofs Dealer pallet (Moonsong…
Browse files Browse the repository at this point in the history
…-Labs#195)

* refactor: ♻️ Rename `ChallengeTickToChallengedProviders` -> `TickToProvidersDeadlines`

* feat: ✨ `ChallengesTicker` can now be paused

* feat: 🚧 Implement `on_finalize` hook to register block weight used

* feat: 🚧 Implement spamming condition check

* feat: 🚧 Update runtime configs with new parameters

* fix: 🐛 Use `mutate` correctly and only run spam check after tick suprasses block fullness period

* fix: 🚨 Update types to new storage element name

* test: 🚧 Write pending tests

* fix: 🐛 Check for spamming after incrementing tic

* test: ✅ Add passing tests of network spammed

* fix: 🐛 Consider block not full when weight left is exactly headroom

* test: Add tests for how much weight is considered block full

* test: ✅ Add test cases for exact number of spammed blocks tolerated

* test: ✅ Add test for ticker not affected in MBM

* test: ✅ Provider is not marked as slashable when network is spammed

* feat: ✨ Add `get_current_tick()` function to `ProofsDealerInterface`

* feat: ✨ Make threshold calculations depend on ticks instead of block numbers to prevent spam attack

* chore: 🏷️ Update `types-bundle` runtime API with ticks instead of blocks

* feat: ✨ Update blockchain service and BSP tasks to use ticks instead of blocks for volunteering

* test: 🧑‍💻 Hide consolo logs behind `verbose` flag in integration tests for better readability

* fix: 🚨 Fix dangling compile error from merge

* chore: 🏷️ Update api-augment

* test: 🐛 Fix integration tests to use new variables and constant names with "tick"

* test: ✅ Add spamming tests for file system pallet

* fix: 🩹 Use less complicated types in file system tests to improve rust analyzer usability

* test: ✅ Add threshold test with stopping time due to spamming attack

* revert: ⏪ Rollback `only` and `networkConfig` flags in threshold testing

* refactor: ♻️ Reorder tests to keep them as they were then adding new test at the end

* chore: 🏷️ Update api-augment

* docs: 📝 Add stopping time docs to proofs dealer pallet

* docs: 📝 Add information on ticks to File System pallet docs

* ci: 🧪 Increase CI tests timeout to allow spamming test to finish

* fix: 🚨 Solve compilation errors and failing tests after merge

* chore: 🏷️ Update `api-augment` after merge

* fix: 🧪 Increase timeout in bspnet tests to 4hs

* fix: 🧪 Reduce timout for CI tests back to 30m and skip long spamming test

* docs: 📝 Add comment to quick return from proof verification

* feat: ✨ Use pallet params in test setup

* fix: 🐛 Fix calculation of weighted slope

* docs: 📝 Update threshold formula docs

* test: ✅ Update tests to work better with rust analyzer

* fix: 🩹 Ammend PR review

* chore: 🏷️ Update `api-augment`

* fix: 🐛 Update not full blocks properly

* test: ✅ Add test wait

* chore: 🏷️ Update `api-augment`
  • Loading branch information
ffarall authored Sep 28, 2024
1 parent 5776e09 commit e748686
Show file tree
Hide file tree
Showing 55 changed files with 3,362 additions and 1,683 deletions.
63 changes: 34 additions & 29 deletions api-augment/dist/interfaces/lookup.js

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

2 changes: 1 addition & 1 deletion api-augment/dist/interfaces/lookup.js.map

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions api-augment/dist/types/interfaces/augment-api-consts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@polkadot/api-base/types/consts";
import type { ApiTypes, AugmentedConst } from "@polkadot/api-base/types";
import type { Option, u128, u16, u32, u64, u8 } from "@polkadot/types-codec";
import type { Codec } from "@polkadot/types-codec/types";
import type { AccountId32, H256 } from "@polkadot/types/interfaces/runtime";
import type { AccountId32, H256, Perbill } from "@polkadot/types/interfaces/runtime";
import type {
FrameSystemLimitsBlockLength,
FrameSystemLimitsBlockWeights,
Expand Down Expand Up @@ -225,9 +225,29 @@ declare module "@polkadot/api-base/types/consts" {
[key: string]: Codec;
};
proofsDealer: {
/**
* The minimum unused weight that a block must have to be considered _not_ full.
*
* This is used as part of the criteria for checking if the network is presumably under a spam attack.
* For example, this can be set to the benchmarked weight of a `submit_proof` extrinsic, which would
* mean that a block is not considered full if a `submit_proof` extrinsic could have still fit in it.
**/
blockFullnessHeadroom: SpWeightsWeightV2Weight & AugmentedConst<ApiType>;
/**
* The period of blocks for which the block fullness is checked.
*
* This is the amount of blocks from the past, for which the block fullness has been checked
* and is stored. Blocks older than `current_block` - [`Config::BlockFullnessPeriod`] are
* cleared from storage.
*
* This constant should be equal or smaller than the [`Config::ChallengeTicksTolerance`] constant,
* if the goal is to prevent spamming attacks that would prevent honest Providers from submitting
* their proofs in time.
**/
blockFullnessPeriod: u32 & AugmentedConst<ApiType>;
/**
* The number of ticks that challenges history is kept for.
* After this many ticks, challenges are removed from `TickToChallengesSeed` StorageMap.
* After this many ticks, challenges are removed from [`TickToChallengesSeed`] StorageMap.
* A "tick" is usually one block, but some blocks may be skipped due to migrations.
**/
challengeHistoryLength: u32 & AugmentedConst<ApiType>;
Expand Down Expand Up @@ -280,6 +300,18 @@ declare module "@polkadot/api-base/types/consts" {
* The minimum period in which a Provider can be challenged, regardless of their stake.
**/
minChallengePeriod: u32 & AugmentedConst<ApiType>;
/**
* The minimum ratio (or percentage if you will) of blocks that must be considered _not_ full,
* from the total number of [`Config::BlockFullnessPeriod`] blocks taken into account.
*
* If less than this percentage of blocks are not full, the networks is considered to be presumably
* under a spam attack.
* This can also be thought of as the maximum ratio of misbehaving collators tolerated. For example,
* if this is set to `Perbill::from_percent(50)`, then if more than half of the last `BlockFullnessPeriod`
* blocks are not full, then one of those blocks surely was produced by an honest collator, meaning
* that there was at least one truly _not_ full block in the last `BlockFullnessPeriod` blocks.
**/
minNotFullBlocksRatio: Perbill & AugmentedConst<ApiType>;
/**
* The number of random challenges that are generated per block, using the random seed
* generated for that block.
Expand Down
12 changes: 4 additions & 8 deletions api-augment/dist/types/interfaces/augment-api-errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ declare module "@polkadot/api-base/types/errors" {
* BSP did not succeed threshold check.
**/
AboveThreshold: AugmentedError<ApiType>;
/**
* Block range to maximum threshold cannot be zero.
**/
BlockRangeToMaximumThresholdCannotBeZero: AugmentedError<ApiType>;
/**
* BSP has already confirmed storing the given file.
**/
Expand Down Expand Up @@ -214,10 +210,6 @@ declare module "@polkadot/api-base/types/errors" {
* Failed to verify proof: required to provide a proof of non-inclusion.
**/
ExpectedNonInclusionProof: AugmentedError<ApiType>;
/**
* Failed to convert block number to threshold.
**/
FailedToConvertBlockNumber: AugmentedError<ApiType>;
/**
* Failed to decode threshold.
**/
Expand Down Expand Up @@ -379,6 +371,10 @@ declare module "@polkadot/api-base/types/errors" {
* BSPs assignment threshold cannot be below asymptote.
**/
ThresholdBelowAsymptote: AugmentedError<ApiType>;
/**
* Tick range to maximum threshold cannot be zero.
**/
TickRangeToMaximumThresholdCannotBeZero: AugmentedError<ApiType>;
/**
* Number of removed BSPs volunteered from storage request prefix did not match the expected number.
**/
Expand Down
10 changes: 10 additions & 0 deletions api-augment/dist/types/interfaces/augment-api-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,16 @@ declare module "@polkadot/api-base/types/events" {
[key: string]: AugmentedEvent<ApiType>;
};
proofsDealer: {
/**
* The [`ChallengesTicker`] has been paused or unpaused.
**/
ChallengesTickerSet: AugmentedEvent<
ApiType,
[paused: bool],
{
paused: bool;
}
>;
/**
* A set of mutations has been applied to the Forest.
**/
Expand Down
Loading

0 comments on commit e748686

Please sign in to comment.