Skip to content

Commit e634ebe

Browse files
committed
add log message back in and move around some state access
1 parent 6848e4a commit e634ebe

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

src/limits.rs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ pub struct FlashblockState {
4949
}
5050

5151
impl FlashblockState {
52+
fn current_flashblock(&self) -> u64 {
53+
self.current_flashblock.load(Ordering::Relaxed)
54+
}
55+
56+
fn max_flashblocks(&self) -> u64 {
57+
self.max_flashblocks.load(Ordering::Relaxed)
58+
}
59+
5260
fn current_gas_limit(&self) -> u64 {
5361
self
5462
.gas_per_flashblock
@@ -116,10 +124,7 @@ impl FlashblockLimits {
116124
/// Advances to the next flashblock in the sequence.
117125
pub fn progress_state(&self) {
118126
let state = self.state.lock().expect("mutex is not poisoned");
119-
let next_flashblock = state.current_flashblock.load(Ordering::Relaxed) + 1;
120-
state
121-
.current_flashblock
122-
.store(next_flashblock, Ordering::Relaxed);
127+
state.current_flashblock.fetch_add(1, Ordering::Relaxed);
123128
}
124129

125130
/// Returns limits for the current flashblock.
@@ -130,13 +135,13 @@ impl FlashblockLimits {
130135
let state = self.state.lock().expect("mutex is not poisoned");
131136
// Check that state was progressed at least once
132137
assert_ne!(
133-
state.current_flashblock.load(Ordering::Relaxed),
138+
state.current_flashblock(),
134139
0,
135140
"Get limits on uninitialized state"
136141
);
137142

138143
// If self.current_flashblock == 1, we are building first flashblock
139-
let deadline = if state.current_flashblock.load(Ordering::Relaxed) == 1 {
144+
let deadline = if state.current_flashblock() == 1 {
140145
state.first_flashblock_interval
141146
} else {
142147
self.interval
@@ -181,7 +186,33 @@ impl ScopedLimits<Flashblocks> for FlashblockLimits {
181186
// Update flashblock state
182187
self.progress_state();
183188

184-
self.get_limits(enclosing)
189+
let limits = self.get_limits(enclosing);
190+
191+
let state = self.state.lock().expect("mutex is not poisoned");
192+
if state.current_flashblock() <= state.max_flashblocks() {
193+
let gas_used = payload.cumulative_gas_used();
194+
let remaining_gas = enclosing.gas_limit.saturating_sub(gas_used);
195+
tracing::info!(
196+
">---> flashblocks: {}/{}, payload txs: {}, gas used: {} ({}%), \
197+
gas_remaining: {} ({}%), next_block_gas_limit: {} ({}%), gas per \
198+
block: {} ({}%), remaining_time: {}ms, gas_limit: {}",
199+
state.current_flashblock(),
200+
state.max_flashblocks(),
201+
payload.history().transactions().count(),
202+
gas_used,
203+
(gas_used * 100 / enclosing.gas_limit),
204+
remaining_gas,
205+
(remaining_gas * 100 / enclosing.gas_limit),
206+
state.current_gas_limit(),
207+
(state.current_gas_limit() * 100 / enclosing.gas_limit),
208+
state.gas_per_flashblock,
209+
(state.gas_per_flashblock * 100 / enclosing.gas_limit),
210+
limits.deadline.expect("deadline is set").as_millis(),
211+
limits.gas_limit
212+
);
213+
}
214+
215+
limits
185216
}
186217
}
187218

0 commit comments

Comments
 (0)