Skip to content

Commit 45be1c8

Browse files
Implement the fees for the events. (#4592)
## Motivation Events costs need to be accounted for. Fixes #4259 ## Proposal Since events are implemented as blobs, it makes sense to have their costs identical to those of blobs. In that way, we avoid having some economic imbalance. ## Test Plan The CI. ## Release Plan This does change the costs for validators and so it is a breaking change. ## Links None.
1 parent 9ca3f60 commit 45be1c8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

linera-execution/src/execution_state_actor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ where
493493
.await?;
494494
let index = *count;
495495
*count = count.checked_add(1).ok_or(ArithmeticError::Overflow)?;
496+
self.resource_controller
497+
.with_state(&mut self.state.system)
498+
.await?
499+
.track_event_published(&value)?;
496500
self.txn_tracker.add_event(stream_id, index, value);
497501
callback.respond(index)
498502
}
@@ -510,6 +514,10 @@ where
510514
})
511515
.await?
512516
.to_event(&event_id)?;
517+
self.resource_controller
518+
.with_state(&mut self.state.system)
519+
.await?
520+
.track_event_read(event.len() as u64)?;
513521
callback.respond(event);
514522
}
515523

linera-execution/src/resources.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ pub struct ResourceTracker {
132132
pub blob_bytes_read: u64,
133133
/// The number of blob bytes published.
134134
pub blob_bytes_published: u64,
135+
/// The number of events read.
136+
pub events_read: u32,
137+
/// The number of events published.
138+
pub events_published: u32,
139+
/// The number of event bytes read.
140+
pub event_bytes_read: u64,
141+
/// The number of event bytes published.
142+
pub event_bytes_published: u64,
135143
/// The change in the number of bytes being stored by user applications.
136144
pub bytes_stored: i32,
137145
/// The number of operations executed.
@@ -499,6 +507,44 @@ where
499507
Ok(())
500508
}
501509

510+
/// Tracks a number of event bytes read.
511+
pub(crate) fn track_event_read(&mut self, count: u64) -> Result<(), ExecutionError> {
512+
{
513+
let tracker = self.tracker.as_mut();
514+
tracker.event_bytes_read = tracker
515+
.event_bytes_read
516+
.checked_add(count)
517+
.ok_or(ArithmeticError::Overflow)?;
518+
tracker.events_read = tracker
519+
.events_read
520+
.checked_add(1)
521+
.ok_or(ArithmeticError::Overflow)?;
522+
}
523+
self.update_balance(self.policy.blob_read_price(count)?)?;
524+
Ok(())
525+
}
526+
527+
/// Tracks a number of event bytes published.
528+
pub(crate) fn track_event_published(
529+
&mut self,
530+
event_bytes: &[u8],
531+
) -> Result<(), ExecutionError> {
532+
let size = event_bytes.len() as u64;
533+
{
534+
let tracker = self.tracker.as_mut();
535+
tracker.event_bytes_published = tracker
536+
.event_bytes_published
537+
.checked_add(size)
538+
.ok_or(ArithmeticError::Overflow)?;
539+
tracker.events_published = tracker
540+
.events_published
541+
.checked_add(1)
542+
.ok_or(ArithmeticError::Overflow)?;
543+
}
544+
self.update_balance(self.policy.blob_published_price(size)?)?;
545+
Ok(())
546+
}
547+
502548
/// Tracks a change in the number of bytes stored.
503549
// TODO(#1536): This is not fully implemented.
504550
#[allow(dead_code)]

0 commit comments

Comments
 (0)