Skip to content

Commit

Permalink
fix(iota-core): assert in case if an advance epoch transaction was ex…
Browse files Browse the repository at this point in the history
…ecuted in the safe mode
  • Loading branch information
valeriyr committed Oct 29, 2024
1 parent 6d2d3c5 commit 5731bed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
21 changes: 14 additions & 7 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4643,7 +4643,11 @@ impl AuthorityState {
gas_cost_summary: &GasCostSummary,
checkpoint: CheckpointSequenceNumber,
epoch_start_timestamp_ms: CheckpointTimestamp,
) -> anyhow::Result<(IotaSystemState, SystemEpochInfoEventV1, TransactionEffects)> {
) -> anyhow::Result<(
IotaSystemState,
Option<SystemEpochInfoEventV1>,
TransactionEffects,
)> {
let mut txns = Vec::new();

if let Some(tx) = self.create_authenticator_state_tx(epoch_store) {
Expand Down Expand Up @@ -4783,12 +4787,15 @@ impl AuthorityState {
.events
.data
.iter()
.find(|event| event.is_system_epoch_info_event())
.expect("end of epoch tx must emit system epoch info event");
let system_epoch_info_event = bcs::from_bytes::<SystemEpochInfoEventV1>(
&system_epoch_info_event.contents,
)
.expect("deserialization should succeed since we asserted that the event is of this type");
.find(|event| event.is_system_epoch_info_event());
let system_epoch_info_event = system_epoch_info_event.map(|event| {
bcs::from_bytes::<SystemEpochInfoEventV1>(&event.contents).expect(
"deserialization should succeed since we asserted that the event is of this type",
)
});
// The system epoch info event can be `None` in case if the `advance_epoch`
// Move function call failed and was executed in the safe mode.
assert!(system_epoch_info_event.is_some() || system_obj.safe_mode());

// We must write tx and effects to the state sync tables so that state sync is
// able to deliver to the transaction to CheckpointExecutor after it is
Expand Down
11 changes: 8 additions & 3 deletions crates/iota-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,11 +1445,16 @@ impl CheckpointBuilder {
)
.await?;

// The system epoch info event can be `None` in case if the `advance_epoch`
// Move function call failed and was executed in the safe mode.
// In this case, the tokens supply should be unchanged.
//
// SAFETY: The number of minted and burnt tokens easily fit into an i64 and due
// to those small numbers, no overflows will occur during conversion or
// subtraction.
let epoch_supply_change = system_epoch_info_event.minted_tokens_amount as i64
- system_epoch_info_event.burnt_tokens_amount as i64;
let epoch_supply_change = system_epoch_info_event.map_or(0, |event| {
event.minted_tokens_amount as i64 - event.burnt_tokens_amount as i64
});

let committee = system_state_obj
.get_current_epoch_committee()
Expand Down Expand Up @@ -1574,7 +1579,7 @@ impl CheckpointBuilder {
checkpoint_effects: &mut Vec<TransactionEffects>,
signatures: &mut Vec<Vec<GenericSignature>>,
checkpoint: CheckpointSequenceNumber,
) -> anyhow::Result<(IotaSystemState, SystemEpochInfoEventV1)> {
) -> anyhow::Result<(IotaSystemState, Option<SystemEpochInfoEventV1>)> {
let (system_state, system_epoch_info_event, effects) = self
.state
.create_and_execute_advance_epoch_tx(
Expand Down

0 comments on commit 5731bed

Please sign in to comment.