Skip to content

Commit

Permalink
rounding in framework
Browse files Browse the repository at this point in the history
  • Loading branch information
zjma committed Dec 2, 2024
1 parent 5d87d94 commit e8d05a7
Show file tree
Hide file tree
Showing 39 changed files with 4,256 additions and 114 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub enum FeatureFlag {
CollectionOwner,
NativeMemoryOperations,
EnableLoaderV2,
NewFlag,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -496,6 +497,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::COLLECTION_OWNER => FeatureFlag::CollectionOwner,
AptosFeatureFlag::NATIVE_MEMORY_OPERATIONS => FeatureFlag::NativeMemoryOperations,
AptosFeatureFlag::ENABLE_LOADER_V2 => FeatureFlag::EnableLoaderV2,
AptosFeatureFlag::NEW_FLAG => FeatureFlag::NewFlag,
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,7 @@ impl AptosVM {
randomness,
} = block_metadata_with_randomness;

let args = vec![
let mut args = vec![
MoveValue::Signer(AccountAddress::ZERO), // Run as 0x0
MoveValue::Address(AccountAddress::from_bytes(id.to_vec()).unwrap()),
MoveValue::U64(epoch),
Expand All @@ -2415,12 +2415,19 @@ impl AptosVM {
.as_move_value(),
];

let mut function_name = BLOCK_PROLOGUE_EXT;

if self.features().is_enabled(FeatureFlag::NEW_FLAG) {
args.insert(0, MoveValue::Signer(AccountAddress::ONE));
function_name = BLOCK_PROLOGUE_EXT_V2;
}

let storage = TraversalStorage::new();

session
.execute_function_bypass_visibility(
&BLOCK_MODULE,
BLOCK_PROLOGUE_EXT,
function_name,
vec![],
serialize_values(&args),
&mut gas_meter,
Expand All @@ -2429,7 +2436,7 @@ impl AptosVM {
)
.map(|_return_vals| ())
.or_else(|e| {
expect_only_successful_execution(e, BLOCK_PROLOGUE_EXT.as_str(), log_context)
expect_only_successful_execution(e, function_name.as_str(), log_context)
})?;
SYSTEM_TRANSACTIONS_EXECUTED.inc();

Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-vm/src/system_module_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub static BLOCK_MODULE: Lazy<ModuleId> = Lazy::new(|| {

pub const BLOCK_PROLOGUE: &IdentStr = ident_str!("block_prologue");
pub const BLOCK_PROLOGUE_EXT: &IdentStr = ident_str!("block_prologue_ext");
pub const BLOCK_PROLOGUE_EXT_V2: &IdentStr = ident_str!("block_prologue_ext_v2");

pub static RECONFIGURATION_WITH_DKG_MODULE: Lazy<ModuleId> = Lazy::new(|| {
ModuleId::new(
Expand Down
10 changes: 3 additions & 7 deletions aptos-move/aptos-vm/src/validator_txns/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ use crate::{
},
AptosVM,
};
use aptos_types::{
dkg::{DKGState, DKGTrait, DKGTranscript, DefaultDKG},
move_utils::as_move_value::AsMoveValue,
on_chain_config::{ConfigurationResource, OnChainConfig},
transaction::TransactionStatus,
};
use aptos_types::{dkg::{DKGState, DKGTrait, DKGTranscript, DefaultDKG}, move_utils::as_move_value::AsMoveValue, NextEpochRounding, on_chain_config::{ConfigurationResource, OnChainConfig}, RoundingResult, transaction::TransactionStatus};
use aptos_vm_logging::log_schema::AdapterLogSchema;
use aptos_vm_types::{
module_and_script_storage::module_storage::AptosModuleStorage, output::VMOutput,
Expand Down Expand Up @@ -97,8 +92,9 @@ impl AptosVM {
return Err(Expected(EpochNotCurrent));
}

let rounding_result = NextEpochRounding::fetch_config(resolver).map(|NextEpochRounding { rounding }| rounding);
// Deserialize transcript and verify it.
let pub_params = DefaultDKG::new_public_params(&in_progress_session_state.metadata);
let pub_params = DefaultDKG::new_public_params(&in_progress_session_state.metadata, rounding_result);
let transcript = bcs::from_bytes::<<DefaultDKG as DKGTrait>::Transcript>(
dkg_node.transcript_bytes.as_slice(),
)
Expand Down
1 change: 1 addition & 0 deletions aptos-move/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ smallvec = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tiny-keccak = { workspace = true }
fixed = { workspace = true }

[dev-dependencies]
aptos-aggregator = { workspace = true, features = ["testing"] }
Expand Down
55 changes: 55 additions & 0 deletions aptos-move/framework/aptos-framework/doc/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This module defines a struct storing the metadata of the block and new block eve
- [Function `block_prologue_common`](#0x1_block_block_prologue_common)
- [Function `block_prologue`](#0x1_block_block_prologue)
- [Function `block_prologue_ext`](#0x1_block_block_prologue_ext)
- [Function `block_prologue_ext_v2`](#0x1_block_block_prologue_ext_v2)
- [Function `get_current_block_height`](#0x1_block_get_current_block_height)
- [Function `emit_new_block_event`](#0x1_block_emit_new_block_event)
- [Function `emit_genesis_block_event`](#0x1_block_emit_genesis_block_event)
Expand All @@ -42,6 +43,7 @@ This module defines a struct storing the metadata of the block and new block eve


<pre><code><b>use</b> <a href="account.md#0x1_account">0x1::account</a>;
<b>use</b> <a href="../../aptos-stdlib/doc/debug.md#0x1_debug">0x1::debug</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
<b>use</b> <a href="event.md#0x1_event">0x1::event</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features">0x1::features</a>;
Expand All @@ -51,6 +53,7 @@ This module defines a struct storing the metadata of the block and new block eve
<b>use</b> <a href="reconfiguration_with_dkg.md#0x1_reconfiguration_with_dkg">0x1::reconfiguration_with_dkg</a>;
<b>use</b> <a href="stake.md#0x1_stake">0x1::stake</a>;
<b>use</b> <a href="state_storage.md#0x1_state_storage">0x1::state_storage</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string">0x1::string</a>;
<b>use</b> <a href="system_addresses.md#0x1_system_addresses">0x1::system_addresses</a>;
<b>use</b> <a href="../../aptos-stdlib/doc/table_with_length.md#0x1_table_with_length">0x1::table_with_length</a>;
<b>use</b> <a href="timestamp.md#0x1_timestamp">0x1::timestamp</a>;
Expand Down Expand Up @@ -704,6 +707,58 @@ The runtime always runs this before executing the transactions in a block.



</details>

<a id="0x1_block_block_prologue_ext_v2"></a>

## Function `block_prologue_ext_v2`

<code><a href="block.md#0x1_block_block_prologue">block_prologue</a>()</code> but trigger reconfiguration with DKG after epoch timed out.


<pre><code><b>fun</b> <a href="block.md#0x1_block_block_prologue_ext_v2">block_prologue_ext_v2</a>(framework: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, vm: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>: <b>address</b>, epoch: u64, round: u64, proposer: <b>address</b>, failed_proposer_indices: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u64&gt;, previous_block_votes_bitvec: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, <a href="timestamp.md#0x1_timestamp">timestamp</a>: u64, randomness_seed: <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a>&lt;<a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="block.md#0x1_block_block_prologue_ext_v2">block_prologue_ext_v2</a>(
framework: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
vm: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>: <b>address</b>,
epoch: u64,
round: u64,
proposer: <b>address</b>,
failed_proposer_indices: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u64&gt;,
previous_block_votes_bitvec: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;,
<a href="timestamp.md#0x1_timestamp">timestamp</a>: u64,
randomness_seed: Option&lt;<a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;&gt;,
) <b>acquires</b> <a href="block.md#0x1_block_BlockResource">BlockResource</a>, <a href="block.md#0x1_block_CommitHistory">CommitHistory</a> {
<a href="../../aptos-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&utf8(b"block_prologue_ext_v2: begin"));
<b>let</b> epoch_interval = <a href="block.md#0x1_block_block_prologue_common">block_prologue_common</a>(
&vm,
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>,
epoch,
round,
proposer,
failed_proposer_indices,
previous_block_votes_bitvec,
<a href="timestamp.md#0x1_timestamp">timestamp</a>
);
<a href="randomness.md#0x1_randomness_on_new_block">randomness::on_new_block</a>(&vm, epoch, round, randomness_seed);

<b>if</b> (<a href="timestamp.md#0x1_timestamp">timestamp</a> - <a href="reconfiguration.md#0x1_reconfiguration_last_reconfiguration_time">reconfiguration::last_reconfiguration_time</a>() &gt;= epoch_interval) {
<a href="reconfiguration_with_dkg.md#0x1_reconfiguration_with_dkg_try_start_v2">reconfiguration_with_dkg::try_start_v2</a>(&framework);
};
<a href="../../aptos-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&utf8(b"block_prologue_ext_v2: end"));
}
</code></pre>



</details>

<a id="0x1_block_get_current_block_height"></a>
Expand Down
Loading

0 comments on commit e8d05a7

Please sign in to comment.