Skip to content

Commit

Permalink
dkg/randomness failure injection
Browse files Browse the repository at this point in the history
  • Loading branch information
zjma committed Mar 2, 2024
1 parent 6181a74 commit a710a0e
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 30 deletions.
130 changes: 130 additions & 0 deletions aptos-move/framework/aptos-framework/doc/dkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
DKG on-chain states and helper functions.


- [Resource `FailureInjectionBlockDKG`](#0x1_dkg_FailureInjectionBlockDKG)
- [Resource `FailureInjectionBlockRandomness`](#0x1_dkg_FailureInjectionBlockRandomness)
- [Struct `DKGSessionMetadata`](#0x1_dkg_DKGSessionMetadata)
- [Struct `DKGStartEvent`](#0x1_dkg_DKGStartEvent)
- [Struct `DKGSessionState`](#0x1_dkg_DKGSessionState)
- [Resource `DKGState`](#0x1_dkg_DKGState)
- [Constants](#@Constants_0)
- [Function `block_dkg`](#0x1_dkg_block_dkg)
- [Function `block_randomness`](#0x1_dkg_block_randomness)
- [Function `initialize`](#0x1_dkg_initialize)
- [Function `start`](#0x1_dkg_start)
- [Function `finish`](#0x1_dkg_finish)
Expand All @@ -32,6 +36,64 @@ DKG on-chain states and helper functions.



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

## Resource `FailureInjectionBlockDKG`

If this resource is present under 0x1, validators should not do DKG (so the epoch change get stuck).
This is test-only.


<pre><code><b>struct</b> <a href="dkg.md#0x1_dkg_FailureInjectionBlockDKG">FailureInjectionBlockDKG</a> <b>has</b> key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>dummy_field: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Resource `FailureInjectionBlockRandomness`

If this resource is present under 0x1, validators should not provider randomness to block (so the execution get stuck).
This is test-only.


<pre><code><b>struct</b> <a href="dkg.md#0x1_dkg_FailureInjectionBlockRandomness">FailureInjectionBlockRandomness</a> <b>has</b> key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>dummy_field: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Struct `DKGSessionMetadata`
Expand Down Expand Up @@ -66,6 +128,18 @@ This can be considered as the public input of DKG.
</dt>
<dd>

</dd>
<dt>
<code>block_dkg: bool</code>
</dt>
<dd>

</dd>
<dt>
<code>block_randomness: bool</code>
</dt>
<dd>

</dd>
</dl>

Expand Down Expand Up @@ -204,6 +278,60 @@ The completed and in-progress DKG sessions.



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

## Function `block_dkg`



<pre><code><b>public</b> <b>fun</b> <a href="dkg.md#0x1_dkg_block_dkg">block_dkg</a>(framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="dkg.md#0x1_dkg_block_dkg">block_dkg</a>(framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>) {
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(framework);
<b>if</b> (!<b>exists</b>&lt;<a href="dkg.md#0x1_dkg_FailureInjectionBlockDKG">FailureInjectionBlockDKG</a>&gt;(@aptos_framework)) {
<b>move_to</b>(framework, <a href="dkg.md#0x1_dkg_FailureInjectionBlockDKG">FailureInjectionBlockDKG</a> {})
}
}
</code></pre>



</details>

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

## Function `block_randomness`



<pre><code><b>public</b> <b>fun</b> <a href="dkg.md#0x1_dkg_block_randomness">block_randomness</a>(framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="dkg.md#0x1_dkg_block_randomness">block_randomness</a>(framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>) {
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(framework);
<b>if</b> (!<b>exists</b>&lt;<a href="dkg.md#0x1_dkg_FailureInjectionBlockDKG">FailureInjectionBlockDKG</a>&gt;(@aptos_framework)) {
<b>move_to</b>(framework, <a href="dkg.md#0x1_dkg_FailureInjectionBlockRandomness">FailureInjectionBlockRandomness</a> {})
}
}
</code></pre>



</details>

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

## Function `initialize`
Expand Down Expand Up @@ -264,6 +392,8 @@ Abort if a DKG is already in progress.
dealer_epoch,
dealer_validator_set,
target_validator_set,
block_dkg: <b>exists</b>&lt;<a href="dkg.md#0x1_dkg_FailureInjectionBlockDKG">FailureInjectionBlockDKG</a>&gt;(@aptos_framework),
block_randomness: <b>exists</b>&lt;<a href="dkg.md#0x1_dkg_FailureInjectionBlockRandomness">FailureInjectionBlockRandomness</a>&gt;(@aptos_framework),
};
<b>let</b> start_time_us = <a href="timestamp.md#0x1_timestamp_now_microseconds">timestamp::now_microseconds</a>();
dkg_state.in_progress = std::option::some(<a href="dkg.md#0x1_dkg_DKGSessionState">DKGSessionState</a> {
Expand Down
26 changes: 26 additions & 0 deletions aptos-move/framework/aptos-framework/sources/dkg.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ module aptos_framework::dkg {
const EDKG_IN_PROGRESS: u64 = 1;
const EDKG_NOT_IN_PROGRESS: u64 = 2;

/// If this resource is present under 0x1, validators should not do DKG (so the epoch change get stuck).
/// This is test-only.
struct FailureInjectionBlockDKG has key {}

/// If this resource is present under 0x1, validators should not provider randomness to block (so the execution get stuck).
/// This is test-only.
struct FailureInjectionBlockRandomness has key {}

/// This can be considered as the public input of DKG.
struct DKGSessionMetadata has copy, drop, store {
dealer_epoch: u64,
dealer_validator_set: vector<ValidatorConsensusInfo>,
target_validator_set: vector<ValidatorConsensusInfo>,
block_dkg: bool,
block_randomness: bool,
}

#[event]
Expand All @@ -40,6 +50,20 @@ module aptos_framework::dkg {
in_progress: Option<DKGSessionState>,
}

public fun block_dkg(framework: &signer) {
system_addresses::assert_aptos_framework(framework);
if (!exists<FailureInjectionBlockDKG>(@aptos_framework)) {
move_to(framework, FailureInjectionBlockDKG {})
}
}

public fun block_randomness(framework: &signer) {
system_addresses::assert_aptos_framework(framework);
if (!exists<FailureInjectionBlockDKG>(@aptos_framework)) {
move_to(framework, FailureInjectionBlockRandomness {})
}
}

/// Called in genesis to initialize on-chain states.
public fun initialize(aptos_framework: &signer) {
system_addresses::assert_aptos_framework(aptos_framework);
Expand All @@ -65,6 +89,8 @@ module aptos_framework::dkg {
dealer_epoch,
dealer_validator_set,
target_validator_set,
block_dkg: exists<FailureInjectionBlockDKG>(@aptos_framework),
block_randomness: exists<FailureInjectionBlockRandomness>(@aptos_framework),
};
let start_time_us = timestamp::now_microseconds();
dkg_state.in_progress = std::option::some(DKGSessionState {
Expand Down
2 changes: 2 additions & 0 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const GOVERNANCE_MODULE_NAME: &str = "aptos_governance";
const CODE_MODULE_NAME: &str = "code";
const VERSION_MODULE_NAME: &str = "version";
const OIDB_MODULE_NAME: &str = "openid_account";
#[allow(dead_code)]
const JWKS_MODULE_NAME: &str = "jwks";
const CONFIG_BUFFER_MODULE_NAME: &str = "config_buffer";
const DKG_MODULE_NAME: &str = "dkg";
Expand Down Expand Up @@ -555,6 +556,7 @@ fn initialize_reconfiguration_state(session: &mut SessionExt) {
);
}

#[allow(dead_code)]
fn initialize_jwks(session: &mut SessionExt) {
exec_function(
session,
Expand Down
4 changes: 2 additions & 2 deletions aptos-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ maplit = { workspace = true }
num_cpus = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_merge = { workspace = true }
serde_yaml = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true }
url = { workspace = true }
regex = { workspace = true }
serde_merge = { workspace = true }

[dev-dependencies]
claims = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion aptos-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn load_remote_config(
warn!("{:?} is not a dir. using initial config", config_dir);
return Ok(None);
}
let mut entries = fs::read_dir(config_dir.clone())?
let entries = fs::read_dir(config_dir.clone())?
.filter_map(|res| {
let Ok(entry) = res else {
return None;
Expand Down
6 changes: 2 additions & 4 deletions aptos-node/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::{create_single_node_test_config, load_remote_config, network};
use crate::{create_single_node_test_config, network};
use aptos_config::{
config::{NetworkConfig, NodeConfig, WaypointConfig},
network_id::NetworkId,
Expand Down Expand Up @@ -119,8 +119,6 @@ fn test_create_single_node_test_config() {

#[test]
fn test_load_remote_config() {
use claims::assert_ok_eq;

aptos_logger::Logger::new()
.level(aptos_logger::Level::Debug)
.init();
Expand All @@ -131,7 +129,7 @@ fn test_load_remote_config() {
let test_dir = aptos_temppath::TempPath::new().as_ref().to_path_buf();
fs::DirBuilder::new()
.recursive(true)
.create(&test_dir.join("remote_configs"))
.create(test_dir.join("remote_configs"))
.expect("Must be able to create temp directory");
initial_config.set_data_dir(test_dir.clone());
// assert_ok_eq!(load_remote_config(&initial_config), None);
Expand Down
6 changes: 1 addition & 5 deletions consensus/src/dag/dag_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use super::{
adapter::{LedgerInfoProvider, TLedgerInfoProvider},
dag_store::DagStore,
errors::DagFetchError,
DAGRpcResult,
adapter::TLedgerInfoProvider, dag_store::DagStore, errors::DagFetchError, DAGRpcResult,
};
use crate::{
dag::{
Expand Down Expand Up @@ -373,7 +370,6 @@ impl TDagFetcher for DagFetcher {
let bounded_executor = bounded_executor.clone();
async move {
let nodes = response.certified_nodes();
let epoch = epoch_state.epoch;
ensure!(
stream::iter(nodes.clone())
.concurrent_map(bounded_executor.clone(), move |node| {
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/dag_state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl SyncModeMessageHandler {
dag_message_result: anyhow::Result<DAGMessage>,
epoch: u64,
author: Author,
responder: RpcResponder,
_responder: RpcResponder,
buffer: &mut Vec<DAGMessage>,
) -> anyhow::Result<Option<CertifiedNodeMessage>> {
match dag_message_result {
Expand Down
1 change: 0 additions & 1 deletion consensus/src/dag/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use aptos_types::{
validator_verifier::ValidatorVerifier,
};
use futures_channel::oneshot;
use rayon::iter::IntoParallelRefIterator;
use serde::{Deserialize, Serialize};
use std::{
cmp::min,
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use aptos_consensus_types::{
common::{Author, Round},
delayed_qc_msg::DelayedQcMsg,
epoch_retrieval::EpochRetrievalRequest,
proof_of_store::{BatchInfo, ProofCache},
proof_of_store::ProofCache,
};
use aptos_crypto::bls12381;
use aptos_dkg::{
Expand Down Expand Up @@ -972,6 +972,7 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
vuf_pp,
keys,
dkg_pub_params.pvss_config.wconfig.clone(),
dkg_session.metadata.block_randomness,
);

Ok(rand_config)
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/pipeline/buffer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl BufferManager {
fn process_commit_message(&mut self, commit_msg: IncomingCommitRequest) -> Option<HashValue> {
let IncomingCommitRequest {
req,
author,
author: _,
protocol,
response_sender,
} = commit_msg;
Expand Down
8 changes: 5 additions & 3 deletions consensus/src/quorum_store/tests/proof_coordinator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
test_utils::{create_vec_signed_transactions, mock_quorum_store_sender::MockQuorumStoreSender},
};
use aptos_consensus_types::proof_of_store::{
BatchId, ProofOfStore, SignedBatchInfo, SignedBatchInfoMsg,
BatchId, ProofCache, ProofOfStore, SignedBatchInfo, SignedBatchInfoMsg,
};
use aptos_crypto::HashValue;
use aptos_executor_types::ExecutorResult;
Expand Down Expand Up @@ -51,7 +51,8 @@ async fn test_proof_coordinator_basic() {
peer: signers[0].author(),
}),
tx,
true,
ProofCache::new(64), // TODO: i'm just making it build...
false, // TODO: i'm just making it build...
);
let (proof_coordinator_tx, proof_coordinator_rx) = channel(100);
let (tx, mut rx) = channel(100);
Expand Down Expand Up @@ -79,7 +80,8 @@ async fn test_proof_coordinator_basic() {
msg => panic!("Expected LocalProof but received: {:?}", msg),
};
// check normal path
assert!(proof_msg.verify(100, &verifier).is_ok());
let cache = ProofCache::new(64);
assert!(proof_msg.verify(100, &verifier, &cache).is_ok());
let proofs = proof_msg.take();
assert_eq!(proofs[0].digest(), digest);
}
8 changes: 5 additions & 3 deletions consensus/src/rand/rand_gen/rand_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,11 @@ impl<S: TShare, D: TAugmentedData> RandManager<S, D> {
},

}
let maybe_ready_blocks = self.block_queue.dequeue_rand_ready_prefix();
if !maybe_ready_blocks.is_empty() {
self.process_ready_blocks(maybe_ready_blocks);
if !self.config.block_randomness {
let maybe_ready_blocks = self.block_queue.dequeue_rand_ready_prefix();
if !maybe_ready_blocks.is_empty() {
self.process_ready_blocks(maybe_ready_blocks);
}
}
}
info!("RandManager stopped");
Expand Down
Loading

0 comments on commit a710a0e

Please sign in to comment.