Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): PCR-2 base changes #5270

Open
wants to merge 5 commits into
base: protocol/pcr2-clean
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ iota-rosetta = { path = "crates/iota-rosetta" }
iota-rpc-loadgen = { path = "crates/iota-rpc-loadgen" }
iota-sdk = { path = "crates/iota-sdk" }
# core-types with json format for REST API
iota-sdk2 = { package = "iota-rust-sdk", git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "2ba6b293bdede769a1d9b4d1aecaede2ff7682dd", features = ["hash", "serde", "schemars"] }
iota-sdk2 = { package = "iota-rust-sdk", git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "175d28d69a3ff8a4c1b936df5ef5d216672dfd26", features = ["hash", "serde", "schemars"] }
iota-simulator = { path = "crates/iota-simulator" }
iota-snapshot = { path = "crates/iota-snapshot" }
iota-source-validation = { path = "crates/iota-source-validation" }
Expand Down
55 changes: 34 additions & 21 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use iota_types::{
TransactionEvents, VerifiedCertifiedTransactionEffects, VerifiedSignedTransactionEffects,
},
error::{ExecutionError, IotaError, IotaResult, UserInputError},
event::{Event, EventID, SystemEpochInfoEventV1},
event::{Event, EventID, SystemEpochInfoEvent, SystemEpochInfoEventV1, SystemEpochInfoEventV2},
executable_transaction::VerifiedExecutableTransaction,
execution_config_utils::to_binary_config,
execution_status::ExecutionStatus,
Expand Down Expand Up @@ -1730,6 +1730,7 @@ impl AuthorityState {

// make a gas object if one was not provided
let mut gas_object_refs = transaction.gas().to_vec();
let reference_gas_price = epoch_store.reference_gas_price();
let ((gas_status, checked_input_objects), mock_gas) = if transaction.gas().is_empty() {
let sender = transaction.sender();
// use a 1B iota coin
Expand All @@ -1747,7 +1748,7 @@ impl AuthorityState {
(
iota_transaction_checks::check_transaction_input_with_given_gas(
epoch_store.protocol_config(),
epoch_store.reference_gas_price(),
reference_gas_price,
&transaction,
input_objects,
receiving_objects,
Expand All @@ -1760,7 +1761,7 @@ impl AuthorityState {
(
iota_transaction_checks::check_transaction_input(
epoch_store.protocol_config(),
epoch_store.reference_gas_price(),
reference_gas_price,
&transaction,
input_objects,
&receiving_objects,
Expand Down Expand Up @@ -1987,7 +1988,7 @@ impl AuthorityState {
if transaction.gas().is_empty() {
iota_transaction_checks::check_transaction_input_with_given_gas(
epoch_store.protocol_config(),
epoch_store.reference_gas_price(),
reference_gas_price,
&transaction,
input_objects,
receiving_objects,
Expand All @@ -1997,7 +1998,7 @@ impl AuthorityState {
} else {
iota_transaction_checks::check_transaction_input(
epoch_store.protocol_config(),
epoch_store.reference_gas_price(),
reference_gas_price,
&transaction,
input_objects,
&receiving_objects,
Expand Down Expand Up @@ -4526,7 +4527,7 @@ impl AuthorityState {
epoch_start_timestamp_ms: CheckpointTimestamp,
) -> anyhow::Result<(
IotaSystemState,
Option<SystemEpochInfoEventV1>,
Option<SystemEpochInfoEvent>,
TransactionEffects,
)> {
let mut txns = Vec::new();
Expand Down Expand Up @@ -4583,16 +4584,30 @@ impl AuthorityState {
));
};

txns.push(EndOfEpochTransactionKind::new_change_epoch(
next_epoch,
next_epoch_protocol_version,
gas_cost_summary.storage_cost,
gas_cost_summary.computation_cost,
gas_cost_summary.storage_rebate,
gas_cost_summary.non_refundable_storage_fee,
epoch_start_timestamp_ms,
next_epoch_system_package_bytes,
));
if config.protocol_defined_base_fee() {
txns.push(EndOfEpochTransactionKind::new_change_epoch_v2(
next_epoch,
next_epoch_protocol_version,
gas_cost_summary.storage_cost,
gas_cost_summary.computation_cost,
gas_cost_summary.computation_cost_burned,
gas_cost_summary.storage_rebate,
gas_cost_summary.non_refundable_storage_fee,
epoch_start_timestamp_ms,
next_epoch_system_package_bytes,
));
} else {
txns.push(EndOfEpochTransactionKind::new_change_epoch(
next_epoch,
next_epoch_protocol_version,
gas_cost_summary.storage_cost,
gas_cost_summary.computation_cost,
gas_cost_summary.storage_rebate,
gas_cost_summary.non_refundable_storage_fee,
epoch_start_timestamp_ms,
next_epoch_system_package_bytes,
));
}

let tx = VerifiedTransaction::new_end_of_epoch_transaction(txns);

Expand All @@ -4609,6 +4624,7 @@ impl AuthorityState {
?next_epoch_protocol_version,
?next_epoch_system_packages,
computation_cost=?gas_cost_summary.computation_cost,
computation_cost_burned=?gas_cost_summary.computation_cost_burned,
storage_cost=?gas_cost_summary.storage_cost,
storage_rebate=?gas_cost_summary.storage_rebate,
non_refundable_storage_fee=?gas_cost_summary.non_refundable_storage_fee,
Expand Down Expand Up @@ -4654,16 +4670,13 @@ impl AuthorityState {
self.prepare_certificate(&execution_guard, &executable_tx, input_objects, epoch_store)?;
let system_obj = get_iota_system_state(&temporary_store.written)
.expect("change epoch tx must write to system object");
// Find the SystemEpochInfoEventV1 emitted by the advance_epoch transaction.
// Find the SystemEpochInfoEvent emitted by the advance_epoch transaction.
let system_epoch_info_event = temporary_store
.events
.data
.iter()
.find(|event| event.is_system_epoch_info_event())
.map(|event| {
bcs::from_bytes::<SystemEpochInfoEventV1>(&event.contents)
.expect("event deserialization should succeed as type was pre-validated")
});
.map(|event| SystemEpochInfoEvent::from(event));
// 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,12 @@ impl AuthorityPerEpochStore {
}

pub fn reference_gas_price(&self) -> u64 {
self.epoch_start_state().reference_gas_price()
// Determine what to use as reference gas price based on protocol config.
if self.protocol_config().protocol_defined_base_fee() {
self.protocol_config().base_gas_price()
} else {
self.epoch_start_state().reference_gas_price()
}
}

pub fn protocol_version(&self) -> ProtocolVersion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ async fn sync_end_of_epoch_checkpoint(
epoch_commitments: vec![ECMHLiveObjectSetDigest::default().into()],
// Do not simulate supply changes in tests.
// We would need to build this checkpoint after the below execution of advance_epoch to
// obtain this number from the SystemEpochInfoEventV1.
// obtain this number from the SystemEpochInfoEvent.
epoch_supply_change: 0,
}),
);
Expand Down
9 changes: 4 additions & 5 deletions crates/iota-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use iota_types::{
digests::{CheckpointContentsDigest, CheckpointDigest},
effects::{TransactionEffects, TransactionEffectsAPI},
error::{IotaError, IotaResult},
event::SystemEpochInfoEventV1,
event::SystemEpochInfoEvent,
executable_transaction::VerifiedExecutableTransaction,
gas::GasCostSummary,
iota_system_state::{
Expand Down Expand Up @@ -1452,9 +1452,8 @@ impl CheckpointBuilder {
// 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.map_or(0, |event| {
event.minted_tokens_amount as i64 - event.burnt_tokens_amount as i64
});
let epoch_supply_change =
system_epoch_info_event.map_or(0, |event| event.supply_change());

let committee = system_state_obj
.get_current_epoch_committee()
Expand Down Expand Up @@ -1581,7 +1580,7 @@ impl CheckpointBuilder {
checkpoint_effects: &mut Vec<TransactionEffects>,
signatures: &mut Vec<Vec<GenericSignature>>,
checkpoint: CheckpointSequenceNumber,
) -> anyhow::Result<(IotaSystemState, Option<SystemEpochInfoEventV1>)> {
) -> anyhow::Result<(IotaSystemState, Option<SystemEpochInfoEvent>)> {
let (system_state, system_epoch_info_event, effects) = self
.state
.create_and_execute_advance_epoch_tx(
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-core/src/rest_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ impl IndexStoreTables {

// Iterate through available, executed checkpoints that have yet to be pruned
// to initialize checkpoint and transaction based indexes.
if let Some(highest_executed_checkpint) =
if let Some(highest_executed_checkpoint) =
checkpoint_store.get_highest_executed_checkpoint_seq_number()?
{
let lowest_available_checkpoint = checkpoint_store
.get_highest_pruned_checkpoint_seq_number()?
.saturating_add(1);

let checkpoint_range = lowest_available_checkpoint..=highest_executed_checkpint;
let checkpoint_range = lowest_available_checkpoint..=highest_executed_checkpoint;

info!(
"Indexing {} checkpoints in range {checkpoint_range:?}",
Expand Down
6 changes: 6 additions & 0 deletions crates/iota-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ async fn test_dev_inspect_object_by_bytes() {
assert_eq!(effects.mutated().len(), 1);
assert!(effects.deleted().is_empty());
assert!(effects.gas_cost_summary().computation_cost > 0);
assert!(effects.gas_cost_summary().computation_cost_burned > 0);

let mut results = results.unwrap();
assert_eq!(results.len(), 1);
let exec_results = results.pop().unwrap();
Expand Down Expand Up @@ -395,6 +397,7 @@ async fn test_dev_inspect_object_by_bytes() {
assert_eq!(effects.mutated().len(), 1);
assert!(effects.deleted().is_empty());
assert!(effects.gas_cost_summary().computation_cost > 0);
assert!(effects.gas_cost_summary().computation_cost_burned > 0);

let mut results = results.unwrap();
assert_eq!(results.len(), 1);
Expand Down Expand Up @@ -499,6 +502,7 @@ async fn test_dev_inspect_unowned_object() {
assert_eq!(effects.mutated().len(), 2);
assert!(effects.deleted().is_empty());
assert!(effects.gas_cost_summary().computation_cost > 0);
assert!(effects.gas_cost_summary().computation_cost_burned > 0);

let mut results = results.unwrap();
assert_eq!(results.len(), 1);
Expand Down Expand Up @@ -613,6 +617,8 @@ async fn test_dev_inspect_dynamic_field() {
// nothing is deleted
assert!(effects.deleted().is_empty());
assert!(effects.gas_cost_summary().computation_cost > 0);
assert!(effects.gas_cost_summary().computation_cost_burned > 0);

assert_eq!(results.len(), 1);
let exec_results = results.pop().unwrap();
let IotaExecutionResult {
Expand Down
7 changes: 7 additions & 0 deletions crates/iota-core/src/unit_tests/gas_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ async fn test_computation_oog_storage_ok_single_gas_coin() -> IotaResult {
|summary, initial_value, final_value| {
let gas_used = summary.net_gas_usage() as u64;
assert!(summary.computation_cost > 0);
assert!(summary.computation_cost_burned > 0);
assert!(summary.storage_cost > 0);
assert!(summary.storage_rebate > 0);
assert_eq!(summary.storage_cost, summary.storage_rebate);
Expand Down Expand Up @@ -344,6 +345,7 @@ async fn test_computation_oog_storage_ok_multi_gas_coins() -> IotaResult {
|summary, initial_value, final_value| {
let gas_used = summary.net_gas_usage() as u64;
assert!(summary.computation_cost > 0);
assert!(summary.computation_cost_burned > 0);
assert!(summary.storage_cost > 0);
assert!(summary.storage_rebate > 0);
assert_eq!(summary.non_refundable_storage_fee, 0);
Expand Down Expand Up @@ -373,6 +375,7 @@ async fn test_computation_oog_storage_ok_computation_is_entire_budget() -> IotaR
|summary, initial_value, final_value| {
let gas_used = summary.net_gas_usage() as u64;
assert!(summary.computation_cost > 0);
assert!(summary.computation_cost_burned > 0);
assert!(summary.storage_cost > 0);
assert!(summary.storage_rebate > 0);
assert_eq!(summary.storage_cost, summary.storage_rebate);
Expand Down Expand Up @@ -404,6 +407,7 @@ async fn test_computation_ok_storage_oog_single_gas_coin() -> IotaResult {
|summary, initial_value, final_value| {
let gas_used = summary.net_gas_usage() as u64;
assert!(summary.computation_cost > 0);
assert!(summary.computation_cost_burned > 0);
assert!(summary.storage_cost > 0);
assert!(summary.storage_rebate > 0);
assert_eq!(summary.storage_cost, summary.storage_rebate);
Expand Down Expand Up @@ -435,6 +439,7 @@ async fn test_computation_ok_storage_oog_multi_gas_coins() -> IotaResult {
|summary, initial_value, final_value| {
let gas_used = summary.net_gas_usage();
assert!(summary.computation_cost > 0);
assert!(summary.computation_cost_burned > 0);
assert!(summary.storage_cost > 0);
assert!(summary.storage_rebate > 0);
assert_eq!(summary.non_refundable_storage_fee, 0);
Expand Down Expand Up @@ -466,6 +471,7 @@ async fn test_computation_ok_storage_oog_computation_is_entire_budget() -> IotaR
|summary, initial_value, final_value| {
let gas_used = summary.net_gas_usage() as u64;
assert!(summary.computation_cost > 0);
assert!(summary.computation_cost_burned > 0);
assert!(summary.storage_cost > 0);
assert!(summary.storage_rebate > 0);
assert_eq!(summary.storage_cost, summary.storage_rebate);
Expand Down Expand Up @@ -504,6 +510,7 @@ async fn test_native_transfer_sufficient_gas() -> IotaResult {
let gas_cost = effects.gas_cost_summary();
assert!(gas_cost.net_gas_usage() as u64 > *MIN_GAS_BUDGET_PRE_RGP);
assert!(gas_cost.computation_cost > 0);
assert!(gas_cost.computation_cost_burned > 0);
assert!(gas_cost.storage_cost > 0);
// Removing genesis object does not have rebate.
assert_eq!(gas_cost.storage_rebate, 0);
Expand Down
12 changes: 6 additions & 6 deletions crates/iota-core/src/unit_tests/pay_iota_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn test_pay_iota_failure_insufficient_gas_balance_one_input_coin() {
#[tokio::test]
async fn test_pay_iota_failure_insufficient_total_balance_one_input_coin() {
let (sender, sender_key): (_, AccountKeyPair) = get_key_pair();
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 500100);
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 1000100);
let recipient1 = dbg_addr(1);
let recipient2 = dbg_addr(2);

Expand All @@ -80,7 +80,7 @@ async fn test_pay_iota_failure_insufficient_total_balance_one_input_coin() {
vec![100, 100],
sender,
sender_key,
500000,
1000000,
)
.await;

Expand Down Expand Up @@ -123,18 +123,18 @@ async fn test_pay_iota_failure_insufficient_gas_balance_multiple_input_coins() {
#[tokio::test]
async fn test_pay_iota_failure_insufficient_total_balance_multiple_input_coins() {
let (sender, sender_key): (_, AccountKeyPair) = get_key_pair();
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 204000);
let coin2 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 303000);
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 404000);
let coin2 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 603000);
let recipient1 = dbg_addr(1);
let recipient2 = dbg_addr(2);

let res = execute_pay_iota(
vec![coin1, coin2],
vec![recipient1, recipient2],
vec![4000, 4000],
vec![8000, 8000],
sender,
sender_key,
500000,
1000000,
)
.await;
assert_eq!(
Expand Down
29 changes: 26 additions & 3 deletions crates/iota-core/tests/staged/iota.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ ChangeEpoch:
SEQ: U8
- SEQ:
TYPENAME: ObjectID
ChangeEpochV2:
STRUCT:
- epoch: U64
- protocol_version:
TYPENAME: ProtocolVersion
- storage_charge: U64
- computation_charge: U64
- computation_charge_burned: U64
- storage_rebate: U64
- non_refundable_storage_fee: U64
- epoch_start_timestamp_ms: U64
- system_packages:
SEQ:
TUPLE:
- TYPENAME: SequenceNumber
- SEQ:
SEQ: U8
- SEQ:
TYPENAME: ObjectID
CheckpointCommitment:
ENUM:
0:
Expand Down Expand Up @@ -312,16 +331,20 @@ EndOfEpochTransactionKind:
NEWTYPE:
TYPENAME: ChangeEpoch
1:
AuthenticatorStateCreate: UNIT
ChangeEpochV2:
NEWTYPE:
TYPENAME: ChangeEpochV2
2:
AuthenticatorStateCreate: UNIT
3:
AuthenticatorStateExpire:
NEWTYPE:
TYPENAME: AuthenticatorStateExpire
3:
4:
BridgeStateCreate:
NEWTYPE:
TYPENAME: ChainIdentifier
4:
5:
BridgeCommitteeInit:
NEWTYPE:
TYPENAME: SequenceNumber
Expand Down
Loading
Loading