Skip to content
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

Milestone mappings storage #1376

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions bee-node/bee-node/src/tools/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use std::str::FromStr;
use bee_ledger::types::{
snapshot::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput, Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{
access::{AsIterator, Exist, Fetch},
backend::StorageBackend,
Expand Down Expand Up @@ -193,7 +198,7 @@ fn exec_inner(tool: &RocksdbTool, storage: &Storage) -> Result<(), RocksdbError>
}
}
},
CF_MILESTONE_INDEX_TO_MILESTONE => match &tool.command {
CF_MILESTONE_INDEX_TO_MILESTONE_METADATA => match &tool.command {
RocksdbCommand::Fetch { key } => {
let key = MilestoneIndex(u32::from_str(key).map_err(|_| RocksdbError::InvalidKey(key.clone()))?);
let value = Fetch::<MilestoneIndex, MilestoneMetadata>::fetch(storage, &key)?;
Expand All @@ -209,6 +214,22 @@ fn exec_inner(tool: &RocksdbTool, storage: &Storage) -> Result<(), RocksdbError>
}
}
},
CF_MILESTONE_ID_TO_MILESTONE_PAYLOAD => match &tool.command {
RocksdbCommand::Fetch { key } => {
let key = MilestoneId::from_str(key).map_err(|_| RocksdbError::InvalidKey(key.clone()))?;
let value = Fetch::<MilestoneId, MilestonePayload>::fetch(storage, &key)?;

println!("Key: {:?}\nValue: {:?}\n", key, value);
}
RocksdbCommand::Iterator => {
let iterator = AsIterator::<MilestoneId, MilestonePayload>::iter(storage)?;

for result in iterator {
let (key, value) = result?;
println!("Key: {:?}\nValue: {:?}\n", key, value);
}
}
},
CF_SNAPSHOT_INFO => match &tool.command {
RocksdbCommand::Fetch { key: _key } => return Err(RocksdbError::UnsupportedCommand),
RocksdbCommand::Iterator => {
Expand Down
25 changes: 23 additions & 2 deletions bee-node/bee-node/src/tools/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use std::str::FromStr;
use bee_ledger::types::{
snapshot::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput, Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{
access::{AsIterator, Exist, Fetch},
backend::StorageBackend,
Expand Down Expand Up @@ -176,7 +181,7 @@ fn exec_inner(tool: &SledTool, storage: &Storage) -> Result<(), SledError> {
}
}
},
TREE_MILESTONE_INDEX_TO_MILESTONE => match &tool.command {
TREE_MILESTONE_INDEX_TO_MILESTONE_METADATA => match &tool.command {
SledCommand::Fetch { key } => {
let key = MilestoneIndex(u32::from_str(key).map_err(|_| SledError::InvalidKey(key.clone()))?);
let value = Fetch::<MilestoneIndex, MilestoneMetadata>::fetch(storage, &key)?;
Expand All @@ -192,6 +197,22 @@ fn exec_inner(tool: &SledTool, storage: &Storage) -> Result<(), SledError> {
}
}
},
TREE_MILESTONE_ID_TO_MILESTONE_PAYLOAD => match &tool.command {
SledCommand::Fetch { key } => {
let key = MilestoneId::from_str(key).map_err(|_| SledError::InvalidKey(key.clone()))?;
let value = Fetch::<MilestoneId, MilestonePayload>::fetch(storage, &key)?;

println!("Key: {:?}\nValue: {:?}\n", key, value);
}
SledCommand::Iterator => {
let iterator = AsIterator::<MilestoneId, MilestonePayload>::iter(storage)?;

for result in iterator {
let (key, value) = result?;
println!("Key: {:?}\nValue: {:?}\n", key, value);
}
}
},
TREE_SNAPSHOT_INFO => match &tool.command {
SledCommand::Fetch { key: _key } => return Err(SledError::UnsupportedCommand),
SledCommand::Iterator => {
Expand Down
16 changes: 12 additions & 4 deletions bee-storage/bee-storage-memory/src/access/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use bee_ledger::types::{
snapshot::info::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput,
Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{
access::{Batch, BatchBuilder},
backend::StorageBackend,
Expand All @@ -30,7 +35,8 @@ pub struct StorageBatch {
output_id_unspent: TableBatch<Unspent, ()>,
ed25519_address_to_output_id: TableBatch<(Ed25519Address, OutputId), ()>,
ledger_index: TableBatch<(), LedgerIndex>,
milestone_index_to_milestone: TableBatch<MilestoneIndex, MilestoneMetadata>,
milestone_index_to_milestone_metadata: TableBatch<MilestoneIndex, MilestoneMetadata>,
milestone_id_to_milestone_payload: TableBatch<MilestoneId, MilestonePayload>,
snapshot_info: TableBatch<(), SnapshotInfo>,
solid_entry_point_to_milestone_index: TableBatch<SolidEntryPoint, MilestoneIndex>,
milestone_index_to_output_diff: TableBatch<MilestoneIndex, OutputDiff>,
Expand Down Expand Up @@ -63,7 +69,8 @@ impl BatchBuilder for Storage {
apply_batch!(output_id_unspent);
apply_batch!(ed25519_address_to_output_id);
apply_batch!(ledger_index);
apply_batch!(milestone_index_to_milestone);
apply_batch!(milestone_index_to_milestone_metadata);
apply_batch!(milestone_id_to_milestone_payload);
apply_batch!(snapshot_info);
apply_batch!(solid_entry_point_to_milestone_index);
apply_batch!(milestone_index_to_output_diff);
Expand Down Expand Up @@ -106,7 +113,8 @@ impl_batch!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_batch!(Unspent, (), output_id_unspent);
impl_batch!((Ed25519Address, OutputId), (), ed25519_address_to_output_id);
impl_batch!((), LedgerIndex, ledger_index);
impl_batch!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_batch!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_batch!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_batch!((), SnapshotInfo, snapshot_info);
impl_batch!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_batch!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/access/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use bee_ledger::types::{
snapshot::info::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput,
Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{access::Delete, backend::StorageBackend};
use bee_tangle::{
message_metadata::MessageMetadata, milestone_metadata::MilestoneMetadata, solid_entry_point::SolidEntryPoint,
Expand Down Expand Up @@ -36,7 +41,8 @@ impl_delete!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_delete!(Unspent, (), output_id_unspent);
impl_delete!((Ed25519Address, OutputId), (), ed25519_address_to_output_id);
impl_delete!((), LedgerIndex, ledger_index);
impl_delete!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_delete!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_delete!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_delete!((), SnapshotInfo, snapshot_info);
impl_delete!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_delete!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/access/exist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use bee_ledger::types::{
snapshot::info::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput,
Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{access::Exist, backend::StorageBackend};
use bee_tangle::{
message_metadata::MessageMetadata, milestone_metadata::MilestoneMetadata, solid_entry_point::SolidEntryPoint,
Expand All @@ -34,7 +39,8 @@ impl_exist!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_exist!(Unspent, (), output_id_unspent);
impl_exist!((Ed25519Address, OutputId), (), ed25519_address_to_output_id);
impl_exist!((), LedgerIndex, ledger_index);
impl_exist!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_exist!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_exist!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_exist!((), SnapshotInfo, snapshot_info);
impl_exist!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_exist!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/access/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
use bee_ledger::types::{
snapshot::info::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{access::Fetch, backend::StorageBackend, system::System};
use bee_tangle::{
message_metadata::MessageMetadata, milestone_metadata::MilestoneMetadata, solid_entry_point::SolidEntryPoint,
Expand All @@ -33,7 +38,8 @@ impl_fetch!(OutputId, CreatedOutput, output_id_to_created_output);
impl_fetch!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_fetch!(Ed25519Address, Vec<OutputId>, ed25519_address_to_output_id);
impl_fetch!((), LedgerIndex, ledger_index);
impl_fetch!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_fetch!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_fetch!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_fetch!((), SnapshotInfo, snapshot_info);
impl_fetch!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_fetch!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/access/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use bee_ledger::types::{
snapshot::info::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput,
Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{
access::{Insert, InsertStrict},
backend::StorageBackend,
Expand Down Expand Up @@ -40,7 +45,8 @@ impl_insert!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_insert!(Unspent, (), output_id_unspent);
impl_insert!((Ed25519Address, OutputId), (), ed25519_address_to_output_id);
impl_insert!((), LedgerIndex, ledger_index);
impl_insert!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_insert!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_insert!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_insert!((), SnapshotInfo, snapshot_info);
impl_insert!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_insert!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/access/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
use bee_ledger::types::{
snapshot::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput, Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{access::AsIterator, backend::StorageBackend, system::System};
use bee_tangle::{
message_metadata::MessageMetadata, milestone_metadata::MilestoneMetadata, solid_entry_point::SolidEntryPoint,
Expand Down Expand Up @@ -58,7 +63,8 @@ impl_iter!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_iter!(Unspent, (), output_id_unspent);
impl_iter!((Ed25519Address, OutputId), (), ed25519_address_to_output_id);
impl_iter!((), LedgerIndex, ledger_index);
impl_iter!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_iter!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_iter!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_iter!((), SnapshotInfo, snapshot_info);
impl_iter!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_iter!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
9 changes: 7 additions & 2 deletions bee-storage/bee-storage-memory/src/access/multi_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
use std::{iter::Map, vec::IntoIter};

use bee_ledger::types::{ConsumedOutput, CreatedOutput, OutputDiff};
use bee_message::{output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{access::MultiFetch, backend::StorageBackend, system::System};
use bee_tangle::{
message_metadata::MessageMetadata, milestone_metadata::MilestoneMetadata, solid_entry_point::SolidEntryPoint,
Expand Down Expand Up @@ -34,6 +38,7 @@ impl_multi_fetch!(MessageId, Message, message_id_to_message);
impl_multi_fetch!(MessageId, MessageMetadata, message_id_to_metadata);
impl_multi_fetch!(OutputId, CreatedOutput, output_id_to_created_output);
impl_multi_fetch!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_multi_fetch!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_multi_fetch!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_multi_fetch!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_multi_fetch!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_multi_fetch!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/access/truncate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
use bee_ledger::types::{
snapshot::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput, Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{access::Truncate, backend::StorageBackend};
use bee_tangle::{
message_metadata::MessageMetadata, milestone_metadata::MilestoneMetadata, solid_entry_point::SolidEntryPoint,
Expand Down Expand Up @@ -35,7 +40,8 @@ impl_truncate!(OutputId, ConsumedOutput, output_id_to_consumed_output);
impl_truncate!(Unspent, (), output_id_unspent);
impl_truncate!((Ed25519Address, OutputId), (), ed25519_address_to_output_id);
impl_truncate!((), LedgerIndex, ledger_index);
impl_truncate!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone);
impl_truncate!(MilestoneIndex, MilestoneMetadata, milestone_index_to_milestone_metadata);
impl_truncate!(MilestoneId, MilestonePayload, milestone_id_to_milestone_payload);
impl_truncate!((), SnapshotInfo, snapshot_info);
impl_truncate!(SolidEntryPoint, MilestoneIndex, solid_entry_point_to_milestone_index);
impl_truncate!(MilestoneIndex, OutputDiff, milestone_index_to_output_diff);
Expand Down
10 changes: 8 additions & 2 deletions bee-storage/bee-storage-memory/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use std::sync::{PoisonError, RwLock};
use bee_ledger::types::{
snapshot::SnapshotInfo, ConsumedOutput, CreatedOutput, LedgerIndex, OutputDiff, Receipt, TreasuryOutput, Unspent,
};
use bee_message::{address::Ed25519Address, output::OutputId, payload::milestone::MilestoneIndex, Message, MessageId};
use bee_message::{
address::Ed25519Address,
output::OutputId,
payload::milestone::{MilestoneId, MilestoneIndex, MilestonePayload},
Message, MessageId,
};
use bee_storage::{
access::{Fetch, Insert},
backend::StorageBackend,
Expand Down Expand Up @@ -59,7 +64,8 @@ pub(crate) struct InnerStorage {
pub(crate) output_id_unspent: Table<Unspent, ()>,
pub(crate) ed25519_address_to_output_id: VecBinTable<Ed25519Address, OutputId>,
pub(crate) ledger_index: SingletonTable<LedgerIndex>,
pub(crate) milestone_index_to_milestone: Table<MilestoneIndex, MilestoneMetadata>,
pub(crate) milestone_index_to_milestone_metadata: Table<MilestoneIndex, MilestoneMetadata>,
pub(crate) milestone_id_to_milestone_payload: Table<MilestoneId, MilestonePayload>,
pub(crate) snapshot_info: SingletonTable<SnapshotInfo>,
pub(crate) solid_entry_point_to_milestone_index: Table<SolidEntryPoint, MilestoneIndex>,
pub(crate) milestone_index_to_output_diff: Table<MilestoneIndex, OutputDiff>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[macro_use]
mod access;

impl_access_test!(
milestone_id_to_milestone_payload_access_memory,
milestone_id_to_milestone_payload_access
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
mod access;

impl_access_test!(
milestone_index_to_milestone_access_sled,
milestone_index_to_milestone_access
milestone_index_to_milestone_metadata_access_memory,
milestone_index_to_milestone_metadata_access
);
Loading