-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: Full node mode #13
Changes from 13 commits
210b324
3794b92
8db467a
a69208c
c23abbc
5613806
7d70c6c
e8d9eba
b1ddad3
66c4eb5
ffd8739
24d7091
34e4da3
8d610d6
ae14d09
783bc30
d8e8ff3
8d70eb2
676d5ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,8 @@ use crate::{metrics, ConsensusInner}; | |
use anyhow::Context as _; | ||
use concurrency::{ctx, metrics::LatencyHistogramExt as _, scope, time}; | ||
use roles::validator; | ||
use std::{ | ||
collections::{BTreeMap, HashMap}, | ||
sync::Arc, | ||
}; | ||
use storage::{ReplicaStateStore, StorageError}; | ||
use std::collections::{BTreeMap, HashMap}; | ||
use storage::{FallbackReplicaStateStore, StorageError}; | ||
use tracing::instrument; | ||
|
||
/// The StateMachine struct contains the state of the replica. This is the most complex state machine and is responsible | ||
|
@@ -27,47 +24,33 @@ pub(crate) struct StateMachine { | |
/// The deadline to receive an input message. | ||
pub(crate) timeout_deadline: time::Deadline, | ||
/// A reference to the storage module. We use it to backup the replica state. | ||
pub(crate) storage: Arc<dyn ReplicaStateStore>, | ||
pub(crate) storage: FallbackReplicaStateStore, | ||
} | ||
|
||
impl StateMachine { | ||
/// Creates a new StateMachine struct. We try to recover a past state from the storage module, | ||
/// otherwise we initialize the state machine with whatever head block we have. | ||
pub(crate) async fn new( | ||
ctx: &ctx::Ctx, | ||
storage: Arc<dyn ReplicaStateStore>, | ||
storage: FallbackReplicaStateStore, | ||
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. why "fallback"? It is supposed to be the primary source of state, with empty state being the fallback, no? 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. or you mean WithFallback? But then do we need that verbosity? 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. Yeah, I've meant "store with fallback" (fallback being based on a 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. I guess that would be better. But why not just ReplicaStateStore? The fallback is an implementation detail from the pov of this function. Perhaps we should make FallbackReplicaStateStore into a trait instead of ReplicaStateStore? |
||
) -> anyhow::Result<Self> { | ||
Ok(match storage.replica_state(ctx).await? { | ||
Some(backup) => { | ||
let mut block_proposal_cache: BTreeMap<_, HashMap<_, _>> = BTreeMap::new(); | ||
for p in backup.proposals { | ||
block_proposal_cache | ||
.entry(p.number) | ||
.or_default() | ||
.insert(p.payload.hash(), p.payload); | ||
} | ||
Self { | ||
view: backup.view, | ||
phase: backup.phase, | ||
high_vote: backup.high_vote, | ||
high_qc: backup.high_qc, | ||
block_proposal_cache, | ||
timeout_deadline: time::Deadline::Infinite, | ||
storage, | ||
} | ||
} | ||
None => { | ||
let head = storage.head_block(ctx).await?; | ||
Self { | ||
view: head.justification.message.view, | ||
phase: validator::Phase::Prepare, | ||
high_vote: head.justification.message, | ||
high_qc: head.justification, | ||
block_proposal_cache: BTreeMap::new(), | ||
timeout_deadline: time::Deadline::Infinite, | ||
storage, | ||
} | ||
} | ||
let backup = storage.replica_state(ctx).await?; | ||
let mut block_proposal_cache: BTreeMap<_, HashMap<_, _>> = BTreeMap::new(); | ||
for proposal in backup.proposals { | ||
block_proposal_cache | ||
.entry(proposal.number) | ||
.or_default() | ||
.insert(proposal.payload.hash(), proposal.payload); | ||
} | ||
|
||
Ok(Self { | ||
view: backup.view, | ||
phase: backup.phase, | ||
high_vote: backup.high_vote, | ||
high_qc: backup.high_qc, | ||
block_proposal_cache, | ||
timeout_deadline: time::Deadline::Infinite, | ||
storage, | ||
}) | ||
} | ||
|
||
|
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.
IMO we can drop support for specifying stuff via env vars. We don't use it and we will use eventually the zksync-era style configuration anyway.