Skip to content

Commit 943936b

Browse files
committed
feat: update epoch state to handle epoch times, total txs, and total outputs
- Renamed BlockFeesMessage to BlockTxsMessage and added fields for total transactions and total output. - Enhanced epoch's info endpoint with new fields for epoch start time, end time, first and last block times, total transactions, and total outputs. - Updated state management to handle new transaction metrics during epoch processing. - Adjusted related tests and configurations to reflect changes in message structures and topics.
1 parent e5c44d5 commit 943936b

File tree

12 files changed

+221
-63
lines changed

12 files changed

+221
-63
lines changed

common/src/messages.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ pub struct StakeRewardDeltasMessage {
123123
}
124124

125125
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
126-
pub struct BlockFeesMessage {
126+
pub struct BlockTxsMessage {
127+
/// Total transactions
128+
pub total_txs: u64,
129+
130+
/// Total output
131+
pub total_output: u128,
132+
127133
/// Total fees
128134
pub total_fees: u64,
129135
}
@@ -134,9 +140,27 @@ pub struct EpochActivityMessage {
134140
/// Epoch which has ended
135141
pub epoch: u64,
136142

143+
/// Epoch start time
144+
pub epoch_start_time: u64,
145+
146+
/// Epoch end time
147+
pub epoch_end_time: u64,
148+
149+
/// First block time
150+
pub first_block_time: u64,
151+
152+
/// Last block time
153+
pub last_block_time: u64,
154+
137155
/// Total blocks in this epoch
138156
pub total_blocks: usize,
139157

158+
/// Total txs in this epoch
159+
pub total_txs: u64,
160+
161+
/// Total outputs of all txs in this epoch
162+
pub total_outputs: u128,
163+
140164
/// Total fees in this epoch
141165
pub total_fees: u64,
142166

@@ -252,10 +276,10 @@ pub enum CardanoMessage {
252276
AddressDeltas(AddressDeltasMessage), // Address deltas received
253277
Withdrawals(WithdrawalsMessage), // Withdrawals from reward accounts
254278
PotDeltas(PotDeltasMessage), // Changes to pot balances
255-
BlockFees(BlockFeesMessage), // Total fees in a block
256-
EpochActivity(EpochActivityMessage), // Total fees and VRF keys for an epoch
257-
DRepState(DRepStateMessage), // Active DReps at epoch end
258-
SPOState(SPOStateMessage), // Active SPOs at epoch end
279+
BlockTxs(BlockTxsMessage), // Transactions Info like total count, total output, total fees in a block
280+
EpochActivity(EpochActivityMessage), // Total fees and VRF keys for an epoch
281+
DRepState(DRepStateMessage), // Active DReps at epoch end
282+
SPOState(SPOStateMessage), // Active SPOs at epoch end
259283
GovernanceProcedures(GovernanceProceduresMessage), // Governance procedures received
260284

261285
// Protocol Parameters

common/src/params.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub const SECURITY_PARAMETER_K: u64 = 2160;
22
pub const TECHNICAL_PARAMETER_POOL_RETIRE_MAX_EPOCH: u64 = 18;
3+
pub const EPOCH_LENGTH: u64 = 432000;

modules/epochs_state/src/epochs_history.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ mod tests {
9191
&block,
9292
&EpochActivityMessage {
9393
epoch: 199,
94+
epoch_start_time: 0,
95+
epoch_end_time: 0,
96+
first_block_time: 0,
97+
last_block_time: 0,
9498
total_blocks: 1,
99+
total_txs: 1,
100+
total_outputs: 100,
95101
total_fees: 50,
96102
vrf_vkey_hashes: vec![],
97103
nonce: None,

modules/epochs_state/src/epochs_state.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use config::Config;
1616
use pallas::ledger::traverse::MultiEraHeader;
1717
use std::sync::Arc;
1818
use tokio::sync::Mutex;
19-
use tracing::{error, info, info_span, Instrument};
19+
use tracing::{error, info, info_span};
2020

2121
mod epoch_activity_publisher;
2222
mod epochs_history;
@@ -35,12 +35,13 @@ const DEFAULT_BOOTSTRAPPED_SUBSCRIBE_TOPIC: (&str, &str) = (
3535
);
3636
const DEFAULT_BLOCK_HEADER_SUBSCRIBE_TOPIC: (&str, &str) =
3737
("block-header-subscribe-topic", "cardano.block.header");
38-
const DEFAULT_BLOCK_FEES_SUBSCRIBE_TOPIC: (&str, &str) =
39-
("block-fees-subscribe-topic", "cardano.block.fees");
38+
const DEFAULT_BLOCK_TXS_SUBSCRIBE_TOPIC: (&str, &str) =
39+
("block-txs-subscribe-topic", "cardano.block.txs");
4040
const DEFAULT_PROTOCOL_PARAMETERS_SUBSCRIBE_TOPIC: (&str, &str) = (
4141
"protocol-parameters-subscribe-topic",
4242
"cardano.protocol.parameters",
4343
);
44+
4445
const DEFAULT_EPOCH_ACTIVITY_PUBLISH_TOPIC: (&str, &str) =
4546
("epoch-activity-publish-topic", "cardano.epoch.activity");
4647

@@ -59,7 +60,7 @@ impl EpochsState {
5960
epochs_history: EpochsHistoryState,
6061
mut bootstrapped_subscription: Box<dyn Subscription<Message>>,
6162
mut headers_subscription: Box<dyn Subscription<Message>>,
62-
mut fees_subscription: Box<dyn Subscription<Message>>,
63+
mut block_txs_subscription: Box<dyn Subscription<Message>>,
6364
mut protocol_parameters_subscription: Box<dyn Subscription<Message>>,
6465
mut epoch_activity_publisher: EpochActivityPublisher,
6566
) -> Result<()> {
@@ -76,12 +77,12 @@ impl EpochsState {
7677

7778
loop {
7879
// Get a mutable state
79-
let mut state = history.lock().await.get_or_init_with(|| State::new());
80+
let mut state = history.lock().await.get_or_init_with(|| State::new(&genesis));
8081
let mut current_block: Option<BlockInfo> = None;
8182

8283
// Read both topics in parallel
8384
let headers_message_f = headers_subscription.read();
84-
let fees_message_f = fees_subscription.read();
85+
let block_txs_message_f = block_txs_subscription.read();
8586

8687
// Handle headers first
8788
let (_, message) = headers_message_f.await?;
@@ -166,18 +167,16 @@ impl EpochsState {
166167
_ => error!("Unexpected message type: {message:?}"),
167168
}
168169

169-
// Handle block fees second so new epoch's fees don't get counted in the last one
170-
let (_, message) = fees_message_f.await?;
170+
// Handle block txs second so new epoch's state don't get counted in the last one
171+
let (_, message) = block_txs_message_f.await?;
171172
match message.as_ref() {
172-
Message::Cardano((block_info, CardanoMessage::BlockFees(fees_msg))) => {
173+
Message::Cardano((block_info, CardanoMessage::BlockTxs(txs_msg))) => {
173174
let span =
174-
info_span!("epochs_state.handle_block_fees", block = block_info.number);
175-
async {
175+
info_span!("epochs_state.handle_block_txs", block = block_info.number);
176+
span.in_scope(|| {
176177
Self::check_sync(&current_block, &block_info);
177-
state.handle_fees(&block_info, fees_msg.total_fees);
178-
}
179-
.instrument(span)
180-
.await;
178+
state.handle_block_txs(&block_info, txs_msg);
179+
});
181180
}
182181

183182
_ => error!("Unexpected message type: {message:?}"),
@@ -203,10 +202,10 @@ impl EpochsState {
203202
.unwrap_or(DEFAULT_BLOCK_HEADER_SUBSCRIBE_TOPIC.1.to_string());
204203
info!("Creating subscriber for headers on '{block_headers_subscribe_topic}'");
205204

206-
let block_fees_subscribe_topic = config
207-
.get_string(DEFAULT_BLOCK_FEES_SUBSCRIBE_TOPIC.0)
208-
.unwrap_or(DEFAULT_BLOCK_FEES_SUBSCRIBE_TOPIC.1.to_string());
209-
info!("Creating subscriber for fees on '{block_fees_subscribe_topic}'");
205+
let block_txs_subscribe_topic = config
206+
.get_string(DEFAULT_BLOCK_TXS_SUBSCRIBE_TOPIC.0)
207+
.unwrap_or(DEFAULT_BLOCK_TXS_SUBSCRIBE_TOPIC.1.to_string());
208+
info!("Creating subscriber for block txs on '{block_txs_subscribe_topic}'");
210209

211210
let protocol_parameters_subscribe_topic = config
212211
.get_string(DEFAULT_PROTOCOL_PARAMETERS_SUBSCRIBE_TOPIC.0)
@@ -242,9 +241,9 @@ impl EpochsState {
242241
// Subscribe
243242
let bootstrapped_subscription = context.subscribe(&bootstrapped_subscribe_topic).await?;
244243
let headers_subscription = context.subscribe(&block_headers_subscribe_topic).await?;
245-
let fees_subscription = context.subscribe(&block_fees_subscribe_topic).await?;
246244
let protocol_parameters_subscription =
247245
context.subscribe(&protocol_parameters_subscribe_topic).await?;
246+
let block_txs_subscription = context.subscribe(&block_txs_subscribe_topic).await?;
248247

249248
// Publisher
250249
let epoch_activity_publisher =
@@ -306,7 +305,7 @@ impl EpochsState {
306305
epochs_history,
307306
bootstrapped_subscription,
308307
headers_subscription,
309-
fees_subscription,
308+
block_txs_subscription,
310309
protocol_parameters_subscription,
311310
epoch_activity_publisher,
312311
)

0 commit comments

Comments
 (0)