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
566 changes: 246 additions & 320 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions common/src/caryatid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,20 @@ impl RollbackAwarePublisher<Message> {
}
}
}

#[macro_export]
macro_rules! declare_cardano_reader {
($name:ident, $msg_constructor:ident, $msg_type:ty) => {
async fn $name(s: &mut Box<dyn Subscription<Message>>) -> Result<(BlockInfo, $msg_type)> {
match s.read_ignoring_rollbacks().await?.1.as_ref() {
Message::Cardano((blk, CardanoMessage::$msg_constructor(body))) => {
Ok((blk.clone(), body.clone()))
}
msg => Err(anyhow!(
"Unexpected message {msg:?} for {} topic",
stringify!($msg_constructor)
)),
}
}
};
}
11 changes: 11 additions & 0 deletions common/src/protocol_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::{bail, Result};
use blake2::{digest::consts::U32, Blake2b, Digest};
use chrono::{DateTime, Utc};
use serde_with::{hex::Hex, serde_as};
use std::fmt::Formatter;
use std::ops::Deref;
use std::{collections::HashMap, fmt::Display};

Expand Down Expand Up @@ -255,11 +256,21 @@ pub struct ProtocolVersion {
pub minor: u64,
}

impl Display for ProtocolVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}", self.major, self.minor)
}
}

impl ProtocolVersion {
pub fn new(major: u64, minor: u64) -> Self {
Self { major, minor }
}

pub fn chang() -> Self {
Self { major: 9, minor: 0 }
}

pub fn is_chang(&self) -> Result<bool> {
if self.major == 9 {
if self.minor != 0 {
Expand Down
30 changes: 21 additions & 9 deletions common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ pub enum BlockIntent {
ValidateAndApply = BlockIntent::Validate.bits | BlockIntent::Apply.bits, // Validate and apply block
}

impl BlockIntent {
pub fn do_validation(&self) -> bool {
(*self & BlockIntent::Validate) == BlockIntent::Validate
}
}

/// Block info, shared across multiple messages
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct BlockInfo {
Expand Down Expand Up @@ -257,6 +263,12 @@ impl PartialOrd for BlockInfo {
}

impl BlockInfo {
pub fn with_intent(&self, intent: BlockIntent) -> BlockInfo {
let mut copy = self.clone();
copy.intent = intent;
copy
}

pub fn is_at_tip(&self) -> bool {
// The slot of a newly-reported block can be later than the slot of the tip.
// This is because the tip is the most recent slot with a _validated_ block,
Expand Down Expand Up @@ -1899,7 +1911,7 @@ pub struct AlonzoBabbageUpdateProposal {
pub enactment_epoch: u64,
}

#[derive(Serialize, PartialEq, Deserialize, Debug, Clone)]
#[derive(Serialize, PartialEq, Eq, Deserialize, Debug, Clone)]
pub struct Constitution {
pub anchor: Anchor,
pub guardrail_script: Option<ScriptHash>,
Expand Down Expand Up @@ -1960,49 +1972,49 @@ impl Committee {
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct ParameterChangeAction {
pub previous_action_id: Option<GovActionId>,
pub protocol_param_update: Box<ProtocolParamUpdate>,
pub script_hash: Option<Vec<u8>>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct HardForkInitiationAction {
pub previous_action_id: Option<GovActionId>,
pub protocol_version: protocol_params::ProtocolVersion,
}

#[serde_as]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct TreasuryWithdrawalsAction {
#[serde_as(as = "Vec<(_, _)>")]
pub rewards: HashMap<Vec<u8>, Lovelace>,
pub script_hash: Option<Vec<u8>>,
}

#[serde_as]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct CommitteeChange {
pub removed_committee_members: HashSet<CommitteeCredential>,
#[serde_as(as = "Vec<(_, _)>")]
pub new_committee_members: HashMap<CommitteeCredential, u64>,
pub terms: RationalNumber,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct UpdateCommitteeAction {
pub previous_action_id: Option<GovActionId>,
pub data: CommitteeChange,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct NewConstitutionAction {
pub previous_action_id: Option<GovActionId>,
pub new_constitution: Constitution,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum GovernanceAction {
ParameterChange(ParameterChangeAction),
HardForkInitiation(HardForkInitiationAction),
Expand Down Expand Up @@ -2212,7 +2224,7 @@ pub struct VotingOutcome {
pub accepted: bool,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct ProposalProcedure {
pub deposit: Lovelace,
pub reward_account: StakeAddress,
Expand Down
Loading