Skip to content

Commit ec6ba56

Browse files
committed
Merge branch 'main' into golddydev/pool-delegators
2 parents c4e6deb + 78ef46f commit ec6ba56

File tree

22 files changed

+442
-217
lines changed

22 files changed

+442
-217
lines changed

common/src/messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(dead_code)]
55

66
use crate::ledger_state::SPOState;
7+
use crate::protocol_params::ProtocolParams;
78
use crate::queries::parameters::{ParametersStateQuery, ParametersStateQueryResponse};
89
use crate::queries::{
910
accounts::{AccountsStateQuery, AccountsStateQueryResponse},

common/src/protocol_params.rs

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
1-
use crate::rational_number::{ChameleonFraction, RationalNumber};
1+
use crate::{
2+
rational_number::{ChameleonFraction, RationalNumber},
3+
BlockVersionData, Committee, Constitution, CostModel, DRepVotingThresholds, ExUnitPrices,
4+
ExUnits, PoolVotingThresholds, ProtocolConsts,
5+
};
26
use chrono::{DateTime, Utc};
37
use serde_with::serde_as;
48

9+
#[derive(Debug, Default, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
10+
pub struct ProtocolParams {
11+
pub byron: Option<ByronParams>,
12+
pub alonzo: Option<AlonzoParams>,
13+
pub shelley: Option<ShelleyParams>,
14+
pub babbage: Option<BabbageParams>,
15+
pub conway: Option<ConwayParams>,
16+
}
17+
518
//
6-
// Shelley protocol parameters
19+
// Byron protocol parameters
720
//
821

9-
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
10-
#[serde(rename_all = "camelCase")]
11-
pub struct ProtocolVersion {
12-
pub minor: u64,
13-
pub major: u64,
22+
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
23+
pub struct ByronParams {
24+
pub block_version_data: BlockVersionData,
25+
pub fts_seed: Option<Vec<u8>>,
26+
pub protocol_consts: ProtocolConsts,
27+
pub start_time: u64,
1428
}
1529

16-
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
17-
#[serde(rename_all = "PascalCase")]
18-
pub enum NonceVariant {
19-
NeutralNonce,
20-
Nonce,
21-
}
30+
//
31+
// Alonzo protocol parameters
32+
//
2233

23-
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
24-
#[serde(rename_all = "camelCase")]
25-
pub struct Nonce {
26-
pub tag: NonceVariant,
27-
pub hash: Option<Vec<u8>>,
34+
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
35+
pub struct AlonzoParams {
36+
pub lovelace_per_utxo_word: u64, // Deprecated after transition to Babbage
37+
pub execution_prices: ExUnitPrices,
38+
pub max_tx_ex_units: ExUnits,
39+
pub max_block_ex_units: ExUnits,
40+
pub max_value_size: u32,
41+
pub collateral_percentage: u32,
42+
pub max_collateral_inputs: u32,
43+
pub plutus_v1_cost_model: Option<CostModel>,
2844
}
2945

46+
//
47+
// Shelley protocol parameters
48+
//
49+
3050
#[serde_as]
3151
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
3252
#[serde(rename_all = "camelCase")]
@@ -106,3 +126,54 @@ pub struct ShelleyParams {
106126
pub system_start: DateTime<Utc>,
107127
pub update_quorum: u32,
108128
}
129+
130+
//
131+
// Babbage protocol parameters
132+
//
133+
134+
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
135+
pub struct BabbageParams {
136+
pub coins_per_utxo_byte: u64,
137+
pub plutus_v2_cost_model: Option<CostModel>,
138+
}
139+
140+
//
141+
// Conway protocol parameters
142+
//
143+
144+
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
145+
pub struct ConwayParams {
146+
pub pool_voting_thresholds: PoolVotingThresholds,
147+
pub d_rep_voting_thresholds: DRepVotingThresholds,
148+
pub committee_min_size: u64,
149+
pub committee_max_term_length: u32,
150+
pub gov_action_lifetime: u32,
151+
pub gov_action_deposit: u64,
152+
pub d_rep_deposit: u64,
153+
pub d_rep_activity: u32,
154+
pub min_fee_ref_script_cost_per_byte: RationalNumber,
155+
pub plutus_v3_cost_model: CostModel,
156+
pub constitution: Constitution,
157+
pub committee: Committee,
158+
}
159+
160+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
161+
#[serde(rename_all = "camelCase")]
162+
pub struct ProtocolVersion {
163+
pub minor: u64,
164+
pub major: u64,
165+
}
166+
167+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
168+
#[serde(rename_all = "PascalCase")]
169+
pub enum NonceVariant {
170+
NeutralNonce,
171+
Nonce,
172+
}
173+
174+
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
175+
#[serde(rename_all = "camelCase")]
176+
pub struct Nonce {
177+
pub tag: NonceVariant,
178+
pub hash: Option<Vec<u8>>,
179+
}

common/src/queries/epochs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::{messages::EpochActivityMessage, KeyHash, ProtocolParams};
1+
use crate::{messages::EpochActivityMessage, protocol_params::ProtocolParams, KeyHash};
2+
3+
pub const DEFAULT_PARAMETERS_QUERY_TOPIC: (&str, &str) =
4+
("parameters-state-query-topic", "cardano.query.parameters");
25

36
pub const DEFAULT_EPOCHS_QUERY_TOPIC: (&str, &str) =
47
("epochs-state-query-topic", "cardano.query.epochs");

common/src/queries/parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ProtocolParams;
1+
use crate::protocol_params::ProtocolParams;
22

33
pub const DEFAULT_PARAMETERS_QUERY_TOPIC: (&str, &str) =
44
("parameters-state-query-topic", "cardano.query.parameters");

common/src/queries/pools.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{KeyHash, PoolEpochState, PoolMetadata, PoolRegistration, PoolRetirement};
1+
use crate::{KeyHash, PoolEpochState, PoolMetadata, PoolRegistration, PoolRetirement, Relay};
22

33
pub const DEFAULT_POOLS_QUERY_TOPIC: (&str, &str) =
44
("pools-state-query-topic", "cardano.query.pools");
@@ -107,8 +107,9 @@ pub struct PoolHistory {
107107
}
108108

109109
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
110-
pub struct PoolRelays {}
111-
110+
pub struct PoolRelays {
111+
pub relays: Vec<Relay>,
112+
}
112113
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
113114
pub struct PoolDelegators {}
114115

common/src/state_history.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ impl StateHistoryStore {
1616
pub fn default_block_store() -> Self {
1717
Self::Bounded(SECURITY_PARAMETER_K)
1818
}
19+
pub fn default_epoch_store() -> Self {
20+
Self::Bounded(2)
21+
}
1922
}
2023

2124
struct HistoryEntry<S> {
@@ -82,6 +85,11 @@ impl<S: Clone + Default> StateHistory<S> {
8285
self.history.iter().find(|entry| entry.index == index).map(|entry| &entry.state)
8386
}
8487

88+
/// Get the most recently stored state at or beore a given index, direct ref
89+
pub fn get_at_or_before(&self, index: u64) -> Option<&S> {
90+
self.history.iter().rev().find(|entry| entry.index <= index).map(|entry| &entry.state)
91+
}
92+
8593
/// Return a reference to the state at the given block number, if it exists
8694
pub fn get_by_index_reverse(&self, index: u64) -> Option<&S> {
8795
self.history.iter().rev().find(|entry| entry.index == index).map(|entry| &entry.state)

common/src/types.rs

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use std::collections::{HashMap, HashSet};
1818
use std::fmt::{Display, Formatter};
1919

2020
/// Protocol era
21-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
21+
#[derive(
22+
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
23+
)]
2224
pub enum Era {
2325
Byron,
2426
Shelley,
@@ -397,7 +399,7 @@ pub struct MultiHostName {
397399
pub dns_name: String,
398400
}
399401

400-
/// Pool relay
402+
/// Pool Relay
401403
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
402404
pub enum Relay {
403405
SingleHostAddr(SingleHostAddr),
@@ -945,51 +947,6 @@ pub struct ProtocolConsts {
945947
pub vss_min_ttl: Option<u32>,
946948
}
947949

948-
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
949-
pub struct AlonzoParams {
950-
pub lovelace_per_utxo_word: u64,
951-
pub execution_prices: ExUnitPrices,
952-
pub max_tx_ex_units: ExUnits,
953-
pub max_block_ex_units: ExUnits,
954-
pub max_value_size: u32,
955-
pub collateral_percentage: u32,
956-
pub max_collateral_inputs: u32,
957-
pub plutus_v1_cost_model: Option<CostModel>,
958-
pub plutus_v2_cost_model: Option<CostModel>,
959-
}
960-
961-
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
962-
pub struct ByronParams {
963-
pub block_version_data: BlockVersionData,
964-
pub fts_seed: Option<Vec<u8>>,
965-
pub protocol_consts: ProtocolConsts,
966-
pub start_time: u64,
967-
}
968-
969-
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
970-
pub struct ConwayParams {
971-
pub pool_voting_thresholds: PoolVotingThresholds,
972-
pub d_rep_voting_thresholds: DRepVotingThresholds,
973-
pub committee_min_size: u64,
974-
pub committee_max_term_length: u32,
975-
pub gov_action_lifetime: u32,
976-
pub gov_action_deposit: u64,
977-
pub d_rep_deposit: u64,
978-
pub d_rep_activity: u32,
979-
pub min_fee_ref_script_cost_per_byte: RationalNumber,
980-
pub plutus_v3_cost_model: CostModel,
981-
pub constitution: Constitution,
982-
pub committee: Committee,
983-
}
984-
985-
#[derive(Debug, Default, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
986-
pub struct ProtocolParams {
987-
pub alonzo: Option<AlonzoParams>,
988-
pub byron: Option<ByronParams>,
989-
pub shelley: Option<protocol_params::ShelleyParams>,
990-
pub conway: Option<ConwayParams>,
991-
}
992-
993950
#[bitmask(u8)]
994951
#[derive(serde::Serialize, serde::Deserialize)]
995952
pub enum ProtocolParamType {
@@ -1068,14 +1025,12 @@ pub struct ProtocolParamUpdate {
10681025
#[serde(default)]
10691026
pub min_pool_cost: Option<Lovelace>,
10701027

1071-
/// AKA lovelacePerUTxOWord, utxoCostPerWord (Alonzo)
1072-
/// TODO: was there any moment, when this value had different
1073-
/// meaning? (words were recounted to bytes)
1028+
/// Cost per 8-byte word (Alonzo) - DEPRECATED after Babbage
10741029
#[serde(skip_serializing_if = "Option::is_none")]
10751030
#[serde(default)]
1076-
pub ada_per_utxo_byte: Option<Lovelace>,
1031+
pub lovelace_per_utxo_word: Option<Lovelace>,
10771032

1078-
/// AKA plutus_v1_cost_model, plutus_v2_cost_model (Shelley)
1033+
/// AKA plutus_v1_cost_model (Shelley), plutus_v2_cost_model (Babbage)
10791034
/// plutus_v3_cost_model (Conway)
10801035
#[serde(skip_serializing_if = "Option::is_none")]
10811036
#[serde(default)]
@@ -1111,6 +1066,11 @@ pub struct ProtocolParamUpdate {
11111066
#[serde(default)]
11121067
pub max_collateral_inputs: Option<u64>,
11131068

1069+
// Cost per byte (Babbage)
1070+
#[serde(skip_serializing_if = "Option::is_none")]
1071+
#[serde(default)]
1072+
pub coins_per_utxo_byte: Option<Lovelace>,
1073+
11141074
/// (Conway)
11151075
#[serde(skip_serializing_if = "Option::is_none")]
11161076
#[serde(default)]

modules/accounts_state/src/state.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::monetary::calculate_monetary_change;
33
use crate::rewards::{RewardsResult, RewardsState};
44
use crate::snapshot::Snapshot;
5+
use acropolis_common::protocol_params::ProtocolParams;
56
use acropolis_common::SPORewards;
67
use acropolis_common::{
78
messages::{
@@ -10,7 +11,7 @@ use acropolis_common::{
1011
},
1112
DRepChoice, DRepCredential, DelegatedStake, InstantaneousRewardSource,
1213
InstantaneousRewardTarget, KeyHash, Lovelace, MoveInstantaneousReward, PoolRegistration, Pot,
13-
ProtocolParams, StakeAddress, StakeCredential, TxCertificate,
14+
StakeAddress, StakeCredential, TxCertificate,
1415
};
1516
use anyhow::{bail, Result};
1617
use dashmap::DashMap;
@@ -932,10 +933,10 @@ impl State {
932933
mod tests {
933934
use super::*;
934935
use acropolis_common::{
935-
rational_number::RationalNumber, AddressNetwork, Anchor, Committee, Constitution,
936-
ConwayParams, CostModel, Credential, DRepVotingThresholds, PoolVotingThresholds, Pot,
937-
PotDelta, ProtocolParams, Ratio, Registration, StakeAddress, StakeAddressDelta,
938-
StakeAddressPayload, StakeAndVoteDelegation, StakeRegistrationAndStakeAndVoteDelegation,
936+
protocol_params::ConwayParams, rational_number::RationalNumber, AddressNetwork, Anchor,
937+
Committee, Constitution, CostModel, Credential, DRepVotingThresholds, PoolVotingThresholds,
938+
Pot, PotDelta, Ratio, Registration, StakeAddress, StakeAddressDelta, StakeAddressPayload,
939+
StakeAndVoteDelegation, StakeRegistrationAndStakeAndVoteDelegation,
939940
StakeRegistrationAndVoteDelegation, VoteDelegation, Withdrawal,
940941
};
941942

0 commit comments

Comments
 (0)