-
Notifications
You must be signed in to change notification settings - Fork 907
Expose functions to do preliminary slashing checks #7783
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
Merged
+85
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
79b64b9
Expose functions to do preliminary slashing checks
dknopik 25d2406
Merge branch 'unstable' into spicy-prelim-slash-check
dknopik 2a333c8
forbid prelim methods
dknopik 338a470
Merge branch 'unstable' into spicy-prelim-slash-check
michaelsproul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ perf.data* | |
*.tar.gz | ||
/bin | ||
genesis.ssz | ||
/clippy.toml | ||
/.cargo | ||
|
||
# IntelliJ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Disallow preliminary slashing checks, | ||
disallowed-methods = [ | ||
{ path = "slashing_protection::slashing_database::SlashingDatabase::preliminary_check_block_proposal", reason = "not safe for slashing checks", replacement = "slashing_protection::slashing_database::SlashingDatabase::check_and_insert_block_proposal" }, | ||
{ path = "slashing_protection::slashing_database::SlashingDatabase::preliminary_check_block_signing_root", reason = "not safe for slashing checks", replacement = "slashing_protection::slashing_database::SlashingDatabase::check_and_insert_block_signing_root" }, | ||
{ path = "slashing_protection::slashing_database::SlashingDatabase::preliminary_check_attestation", reason = "not safe for slashing checks", replacement = "slashing_protection::slashing_database::SlashingDatabase::check_and_insert_attestation" }, | ||
{ path = "slashing_protection::slashing_database::SlashingDatabase::preliminary_check_attestation_signing_root", reason = "not safe for slashing checks", replacement = "slashing_protection::slashing_database::SlashingDatabase::check_and_insert_attestation_signing_root" }, | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -599,6 +599,40 @@ impl SlashingDatabase { | |
Ok(safe) | ||
} | ||
|
||
/// Check whether a block would be safe to sign if we were to sign it now. | ||
/// | ||
/// The database is not modified, and therefore multiple threads reading the database might get | ||
/// the same result. Therefore: | ||
/// | ||
/// DO NOT USE THIS FUNCTION TO DECIDE IF A BLOCK IS SAFE TO SIGN! | ||
pub fn preliminary_check_block_proposal( | ||
&self, | ||
validator_pubkey: &PublicKeyBytes, | ||
block_header: &BeaconBlockHeader, | ||
domain: Hash256, | ||
) -> Result<Safe, NotSafe> { | ||
#[allow(clippy::disallowed_methods)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needed, as even disallowed methods may not call disallowed methods |
||
self.preliminary_check_block_signing_root( | ||
validator_pubkey, | ||
block_header.slot, | ||
block_header.signing_root(domain).into(), | ||
) | ||
} | ||
|
||
/// As for `preliminary_check_block_proposal` but without requiring the whole `BeaconBlockHeader`. | ||
/// | ||
/// DO NOT USE THIS FUNCTION TO DECIDE IF A BLOCK IS SAFE TO SIGN! | ||
pub fn preliminary_check_block_signing_root( | ||
&self, | ||
validator_pubkey: &PublicKeyBytes, | ||
slot: Slot, | ||
signing_root: SigningRoot, | ||
) -> Result<Safe, NotSafe> { | ||
let mut conn = self.conn_pool.get()?; | ||
let txn = conn.transaction_with_behavior(TransactionBehavior::Exclusive)?; | ||
self.check_block_proposal(&txn, validator_pubkey, slot, signing_root) | ||
} | ||
|
||
/// Check an attestation for slash safety, and if it is safe, record it in the database. | ||
/// | ||
/// The checking and inserting happen atomically and exclusively. We enforce exclusivity | ||
|
@@ -670,6 +704,49 @@ impl SlashingDatabase { | |
Ok(safe) | ||
} | ||
|
||
/// Check whether an attestation would be safe to sign if we were to sign it now. | ||
/// | ||
/// The database is not modified, and therefore multiple threads reading the database might get | ||
/// the same result. Therefore: | ||
/// | ||
/// DO NOT USE THIS FUNCTION TO DECIDE IF AN ATTESTATION IS SAFE TO SIGN! | ||
pub fn preliminary_check_attestation( | ||
&self, | ||
validator_pubkey: &PublicKeyBytes, | ||
attestation: &AttestationData, | ||
domain: Hash256, | ||
) -> Result<Safe, NotSafe> { | ||
let attestation_signing_root = attestation.signing_root(domain).into(); | ||
#[allow(clippy::disallowed_methods)] | ||
self.preliminary_check_attestation_signing_root( | ||
validator_pubkey, | ||
attestation.source.epoch, | ||
attestation.target.epoch, | ||
attestation_signing_root, | ||
) | ||
} | ||
|
||
/// As for `preliminary_check_attestation` but without requiring the whole `AttestationData`. | ||
/// | ||
/// DO NOT USE THIS FUNCTION TO DECIDE IF AN ATTESTATION IS SAFE TO SIGN! | ||
pub fn preliminary_check_attestation_signing_root( | ||
&self, | ||
validator_pubkey: &PublicKeyBytes, | ||
att_source_epoch: Epoch, | ||
att_target_epoch: Epoch, | ||
att_signing_root: SigningRoot, | ||
) -> Result<Safe, NotSafe> { | ||
let mut conn = self.conn_pool.get()?; | ||
let txn = conn.transaction_with_behavior(TransactionBehavior::Exclusive)?; | ||
self.check_attestation( | ||
&txn, | ||
validator_pubkey, | ||
att_source_epoch, | ||
att_target_epoch, | ||
att_signing_root, | ||
) | ||
} | ||
|
||
/// Import slashing protection from another client in the interchange format. | ||
/// | ||
/// This function will atomically import the entire interchange, failing if *any* | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this was here