@@ -125,18 +125,23 @@ impl KeyRotationController {
125
125
let current_rotation_epoch = key_rotation_info. current_rotation_starting_epoch_id ( ) ;
126
126
127
127
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
+
128
133
let ( action, execution_epoch) = match secondary_rotation_id {
129
134
None => {
130
135
// we don't have any secondary key, meaning the next thing we could possibly do is to pre-announce new key
131
136
// an epoch before next rotation
132
- let rotation_id = current_rotation + 1 ;
137
+ let rotation_id = next_rotation_id ;
133
138
134
139
(
135
140
KeyRotationActionState :: PreAnnounce { rotation_id } ,
136
141
next_rotation_epoch - 1 ,
137
142
)
138
143
}
139
- Some ( id) if id == current_rotation - 1 => {
144
+ Some ( id) if Some ( id ) == prev_rotation_id => {
140
145
// our secondary key is from the previous rotation, meaning the next thing we have to do
141
146
// is to remove it (we have clearly already rotated)
142
147
( KeyRotationActionState :: PurgeOld , current_rotation_epoch + 1 )
@@ -146,7 +151,7 @@ impl KeyRotationController {
146
151
// next rotation, and we have to swap it into the primary
147
152
( KeyRotationActionState :: SwapDefault , current_rotation_epoch)
148
153
}
149
- Some ( id) if id == current_rotation + 1 => {
154
+ Some ( id) if id == next_rotation_id => {
150
155
// our secondary key is from the upcoming rotation, meaning it's the pre-announced key, meaning
151
156
// the next thing we have to do is to swap it into the primary
152
157
( KeyRotationActionState :: SwapDefault , next_rotation_epoch)
0 commit comments