Skip to content
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
9 changes: 8 additions & 1 deletion .github/workflows/run-tests-on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ jobs:
run: |
cargo clippy \
--package acropolis_common \
--package acropolis_codec
--package acropolis_codec \
--package acropolis_module_assets_state \
--package acropolis_module_block_unpacker \
--package acropolis_module_consensus \
--package acropolis_module_drdd_state \
--package acropolis_module_snapshot_bootstrapper \
--package acropolis_module_spdd_state \
--package acropolis_module_utxo_state

- name: Run Build
run: cargo build --verbose
Expand Down
10 changes: 8 additions & 2 deletions modules/assets_state/src/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ pub struct AssetRegistry {
id_to_key: Vec<AssetKey>,
}

impl Default for AssetRegistry {
fn default() -> Self {
Self::new()
}
}

impl AssetRegistry {
pub fn new() -> Self {
Self {
Expand All @@ -52,8 +58,8 @@ impl AssetRegistry {

pub fn lookup_id(&self, policy: &PolicyId, name: &AssetName) -> Option<AssetId> {
let key = AssetKey {
policy: Arc::new(policy.clone()),
name: Arc::new(name.clone()),
policy: Arc::new(*policy),
name: Arc::new(*name),
};
self.key_to_id.get(&key).copied()
}
Expand Down
35 changes: 17 additions & 18 deletions modules/assets_state/src/assets_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl AssetsState {
// Always handle the mint deltas (This is how assets get initialized)
{
let mut reg = registry.lock().await;
state = match state.handle_mint_deltas(&deltas_msg.deltas, &mut *reg) {
state = match state.handle_mint_deltas(&deltas_msg.deltas, &mut reg) {
Ok(new_state) => new_state,
Err(e) => {
error!("Asset deltas handling error: {e:#}");
Expand All @@ -97,7 +97,7 @@ impl AssetsState {
if storage_config.store_info {
let mut reg = registry.lock().await;
state = match state
.handle_cip25_metadata(&mut *reg, &deltas_msg.cip25_metadata_updates)
.handle_cip25_metadata(&mut reg, &deltas_msg.cip25_metadata_updates)
{
Ok(new_state) => new_state,
Err(e) => {
Expand Down Expand Up @@ -125,20 +125,19 @@ impl AssetsState {

if storage_config.store_info {
let reg = registry.lock().await;
state =
match state.handle_cip68_metadata(&utxo_deltas_msg.deltas, &*reg) {
Ok(new_state) => new_state,
Err(e) => {
error!("CIP-68 metadata handling error: {e:#}");
state
}
};
state = match state.handle_cip68_metadata(&utxo_deltas_msg.deltas, &reg)
{
Ok(new_state) => new_state,
Err(e) => {
error!("CIP-68 metadata handling error: {e:#}");
state
}
};
}

if storage_config.store_transactions.is_enabled() {
let reg = registry.lock().await;
state = match state.handle_transactions(&utxo_deltas_msg.deltas, &*reg)
{
state = match state.handle_transactions(&utxo_deltas_msg.deltas, &reg) {
Ok(new_state) => new_state,
Err(e) => {
error!("Transactions handling error: {e:#}");
Expand All @@ -161,7 +160,7 @@ impl AssetsState {
Self::check_sync(&current_block, block_info, "address");

let reg = registry.lock().await;
state = match state.handle_address_deltas(&address_deltas_msg.deltas, &*reg)
state = match state.handle_address_deltas(&address_deltas_msg.deltas, &reg)
{
Ok(new_state) => new_state,
Err(e) => {
Expand Down Expand Up @@ -299,7 +298,7 @@ impl AssetsState {
}
AssetsStateQuery::GetAssetInfo { policy, name } => {
let reg = registry.lock().await;
match reg.lookup_id(&policy, &name) {
match reg.lookup_id(policy, name) {
Some(asset_id) => match state.get_asset_info(&asset_id, &reg) {
Ok(Some(info)) => AssetsStateQueryResponse::AssetInfo(info),
Ok(None) => AssetsStateQueryResponse::NotFound,
Expand All @@ -318,7 +317,7 @@ impl AssetsState {
}
AssetsStateQuery::GetAssetHistory { policy, name } => {
let reg = registry.lock().await;
match reg.lookup_id(&policy, &name) {
match reg.lookup_id(policy, name) {
Some(asset_id) => match state.get_asset_history(&asset_id) {
Ok(Some(history)) => {
AssetsStateQueryResponse::AssetHistory(history)
Expand All @@ -339,7 +338,7 @@ impl AssetsState {
}
AssetsStateQuery::GetAssetAddresses { policy, name } => {
let reg = registry.lock().await;
match reg.lookup_id(&policy, &name) {
match reg.lookup_id(policy, name) {
Some(asset_id) => match state.get_asset_addresses(&asset_id) {
Ok(Some(addresses)) => {
AssetsStateQueryResponse::AssetAddresses(addresses)
Expand All @@ -360,7 +359,7 @@ impl AssetsState {
}
AssetsStateQuery::GetAssetTransactions { policy, name } => {
let reg = registry.lock().await;
match reg.lookup_id(&policy, &name) {
match reg.lookup_id(policy, name) {
Some(asset_id) => match state.get_asset_transactions(&asset_id) {
Ok(Some(txs)) => AssetsStateQueryResponse::AssetTransactions(txs),
Ok(None) => AssetsStateQueryResponse::NotFound,
Expand All @@ -379,7 +378,7 @@ impl AssetsState {
}
AssetsStateQuery::GetPolicyIdAssets { policy } => {
let reg = registry.lock().await;
match state.get_policy_assets(&policy, &reg) {
match state.get_policy_assets(policy, &reg) {
Ok(Some(assets)) => AssetsStateQueryResponse::PolicyIdAssets(assets),
Ok(None) => AssetsStateQueryResponse::NotFound,
Err(e) => AssetsStateQueryResponse::Error(e.to_string()),
Expand Down
23 changes: 9 additions & 14 deletions modules/assets_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use acropolis_common::{
math::update_value_with_delta,
queries::assets::{AssetHistory, PolicyAssets},
Address, AddressDelta, AssetAddressEntry, AssetInfoRecord, AssetMetadataStandard,
AssetMintRecord, AssetName, Datum, Lovelace, NativeAssetDelta, PolicyAsset, PolicyId,
AssetMintRecord, AssetName, Datum, Lovelace, NativeAssetsDelta, PolicyAsset, PolicyId,
ShelleyAddress, TxIdentifier, UTXODelta,
};
use anyhow::Result;
Expand All @@ -27,19 +27,14 @@ pub struct AssetsStorageConfig {
pub index_by_policy: bool,
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy)]
pub enum StoreTransactions {
#[default]
None,
All,
Last(u64),
}

impl Default for StoreTransactions {
fn default() -> Self {
StoreTransactions::None
}
}

impl StoreTransactions {
pub fn is_enabled(&self) -> bool {
!matches!(self, StoreTransactions::None)
Expand Down Expand Up @@ -123,7 +118,7 @@ impl State {
if let Some(key) = registry.lookup(*id) {
out.push(PolicyAsset {
policy: *key.policy,
name: key.name.as_ref().clone(),
name: *key.name.as_ref(),
quantity: *amount,
});
}
Expand Down Expand Up @@ -235,7 +230,7 @@ impl State {
let key = registry.lookup(*asset_id)?;
Some(PolicyAsset {
policy: *policy_id,
name: (*key.name).clone(),
name: *key.name,
quantity: *supply,
})
})
Expand Down Expand Up @@ -273,7 +268,7 @@ impl State {

pub fn handle_mint_deltas(
&self,
deltas: &[(TxIdentifier, Vec<(PolicyId, Vec<NativeAssetDelta>)>)],
deltas: &[(TxIdentifier, NativeAssetsDelta)],
registry: &mut AssetRegistry,
) -> Result<Self> {
let mut new_supply = self.supply.clone();
Expand All @@ -286,7 +281,7 @@ impl State {
for (tx_identifier, tx_deltas) in deltas {
for (policy_id, asset_deltas) in tx_deltas {
for delta in asset_deltas {
let asset_id = registry.get_or_insert(*policy_id, delta.name.clone());
let asset_id = registry.get_or_insert(*policy_id, delta.name);

if let Some(supply) = new_supply.as_mut() {
let delta_amount = delta.amount;
Expand Down Expand Up @@ -314,7 +309,7 @@ impl State {
.entry(asset_id)
.and_modify(|rec| rec.mint_or_burn_count += 1)
.or_insert(AssetInfoRecord {
initial_mint_tx: tx_identifier.clone(),
initial_mint_tx: *tx_identifier,
mint_or_burn_count: 1,
onchain_metadata: None,
metadata_standard: None,
Expand Down Expand Up @@ -385,7 +380,7 @@ impl State {
if let Some(asset_id) = registry.lookup_id(policy_id, &asset.name) {
let entry = txs_map.entry(asset_id).or_default();

let should_push = entry.back().map_or(true, |last| last != &tx_identifier);
let should_push = entry.back() != Some(&tx_identifier);

if should_push {
entry.push_back(tx_identifier);
Expand Down
2 changes: 1 addition & 1 deletion modules/consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Consensus {
block_info,
CardanoMessage::BlockValidation(status),
)) => match status {
ValidationStatus::Go => all_ok && true,
ValidationStatus::Go => all_ok,
ValidationStatus::NoGo(err) => {
error!(
block = block_info.number,
Expand Down
4 changes: 2 additions & 2 deletions modules/spdd_state/src/spdd_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ impl SPDDState {
}
};

return Arc::new(Message::StateQueryResponse(StateQueryResponse::SPDD(
Arc::new(Message::StateQueryResponse(StateQueryResponse::SPDD(
response,
)));
)))
}
});

Expand Down
2 changes: 1 addition & 1 deletion modules/spdd_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl State {
// we plus 2 to epoch number
pub fn get_epoch_total_active_stakes(&self, epoch: u64) -> Option<u64> {
if epoch <= 2 {
return None;
None
} else {
self.spdd_history
.get_by_index(epoch - 2)
Expand Down
2 changes: 1 addition & 1 deletion modules/utxo_state/src/address_delta_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl AddressDeltaObserver for AddressDeltaPublisher {
Message::Cardano((block.clone(), CardanoMessage::AddressDeltas(message)));
self.context
.message_bus
.publish(&topic, Arc::new(message_enum))
.publish(topic, Arc::new(message_enum))
.await
.unwrap_or_else(|e| error!("Failed to publish: {e}"));
}
Expand Down
2 changes: 1 addition & 1 deletion modules/utxo_state/src/fjall_async_immutable_utxo_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl FjallAsyncImmutableUTXOStore {
fn should_flush(&self) -> bool {
let count = self.write_counter.fetch_add(1, Ordering::Relaxed) + 1;
let threshold = self.flush_every.load(Ordering::Relaxed);
threshold != 0 && count % threshold == 0
threshold != 0 && count.is_multiple_of(threshold)
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/utxo_state/src/fjall_immutable_utxo_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl FjallImmutableUTXOStore {
fn should_flush(&self) -> bool {
let count = self.write_counter.fetch_add(1, Ordering::Relaxed) + 1;
let threshold = self.flush_every.load(Ordering::Relaxed);
threshold != 0 && count % threshold == 0
threshold != 0 && count.is_multiple_of(threshold)
}
}

Expand Down
Loading