Skip to content

Commit bd76a17

Browse files
committed
Merge branch 'protocol/pcr2-clean' into protocol/pcr2-iota-analytics-indexer
2 parents 07166bf + c507e95 commit bd76a17

File tree

57 files changed

+1760
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1760
-430
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ iota-rosetta = { path = "crates/iota-rosetta" }
414414
iota-rpc-loadgen = { path = "crates/iota-rpc-loadgen" }
415415
iota-sdk = { path = "crates/iota-sdk" }
416416
# core-types with json format for REST API
417-
iota-sdk2 = { package = "iota-rust-sdk", git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "2ba6b293bdede769a1d9b4d1aecaede2ff7682dd", features = ["hash", "serde", "schemars"] }
417+
iota-sdk2 = { package = "iota-rust-sdk", git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "175d28d69a3ff8a4c1b936df5ef5d216672dfd26", features = ["hash", "serde", "schemars"] }
418418
iota-simulator = { path = "crates/iota-simulator" }
419419
iota-snapshot = { path = "crates/iota-snapshot" }
420420
iota-source-validation = { path = "crates/iota-source-validation" }

crates/iota-core/src/authority.rs

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use iota_types::{
6666
TransactionEvents, VerifiedCertifiedTransactionEffects, VerifiedSignedTransactionEffects,
6767
},
6868
error::{ExecutionError, IotaError, IotaResult, UserInputError},
69-
event::{Event, EventID, SystemEpochInfoEventV1},
69+
event::{Event, EventID, SystemEpochInfoEvent, SystemEpochInfoEventV1, SystemEpochInfoEventV2},
7070
executable_transaction::VerifiedExecutableTransaction,
7171
execution_config_utils::to_binary_config,
7272
execution_status::ExecutionStatus,
@@ -1730,6 +1730,7 @@ impl AuthorityState {
17301730

17311731
// make a gas object if one was not provided
17321732
let mut gas_object_refs = transaction.gas().to_vec();
1733+
let reference_gas_price = epoch_store.reference_gas_price();
17331734
let ((gas_status, checked_input_objects), mock_gas) = if transaction.gas().is_empty() {
17341735
let sender = transaction.sender();
17351736
// use a 1B iota coin
@@ -1747,7 +1748,7 @@ impl AuthorityState {
17471748
(
17481749
iota_transaction_checks::check_transaction_input_with_given_gas(
17491750
epoch_store.protocol_config(),
1750-
epoch_store.reference_gas_price(),
1751+
reference_gas_price,
17511752
&transaction,
17521753
input_objects,
17531754
receiving_objects,
@@ -1760,7 +1761,7 @@ impl AuthorityState {
17601761
(
17611762
iota_transaction_checks::check_transaction_input(
17621763
epoch_store.protocol_config(),
1763-
epoch_store.reference_gas_price(),
1764+
reference_gas_price,
17641765
&transaction,
17651766
input_objects,
17661767
&receiving_objects,
@@ -1987,7 +1988,7 @@ impl AuthorityState {
19871988
if transaction.gas().is_empty() {
19881989
iota_transaction_checks::check_transaction_input_with_given_gas(
19891990
epoch_store.protocol_config(),
1990-
epoch_store.reference_gas_price(),
1991+
reference_gas_price,
19911992
&transaction,
19921993
input_objects,
19931994
receiving_objects,
@@ -1997,7 +1998,7 @@ impl AuthorityState {
19971998
} else {
19981999
iota_transaction_checks::check_transaction_input(
19992000
epoch_store.protocol_config(),
2000-
epoch_store.reference_gas_price(),
2001+
reference_gas_price,
20012002
&transaction,
20022003
input_objects,
20032004
&receiving_objects,
@@ -4526,7 +4527,7 @@ impl AuthorityState {
45264527
epoch_start_timestamp_ms: CheckpointTimestamp,
45274528
) -> anyhow::Result<(
45284529
IotaSystemState,
4529-
Option<SystemEpochInfoEventV1>,
4530+
Option<SystemEpochInfoEvent>,
45304531
TransactionEffects,
45314532
)> {
45324533
let mut txns = Vec::new();
@@ -4583,16 +4584,30 @@ impl AuthorityState {
45834584
));
45844585
};
45854586

4586-
txns.push(EndOfEpochTransactionKind::new_change_epoch(
4587-
next_epoch,
4588-
next_epoch_protocol_version,
4589-
gas_cost_summary.storage_cost,
4590-
gas_cost_summary.computation_cost,
4591-
gas_cost_summary.storage_rebate,
4592-
gas_cost_summary.non_refundable_storage_fee,
4593-
epoch_start_timestamp_ms,
4594-
next_epoch_system_package_bytes,
4595-
));
4587+
if config.protocol_defined_base_fee() {
4588+
txns.push(EndOfEpochTransactionKind::new_change_epoch_v2(
4589+
next_epoch,
4590+
next_epoch_protocol_version,
4591+
gas_cost_summary.storage_cost,
4592+
gas_cost_summary.computation_cost,
4593+
gas_cost_summary.computation_cost_burned,
4594+
gas_cost_summary.storage_rebate,
4595+
gas_cost_summary.non_refundable_storage_fee,
4596+
epoch_start_timestamp_ms,
4597+
next_epoch_system_package_bytes,
4598+
));
4599+
} else {
4600+
txns.push(EndOfEpochTransactionKind::new_change_epoch(
4601+
next_epoch,
4602+
next_epoch_protocol_version,
4603+
gas_cost_summary.storage_cost,
4604+
gas_cost_summary.computation_cost,
4605+
gas_cost_summary.storage_rebate,
4606+
gas_cost_summary.non_refundable_storage_fee,
4607+
epoch_start_timestamp_ms,
4608+
next_epoch_system_package_bytes,
4609+
));
4610+
}
45964611

45974612
let tx = VerifiedTransaction::new_end_of_epoch_transaction(txns);
45984613

@@ -4609,6 +4624,7 @@ impl AuthorityState {
46094624
?next_epoch_protocol_version,
46104625
?next_epoch_system_packages,
46114626
computation_cost=?gas_cost_summary.computation_cost,
4627+
computation_cost_burned=?gas_cost_summary.computation_cost_burned,
46124628
storage_cost=?gas_cost_summary.storage_cost,
46134629
storage_rebate=?gas_cost_summary.storage_rebate,
46144630
non_refundable_storage_fee=?gas_cost_summary.non_refundable_storage_fee,
@@ -4654,16 +4670,13 @@ impl AuthorityState {
46544670
self.prepare_certificate(&execution_guard, &executable_tx, input_objects, epoch_store)?;
46554671
let system_obj = get_iota_system_state(&temporary_store.written)
46564672
.expect("change epoch tx must write to system object");
4657-
// Find the SystemEpochInfoEventV1 emitted by the advance_epoch transaction.
4673+
// Find the SystemEpochInfoEvent emitted by the advance_epoch transaction.
46584674
let system_epoch_info_event = temporary_store
46594675
.events
46604676
.data
46614677
.iter()
46624678
.find(|event| event.is_system_epoch_info_event())
4663-
.map(|event| {
4664-
bcs::from_bytes::<SystemEpochInfoEventV1>(&event.contents)
4665-
.expect("event deserialization should succeed as type was pre-validated")
4666-
});
4679+
.map(|event| SystemEpochInfoEvent::from(event));
46674680
// The system epoch info event can be `None` in case if the `advance_epoch`
46684681
// Move function call failed and was executed in the safe mode.
46694682
assert!(system_epoch_info_event.is_some() || system_obj.safe_mode());

crates/iota-core/src/authority/authority_per_epoch_store.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,12 @@ impl AuthorityPerEpochStore {
11031103
}
11041104

11051105
pub fn reference_gas_price(&self) -> u64 {
1106-
self.epoch_start_state().reference_gas_price()
1106+
// Determine what to use as reference gas price based on protocol config.
1107+
if self.protocol_config().protocol_defined_base_fee() {
1108+
self.protocol_config().base_gas_price()
1109+
} else {
1110+
self.epoch_start_state().reference_gas_price()
1111+
}
11071112
}
11081113

11091114
pub fn protocol_version(&self) -> ProtocolVersion {

crates/iota-core/src/checkpoints/checkpoint_executor/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ async fn sync_end_of_epoch_checkpoint(
466466
epoch_commitments: vec![ECMHLiveObjectSetDigest::default().into()],
467467
// Do not simulate supply changes in tests.
468468
// We would need to build this checkpoint after the below execution of advance_epoch to
469-
// obtain this number from the SystemEpochInfoEventV1.
469+
// obtain this number from the SystemEpochInfoEvent.
470470
epoch_supply_change: 0,
471471
}),
472472
);

crates/iota-core/src/checkpoints/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use iota_types::{
3333
digests::{CheckpointContentsDigest, CheckpointDigest},
3434
effects::{TransactionEffects, TransactionEffectsAPI},
3535
error::{IotaError, IotaResult},
36-
event::SystemEpochInfoEventV1,
36+
event::SystemEpochInfoEvent,
3737
executable_transaction::VerifiedExecutableTransaction,
3838
gas::GasCostSummary,
3939
iota_system_state::{
@@ -1452,9 +1452,8 @@ impl CheckpointBuilder {
14521452
// SAFETY: The number of minted and burnt tokens easily fit into an i64 and due
14531453
// to those small numbers, no overflows will occur during conversion or
14541454
// subtraction.
1455-
let epoch_supply_change = system_epoch_info_event.map_or(0, |event| {
1456-
event.minted_tokens_amount as i64 - event.burnt_tokens_amount as i64
1457-
});
1455+
let epoch_supply_change =
1456+
system_epoch_info_event.map_or(0, |event| event.supply_change());
14581457

14591458
let committee = system_state_obj
14601459
.get_current_epoch_committee()
@@ -1581,7 +1580,7 @@ impl CheckpointBuilder {
15811580
checkpoint_effects: &mut Vec<TransactionEffects>,
15821581
signatures: &mut Vec<Vec<GenericSignature>>,
15831582
checkpoint: CheckpointSequenceNumber,
1584-
) -> anyhow::Result<(IotaSystemState, Option<SystemEpochInfoEventV1>)> {
1583+
) -> anyhow::Result<(IotaSystemState, Option<SystemEpochInfoEvent>)> {
15851584
let (system_state, system_epoch_info_event, effects) = self
15861585
.state
15871586
.create_and_execute_advance_epoch_tx(

crates/iota-core/src/rest_index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ impl IndexStoreTables {
187187

188188
// Iterate through available, executed checkpoints that have yet to be pruned
189189
// to initialize checkpoint and transaction based indexes.
190-
if let Some(highest_executed_checkpint) =
190+
if let Some(highest_executed_checkpoint) =
191191
checkpoint_store.get_highest_executed_checkpoint_seq_number()?
192192
{
193193
let lowest_available_checkpoint = checkpoint_store
194194
.get_highest_pruned_checkpoint_seq_number()?
195195
.saturating_add(1);
196196

197-
let checkpoint_range = lowest_available_checkpoint..=highest_executed_checkpint;
197+
let checkpoint_range = lowest_available_checkpoint..=highest_executed_checkpoint;
198198

199199
info!(
200200
"Indexing {} checkpoints in range {checkpoint_range:?}",

crates/iota-core/src/unit_tests/authority_tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ async fn test_dev_inspect_object_by_bytes() {
327327
assert_eq!(effects.mutated().len(), 1);
328328
assert!(effects.deleted().is_empty());
329329
assert!(effects.gas_cost_summary().computation_cost > 0);
330+
assert!(effects.gas_cost_summary().computation_cost_burned > 0);
331+
330332
let mut results = results.unwrap();
331333
assert_eq!(results.len(), 1);
332334
let exec_results = results.pop().unwrap();
@@ -395,6 +397,7 @@ async fn test_dev_inspect_object_by_bytes() {
395397
assert_eq!(effects.mutated().len(), 1);
396398
assert!(effects.deleted().is_empty());
397399
assert!(effects.gas_cost_summary().computation_cost > 0);
400+
assert!(effects.gas_cost_summary().computation_cost_burned > 0);
398401

399402
let mut results = results.unwrap();
400403
assert_eq!(results.len(), 1);
@@ -499,6 +502,7 @@ async fn test_dev_inspect_unowned_object() {
499502
assert_eq!(effects.mutated().len(), 2);
500503
assert!(effects.deleted().is_empty());
501504
assert!(effects.gas_cost_summary().computation_cost > 0);
505+
assert!(effects.gas_cost_summary().computation_cost_burned > 0);
502506

503507
let mut results = results.unwrap();
504508
assert_eq!(results.len(), 1);
@@ -613,6 +617,8 @@ async fn test_dev_inspect_dynamic_field() {
613617
// nothing is deleted
614618
assert!(effects.deleted().is_empty());
615619
assert!(effects.gas_cost_summary().computation_cost > 0);
620+
assert!(effects.gas_cost_summary().computation_cost_burned > 0);
621+
616622
assert_eq!(results.len(), 1);
617623
let exec_results = results.pop().unwrap();
618624
let IotaExecutionResult {

crates/iota-core/src/unit_tests/gas_tests.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ async fn test_computation_oog_storage_ok_single_gas_coin() -> IotaResult {
316316
|summary, initial_value, final_value| {
317317
let gas_used = summary.net_gas_usage() as u64;
318318
assert!(summary.computation_cost > 0);
319+
assert!(summary.computation_cost_burned > 0);
319320
assert!(summary.storage_cost > 0);
320321
assert!(summary.storage_rebate > 0);
321322
assert_eq!(summary.storage_cost, summary.storage_rebate);
@@ -344,6 +345,7 @@ async fn test_computation_oog_storage_ok_multi_gas_coins() -> IotaResult {
344345
|summary, initial_value, final_value| {
345346
let gas_used = summary.net_gas_usage() as u64;
346347
assert!(summary.computation_cost > 0);
348+
assert!(summary.computation_cost_burned > 0);
347349
assert!(summary.storage_cost > 0);
348350
assert!(summary.storage_rebate > 0);
349351
assert_eq!(summary.non_refundable_storage_fee, 0);
@@ -373,6 +375,7 @@ async fn test_computation_oog_storage_ok_computation_is_entire_budget() -> IotaR
373375
|summary, initial_value, final_value| {
374376
let gas_used = summary.net_gas_usage() as u64;
375377
assert!(summary.computation_cost > 0);
378+
assert!(summary.computation_cost_burned > 0);
376379
assert!(summary.storage_cost > 0);
377380
assert!(summary.storage_rebate > 0);
378381
assert_eq!(summary.storage_cost, summary.storage_rebate);
@@ -404,6 +407,7 @@ async fn test_computation_ok_storage_oog_single_gas_coin() -> IotaResult {
404407
|summary, initial_value, final_value| {
405408
let gas_used = summary.net_gas_usage() as u64;
406409
assert!(summary.computation_cost > 0);
410+
assert!(summary.computation_cost_burned > 0);
407411
assert!(summary.storage_cost > 0);
408412
assert!(summary.storage_rebate > 0);
409413
assert_eq!(summary.storage_cost, summary.storage_rebate);
@@ -435,6 +439,7 @@ async fn test_computation_ok_storage_oog_multi_gas_coins() -> IotaResult {
435439
|summary, initial_value, final_value| {
436440
let gas_used = summary.net_gas_usage();
437441
assert!(summary.computation_cost > 0);
442+
assert!(summary.computation_cost_burned > 0);
438443
assert!(summary.storage_cost > 0);
439444
assert!(summary.storage_rebate > 0);
440445
assert_eq!(summary.non_refundable_storage_fee, 0);
@@ -466,6 +471,7 @@ async fn test_computation_ok_storage_oog_computation_is_entire_budget() -> IotaR
466471
|summary, initial_value, final_value| {
467472
let gas_used = summary.net_gas_usage() as u64;
468473
assert!(summary.computation_cost > 0);
474+
assert!(summary.computation_cost_burned > 0);
469475
assert!(summary.storage_cost > 0);
470476
assert!(summary.storage_rebate > 0);
471477
assert_eq!(summary.storage_cost, summary.storage_rebate);
@@ -504,6 +510,7 @@ async fn test_native_transfer_sufficient_gas() -> IotaResult {
504510
let gas_cost = effects.gas_cost_summary();
505511
assert!(gas_cost.net_gas_usage() as u64 > *MIN_GAS_BUDGET_PRE_RGP);
506512
assert!(gas_cost.computation_cost > 0);
513+
assert!(gas_cost.computation_cost_burned > 0);
507514
assert!(gas_cost.storage_cost > 0);
508515
// Removing genesis object does not have rebate.
509516
assert_eq!(gas_cost.storage_rebate, 0);

crates/iota-core/src/unit_tests/pay_iota_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async fn test_pay_iota_failure_insufficient_gas_balance_one_input_coin() {
7070
#[tokio::test]
7171
async fn test_pay_iota_failure_insufficient_total_balance_one_input_coin() {
7272
let (sender, sender_key): (_, AccountKeyPair) = get_key_pair();
73-
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 500100);
73+
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 1000100);
7474
let recipient1 = dbg_addr(1);
7575
let recipient2 = dbg_addr(2);
7676

@@ -80,7 +80,7 @@ async fn test_pay_iota_failure_insufficient_total_balance_one_input_coin() {
8080
vec![100, 100],
8181
sender,
8282
sender_key,
83-
500000,
83+
1000000,
8484
)
8585
.await;
8686

@@ -123,18 +123,18 @@ async fn test_pay_iota_failure_insufficient_gas_balance_multiple_input_coins() {
123123
#[tokio::test]
124124
async fn test_pay_iota_failure_insufficient_total_balance_multiple_input_coins() {
125125
let (sender, sender_key): (_, AccountKeyPair) = get_key_pair();
126-
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 204000);
127-
let coin2 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 303000);
126+
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 404000);
127+
let coin2 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 603000);
128128
let recipient1 = dbg_addr(1);
129129
let recipient2 = dbg_addr(2);
130130

131131
let res = execute_pay_iota(
132132
vec![coin1, coin2],
133133
vec![recipient1, recipient2],
134-
vec![4000, 4000],
134+
vec![8000, 8000],
135135
sender,
136136
sender_key,
137-
500000,
137+
1000000,
138138
)
139139
.await;
140140
assert_eq!(

0 commit comments

Comments
 (0)