Skip to content

Commit bc8c43a

Browse files
chore: Make CallContext::time required
1 parent fbd1cee commit bc8c43a

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

rs/protobuf/def/state/canister_state_bits/v1/canister_state_bits.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ message CallContext {
3030
bool responded = 5;
3131
state.queues.v1.Funds available_funds = 6;
3232
bool deleted = 8;
33-
optional uint64 time_nanos = 9;
33+
uint64 time_nanos = 9;
3434
uint64 instructions_executed = 10;
3535
}
3636

rs/protobuf/src/gen/state/state.canister_state_bits.v1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub struct CallContext {
77
pub available_funds: ::core::option::Option<super::super::queues::v1::Funds>,
88
#[prost(bool, tag = "8")]
99
pub deleted: bool,
10-
#[prost(uint64, optional, tag = "9")]
11-
pub time_nanos: ::core::option::Option<u64>,
10+
#[prost(uint64, tag = "9")]
11+
pub time_nanos: u64,
1212
#[prost(uint64, tag = "10")]
1313
pub instructions_executed: u64,
1414
#[prost(oneof = "call_context::CallOrigin", tags = "1, 2, 3, 4, 7")]

rs/replicated_state/src/canister_state/system_state/call_context_manager.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ pub struct CallContext {
4040
/// Cycles that were sent in the request that created the `CallContext`.
4141
available_cycles: Cycles,
4242

43-
/// Point in time at which the `CallContext` was created. This field is only
44-
/// optional to accommodate contexts that were created before this field was
45-
/// added.
46-
time: Option<Time>,
43+
/// Point in time at which the `CallContext` was created.
44+
time: Time,
4745

4846
/// The total number of instructions executed in the given call context.
4947
/// This value is used for the `ic0.performance_counter` type 1.
@@ -63,7 +61,7 @@ impl CallContext {
6361
responded,
6462
deleted,
6563
available_cycles,
66-
time: Some(time),
64+
time,
6765
instructions_executed: NumInstructions::default(),
6866
}
6967
}
@@ -113,7 +111,7 @@ impl CallContext {
113111
}
114112

115113
/// The point in time at which the call context was created.
116-
pub fn time(&self) -> Option<Time> {
114+
pub fn time(&self) -> Time {
117115
self.time
118116
}
119117

@@ -132,7 +130,7 @@ impl From<&CallContext> for pb::CallContext {
132130
responded: item.responded,
133131
deleted: item.deleted,
134132
available_funds: Some((&funds).into()),
135-
time_nanos: item.time.map(|t| t.as_nanos_since_unix_epoch()),
133+
time_nanos: item.time.as_nanos_since_unix_epoch(),
136134
instructions_executed: item.instructions_executed.get(),
137135
}
138136
}
@@ -149,7 +147,7 @@ impl TryFrom<pb::CallContext> for CallContext {
149147
responded: value.responded,
150148
deleted: value.deleted,
151149
available_cycles: funds.cycles(),
152-
time: value.time_nanos.map(Time::from_nanos_since_unix_epoch),
150+
time: Time::from_nanos_since_unix_epoch(value.time_nanos),
153151
instructions_executed: value.instructions_executed.into(),
154152
})
155153
}
@@ -335,7 +333,7 @@ impl CallContextManager {
335333
responded: false,
336334
deleted: false,
337335
available_cycles: cycles,
338-
time: Some(time),
336+
time,
339337
instructions_executed: NumInstructions::default(),
340338
},
341339
);
@@ -581,15 +579,10 @@ impl CallContextManager {
581579
// context that isn't old enough.
582580
self.call_contexts
583581
.iter()
584-
.take_while(|(_, call_context)| match call_context.time() {
585-
Some(context_time) => context_time + age <= current_time,
586-
None => true,
587-
})
582+
.take_while(|(_, call_context)| call_context.time() + age <= current_time)
588583
.filter_map(|(_, call_context)| {
589-
if let Some(time) = call_context.time() {
590-
if !call_context.is_deleted() {
591-
return Some((call_context.call_origin(), time));
592-
}
584+
if !call_context.is_deleted() {
585+
return Some((call_context.call_origin(), call_context.time()));
593586
}
594587
None
595588
})

rs/test_utilities/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl CanisterStateBuilder {
306306
let call_context_id = call_context_manager.new_call_context(
307307
call_context.call_origin().clone(),
308308
call_context.available_cycles(),
309-
call_context.time().unwrap(),
309+
call_context.time(),
310310
);
311311

312312
let call_context_in_call_context_manager = call_context_manager

0 commit comments

Comments
 (0)