Disputes which are unknown for the Runtime are sent with priority by the Provisioner when preparing inherent data (#5336)

* Implement MallocSizeOf for DisputeState

* Implementation of `Disputes` Runtime API message

* Modify on-chain dispute import

* Add feature flag for the new functionality

* Update node/core/provisioner/src/onchain_disputes.rs

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>

* Add target to log messages

* Update node/core/provisioner/src/lib.rs

Co-authored-by: Andronik <write@reusable.software>

* Use `staging-client` feature to enable the client code using the staging runtime api

* Remove TODO comment

* Don't filter out DisputeState

* Fix disputes selection logic

* spelling

* Tests

* Rename `Disputes` message to `StagingDisputes`

* Update node/core/provisioner/src/lib.rs

Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>

* Code review feedback

- Logging
- Separate error module
- Add additional fields for GetOnchainDisputesErr
- logging and impl MallocSizeOf
- fix impl MallocSizeOf for DisputeState
- fix tests

* Update node/core/provisioner/src/error.rs

Co-authored-by: Andronik <write@reusable.software>

* Update node/core/provisioner/src/lib.rs

Co-authored-by: Andronik <write@reusable.software>

* Update node/core/provisioner/src/lib.rs

Co-authored-by: Andronik <write@reusable.software>

* Apply suggestions from code review

dummy metrics instance

Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>

* Revert "Apply suggestions from code review"

This reverts commit 6dc518cbf77e037ff4760d315938a68c806e662e.

* Code review feedback: #[cfg(test)] for new_dummy() in metrics

* Code review feedback: break the disputes generation logic in separate functions

* Code review feedback - align_eight

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>
This commit is contained in:
Tsvetomir Dimitrov
2022-05-06 15:58:04 +03:00
committed by GitHub
parent 673a32d968
commit 20e56a453c
14 changed files with 753 additions and 94 deletions
+24 -2
View File
@@ -21,8 +21,8 @@ use parity_util_mem::{MallocSizeOf, MallocSizeOfExt};
use sp_consensus_babe::Epoch;
use polkadot_primitives::v2::{
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent,
CommittedCandidateReceipt, CoreState, GroupRotationInfo, Hash, Id as ParaId,
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, CoreState, DisputeState, GroupRotationInfo, Hash, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, PersistedValidationData,
PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
@@ -47,6 +47,7 @@ const ON_CHAIN_VOTES_CACHE_SIZE: usize = 3 * 1024;
const PVFS_REQUIRE_PRECHECK_SIZE: usize = 1024;
const VALIDATION_CODE_HASH_CACHE_SIZE: usize = 64 * 1024;
const VERSION_CACHE_SIZE: usize = 4 * 1024;
const DISPUTES_CACHE_SIZE: usize = 64 * 1024;
struct ResidentSizeOf<T>(T);
@@ -115,6 +116,10 @@ pub(crate) struct RequestResultCache {
ResidentSizeOf<Option<ValidationCodeHash>>,
>,
version: MemoryLruCache<Hash, ResidentSizeOf<u32>>,
disputes: MemoryLruCache<
Hash,
ResidentSizeOf<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>>,
>,
}
impl Default for RequestResultCache {
@@ -142,6 +147,7 @@ impl Default for RequestResultCache {
pvfs_require_precheck: MemoryLruCache::new(PVFS_REQUIRE_PRECHECK_SIZE),
validation_code_hash: MemoryLruCache::new(VALIDATION_CODE_HASH_CACHE_SIZE),
version: MemoryLruCache::new(VERSION_CACHE_SIZE),
disputes: MemoryLruCache::new(DISPUTES_CACHE_SIZE),
}
}
}
@@ -407,6 +413,21 @@ impl RequestResultCache {
pub(crate) fn cache_version(&mut self, key: Hash, value: u32) {
self.version.insert(key, ResidentSizeOf(value));
}
pub(crate) fn disputes(
&mut self,
relay_parent: &Hash,
) -> Option<&Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>> {
self.disputes.get(relay_parent).map(|v| &v.0)
}
pub(crate) fn cache_disputes(
&mut self,
relay_parent: Hash,
value: Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>,
) {
self.disputes.insert(relay_parent, ResidentSizeOf(value));
}
}
pub(crate) enum RequestResult {
@@ -442,4 +463,5 @@ pub(crate) enum RequestResult {
SubmitPvfCheckStatement(Hash, PvfCheckStatement, ValidatorSignature, ()),
ValidationCodeHash(Hash, ParaId, OccupiedCoreAssumption, Option<ValidationCodeHash>),
Version(Hash, u32),
StagingDisputes(Hash, Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>),
}