-
Notifications
You must be signed in to change notification settings - Fork 5
ChainStore module #138
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
Merged
Merged
ChainStore module #138
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
750ff58
feat: first pass at a chain store
SupernaviX 49d0888
feat: wire block queries up to API
SupernaviX 3bacc44
feat: store block cbor
SupernaviX ce3a99b
feat: add BlockInfo fields
SupernaviX f895149
feat: populate remaining BlockInfo fields
SupernaviX 62cba55
feat: support getting blocks by epoch+slot
SupernaviX 704ad6a
feat: support getting next and previous blocks
SupernaviX 1e9f1a1
feat: return transactions and transactions cbor
SupernaviX 2c21d6b
feat: accept hash or number in state query
SupernaviX f0183fe
Add blocks/latest blockfrost REST endpoint
alexwoods 642e0fa
Implement some serialization for BlockInfo
alexwoods 89ae89b
Add more handlers for blocks endpoints
alexwoods 07866db
Add blocks endpoints for txs and txs/cbor
alexwoods dcae45d
Add blocks next and previous endpoints for blockfrost
alexwoods 3fddbd7
Standardise some blocks handler function names
alexwoods d161cc5
Merge branch 'main' into sg/chain-store
alexwoods f307dfe
Correct placement of use for tests
alexwoods 92cc028
cargo fmt of uses
alexwoods 8c8d23d
Add paging to blocks /next and /previous endpoints
alexwoods 651fc55
Correct function parameters for previous
alexwoods b228345
Add missing paging parameters to queries (still need implementing)
alexwoods c35850f
Apply paging and ordering to /txs and /txs/cbor endpoints
alexwoods 7ccbb9f
Add /blocks/{hash_or_number}/addresses endpoint
alexwoods e542e38
Merge remote-tracking branch 'origin/main' into sg/chain-store
alexwoods 60ada5d
Add delegates to protocol params
alexwoods 61a3464
Merge remote-tracking branch 'origin/main' into sg/chain-store
alexwoods eb5942c
Add serde serialisation hints to fix Shelley params read/write
alexwoods 5120ce7
cargo fmt cleanup
alexwoods e50bd8c
Correct matching of byron and shelley genesis slot issuers
alexwoods e1c5d24
Add clear-on-start option to chain store module
alexwoods 368f201
Create a type for VRFKey
alexwoods 575d094
Add lookups for block hashes and tx hashes
alexwoods c29152d
Merge remote-tracking branch 'origin/main' into sg/chain-store
alexwoods b24bd0f
Restore setting
alexwoods 1e6c620
Move codec lib to top
alexwoods 8daf1d8
Use crypto::keyhash_244 instead of cryptoxide
alexwoods cec7395
Make import of GenesisDelegate consistent with other types imports
alexwoods 251fd26
Add comments for params message reading
alexwoods ab113f2
Get block number from key if possible
alexwoods 80d42ce
Tidy up redundant code
alexwoods 70005d5
Add unit test for get_blocks_by_number_range
alexwoods 4c89113
Add a helper function for REST queries
alexwoods 67acca4
Merge remote-tracking branch 'origin/main' into sg/chain-store
alexwoods 6f6ab7b
Move bech-order address helper to common
alexwoods 669921f
Move byte array types into own mod
alexwoods 90a757f
Add FromHex impl for byte arrays
alexwoods acae2ee
Remove incorrect old comment
alexwoods 88dedb9
Add self to authors
0e54ebd
cargo fmt run
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,13 @@ | ||
| [package] | ||
| name = "acropolis_codec" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [dependencies] | ||
| acropolis_common = { path = "../common" } | ||
|
|
||
| anyhow = { workspace = true } | ||
| pallas = { workspace = true } | ||
| pallas-primitives = { workspace = true } | ||
| pallas-traverse = { workspace = true } | ||
| tracing = { workspace = true } |
This file contains hidden or 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,43 @@ | ||
| use acropolis_common::{ | ||
| GenesisDelegate, HeavyDelegate, crypto::keyhash_224, queries::blocks::BlockIssuer, | ||
| }; | ||
| use pallas_primitives::byron::BlockSig::DlgSig; | ||
| use pallas_traverse::MultiEraHeader; | ||
| use std::collections::HashMap; | ||
|
|
||
| pub fn map_to_block_issuer( | ||
| header: &MultiEraHeader, | ||
| byron_heavy_delegates: &HashMap<Vec<u8>, HeavyDelegate>, | ||
| shelley_genesis_delegates: &HashMap<Vec<u8>, GenesisDelegate>, | ||
| ) -> Option<BlockIssuer> { | ||
| match header.issuer_vkey() { | ||
| Some(vkey) => match header { | ||
| MultiEraHeader::ShelleyCompatible(_) => { | ||
| let digest = keyhash_224(vkey); | ||
| if let Some(issuer) = shelley_genesis_delegates | ||
| .values() | ||
| .find(|v| v.delegate == digest) | ||
| .map(|i| BlockIssuer::GenesisDelegate(i.clone())) | ||
| { | ||
| Some(issuer) | ||
| } else { | ||
| Some(BlockIssuer::SPO(vkey.to_vec())) | ||
| } | ||
| } | ||
| _ => Some(BlockIssuer::SPO(vkey.to_vec())), | ||
| }, | ||
| None => match header { | ||
| MultiEraHeader::Byron(_) => match header.as_byron() { | ||
| Some(block_head) => match &block_head.consensus_data.3 { | ||
| DlgSig(sig) => byron_heavy_delegates | ||
| .values() | ||
| .find(|v| v.issuer_pk == *sig.0.issuer) | ||
| .map(|i| BlockIssuer::HeavyDelegate(i.clone())), | ||
| _ => None, | ||
| }, | ||
| None => None, | ||
| }, | ||
| _ => None, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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,2 @@ | ||
| pub mod block; | ||
| pub mod map_parameters; |
This file contains hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| use crate::serialization::{Bech32Conversion, Bech32WithHrp}; | ||
| use anyhow::Error; | ||
| use hex::{FromHex, FromHexError}; | ||
| use serde_with::{hex::Hex, serde_as}; | ||
| use std::ops::Deref; | ||
|
|
||
| macro_rules! declare_byte_array_type { | ||
| ($name:ident, $size:expr) => { | ||
| /// $name | ||
| #[serde_as] | ||
| #[derive( | ||
| Default, Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, | ||
| )] | ||
| pub struct $name(#[serde_as(as = "Hex")] pub [u8; $size]); | ||
|
|
||
| impl From<[u8; $size]> for $name { | ||
| fn from(bytes: [u8; $size]) -> Self { | ||
| Self(bytes) | ||
| } | ||
| } | ||
|
|
||
| impl FromHex for $name { | ||
| type Error = FromHexError; | ||
|
|
||
| fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> { | ||
| Ok(match Self::try_from(Vec::<u8>::from_hex(hex)?) { | ||
| Ok(b) => Ok(b), | ||
| Err(_) => Err(FromHexError::InvalidStringLength), | ||
| }?) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<Vec<u8>> for $name { | ||
| type Error = Vec<u8>; | ||
| fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error> { | ||
| Ok($name(vec.try_into()?)) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&[u8]> for $name { | ||
| type Error = std::array::TryFromSliceError; | ||
| fn try_from(arr: &[u8]) -> Result<Self, Self::Error> { | ||
| Ok($name(arr.try_into()?)) | ||
| } | ||
| } | ||
|
|
||
| impl AsRef<[u8]> for $name { | ||
| fn as_ref(&self) -> &[u8] { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl Deref for $name { | ||
| type Target = [u8; $size]; | ||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| macro_rules! declare_byte_array_type_with_bech32 { | ||
| ($name:ident, $size:expr, $hrp:expr) => { | ||
| declare_byte_array_type!($name, $size); | ||
| impl Bech32Conversion for $name { | ||
| fn to_bech32(&self) -> Result<String, anyhow::Error> { | ||
| self.0.to_vec().to_bech32_with_hrp($hrp) | ||
| } | ||
| fn from_bech32(s: &str) -> Result<Self, anyhow::Error> { | ||
| match Vec::<u8>::from_bech32_with_hrp(s, $hrp) { | ||
| Ok(v) => match Self::try_from(v) { | ||
| Ok(s) => Ok(s), | ||
| Err(_) => Err(Error::msg(format!( | ||
| "Bad vector input to {}", | ||
| stringify!($name) | ||
| ))), | ||
| }, | ||
| Err(e) => Err(e), | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| declare_byte_array_type!(BlockHash, 32); | ||
|
|
||
| declare_byte_array_type!(TxHash, 32); | ||
|
|
||
| declare_byte_array_type_with_bech32!(VRFKey, 32, "vrf_vk"); |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.