-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
349 additions
and
47 deletions.
There are no files selected for viewing
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,72 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! This module defines physical storage schema for DAG. | ||
//! | ||
//! Serialized bytes identified by node digest. | ||
//! ```text | ||
//! |<---key---->|<---value--->| | ||
//! | digest | node/certified node | | ||
//! ``` | ||
use crate::dag::{CertifiedNode, Node}; | ||
use anyhow::Result; | ||
use aptos_crypto::HashValue; | ||
use aptos_schemadb::{ | ||
define_schema, | ||
schema::{KeyCodec, ValueCodec}, | ||
ColumnFamilyName, | ||
}; | ||
|
||
pub const NODE_CF_NAME: ColumnFamilyName = "node"; | ||
|
||
define_schema!(NodeSchema, HashValue, Node, NODE_CF_NAME); | ||
|
||
impl KeyCodec<NodeSchema> for HashValue { | ||
fn encode_key(&self) -> Result<Vec<u8>> { | ||
Ok(self.to_vec()) | ||
} | ||
|
||
fn decode_key(data: &[u8]) -> Result<Self> { | ||
Ok(HashValue::from_slice(data)?) | ||
} | ||
} | ||
|
||
impl ValueCodec<NodeSchema> for Node { | ||
fn encode_value(&self) -> Result<Vec<u8>> { | ||
Ok(bcs::to_bytes(&self)?) | ||
} | ||
|
||
fn decode_value(data: &[u8]) -> Result<Self> { | ||
Ok(bcs::from_bytes(data)?) | ||
} | ||
} | ||
|
||
pub const CERTIFIED_NODE_CF_NAME: ColumnFamilyName = "certified_node"; | ||
|
||
define_schema!( | ||
CertifiedNodeSchema, | ||
HashValue, | ||
CertifiedNode, | ||
CERTIFIED_NODE_CF_NAME | ||
); | ||
|
||
impl KeyCodec<CertifiedNodeSchema> for HashValue { | ||
fn encode_key(&self) -> Result<Vec<u8>> { | ||
Ok(self.to_vec()) | ||
} | ||
|
||
fn decode_key(data: &[u8]) -> Result<Self> { | ||
Ok(HashValue::from_slice(data)?) | ||
} | ||
} | ||
|
||
impl ValueCodec<CertifiedNodeSchema> for CertifiedNode { | ||
fn encode_value(&self) -> Result<Vec<u8>> { | ||
Ok(bcs::to_bytes(&self)?) | ||
} | ||
|
||
fn decode_value(data: &[u8]) -> Result<Self> { | ||
Ok(bcs::from_bytes(data)?) | ||
} | ||
} |
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
Oops, something went wrong.