Skip to content
Open
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 @@ -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,

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 @@ -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::*;
Expand All @@ -113,6 +113,7 @@ mod tests {
hex::decode(include_str!("./data/7854823.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
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.

Given this is a validator, shouldn't this be 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 @@ -183,7 +183,7 @@ mod tests {
protocol_params::NonceHash,
serialization::Bech32Conversion,
validation::{VrfLeaderValueTooBigError, WrongLeaderVrfKeyError},
BlockHash, BlockStatus, Era,
BlockHash, BlockIntent, BlockStatus, Era,
};

use super::*;
Expand All @@ -206,6 +206,7 @@ mod tests {
hex::decode(include_str!("./data/4490511.cbor")).unwrap();
let block_info = BlockInfo {
status: BlockStatus::Immutable,
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.

Validate

slot: 4492800,
hash: BlockHash::try_from(
hex::decode("aa83acbf5904c0edfe4d79b3689d3d00fcfc553cf360fd2229b98d464c28e9de")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
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 @@ -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()),
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 @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
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 @@ -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};
Expand Down Expand Up @@ -329,6 +329,7 @@ impl MithrilSnapshotFetcher {

let block_info = BlockInfo {
status: BlockStatus::Immutable,
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.

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,
genesis_values::GenesisValues,
messages::{CardanoMessage, Message, RawBlockMessage},
upstream_cache::{UpstreamCache, UpstreamCacheRecord},
Expand Down Expand Up @@ -230,6 +230,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/snapshot_bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
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 @@ -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;
Expand All @@ -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(),
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