sigil-consensus · view_change
Source declarations, signatures and documentation for view_change.
Source: sigil/node/sigil-consensus/src/view_change.rs. SHA-256: ea54a867db540ae019df8243ecd5ff5acf7a831003827ea0c9784f14b2eff447.
This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.
view_change::ViewChangeReason
Reason for requesting a view change.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ViewChangeReason {
/// The proposer did not produce a block within the timeout.
Timeout,
/// The proposed block was invalid.
InvalidBlock,
/// The expected proposer is offline or unreachable.
MissingProposer,
}Source line: 18.
view_change::ViewChangeReason::signing_tag
Stable protocol tag included in signed view-change payloads.
pub fn signing_tag(self) -> &'static [u8];Source line: 39.
view_change::ViewChangeMessage
A view change request from a validator.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ViewChangeMessage {
/// DID of the requesting validator.
pub validator_did: String,
/// Block height where the view change is requested.
pub height: u64,
/// View this validator is leaving.
pub from_view: u64,
/// New view number being requested.
pub view: u64,
/// Why this validator is requesting a view change.
pub reason: ViewChangeReason,
/// Ed25519 signature over (height || epoch || from_view || view || reason).
pub signature: Vec<u8>
}Source line: 50.
view_change::ViewChangeCertificate
Quorum certificate proving 2/3+ stake requested the same new view.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ViewChangeCertificate {
/// Block height where the view change is requested.
pub height: u64,
/// Epoch for signature payloads.
pub epoch: u64,
/// New view certified by the messages.
pub view: u64,
/// Signed view-change messages forming the quorum certificate.
pub messages: Vec<ViewChangeMessage>
}Source line: 67.
view_change::ViewChangeCertificate::digest
Hash the certificate into a stable byte string for new-view signing.
pub fn digest(&self) -> [u8; 32];Source line: 80.
view_change::ViewChangeCertificate::verify
Verify every signed view-change message and that the certificate has quorum.
pub fn verify(
&self,
current_view: u64,
validator_set: &ValidatorSet,
) -> Result<(), ConsensusError>;Source line: 101.
view_change::NewViewMessage
New-view message from the elected proposer for a certified view.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NewViewMessage {
/// DID of the proposer for the certified new view.
pub proposer_did: String,
/// Block height where the view change applies.
pub height: u64,
/// Certified view number.
pub view: u64,
/// Quorum certificate authorizing the view change.
pub certificate: ViewChangeCertificate,
/// Ed25519 signature over the new-view envelope and certificate digest.
pub signature: Vec<u8>
}Source line: 173.
view_change::ViewChangeTracker
Tracks view change messages and determines when a view change should occur.
pub struct ViewChangeTracker {
}Source line: 187.
view_change::ViewChangeTracker::new
Create a new view change tracker.
pub fn new(height: u64, epoch: u64, current_view: u64, validator_set: ValidatorSet) -> Self;Source line: 202.
view_change::ViewChangeTracker::add_view_change
Add a view change message from a validator.
Validates that:
- The message is for the current height
- The message requests a higher view than the current view
- The validator is in the active set
- The validator has not already submitted a view change message
- The Ed25519 signature is valid
Returns true if the view change threshold has been reached.
pub fn add_view_change(&mut self, msg: ViewChangeMessage) -> Result<bool, ConsensusError>;Source line: 222.
view_change::ViewChangeTracker::should_change_view
Check if the view change threshold has been reached.
A view change occurs when 2/3+ of the total stake has submitted view change messages.
pub fn should_change_view(&self) -> bool;Source line: 290.
view_change::ViewChangeTracker::ready_view
Returns the highest target view with a quorum certificate ready.
If a lower target view is certified but its elected proposer never
broadcasts NewView, validators must still be able to certify a later
target view and make progress.
pub fn ready_view(&self) -> Option<u64>;Source line: 299.
view_change::ViewChangeTracker::view_change_certificate
Returns a quorum certificate for the highest ready target view.
pub fn view_change_certificate(&self) -> Option<ViewChangeCertificate>;Source line: 318.
view_change::ViewChangeTracker::current_view
Returns the current view number.
pub fn current_view(&self) -> u64;Source line: 335.
view_change::ViewChangeTracker::message_count
Returns the number of view change messages received.
pub fn message_count(&self) -> usize;Source line: 340.
view_change::ViewChangeTracker::view_change_stake
Returns the total stake of validators that have requested a view change.
pub fn view_change_stake(&self) -> u64;Source line: 348.
view_change::ViewChangeTracker::view_change_stake_for_view
Returns the total stake requesting a specific target view.
pub fn view_change_stake_for_view(&self, view: u64) -> Option<u64>;Source line: 357.
view_change::ViewChangeTracker::advance_view
Advance to the next view. Clears accumulated messages.
pub fn advance_view(&mut self);Source line: 367.
view_change::ViewChangeTracker::advance_to_view
Advance to a certified view. Clears accumulated messages.
pub fn advance_to_view(&mut self, new_view: u64);Source line: 372.
view_change::ViewChangeTracker::reset
Reset the tracker for a new height.
pub fn reset(&mut self, new_height: u64, new_epoch: u64);Source line: 383.
view_change::next_proposer_after_view_change
Determine the next proposer after a view change.
The proposer for view N+1 is elected using the same deterministic algorithm but with a modified seed that incorporates the new view number.
pub fn next_proposer_after_view_change(
validator_set: &ValidatorSet,
config: &ElectionConfig,
height: u64,
new_view: u64,
epoch_seed: &SigilHash,
) -> String;Source line: 395.