Skip to content

Commit

Permalink
fix chunk_to_commit.is_reconfig (#15226) (#15234)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7ef6e66)

Co-authored-by: Alden Hu <[email protected]>
  • Loading branch information
github-actions[bot] and msmouse authored Nov 7, 2024
1 parent 1086a5e commit fcd2ded
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion execution/executor-types/src/state_compute_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl StateComputeResult {
.state_updates_before_last_checkpoint
.as_ref(),
sharded_state_cache: Some(&self.execution_output.state_cache.sharded_state_cache),
is_reconfig: self.execution_output.block_end_info.is_some(),
is_reconfig: self.execution_output.next_epoch_state.is_some(),
}
}
}
8 changes: 7 additions & 1 deletion storage/aptosdb/src/db/include/aptosdb_testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ impl ChunkToCommitOwned {
&transaction_infos,
);

let is_reconfig = transaction_outputs
.iter()
.rev()
.flat_map(TransactionOutput::events)
.any(ContractEvent::is_new_epoch_event);

Self {
first_version,
transactions,
Expand All @@ -165,7 +171,7 @@ impl ChunkToCommitOwned {
per_version_state_updates,
state_updates_until_last_checkpoint,
sharded_state_cache: None,
is_reconfig: false,
is_reconfig,
}
}

Expand Down
12 changes: 12 additions & 0 deletions storage/aptosdb/src/db/include/aptosdb_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ impl AptosDB {
current_epoch,
);

// Ensure that state tree at the end of the epoch is persisted.
if ledger_info_with_sig.ledger_info().ends_epoch() {
let state_snapshot = self.state_store.get_state_snapshot_before(version + 1)?;
ensure!(
state_snapshot.is_some() && state_snapshot.as_ref().unwrap().0 == version,
"State checkpoint not persisted at the end of the epoch, version {}, next_epoch {}, snapshot in db: {:?}",
version,
ledger_info_with_sig.ledger_info().next_block_epoch(),
state_snapshot,
);
}

// Put write to batch.
self.ledger_db
.metadata_db()
Expand Down
23 changes: 16 additions & 7 deletions types/src/proptest_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use crate::{
account_address::{self, AccountAddress},
account_config::{AccountResource, CoinStoreResource},
account_config::{
AccountResource, CoinStoreResource, NewEpochEvent, NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG,
},
aggregate_signature::PartialSignatures,
block_info::{BlockInfo, Round},
block_metadata::BlockMetadata,
Expand Down Expand Up @@ -1163,6 +1165,11 @@ impl BlockGen {
self,
universe: &mut AccountInfoUniverse,
) -> (Vec<TransactionToCommit>, LedgerInfo) {
let num_txns = self.txn_gens.len() + 1;

// materialize ledger info
let ledger_info = self.ledger_info_gen.materialize(universe, num_txns);

let mut txns_to_commit = Vec::new();

// materialize user transactions
Expand All @@ -1179,16 +1186,18 @@ impl BlockGen {
),
arr![HashMap::new(); 16],
WriteSet::default(),
Vec::new(),
if ledger_info.ends_epoch() {
vec![ContractEvent::new_v2(
NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.clone(),
bcs::to_bytes(&NewEpochEvent::dummy()).unwrap(),
)]
} else {
vec![]
},
false,
TransactionAuxiliaryData::default(),
));

// materialize ledger info
let ledger_info = self
.ledger_info_gen
.materialize(universe, txns_to_commit.len());

(txns_to_commit, ledger_info)
}
}
Expand Down

0 comments on commit fcd2ded

Please sign in to comment.