-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: refactor and rocksdb implementation (#123)
* refactor: move storage & redis into its own crates * fix: import errors with redis * feat: create skeleton for rocksdb * feat: seperate out config into its own crate * feat: seperate out da into its own crate * fix: errors with moving crates around * merge: diff patch co-authored by: Ryan Ford <ryan@deltadevs.xyz> * feat: replace todos with stuff in database * fix: remove anyhow macro * feat: refactor Digest and add basic tests * fix: cargo clippy error * fix: Digest hash refactor * fix: remove packages * fix: remove n * fix: remove remove n * fix: the only good thing the bot recommended * fix: ci failings
- Loading branch information
Showing
26 changed files
with
805 additions
and
550 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,26 @@ | ||
[package] | ||
name = "prism-da" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
description.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
keywords.workspace = true | ||
readme.workspace = true | ||
|
||
[dependencies] | ||
async-trait = { workspace = true } | ||
serde = { workspace = true } | ||
ed25519-dalek = { workspace = true } | ||
tokio = { workspace = true } | ||
bincode = { workspace = true } | ||
hex = { workspace = true } | ||
log = { workspace = true } | ||
celestia-rpc = { workspace = true } | ||
celestia-types = { workspace = true } | ||
anyhow = { workspace = true } | ||
prism-common = { workspace = true } | ||
prism-errors = { workspace = true } | ||
sp1-sdk = { workspace = true } |
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
File renamed without changes.
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,75 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use ed25519_dalek::{Signature, Signer, SigningKey, VerifyingKey}; | ||
use prism_common::{operation::Operation, tree::Digest}; | ||
use serde::{Deserialize, Serialize}; | ||
use sp1_sdk::SP1ProofWithPublicValues; | ||
use tokio::sync::broadcast; | ||
|
||
pub mod celestia; | ||
pub mod consts; | ||
pub mod memory; | ||
|
||
// FinalizedEpoch is the data structure that represents the finalized epoch data, and is posted to the DA layer. | ||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct FinalizedEpoch { | ||
pub height: u64, | ||
pub prev_commitment: Digest, | ||
pub current_commitment: Digest, | ||
pub proof: SP1ProofWithPublicValues, | ||
pub signature: Option<String>, | ||
} | ||
|
||
impl FinalizedEpoch { | ||
pub fn insert_signature(&mut self, key: &SigningKey) { | ||
let plaintext = bincode::serialize(&self).unwrap(); | ||
let signature = key.sign(&plaintext); | ||
self.signature = Some(hex::encode(signature.to_bytes())); | ||
} | ||
|
||
pub fn verify_signature(&self, vk: VerifyingKey) -> Result<()> { | ||
let epoch_without_signature = FinalizedEpoch { | ||
height: self.height, | ||
prev_commitment: self.prev_commitment, | ||
current_commitment: self.current_commitment, | ||
proof: self.proof.clone(), | ||
signature: None, | ||
}; | ||
|
||
let message = bincode::serialize(&epoch_without_signature) | ||
.map_err(|e| anyhow::anyhow!("Failed to serialize epoch: {}", e))?; | ||
|
||
let signature = self | ||
.signature | ||
.as_ref() | ||
.ok_or_else(|| anyhow::anyhow!("No signature present"))?; | ||
|
||
let signature_bytes = hex::decode(signature) | ||
.map_err(|e| anyhow::anyhow!("Failed to decode signature: {}", e))?; | ||
|
||
if signature_bytes.len() != 64 { | ||
return Err(anyhow::anyhow!("Invalid signature length")); | ||
} | ||
|
||
let signature: Signature = signature_bytes | ||
.as_slice() | ||
.try_into() | ||
.map_err(|_| anyhow::anyhow!("Invalid signature length"))?; | ||
|
||
vk.verify_strict(&message, &signature) | ||
.map_err(|e| anyhow::anyhow!("Signature verification failed: {}", e))?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
pub trait DataAvailabilityLayer: Send + Sync { | ||
async fn get_latest_height(&self) -> Result<u64>; | ||
async fn initialize_sync_target(&self) -> Result<u64>; | ||
async fn get_finalized_epoch(&self, height: u64) -> Result<Option<FinalizedEpoch>>; | ||
async fn submit_finalized_epoch(&self, epoch: FinalizedEpoch) -> Result<u64>; | ||
async fn get_operations(&self, height: u64) -> Result<Vec<Operation>>; | ||
async fn submit_operations(&self, operations: Vec<Operation>) -> Result<u64>; | ||
async fn start(&self) -> Result<()>; | ||
fn subscribe_to_heights(&self) -> broadcast::Receiver<u64>; | ||
} |
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
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.