Skip to content

Commit ba86a00

Browse files
committed
fixed panic during first key rotation
1 parent 7d7d7bd commit ba86a00

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

nym-node/src/node/key_rotation/controller.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,23 @@ impl KeyRotationController {
125125
let current_rotation_epoch = key_rotation_info.current_rotation_starting_epoch_id();
126126

127127
let secondary_rotation_id = self.managed_keys.keys.secondary_key_rotation_id();
128+
129+
let next_rotation_id = current_rotation + 1;
130+
// edge case for rotation 0
131+
let prev_rotation_id = current_rotation.checked_sub(1);
132+
128133
let (action, execution_epoch) = match secondary_rotation_id {
129134
None => {
130135
// we don't have any secondary key, meaning the next thing we could possibly do is to pre-announce new key
131136
// an epoch before next rotation
132-
let rotation_id = current_rotation + 1;
137+
let rotation_id = next_rotation_id;
133138

134139
(
135140
KeyRotationActionState::PreAnnounce { rotation_id },
136141
next_rotation_epoch - 1,
137142
)
138143
}
139-
Some(id) if id == current_rotation - 1 => {
144+
Some(id) if Some(id) == prev_rotation_id => {
140145
// our secondary key is from the previous rotation, meaning the next thing we have to do
141146
// is to remove it (we have clearly already rotated)
142147
(KeyRotationActionState::PurgeOld, current_rotation_epoch + 1)
@@ -146,7 +151,7 @@ impl KeyRotationController {
146151
// next rotation, and we have to swap it into the primary
147152
(KeyRotationActionState::SwapDefault, current_rotation_epoch)
148153
}
149-
Some(id) if id == current_rotation + 1 => {
154+
Some(id) if id == next_rotation_id => {
150155
// our secondary key is from the upcoming rotation, meaning it's the pre-announced key, meaning
151156
// the next thing we have to do is to swap it into the primary
152157
(KeyRotationActionState::SwapDefault, next_rotation_epoch)

0 commit comments

Comments
 (0)