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
12 changes: 12 additions & 0 deletions common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,24 @@ pub enum BlockStatus {
RolledBack, // Volatile, restarted after rollback
}

/// Block status
#[bitmask(u8)]
#[derive(serde::Serialize, serde::Deserialize)]
pub enum BlockIntent {
Validate = 0b00000001, // Just validate the block
Apply = 0b00000010, // Apply the block
ValidateAndApply = BlockIntent::Validate.bits | BlockIntent::Apply.bits, // Validate and apply block
}

/// Block info, shared across multiple messages
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct BlockInfo {
/// Block status
pub status: BlockStatus,

/// Block intent
pub intent: BlockIntent,

/// Slot number
pub slot: u64,

Expand Down
3 changes: 2 additions & 1 deletion common/src/upstream_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ impl Storage for FileStorage {
#[cfg(test)]
mod test {
use crate::upstream_cache::{Storage, UpstreamCacheImpl, UpstreamCacheRecord};
use crate::{messages::RawBlockMessage, BlockHash, BlockInfo, BlockStatus, Era};
use crate::{messages::RawBlockMessage, BlockHash, BlockInfo, BlockIntent, BlockStatus, Era};
use anyhow::Result;
use std::{collections::HashMap, sync::Arc};

fn blk(n: u64) -> BlockInfo {
BlockInfo {
status: BlockStatus::Volatile,
intent: BlockIntent::Apply,
slot: n,
number: n,
hash: BlockHash::default(),
Expand Down
3 changes: 2 additions & 1 deletion modules/block_vrf_validator/src/ouroboros/praos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn vrf_result<'a>(header: &'a MultiEraHeader) -> Option<&'a VrfCert> {
mod tests {
use acropolis_common::{
crypto::keyhash_256, protocol_params::NonceHash, serialization::Bech32Conversion,
BlockHash, BlockStatus, Era,
BlockHash, BlockIntent, BlockStatus, Era,
};

use super::*;
Expand All @@ -114,6 +114,7 @@ mod tests {
hex::decode(include_str!("./data/7854823.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Validate,
slot: 73614529,
hash: BlockHash::try_from(
hex::decode("4884996cff870563ffddab5d1255a82a58482ba9351536f5b72c882f883c8947")
Expand Down
8 changes: 7 additions & 1 deletion modules/block_vrf_validator/src/ouroboros/tpraos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mod tests {
protocol_params::NonceHash,
serialization::Bech32Conversion,
validation::{VrfLeaderValueTooBigError, WrongLeaderVrfKeyError},
BlockHash, BlockStatus, Era,
BlockHash, BlockIntent, BlockStatus, Era,
};

use super::*;
Expand All @@ -207,6 +207,7 @@ mod tests {
hex::decode(include_str!("./data/4490511.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Validate,
slot: 4492800,
hash: BlockHash::try_from(
hex::decode("aa83acbf5904c0edfe4d79b3689d3d00fcfc553cf360fd2229b98d464c28e9de")
Expand Down Expand Up @@ -259,6 +260,7 @@ mod tests {
hex::decode(include_str!("./data/4556956.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 5824849,
hash: BlockHash::try_from(
hex::decode("1038b2c76a23ea7d89cbd84d7744c97560eb3412661beed6959d748e24ff8229")
Expand Down Expand Up @@ -317,6 +319,7 @@ mod tests {
hex::decode(include_str!("./data/4576496.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 6220749,
hash: BlockHash::try_from(
hex::decode("d78e446b6540612e161ebdda32ee1715ef0f9fc68e890c7e3aae167b0354f998")
Expand Down Expand Up @@ -375,6 +378,7 @@ mod tests {
hex::decode(include_str!("./data/4576496.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 6220749,
hash: BlockHash::try_from(
hex::decode("d78e446b6540612e161ebdda32ee1715ef0f9fc68e890c7e3aae167b0354f998")
Expand Down Expand Up @@ -434,6 +438,7 @@ mod tests {
hex::decode(include_str!("./data/4576496.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 6220749,
hash: BlockHash::try_from(
hex::decode("d78e446b6540612e161ebdda32ee1715ef0f9fc68e890c7e3aae167b0354f998")
Expand Down Expand Up @@ -502,6 +507,7 @@ mod tests {
hex::decode(include_str!("./data/4576496.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 6220749,
hash: BlockHash::try_from(
hex::decode("d78e446b6540612e161ebdda32ee1715ef0f9fc68e890c7e3aae167b0354f998")
Expand Down
1 change: 1 addition & 0 deletions modules/chain_store/src/stores/fjall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ mod tests {
let timestamp = block.wallclock(&genesis);
BlockInfo {
status: acropolis_common::BlockStatus::Immutable,
intent: acropolis_common::BlockIntent::Apply,
slot: block.slot(),
number: block.number(),
hash: BlockHash::from(*block.hash()),
Expand Down
5 changes: 4 additions & 1 deletion modules/epochs_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,14 @@ mod tests {
crypto::keyhash_224,
protocol_params::{Nonce, NonceHash},
state_history::{StateHistory, StateHistoryStore},
BlockHash, BlockInfo, BlockStatus, Era,
BlockHash, BlockInfo, BlockIntent, BlockStatus, Era,
};
use tokio::sync::Mutex;

fn make_block(epoch: u64) -> BlockInfo {
BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 0,
number: epoch * 10,
hash: BlockHash::default(),
Expand All @@ -329,6 +330,7 @@ mod tests {
fn make_new_epoch_block(epoch: u64) -> BlockInfo {
BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 0,
number: epoch * 10,
hash: BlockHash::default(),
Expand All @@ -343,6 +345,7 @@ mod tests {
fn make_rolled_back_block(epoch: u64) -> BlockInfo {
BlockInfo {
status: BlockStatus::RolledBack,
intent: BlockIntent::Apply,
slot: 0,
number: epoch * 10,
hash: BlockHash::default(),
Expand Down
5 changes: 3 additions & 2 deletions modules/genesis_bootstrapper/src/genesis_bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use acropolis_common::{
CardanoMessage, GenesisCompleteMessage, GenesisUTxOsMessage, Message, PotDeltasMessage,
UTXODeltasMessage,
},
Address, BlockHash, BlockInfo, BlockStatus, ByronAddress, Era, GenesisDelegates, Lovelace,
LovelaceDelta, Pot, PotDelta, TxHash, TxIdentifier, TxOutRef, TxOutput, TxUTxODeltas,
Address, BlockHash, BlockInfo, BlockIntent, BlockStatus, ByronAddress, Era, GenesisDelegates,
Lovelace, LovelaceDelta, Pot, PotDelta, TxHash, TxIdentifier, TxOutRef, TxOutput, TxUTxODeltas,
UTxOIdentifier, Value,
};
use anyhow::Result;
Expand Down Expand Up @@ -133,6 +133,7 @@ impl GenesisBootstrapper {
// Construct messages
let block_info = BlockInfo {
status: BlockStatus::Bootstrap,
intent: BlockIntent::Apply,
slot: 0,
number: 0,
hash: BlockHash::default(),
Expand Down
3 changes: 2 additions & 1 deletion modules/governance_state/src/alonzo_babbage_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod tests {
use crate::alonzo_babbage_voting::AlonzoBabbageVoting;
use acropolis_common::{
rational_number::rational_number_from_f32, AlonzoBabbageUpdateProposal,
AlonzoBabbageVotingOutcome, BlockHash, BlockInfo, BlockStatus, GenesisKeyhash,
AlonzoBabbageVotingOutcome, BlockHash, BlockInfo, BlockIntent, BlockStatus, GenesisKeyhash,
ProtocolParamUpdate,
};
use anyhow::Result;
Expand Down Expand Up @@ -157,6 +157,7 @@ mod tests {
let mut proposal = Vec::new();
let blk = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot,
number: slot,
epoch,
Expand Down
3 changes: 2 additions & 1 deletion modules/historical_epochs_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl State {
#[cfg(test)]
mod tests {
use super::*;
use acropolis_common::{BlockHash, BlockStatus, Era, PoolId};
use acropolis_common::{BlockHash, BlockIntent, BlockStatus, Era, PoolId};
use tempfile::TempDir;

fn make_ea(epoch: u64) -> EpochActivityMessage {
Expand All @@ -131,6 +131,7 @@ mod tests {
fn make_block_info(epoch: u64, new_epoch: bool) -> BlockInfo {
BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 0,
hash: BlockHash::default(),
epoch_slot: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl VolatileHistoricalEpochsState {

#[cfg(test)]
mod tests {
use acropolis_common::{BlockHash, BlockStatus, Era};
use acropolis_common::{BlockHash, BlockIntent, BlockStatus, Era};

use super::*;

Expand All @@ -70,6 +70,7 @@ mod tests {
number: 1,
epoch: 1,
status: BlockStatus::Volatile,
intent: BlockIntent::Apply,
slot: 1,
hash: BlockHash::default(),
epoch_slot: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use acropolis_common::{
configuration::StartupMethod,
genesis_values::GenesisValues,
messages::{CardanoMessage, Message, RawBlockMessage},
BlockHash, BlockInfo, BlockStatus, Era,
BlockHash, BlockInfo, BlockIntent, BlockStatus, Era,
};
use anyhow::{anyhow, bail, Result};
use caryatid_sdk::{module, Context};
Expand Down Expand Up @@ -330,6 +330,8 @@ impl MithrilSnapshotFetcher {

let block_info = BlockInfo {
status: BlockStatus::Immutable,
// Consensus will set the Validate bit if wanted
intent: BlockIntent::Apply,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally thought this should be configurable but actually it will be consensus which sets the Validate bit if it wants to, so this is fine as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment to the code to that effect

slot,
number,
hash: BlockHash::from(*block.hash()),
Expand Down
3 changes: 2 additions & 1 deletion modules/peer_network_interface/src/peer_network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod connection;
mod network;

use acropolis_common::{
BlockInfo, BlockStatus,
BlockInfo, BlockIntent, BlockStatus,
commands::chain_sync::ChainSyncCommand,
genesis_values::GenesisValues,
messages::{CardanoMessage, Command, Message, RawBlockMessage, StateTransitionMessage},
Expand Down Expand Up @@ -278,6 +278,7 @@ impl BlockSink {
} else {
BlockStatus::Volatile
},
intent: BlockIntent::Apply,
slot,
number: header.number,
hash: header.hash,
Expand Down
3 changes: 2 additions & 1 deletion modules/snapshot_bootstrapper/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::nonces::{NonceContext, NonceContextError};
use crate::publisher::EpochContext;
use acropolis_common::genesis_values::GenesisValues;
use acropolis_common::protocol_params::Nonces;
use acropolis_common::{BlockInfo, BlockStatus, Era, Point};
use acropolis_common::{BlockInfo, BlockIntent, BlockStatus, Era, Point};
use std::path::{Path, PathBuf};
use thiserror::Error;

Expand Down Expand Up @@ -72,6 +72,7 @@ impl BootstrapContext {
let (_, epoch_slot) = genesis.slot_to_epoch(slot);
let block_info = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot,
number: header.block_number,
hash: *hash,
Expand Down
3 changes: 2 additions & 1 deletion modules/spo_state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use acropolis_common::{
messages::{
EpochActivityMessage, SPORewardsMessage, SPOStakeDistributionMessage, TxCertificatesMessage,
},
BlockHash, BlockInfo, BlockStatus, Era, TxCertificateWithPos,
BlockHash, BlockInfo, BlockIntent, BlockStatus, Era, TxCertificateWithPos,
};

use crate::store_config::StoreConfig;
Expand Down Expand Up @@ -62,6 +62,7 @@ pub fn save_blocks_store_config() -> StoreConfig {
pub fn new_block(epoch: u64) -> BlockInfo {
BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 0,
number: 10 * epoch,
hash: BlockHash::default(),
Expand Down
7 changes: 4 additions & 3 deletions modules/stake_delta_filter/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ mod test {
use crate::*;
use acropolis_common::hash::Hash;
use acropolis_common::{
messages::AddressDeltasMessage, Address, AddressDelta, BlockHash, BlockInfo, BlockStatus,
ByronAddress, Era, ShelleyAddress, ShelleyAddressDelegationPart, ShelleyAddressPaymentPart,
ShelleyAddressPointer, StakeAddress, StakeCredential,
messages::AddressDeltasMessage, Address, AddressDelta, BlockHash, BlockInfo, BlockIntent,
BlockStatus, ByronAddress, Era, ShelleyAddress, ShelleyAddressDelegationPart,
ShelleyAddressPaymentPart, ShelleyAddressPointer, StakeAddress, StakeCredential,
};
use acropolis_common::{TxIdentifier, Value};
use bech32::{Bech32, Hrp};
Expand Down Expand Up @@ -586,6 +586,7 @@ mod test {

let block = BlockInfo {
status: BlockStatus::Immutable,
intent: BlockIntent::Apply,
slot: 2498243,
number: 1,
hash: BlockHash::default(),
Expand Down
5 changes: 3 additions & 2 deletions modules/utxo_state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ mod tests {
use super::*;
use crate::InMemoryImmutableUTXOStore;
use acropolis_common::{
Address, AssetName, BlockHash, ByronAddress, Datum, Era, NativeAsset, ReferenceScript,
TxUTxODeltas, Value,
Address, AssetName, BlockHash, BlockIntent, ByronAddress, Datum, Era, NativeAsset,
ReferenceScript, TxUTxODeltas, Value,
};
use config::Config;
use tokio::sync::Mutex;
Expand All @@ -423,6 +423,7 @@ mod tests {
fn create_block(status: BlockStatus, slot: u64, number: u64) -> BlockInfo {
BlockInfo {
status,
intent: BlockIntent::Apply,
slot,
number,
hash: BlockHash::default(),
Expand Down
3 changes: 2 additions & 1 deletion processes/golden_tests/src/test_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use acropolis_common::{
CardanoMessage, Message, RawTxsMessage, SnapshotDumpMessage, SnapshotMessage,
SnapshotStateMessage,
},
BlockHash, BlockInfo, BlockStatus, Era,
BlockHash, BlockInfo, BlockIntent, BlockStatus, Era,
};
use anyhow::{Context as AnyhowContext, Result};
use caryatid_sdk::{module, Context};
Expand Down Expand Up @@ -40,6 +40,7 @@ impl TestModule {
let transaction_message = Message::Cardano((
BlockInfo {
status: BlockStatus::Volatile,
intent: BlockIntent::Apply,
slot: 1,
number: 1,
hash: BlockHash::default(),
Expand Down
2 changes: 1 addition & 1 deletion processes/indexer/src/indices/fjall_pool_cost_index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused)]
use acropolis_codec::map_parameters::to_pool_id;
use acropolis_codec::utils::to_pool_id;
use acropolis_common::{BlockInfo, Lovelace, PoolId};
use acropolis_module_custom_indexer::chain_index::ChainIndex;
use anyhow::Result;
Expand Down
2 changes: 1 addition & 1 deletion processes/indexer/src/indices/in_memory_pool_cost_index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused)]
use acropolis_codec::map_parameters::to_pool_id;
use acropolis_codec::utils::to_pool_id;
use acropolis_common::{BlockInfo, Lovelace, PoolId};
use acropolis_module_custom_indexer::chain_index::ChainIndex;
use anyhow::Result;
Expand Down