-
Notifications
You must be signed in to change notification settings - Fork 18
Duty logic validation for consensus messages #228
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
Merged
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
89f0306
duty logic validation
diegomrsantos 62596d7
add duties tracker
diegomrsantos e2c6186
fix compilation and simplify
diegomrsantos 9a2ebaf
Merge branch 'unstable' into duty-logic
diegomrsantos f48e866
add parking_lot
diegomrsantos 43a00db
add proposers duties tracking
diegomrsantos 17075d3
uncomment pre-commit
diegomrsantos 3ccb16a
simplify duties tracking
diegomrsantos 763589b
use dashmap
diegomrsantos 4dc2620
update docs for SyncCommitteePerPeriod
diegomrsantos 1e7b599
remove metrics
diegomrsantos 80ff366
improvements
diegomrsantos ae6a864
remove functions not used in BeaconNetwork
diegomrsantos 2684a67
remove slots_per_epoch from Validator
diegomrsantos c63075b
remove extra #
diegomrsantos f0e9e89
Merge branch 'unstable' into duty-logic
diegomrsantos efb45e2
remove unnecessary get_slot_start_time
diegomrsantos 36b0a68
propagate error instead of failing silently
diegomrsantos 070d434
improve logging adding gossipsub and ssv msg id
diegomrsantos 9c9d3f1
change log to trace
diegomrsantos 2bd726a
remove unnecessary things from proposers tracking
diegomrsantos 812e09a
better error handling in poll_beacon_proposers
diegomrsantos 31b1a7e
remove estimated_epoch_at_slot
diegomrsantos d0e43d2
remove estimated_time_at_slot
diegomrsantos f40dc52
remove is_first_slot_of_epoch
diegomrsantos 439d3b9
remove BeaconNetwork
diegomrsantos 5a98514
Merge branch 'unstable' into duty-logic
diegomrsantos 91db909
add issue to todo
diegomrsantos de8938d
propagate error in message_lateness
diegomrsantos 7f74742
use into() for ValidatorIndex
diegomrsantos 5f367fa
remove comment
diegomrsantos db85d16
decrease duplication in partial_signature tests
diegomrsantos 8e7c892
fix constants values
diegomrsantos ee4cc61
fix test and refactor duty_limit
diegomrsantos cae7132
Merge branch 'unstable' into duty-logic
diegomrsantos 8797378
rename var and fix typo
diegomrsantos 37ba5a8
add test_early_message_fails_validation and test_late_message_fails_v…
diegomrsantos ce86f70
make test_validate_ssv_message_consensus_success easier to understand
diegomrsantos 415c9c7
fix duty limit comparison
diegomrsantos 401d245
Merge branch 'unstable' into duty-logic
diegomrsantos 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#!/bin/sh | ||
echo "Running cargo fmt --all..." | ||
cargo +nightly fmt --all || exit 1 | ||
|
||
echo "Running cargo clippy --all..." | ||
cargo clippy --all || exit 1 | ||
|
||
echo "Running cargo sort workspace..." | ||
cargo sort --workspace || exit 1 | ||
##!/bin/sh | ||
#echo "Running cargo fmt --all..." | ||
#cargo +nightly fmt --all || exit 1 | ||
# | ||
#echo "Running cargo clippy --all..." | ||
#cargo clippy --all || exit 1 | ||
# | ||
#echo "Running cargo sort workspace..." | ||
#cargo sort --workspace || exit 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -5,20 +5,26 @@ edition = { workspace = true } | |
authors = ["Sigma Prime <[email protected]>"] | ||
|
||
[dependencies] | ||
beacon_node_fallback = { workspace = true } | ||
bls = { workspace = true } | ||
dashmap = { workspace = true } | ||
database = { workspace = true } | ||
eth2 = { workspace = true } | ||
ethereum_ssz = { workspace = true } | ||
gossipsub = { workspace = true } | ||
hex = { workspace = true } | ||
openssl = { workspace = true } | ||
parking_lot = { workspace = true } | ||
processor = { workspace = true } | ||
safe_arith = { workspace = true } | ||
sha2 = { workspace = true } | ||
slot_clock = { workspace = true } | ||
ssv_types = { workspace = true } | ||
task_executor = { workspace = true } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true } | ||
tracing = { workspace = true } | ||
types = { workspace = true } | ||
|
||
[dev-dependencies] | ||
bls = { workspace = true } | ||
|
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,121 @@ | ||
use std::time::{Duration, SystemTime}; | ||
|
||
use slot_clock::SlotClock; | ||
use types::{Epoch, Slot}; | ||
|
||
/// Wrapper around SlotClock to provide beacon chain network functionality | ||
#[derive(Clone)] | ||
pub struct BeaconNetwork<S: SlotClock> { | ||
slot_clock: S, | ||
slots_per_epoch: u64, | ||
epochs_per_sync_committee_period: u64, | ||
} | ||
|
||
impl<S: SlotClock> BeaconNetwork<S> { | ||
/// Create a new BeaconNetwork | ||
pub fn new(slot_clock: S, slots_per_epoch: u64, epochs_per_sync_committee_period: u64) -> Self { | ||
Self { | ||
slot_clock, | ||
slots_per_epoch, | ||
epochs_per_sync_committee_period, | ||
} | ||
} | ||
|
||
/// Returns the slot clock | ||
pub fn slot_clock(&self) -> &S { | ||
&self.slot_clock | ||
} | ||
|
||
/// Returns the slot duration | ||
pub fn slot_duration(&self) -> Duration { | ||
self.slot_clock.slot_duration() | ||
} | ||
|
||
/// Returns the number of slots per epoch | ||
pub fn slots_per_epoch(&self) -> u64 { | ||
self.slots_per_epoch | ||
} | ||
|
||
/// Estimates the current slot | ||
pub fn estimated_current_slot(&self) -> Slot { | ||
self.slot_clock.now().unwrap_or_default() | ||
} | ||
|
||
/// Estimates the slot at the given time | ||
pub fn estimated_slot_at_time(&self, time: SystemTime) -> Slot { | ||
let since_unix = time | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.unwrap_or_default(); | ||
|
||
self.slot_clock.slot_of(since_unix).unwrap_or_default() | ||
} | ||
|
||
/// Estimates the time at the given slot | ||
pub fn estimated_time_at_slot(&self, slot: Slot) -> SystemTime { | ||
let duration = self.slot_clock.start_of(slot).unwrap_or_default(); | ||
SystemTime::UNIX_EPOCH + duration | ||
} | ||
|
||
/// Estimates the current epoch | ||
pub fn estimated_current_epoch(&self) -> Epoch { | ||
self.estimated_epoch_at_slot(self.estimated_current_slot()) | ||
} | ||
|
||
/// Estimates the epoch at the given slot | ||
pub fn estimated_epoch_at_slot(&self, slot: Slot) -> Epoch { | ||
Epoch::new(slot.as_u64() / self.slots_per_epoch) | ||
} | ||
dknopik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Returns the first slot at the given epoch | ||
pub fn first_slot_at_epoch(&self, epoch: u64) -> Slot { | ||
Slot::new(epoch * self.slots_per_epoch) | ||
} | ||
dknopik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Returns the start time of the given epoch | ||
pub fn epoch_start_time(&self, epoch: u64) -> SystemTime { | ||
self.estimated_time_at_slot(self.first_slot_at_epoch(epoch)) | ||
} | ||
|
||
/// Returns the start time of the given slot | ||
pub fn get_slot_start_time(&self, slot: Slot) -> SystemTime { | ||
self.estimated_time_at_slot(slot) | ||
} | ||
|
||
/// Returns the end time of the given slot | ||
pub fn get_slot_end_time(&self, slot: Slot) -> SystemTime { | ||
self.estimated_time_at_slot(slot + 1) | ||
} | ||
|
||
/// Checks if the given slot is the first slot of its epoch | ||
pub fn is_first_slot_of_epoch(&self, slot: Slot) -> bool { | ||
slot.as_u64() % self.slots_per_epoch == 0 | ||
} | ||
|
||
/// Returns the first slot of the given epoch | ||
pub fn get_epoch_first_slot(&self, epoch: u64) -> Slot { | ||
self.first_slot_at_epoch(epoch) | ||
} | ||
|
||
/// Returns the number of epochs per sync committee period | ||
pub fn epochs_per_sync_committee_period(&self) -> u64 { | ||
self.epochs_per_sync_committee_period | ||
} | ||
|
||
/// Estimates the sync committee period at the given epoch | ||
pub fn estimated_sync_committee_period_at_epoch(&self, epoch: Epoch) -> u64 { | ||
epoch.as_u64() / self.epochs_per_sync_committee_period | ||
} | ||
|
||
/// Returns the first epoch of the given sync committee period | ||
pub fn first_epoch_of_sync_period(&self, period: u64) -> u64 { | ||
period * self.epochs_per_sync_committee_period | ||
} | ||
|
||
/// Returns the last slot of the given sync committee period | ||
pub fn last_slot_of_sync_period(&self, period: u64) -> Slot { | ||
let last_epoch = self.first_epoch_of_sync_period(period + 1) - 1; | ||
// If we are in the sync committee that ends at slot x we do not generate a message | ||
// during slot x-1 as it will never be included, hence -2. | ||
self.get_epoch_first_slot(last_epoch + 1) - 2 | ||
dknopik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.