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

Remove Clone trait for validator verifier #14847

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions consensus/safety-rules/src/fuzzing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ prop_compose! {
validator_infos,
);
if include_epoch_state {
Some(EpochState {
Some(EpochState::new(
epoch,
verifier
})
))
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/safety-rules/src/tests/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ fn test_validator_not_in_set(safety_rules: &Callback) {
next_epoch_state.epoch = 1;
let rand_signer = ValidatorSigner::random([0xFu8; 32]);
next_epoch_state.verifier =
ValidatorVerifier::new_single(rand_signer.author(), rand_signer.public_key());
ValidatorVerifier::new_single(rand_signer.author(), rand_signer.public_key()).into();
let a2 = test_utils::make_proposal_with_parent_and_overrides(
Payload::empty(false, true),
round + 2,
Expand Down Expand Up @@ -634,7 +634,7 @@ fn test_key_not_in_store(safety_rules: &Callback) {
next_epoch_state.epoch = 1;
let rand_signer = ValidatorSigner::random([0xFu8; 32]);
next_epoch_state.verifier =
ValidatorVerifier::new_single(signer.author(), rand_signer.public_key());
ValidatorVerifier::new_single(signer.author(), rand_signer.public_key()).into();
let a2 = test_utils::make_proposal_with_parent_and_overrides(
Payload::empty(false, true),
round + 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ mod test {
100,
);
let validator_verifier = ValidatorVerifier::new(vec![validator_consensus_info]);
let epoch_state = EpochState::new(current_epoch, validator_verifier.clone());
let epoch_state = EpochState::new(current_epoch, validator_verifier);

// Verify the commit proof and ensure it fails (the signature set is insufficient)
let error = commit_decision
Expand Down Expand Up @@ -1119,7 +1119,7 @@ mod test {
100,
);
let validator_verifier = ValidatorVerifier::new(vec![validator_consensus_info]);
let epoch_state = EpochState::new(current_epoch, validator_verifier.clone());
let epoch_state = EpochState::new(current_epoch, validator_verifier);

// Verify the ordered proof and ensure it fails (the signature set is insufficient)
let error = ordered_block
Expand Down Expand Up @@ -1242,7 +1242,7 @@ mod test {
100,
);
let validator_verifier = ValidatorVerifier::new(vec![validator_consensus_info]);
let epoch_state = EpochState::new(current_epoch, validator_verifier.clone());
let epoch_state = EpochState::new(current_epoch, validator_verifier);

// Verify the block payload signatures and ensure it fails (the signature set is insufficient)
let error = block_payload
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/consensus_observer/observer/active_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ async fn extract_on_chain_configs(
let validator_set: ValidatorSet = on_chain_configs
.get()
.expect("Failed to get the validator set from the on-chain configs!");
let epoch_state = Arc::new(EpochState {
epoch: on_chain_configs.epoch(),
verifier: (&validator_set).into(),
});
let epoch_state = Arc::new(EpochState::new(
on_chain_configs.epoch(),
(&validator_set).into(),
));

// Extract the consensus config (or use the default if it's missing)
let onchain_consensus_config: anyhow::Result<OnChainConsensusConfig> = on_chain_configs.get();
Expand Down
12 changes: 9 additions & 3 deletions consensus/src/consensus_observer/observer/payload_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,11 @@ mod test {
validator_signer.public_key(),
100,
);
let validator_verifier = ValidatorVerifier::new(vec![validator_consensus_info]);
let epoch_state = EpochState::new(next_epoch, validator_verifier.clone());
let validator_verifier = Arc::new(ValidatorVerifier::new(vec![validator_consensus_info]));
let epoch_state = EpochState {
epoch: next_epoch,
verifier: validator_verifier.clone(),
};

// Verify the block payload signatures (for this epoch)
block_payload_store.verify_payload_signatures(&epoch_state);
Expand All @@ -997,7 +1000,10 @@ mod test {
);

// Create an epoch state for the future epoch (with a non-empty verifier)
let epoch_state = EpochState::new(future_epoch, validator_verifier);
let epoch_state = EpochState {
epoch: future_epoch,
verifier: validator_verifier.clone(),
};

// Verify the block payload signatures (for the future epoch)
block_payload_store.verify_payload_signatures(&epoch_state);
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/tests/dag_driver_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn setup(
) -> DagDriver {
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});

let mock_ledger_info = LedgerInfo::mock_genesis(None);
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/tests/dag_state_sync_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async fn test_dag_state_sync() {
let validators = validator_verifier.get_ordered_account_addresses();
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});
let storage = Arc::new(MockStorage::new());

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/tests/dag_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn setup() -> (
let (signers, validator_verifier) = random_validator_verifier(4, None, false);
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});
let storage = Arc::new(MockStorage::new());
let payload_manager = Arc::new(MockPayloadManager {});
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/tests/fetcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn test_dag_fetcher_receiver() {
let (signers, validator_verifier) = random_validator_verifier(4, None, false);
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});
let storage = Arc::new(MockStorage::new());
let dag = Arc::new(DagStore::new(
Expand Down
10 changes: 4 additions & 6 deletions consensus/src/dag/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ impl DagBootstrapUnit {
>,
all_signers: Vec<ValidatorSigner>,
) -> (Self, UnboundedReceiver<OrderedBlocks>) {
let epoch_state = Arc::new(EpochState {
epoch,
verifier: storage.get_validator_set().into(),
});
let epoch_state = Arc::new(EpochState::new(epoch, storage.get_validator_set().into()));
let ledger_info = generate_ledger_info_with_sig(&all_signers, storage.get_ledger_info());
let dag_storage =
dag_test::MockStorage::new_with_ledger_info(ledger_info, epoch_state.clone());
Expand Down Expand Up @@ -136,7 +133,7 @@ fn create_network(
playground: &mut NetworkPlayground,
id: usize,
author: Author,
validators: ValidatorVerifier,
validators: Arc<ValidatorVerifier>,
) -> (
NetworkSender,
Box<
Expand Down Expand Up @@ -178,6 +175,7 @@ fn bootstrap_nodes(
validators: ValidatorVerifier,
) -> (Vec<DagBootstrapUnit>, Vec<UnboundedReceiver<OrderedBlocks>>) {
let peers_and_metadata = playground.peer_protocols();
let validators = Arc::new(validators);
let (nodes, ordered_node_receivers) = signers
.iter()
.enumerate()
Expand All @@ -194,7 +192,7 @@ fn bootstrap_nodes(
.insert_connection_metadata(peer_network_id, conn_meta)
.unwrap();

let (_, storage) = MockStorage::start_for_testing((&validators).into());
let (_, storage) = MockStorage::start_for_testing((&*validators).into());
let (network, network_events) =
create_network(playground, id, signer.author(), validators.clone());

Expand Down
4 changes: 2 additions & 2 deletions consensus/src/dag/tests/order_rule_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ proptest! {
let nodes = generate_dag_nodes(&dag, &validators);
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});
let mut dag = InMemDag::new_empty(epoch_state.clone(), 0, TEST_DAG_WINDOW);
for round_nodes in &nodes {
Expand Down Expand Up @@ -219,7 +219,7 @@ fn test_order_rule_basic() {
let nodes = generate_dag_nodes(&dag, &validators);
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});
let mut dag = InMemDag::new_empty(epoch_state.clone(), 0, TEST_DAG_WINDOW);
for round_nodes in &nodes {
Expand Down
5 changes: 3 additions & 2 deletions consensus/src/dag/tests/rb_handler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn test_node_broadcast_receiver_succeed() {
let (signers, validator_verifier) = random_validator_verifier(4, None, false);
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier.clone(),
verifier: validator_verifier.into(),
});
let signers: Vec<_> = signers.into_iter().map(Arc::new).collect();

Expand Down Expand Up @@ -101,6 +101,7 @@ async fn test_node_broadcast_receiver_succeed() {
#[tokio::test]
async fn test_node_broadcast_receiver_failure() {
let (signers, validator_verifier) = random_validator_verifier(4, None, false);
let validator_verifier = Arc::new(validator_verifier);
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier.clone(),
Expand Down Expand Up @@ -197,7 +198,7 @@ async fn test_node_broadcast_receiver_storage() {
let signers: Vec<_> = signers.into_iter().map(Arc::new).collect();
let epoch_state = Arc::new(EpochState {
epoch: 1,
verifier: validator_verifier,
verifier: validator_verifier.into(),
});

let storage = Arc::new(MockStorage::new());
Expand Down
5 changes: 1 addition & 4 deletions consensus/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,10 +1063,7 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
let validator_set: ValidatorSet = payload
.get()
.expect("failed to get ValidatorSet from payload");
let epoch_state = Arc::new(EpochState {
epoch: payload.epoch(),
verifier: (&validator_set).into(),
});
let epoch_state = Arc::new(EpochState::new(payload.epoch(), (&validator_set).into()));

self.epoch_state = Some(epoch_state.clone());

Expand Down
3 changes: 2 additions & 1 deletion consensus/src/liveness/leader_reputation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ fn test_extract_epoch_to_proposers_impl() {
.iter()
.map(|author| ValidatorConsensusInfo::new(*author, public_key.clone(), 1))
.collect::<Vec<_>>(),
),
)
.into(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub struct NetworkSender {
// Self sender and self receivers provide a shortcut for sending the messages to itself.
// (self sending is not supported by the networking API).
self_sender: aptos_channels::UnboundedSender<Event<ConsensusMsg>>,
validators: ValidatorVerifier,
validators: Arc<ValidatorVerifier>,
time_service: aptos_time_service::TimeService,
}

Expand All @@ -207,7 +207,7 @@ impl NetworkSender {
author: Author,
consensus_network_client: ConsensusNetworkClient<NetworkClient<ConsensusMsg>>,
self_sender: aptos_channels::UnboundedSender<Event<ConsensusMsg>>,
validators: ValidatorVerifier,
validators: Arc<ValidatorVerifier>,
) -> Self {
NetworkSender {
author,
Expand Down
2 changes: 2 additions & 0 deletions consensus/src/network_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ mod tests {
let mut playground = NetworkPlayground::new(runtime.handle().clone());
let mut nodes = Vec::new();
let (signers, validator_verifier) = random_validator_verifier(num_nodes, None, false);
let validator_verifier = Arc::new(validator_verifier);
let peers: Vec<_> = signers.iter().map(|signer| signer.author()).collect();
let peers_and_metadata = PeersAndMetadata::new(&[NetworkId::Validator]);

Expand Down Expand Up @@ -741,6 +742,7 @@ mod tests {
let mut playground = NetworkPlayground::new(runtime.handle().clone());
let mut nodes = Vec::new();
let (signers, validator_verifier) = random_validator_verifier(num_nodes, None, false);
let validator_verifier = Arc::new(validator_verifier);
let peers: Vec<_> = signers.iter().map(|signer| signer.author()).collect();
let peers_and_metadata = PeersAndMetadata::new(&[NetworkId::Validator]);

Expand Down
5 changes: 3 additions & 2 deletions consensus/src/pipeline/tests/buffer_manager_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn prepare_buffer_manager(
HashValue,
Vec<ValidatorSigner>,
Receiver<OrderedBlocks>,
ValidatorVerifier,
Arc<ValidatorVerifier>,
) {
let num_nodes = 1;
let channel_size = 30;
Expand Down Expand Up @@ -114,6 +114,7 @@ pub fn prepare_buffer_manager(
let consensus_network_client = ConsensusNetworkClient::new(network_client);

let (self_loop_tx, self_loop_rx) = aptos_channels::new_unbounded_test();
let validators = Arc::new(validators);
let network = NetworkSender::new(
author,
consensus_network_client,
Expand Down Expand Up @@ -190,7 +191,7 @@ pub fn launch_buffer_manager() -> (
Runtime,
Vec<ValidatorSigner>,
Receiver<OrderedBlocks>,
ValidatorVerifier,
Arc<ValidatorVerifier>,
) {
let runtime = consensus_runtime();

Expand Down
4 changes: 2 additions & 2 deletions consensus/src/quorum_store/batch_requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<T: QuorumStoreSender + Sync + 'static> BatchRequester<T> {
retry_interval_ms: usize,
rpc_timeout_ms: usize,
network_sender: T,
validator_verifier: ValidatorVerifier,
validator_verifier: Arc<ValidatorVerifier>,
) -> Self {
Self {
epoch,
Expand All @@ -124,7 +124,7 @@ impl<T: QuorumStoreSender + Sync + 'static> BatchRequester<T> {
retry_interval_ms,
rpc_timeout_ms,
network_sender,
validator_verifier: Arc::new(validator_verifier),
validator_verifier,
}
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/quorum_store/proof_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl ProofCoordinator {
mut self,
mut rx: Receiver<ProofCoordinatorCommand>,
mut network_sender: impl QuorumStoreSender,
validator_verifier: ValidatorVerifier,
validator_verifier: Arc<ValidatorVerifier>,
) {
let mut interval = time::interval(Duration::from_millis(100));
loop {
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/quorum_store/quorum_store_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct InnerBuilder {
mempool_txn_pull_timeout_ms: u64,
aptos_db: Arc<dyn DbReader>,
network_sender: NetworkSender,
verifier: ValidatorVerifier,
verifier: Arc<ValidatorVerifier>,
proof_cache: ProofCache,
backend: SecureBackend,
coordinator_tx: Sender<CoordinatorCommand>,
Expand Down Expand Up @@ -161,7 +161,7 @@ impl InnerBuilder {
mempool_txn_pull_timeout_ms: u64,
aptos_db: Arc<dyn DbReader>,
network_sender: NetworkSender,
verifier: ValidatorVerifier,
verifier: Arc<ValidatorVerifier>,
proof_cache: ProofCache,
backend: SecureBackend,
quorum_store_storage: Arc<dyn QuorumStoreStorage>,
Expand Down
7 changes: 4 additions & 3 deletions consensus/src/quorum_store/tests/batch_requester_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ async fn test_batch_request_exists() {
1_000,
1_000,
MockBatchRequester::new(batch_response),
ValidatorVerifier::new_single(validator_signer.author(), validator_signer.public_key()),
ValidatorVerifier::new_single(validator_signer.author(), validator_signer.public_key())
.into(),
);

let (_, subscriber_rx) = oneshot::channel();
Expand Down Expand Up @@ -184,7 +185,7 @@ async fn test_batch_request_not_exists_not_expired() {
retry_interval_ms,
1_000,
MockBatchRequester::new(batch_response),
validator_verifier,
validator_verifier.into(),
);

let request_start = Instant::now();
Expand Down Expand Up @@ -232,7 +233,7 @@ async fn test_batch_request_not_exists_expired() {
retry_interval_ms,
1_000,
MockBatchRequester::new(batch_response),
validator_verifier,
validator_verifier.into(),
);

let request_start = Instant::now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async fn test_proof_coordinator_basic() {
let (proof_coordinator_tx, proof_coordinator_rx) = channel(100);
let (tx, mut rx) = channel(100);
let network_sender = MockQuorumStoreSender::new(tx);
let verifier = Arc::new(verifier);
tokio::spawn(proof_coordinator.start(proof_coordinator_rx, network_sender, verifier.clone()));

let batch_author = signers[0].author();
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/rand/rand_gen/rand_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ mod tests {
let rand_config = RandConfig::new(
authors[my_index],
target_epoch,
verifier,
verifier.into(),
vuf_pub_params,
rand_keys,
weighted_config,
Expand Down
Loading
Loading