diff --git a/common/src/types.rs b/common/src/types.rs index d7c90545..b7174e30 100644 --- a/common/src/types.rs +++ b/common/src/types.rs @@ -142,12 +142,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, diff --git a/common/src/upstream_cache.rs b/common/src/upstream_cache.rs index c8cae2a3..d209338f 100644 --- a/common/src/upstream_cache.rs +++ b/common/src/upstream_cache.rs @@ -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(), diff --git a/modules/block_vrf_validator/src/ouroboros/praos.rs b/modules/block_vrf_validator/src/ouroboros/praos.rs index e6275faf..c3018002 100644 --- a/modules/block_vrf_validator/src/ouroboros/praos.rs +++ b/modules/block_vrf_validator/src/ouroboros/praos.rs @@ -92,7 +92,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::*; @@ -113,6 +113,7 @@ mod tests { hex::decode(include_str!("./data/7854823.cbor")).unwrap(); let block_info = BlockInfo { status: BlockStatus::Immutable, + intent: BlockIntent::Apply, slot: 73614529, hash: BlockHash::try_from( hex::decode("4884996cff870563ffddab5d1255a82a58482ba9351536f5b72c882f883c8947") diff --git a/modules/block_vrf_validator/src/ouroboros/tpraos.rs b/modules/block_vrf_validator/src/ouroboros/tpraos.rs index 65f21e3d..bb0d59f3 100644 --- a/modules/block_vrf_validator/src/ouroboros/tpraos.rs +++ b/modules/block_vrf_validator/src/ouroboros/tpraos.rs @@ -183,7 +183,7 @@ mod tests { protocol_params::NonceHash, serialization::Bech32Conversion, validation::{VrfLeaderValueTooBigError, WrongLeaderVrfKeyError}, - BlockHash, BlockStatus, Era, + BlockHash, BlockIntent, BlockStatus, Era, }; use super::*; @@ -206,6 +206,7 @@ mod tests { hex::decode(include_str!("./data/4490511.cbor")).unwrap(); let block_info = BlockInfo { status: BlockStatus::Immutable, + intent: BlockIntent::Apply, slot: 4492800, hash: BlockHash::try_from( hex::decode("aa83acbf5904c0edfe4d79b3689d3d00fcfc553cf360fd2229b98d464c28e9de") @@ -258,6 +259,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") @@ -316,6 +318,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") @@ -374,6 +377,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") @@ -433,6 +437,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") @@ -501,6 +506,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") diff --git a/modules/chain_store/src/stores/fjall.rs b/modules/chain_store/src/stores/fjall.rs index 3c6adecb..43463787 100644 --- a/modules/chain_store/src/stores/fjall.rs +++ b/modules/chain_store/src/stores/fjall.rs @@ -296,6 +296,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()), diff --git a/modules/epochs_state/src/state.rs b/modules/epochs_state/src/state.rs index 3f379e0e..553da0c9 100644 --- a/modules/epochs_state/src/state.rs +++ b/modules/epochs_state/src/state.rs @@ -273,13 +273,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(), @@ -294,6 +295,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(), @@ -308,6 +310,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(), diff --git a/modules/genesis_bootstrapper/src/genesis_bootstrapper.rs b/modules/genesis_bootstrapper/src/genesis_bootstrapper.rs index fb096bdd..8cc11d5f 100644 --- a/modules/genesis_bootstrapper/src/genesis_bootstrapper.rs +++ b/modules/genesis_bootstrapper/src/genesis_bootstrapper.rs @@ -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; @@ -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(), diff --git a/modules/governance_state/src/alonzo_babbage_voting.rs b/modules/governance_state/src/alonzo_babbage_voting.rs index f4992e5d..2612fda5 100644 --- a/modules/governance_state/src/alonzo_babbage_voting.rs +++ b/modules/governance_state/src/alonzo_babbage_voting.rs @@ -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; @@ -157,6 +157,7 @@ mod tests { let mut proposal = Vec::new(); let blk = BlockInfo { status: BlockStatus::Immutable, + intent: BlockIntent::Apply, slot, number: slot, epoch, diff --git a/modules/historical_epochs_state/src/state.rs b/modules/historical_epochs_state/src/state.rs index 7af155d7..83ab96df 100644 --- a/modules/historical_epochs_state/src/state.rs +++ b/modules/historical_epochs_state/src/state.rs @@ -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 { @@ -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, diff --git a/modules/historical_epochs_state/src/volatile_historical_epochs_state.rs b/modules/historical_epochs_state/src/volatile_historical_epochs_state.rs index c0872e4e..ac17d9d5 100644 --- a/modules/historical_epochs_state/src/volatile_historical_epochs_state.rs +++ b/modules/historical_epochs_state/src/volatile_historical_epochs_state.rs @@ -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::*; @@ -70,6 +70,7 @@ mod tests { number: 1, epoch: 1, status: BlockStatus::Volatile, + intent: BlockIntent::Apply, slot: 1, hash: BlockHash::default(), epoch_slot: 1, diff --git a/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs b/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs index 5df5cd22..9723a284 100644 --- a/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs +++ b/modules/mithril_snapshot_fetcher/src/mithril_snapshot_fetcher.rs @@ -4,7 +4,7 @@ use acropolis_common::{ 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}; @@ -329,6 +329,7 @@ impl MithrilSnapshotFetcher { let block_info = BlockInfo { status: BlockStatus::Immutable, + intent: BlockIntent::Apply, slot, number, hash: BlockHash::from(*block.hash()), diff --git a/modules/peer_network_interface/src/peer_network_interface.rs b/modules/peer_network_interface/src/peer_network_interface.rs index bcb86683..d9fdd17c 100644 --- a/modules/peer_network_interface/src/peer_network_interface.rs +++ b/modules/peer_network_interface/src/peer_network_interface.rs @@ -4,7 +4,7 @@ mod connection; mod network; use acropolis_common::{ - BlockInfo, BlockStatus, + BlockInfo, BlockIntent, BlockStatus, genesis_values::GenesisValues, messages::{CardanoMessage, Message, RawBlockMessage}, upstream_cache::{UpstreamCache, UpstreamCacheRecord}, @@ -230,6 +230,7 @@ impl BlockSink { } else { BlockStatus::Volatile }, + intent: BlockIntent::Apply, slot, number: header.number, hash: header.hash, diff --git a/modules/snapshot_bootstrapper/src/snapshot_bootstrapper.rs b/modules/snapshot_bootstrapper/src/snapshot_bootstrapper.rs index 9f22c356..8b8c8a1b 100644 --- a/modules/snapshot_bootstrapper/src/snapshot_bootstrapper.rs +++ b/modules/snapshot_bootstrapper/src/snapshot_bootstrapper.rs @@ -12,7 +12,7 @@ use acropolis_common::{ StreamingSnapshotParser, }, stake_addresses::AccountState, - BlockHash, BlockInfo, BlockStatus, Era, GenesisDelegates, + BlockHash, BlockInfo, BlockIntent, BlockStatus, Era, GenesisDelegates, }; use anyhow::Result; use caryatid_sdk::{module, Context}; @@ -68,6 +68,7 @@ impl SnapshotHandler { // This represents the last block included in the snapshot Ok(BlockInfo { status: BlockStatus::Immutable, // Snapshot blocks are immutable + intent: BlockIntent::Apply, // Assume snapshot blocks are valid slot: 0, // TODO: Extract from snapshot metadata if available number: 0, // TODO: Extract from snapshot metadata if available hash: BlockHash::default(), // TODO: Extract from snapshot metadata if available diff --git a/modules/spo_state/src/test_utils.rs b/modules/spo_state/src/test_utils.rs index 8babf02f..2f932232 100644 --- a/modules/spo_state/src/test_utils.rs +++ b/modules/spo_state/src/test_utils.rs @@ -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; @@ -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(), diff --git a/modules/stake_delta_filter/src/utils.rs b/modules/stake_delta_filter/src/utils.rs index c839a8b7..15afd198 100644 --- a/modules/stake_delta_filter/src/utils.rs +++ b/modules/stake_delta_filter/src/utils.rs @@ -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}; @@ -586,6 +586,7 @@ mod test { let block = BlockInfo { status: BlockStatus::Immutable, + intent: BlockIntent::Apply, slot: 2498243, number: 1, hash: BlockHash::default(), diff --git a/modules/utxo_state/src/state.rs b/modules/utxo_state/src/state.rs index f9c24c47..3f0541b7 100644 --- a/modules/utxo_state/src/state.rs +++ b/modules/utxo_state/src/state.rs @@ -396,8 +396,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; @@ -412,6 +412,7 @@ mod tests { fn create_block(status: BlockStatus, slot: u64, number: u64) -> BlockInfo { BlockInfo { status, + intent: BlockIntent::Apply, slot, number, hash: BlockHash::default(), diff --git a/processes/golden_tests/src/test_module.rs b/processes/golden_tests/src/test_module.rs index cea7c49a..6b23e07e 100644 --- a/processes/golden_tests/src/test_module.rs +++ b/processes/golden_tests/src/test_module.rs @@ -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}; @@ -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(),