Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[DONTMERGE] Add debug logs and make approval voting failable #3783

Open
wants to merge 97 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
d12cde4
Add debug logs and make approval voting failable
Lldenaurois Sep 4, 2021
1f898c7
Merge remote-tracking branch 'origin/master' into ladi-logging-disputes
Lldenaurois Sep 5, 2021
10fffc6
Increase MALICIOUS_FREQUENCY
Lldenaurois Sep 5, 2021
bf75f08
Reduce to 5000
Lldenaurois Sep 6, 2021
65f7767
IssueLocalStatement on malicious approval vote
Lldenaurois Sep 6, 2021
3333849
Move to uniform distributionary cycle
Lldenaurois Sep 7, 2021
175ed47
Update offset calculation
Lldenaurois Sep 7, 2021
ac9f924
Add logging
Lldenaurois Sep 7, 2021
e10d910
Merge remote-tracking branch 'origin/master' into ladi-logging-disputes
Lldenaurois Sep 7, 2021
1e357f1
Update dependencies
Lldenaurois Sep 7, 2021
4cc2878
Issue dispute more regularly
Lldenaurois Sep 8, 2021
c37096d
Merge remote-tracking branch 'origin/master' into ladi-logging-disputes
Lldenaurois Sep 8, 2021
84b3422
Retrigger
Lldenaurois Sep 8, 2021
bb7bb2f
Modify where we reset counter
Lldenaurois Sep 8, 2021
dfbc50b
Trigger new build
Lldenaurois Sep 9, 2021
ed71d2d
Merge remote-tracking branch 'origin/master' into ladi-logging-disputes
Lldenaurois Sep 9, 2021
22bd95a
Create malicious candidate backing
Lldenaurois Sep 9, 2021
cd30b94
Merge branch 'master' into ladi-logging-disputes
rphmeier Sep 15, 2021
b2e7087
really back bad candidates
rphmeier Sep 15, 2021
0c4a781
update beefy-gadget
rphmeier Sep 15, 2021
733f108
fix grandpa-bridge-gadget refs
rphmeier Sep 15, 2021
3d135fe
Fix Cargo.lock
Lldenaurois Sep 16, 2021
106c876
instantiate malicious commitments explicitly
rphmeier Sep 16, 2021
050689b
Merge branch 'master' into ladi-logging-disputes and detach from Subs…
rphmeier Sep 21, 2021
5764bb4
Increase Frequency (lower BASE_MIN)
Lldenaurois Sep 23, 2021
61f2c13
Retrigger
Lldenaurois Sep 23, 2021
0789bb9
Add logging to approval voting
Lldenaurois Sep 23, 2021
c663ebd
Modify print statements
Lldenaurois Sep 24, 2021
91e5eaa
Add more logs
Lldenaurois Sep 24, 2021
dbf8b8b
Fix watermark
Lldenaurois Sep 24, 2021
f924252
Retrigger
Lldenaurois Sep 24, 2021
8650564
Fix unused errors
Lldenaurois Sep 24, 2021
46551d1
Remove feature flag
Lldenaurois Sep 24, 2021
dd1b115
Remove unused imports
Lldenaurois Sep 24, 2021
d486616
Allow dead code
Lldenaurois Sep 24, 2021
bca88ea
Remove unnecessary feature
Lldenaurois Sep 24, 2021
e4f5fbe
Remove ui test
Lldenaurois Sep 24, 2021
0b63b3a
Remove gitlab
Lldenaurois Sep 24, 2021
cac79f1
Merge branch 'master' into ladi-logging-disputes
ordian Sep 30, 2021
ccdebd0
revert changes to bridges
ordian Sep 30, 2021
ef8591f
revert some more changes
ordian Sep 30, 2021
b03e1bb
more reverts
ordian Sep 30, 2021
3a08e2b
backing: replace chunk misbehavior
ordian Oct 1, 2021
06dd295
approval-voting: lower the frequency of misbehavior
ordian Oct 1, 2021
dade923
Merge branch 'master' into ladi-logging-disputes
ordian Oct 2, 2021
2cd9542
Merge branch 'master' into ladi-logging-disputes
ordian Oct 3, 2021
bff00af
switch substrate to polkadot-v0.9.13 branch
s3krit Nov 15, 2021
b917461
move paras inherent filtering to runtime (#4028)
drahnr Nov 16, 2021
a4fb3d6
prefer code upgrades in inherent filtering (#4334)
drahnr Nov 19, 2021
072019b
add additional assurances to `create_inherent` (#4349)
drahnr Nov 24, 2021
aac3683
Inherent filtering follow up (#4305)
emostov Nov 23, 2021
847bbb8
add parent header hash to logs, provide pre and post inherent data nu…
Lldenaurois Nov 27, 2021
5d2ee2c
Fix build errors
Lldenaurois Nov 27, 2021
3779292
Dispute spam protection (#4134)
eskimor Nov 19, 2021
c0d7044
[BACKPORT] backport changes for v0.9.13 (#4385)
drahnr Nov 29, 2021
4f96620
Merge remote-tracking branch 'parity/release-v0.9.13' into ladi-loggi…
Lldenaurois Nov 30, 2021
543eec0
Fix build
Lldenaurois Nov 30, 2021
e193014
Increase reversion frequency to 100%
Lldenaurois Nov 30, 2021
a503e70
Change line
Lldenaurois Dec 1, 2021
c6a6876
Fix gitlab-ci
Lldenaurois Dec 1, 2021
5156917
Bump line
Lldenaurois Dec 1, 2021
d4ce775
Remove backing tests
Lldenaurois Dec 1, 2021
95db2e2
Merge branch 'ladi-backport-logging' into ladi-logging-disputes
Lldenaurois Dec 2, 2021
a2cc915
Fix warnings
Lldenaurois Dec 2, 2021
a12a544
Merge remote-tracking branch 'parity/ladi-backport-logging' into ladi…
Lldenaurois Dec 2, 2021
280f16e
Remove unused Debug log target
Lldenaurois Dec 2, 2021
217100c
Move revert frequency to 100%
Lldenaurois Dec 3, 2021
d231167
remove integration test
Lldenaurois Dec 3, 2021
d194180
WIP
Lldenaurois Dec 16, 2021
4d11c41
Merge remote-tracking branch 'parity/master' into ladi-logging-disputes
Lldenaurois Dec 16, 2021
cea63de
Merge remote-tracking branch 'parity/master' into ladi-logging-disputes
Lldenaurois Dec 18, 2021
a629ea4
Ignore test
Lldenaurois Dec 18, 2021
29989a2
Remove integration test
Lldenaurois Dec 19, 2021
10e09a2
Add `without_storage_info`
ggwpez Jan 19, 2022
4c0887a
Remove `generate_storage_info`
ggwpez Jan 19, 2022
e0efa29
Add more `without_storage_info`
ggwpez Jan 19, 2022
d1ae091
Merge remote-tracking branch 'origin/master' into oty-without-storage…
Jan 20, 2022
dd84aa8
update lockfile for {"substrate"}
Jan 20, 2022
f802fd4
Merge remote-tracking branch 'parity/master' into ladi-logging-disputes
Lldenaurois Jan 20, 2022
b223987
Merge remote-tracking branch 'parity/oty-without-storage-info' into l…
Lldenaurois Jan 20, 2022
05ff8d4
Increase Malicious base
Lldenaurois Jan 21, 2022
7641d6c
Update Rococo to 1-day lease (#4761)
SBalaguer Jan 21, 2022
ca490a1
Update Rococo to 1-day lease (#4761)
SBalaguer Jan 21, 2022
f7d997d
Decrease malicious base and remove adder collator test
Lldenaurois Jan 21, 2022
e63e448
Remove malicious approval voting
Lldenaurois Jan 21, 2022
c6a16d1
Enable disputes testing without needing to run collators
Lldenaurois Jan 21, 2022
58726b9
Remove collator protocol tests
Lldenaurois Jan 22, 2022
d6b1965
Merge remote-tracking branch 'parity/rk-prep-v0.9.16' into ladi-loggi…
Lldenaurois Jan 22, 2022
cdfd5be
v0.9.16 version bumps (#4766)
chevdor Jan 22, 2022
9dd8afa
Update deps
chevdor Jan 22, 2022
8664023
Update Substrate for 0.9.16 (#4769)
bkchr Jan 23, 2022
56a6e68
Merge branch 'rk-prep-v0.9.16' of github.com:paritytech/polkadot into…
eskimor Jan 24, 2022
97879a8
Prep 0.9.16 (#4773)
chevdor Jan 24, 2022
22a7690
Merge branch 'release-v0.9.16' into rk-prep-v0.9.16
eskimor Jan 25, 2022
cd4b791
Merge remote-tracking branch 'parity/rk-prep-v0.9.16' into ladi-loggi…
Lldenaurois Jan 25, 2022
a9414ee
Diener: Update substrate dependencies to a-sync-all-forks
Lldenaurois Jan 27, 2022
61de01c
Merge remote-tracking branch 'parity/rk-prep-v0.9.16' into ladi-loggi…
Lldenaurois Jan 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test-build-linux-stable:
script:
- ./scripts/gitlab/test_linux_stable.sh
# we're using the bin built here, instead of having a parallel `build-linux-release`
- time cargo build --release --verbose --bin polkadot
- time cargo build --release --verbose --bin polkadot --features disputes
- sccache -s
# pack artifacts
- mkdir -p ./artifacts
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/core/approval-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
rand = "0.5"
futures = "0.3.17"
futures-timer = "3.0.2"
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["bit-vec", "derive"] }
Expand Down
95 changes: 79 additions & 16 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
//! of others. It uses this information to determine when candidates and blocks have
//! been sufficiently approved to finalize.

use rand::distributions::{Distribution, Normal};
use std::sync::atomic::{AtomicU64, Ordering};

use kvdb::KeyValueDB;
use polkadot_node_jaeger as jaeger;
use polkadot_node_primitives::{
Expand Down Expand Up @@ -97,6 +100,9 @@ const APPROVAL_CHECKING_TIMEOUT: Duration = Duration::from_secs(120);
const APPROVAL_CACHE_SIZE: usize = 1024;
const TICK_TOO_FAR_IN_FUTURE: Tick = 20; // 10 seconds.
const LOG_TARGET: &str = "parachain::approval-voting";
const DEBUG_LOG_TARGET: &str = "parachain::ladi-debug-approval-voting";
const MALICIOUS_MEAN: f64 = 2_500f64;
const MALICIOUS_SDEV: f64 = 70f64;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: .._STDDEV is the common abbreviation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wanted MEAN and SDEV to have the same length :)


/// Configuration for the approval voting subsystem
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -342,12 +348,15 @@ where
{
fn start(self, ctx: Context) -> SpawnedSubsystem {
let backend = DbBackend::new(self.db.clone(), self.db_config);
let normal = Normal::new(MALICIOUS_MEAN, MALICIOUS_SDEV);
let offset: u64 = normal.sample(&mut rand::thread_rng()).round() as u64;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend adding 3 * STDDEV which means 99.7% are not edited, but you avoid hickups due to huge outliers.

let future = run::<DbBackend, Context>(
ctx,
self,
Box::new(SystemClock),
Box::new(RealAssignmentCriteria),
backend,
offset,
)
.map_err(|e| SubsystemError::with_origin("approval-voting", e))
.boxed();
Expand Down Expand Up @@ -479,8 +488,9 @@ struct ApprovalStatus {
block_tick: Tick,
}

#[derive(Copy, Clone)]
#[derive(Clone)]
enum ApprovalOutcome {
Malicious((CandidateReceipt, SessionIndex)),
Approved,
Failed,
TimedOut,
Expand All @@ -499,6 +509,18 @@ impl ApprovalState {
fn failed(validator_index: ValidatorIndex, candidate_hash: CandidateHash) -> Self {
Self { validator_index, candidate_hash, approval_outcome: ApprovalOutcome::Failed }
}
fn malicious(
validator_index: ValidatorIndex,
candidate_hash: CandidateHash,
candidate: CandidateReceipt,
session: SessionIndex,
) -> Self {
Self {
validator_index,
candidate_hash,
approval_outcome: ApprovalOutcome::Malicious((candidate, session)),
}
}
}

struct CurrentlyCheckingSet {
Expand Down Expand Up @@ -663,6 +685,7 @@ async fn run<B, Context>(
clock: Box<dyn Clock + Send + Sync>,
assignment_criteria: Box<dyn AssignmentCriteria + Send + Sync>,
mut backend: B,
offset: u64,
) -> SubsystemResult<()>
where
Context: SubsystemContext<Message = ApprovalVotingMessage>,
Expand All @@ -680,6 +703,7 @@ where
let mut wakeups = Wakeups::default();
let mut currently_checking_set = CurrentlyCheckingSet::default();
let mut approvals_cache = lru::LruCache::new(APPROVAL_CACHE_SIZE);
let counter = AtomicU64::new(0);

let mut last_finalized_height: Option<BlockNumber> = None;

Expand Down Expand Up @@ -727,26 +751,42 @@ where
}
) = approval_state;

if matches!(approval_outcome, ApprovalOutcome::Approved) {
let mut approvals: Vec<Action> = relay_block_hashes
.into_iter()
.map(|block_hash|
Action::IssueApproval(
candidate_hash,
ApprovalVoteRequest {
validator_index,
block_hash,
},
match approval_outcome {
ApprovalOutcome::Approved => {
let mut approvals: Vec<Action> = relay_block_hashes
.into_iter()
.map(|block_hash|
Action::IssueApproval(
candidate_hash,
ApprovalVoteRequest {
validator_index,
block_hash,
},
)
)
)
.collect();
actions.append(&mut approvals);
.collect();
actions.append(&mut approvals);
}
ApprovalOutcome::Malicious((candidate, session_index)) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a lot of extra machinery to add instead of just sending the message from within the if coin_flip == 0 block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was debating whether or not to do it simply with the coin_flip == 0, but thought maybe this was a little cleaner.

I realize we aren't going to be re-using this code, but it wasn't a large change. Will keep in mind to keep it simple going forward.

let sender = ctx.sender();
sender
.send_message(
DisputeCoordinatorMessage::IssueLocalStatement(
session_index,
candidate_hash,
candidate,
false,
)
.into(),
)
.await;
}
_ => {},
}

actions
}
};

if handle_actions(
&mut ctx,
&mut state,
Expand All @@ -757,6 +797,7 @@ where
&mut approvals_cache,
&mut subsystem.mode,
actions,
if counter.fetch_add(1, Ordering::SeqCst) == offset { true } else { false },
Copy link
Contributor

@drahnr drahnr Sep 7, 2021

Choose a reason for hiding this comment

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

nit: the if case can be dropped :) just use the boolean expression

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added logging in these two cases, so for now I'll leave it as an if-statement. I'll keep the logging for deploying to one node but can drop the logging before deploying to all validators.

)
.await?
{
Expand Down Expand Up @@ -804,6 +845,7 @@ async fn handle_actions(
approvals_cache: &mut lru::LruCache<CandidateHash, ApprovalOutcome>,
mode: &mut Mode,
actions: Vec<Action>,
malicious: bool,
) -> SubsystemResult<bool> {
let mut conclude = false;

Expand Down Expand Up @@ -892,6 +934,7 @@ async fn handle_actions(
validator_index,
block_hash,
backing_group,
malicious,
)
.await
},
Expand Down Expand Up @@ -2079,6 +2122,7 @@ async fn launch_approval(
validator_index: ValidatorIndex,
block_hash: Hash,
backing_group: GroupIndex,
malicious: bool,
) -> SubsystemResult<RemoteHandle<ApprovalState>> {
let (a_tx, a_rx) = oneshot::channel();
let (code_tx, code_rx) = oneshot::channel();
Expand Down Expand Up @@ -2227,7 +2271,26 @@ async fn launch_approval(
let expected_commitments_hash = candidate.commitments_hash;
if commitments.hash() == expected_commitments_hash {
let _ = metrics_guard.take();
return ApprovalState::approved(validator_index, candidate_hash)
if !malicious {
tracing::debug!(
target: DEBUG_LOG_TARGET,
"ladi-debug-approval APPROVED {:?}",
candidate_hash,
);
return ApprovalState::approved(validator_index, candidate_hash)
} else {
tracing::debug!(
target: DEBUG_LOG_TARGET,
"ladi-debug-approval FAILED {:?}",
candidate_hash
);
return ApprovalState::malicious(
validator_index,
candidate_hash,
candidate.clone(),
session_index,
)
}
} else {
// Commitments mismatch - issue a dispute.
sender
Expand Down
1 change: 1 addition & 0 deletions node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
clock.clone(),
assignment_criteria,
backend,
MALICIOUS_MEAN as u64,
);

let test_fut = test(TestHarness { virtual_overseer, clock, sync_oracle_handle });
Expand Down
Loading