-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure consistency between chain and ledger (#108)
- Loading branch information
Showing
6 changed files
with
195 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,69 @@ | ||
use gasket::framework::*; | ||
use pallas::ledger::configs::byron::GenesisFile; | ||
|
||
use crate::prelude::*; | ||
use crate::storage::applydb::ApplyDB; | ||
|
||
pub type UpstreamPort = gasket::messaging::tokio::InputPort<RollEvent>; | ||
|
||
#[derive(Stage)] | ||
#[stage(name = "ledger", unit = "RollEvent", worker = "Worker")] | ||
pub struct Stage { | ||
ledger: ApplyDB, | ||
genesis: GenesisFile, | ||
|
||
pub upstream: UpstreamPort, | ||
|
||
#[metric] | ||
block_count: gasket::metrics::Counter, | ||
|
||
#[metric] | ||
wal_count: gasket::metrics::Counter, | ||
} | ||
|
||
impl Stage { | ||
pub fn new(ledger: ApplyDB, genesis: GenesisFile) -> Self { | ||
Self { | ||
ledger, | ||
genesis, | ||
upstream: Default::default(), | ||
// downstream: Default::default(), | ||
block_count: Default::default(), | ||
wal_count: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Stage {} | ||
|
||
pub struct Worker; | ||
|
||
#[async_trait::async_trait(?Send)] | ||
impl gasket::framework::Worker<Stage> for Worker { | ||
async fn bootstrap(_stage: &Stage) -> Result<Self, WorkerError> { | ||
Ok(Self) | ||
} | ||
|
||
async fn schedule( | ||
&mut self, | ||
stage: &mut Stage, | ||
) -> Result<WorkSchedule<RollEvent>, WorkerError> { | ||
let msg = stage.upstream.recv().await.or_panic()?; | ||
|
||
Ok(WorkSchedule::Unit(msg.payload)) | ||
} | ||
|
||
async fn execute(&mut self, unit: &RollEvent, stage: &mut Stage) -> Result<(), WorkerError> { | ||
match unit { | ||
RollEvent::Apply(_, _, cbor) => { | ||
stage.ledger.apply_block(cbor).or_panic()?; | ||
} | ||
RollEvent::Undo(_, _, cbor) => { | ||
stage.ledger.undo_block(cbor).or_panic()?; | ||
} | ||
RollEvent::Origin => stage.ledger.apply_origin(&stage.genesis).or_panic()?, | ||
}; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.