Skip to content

Commit 47d9d26

Browse files
committed
Refactor continued
1 parent 4c23cfa commit 47d9d26

File tree

54 files changed

+346
-287
lines changed

Some content is hidden

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

54 files changed

+346
-287
lines changed

chain/chain/src/runtime/tests.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,15 @@ fn test_validator_rotation() {
436436
let block_producers: Vec<_> =
437437
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
438438
let signer =
439-
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref());
439+
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref())
440+
.into();
440441
// test1 doubles stake and the new account stakes the same, so test2 will be kicked out.`
441442
let staking_transaction = stake(1, &signer, &block_producers[0], TESTING_INIT_STAKE * 2);
442443
let new_account = AccountId::try_from(format!("test{}", num_nodes + 1)).unwrap();
443444
let new_validator = create_test_signer(new_account.as_str());
444-
let new_signer =
445-
InMemorySigner::from_seed(new_account.clone(), KeyType::ED25519, new_account.as_ref());
445+
let new_signer: Signer =
446+
InMemorySigner::from_seed(new_account.clone(), KeyType::ED25519, new_account.as_ref())
447+
.into();
446448
let create_account_transaction = SignedTransaction::create_account(
447449
2,
448450
block_producers[0].validator_id().clone(),
@@ -460,7 +462,8 @@ fn test_validator_rotation() {
460462
validators[1].clone(),
461463
KeyType::ED25519,
462464
validators[1].as_ref(),
463-
);
465+
)
466+
.into();
464467
vec![
465468
staking_transaction,
466469
create_account_transaction,
@@ -522,7 +525,8 @@ fn test_validator_stake_change() {
522525
let block_producers: Vec<_> =
523526
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
524527
let signer =
525-
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref());
528+
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref())
529+
.into();
526530

527531
let desired_stake = 2 * TESTING_INIT_STAKE / 3;
528532
let staking_transaction = stake(1, &signer, &block_producers[0], desired_stake);
@@ -559,7 +563,7 @@ fn test_validator_stake_change_multiple_times() {
559563
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
560564
let signers: Vec<_> = validators
561565
.iter()
562-
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
566+
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into())
563567
.collect();
564568

565569
let staking_transaction = stake(1, &signers[0], &block_producers[0], TESTING_INIT_STAKE - 1);
@@ -654,7 +658,7 @@ fn test_stake_in_last_block_of_an_epoch() {
654658
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
655659
let signers: Vec<_> = validators
656660
.iter()
657-
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
661+
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into())
658662
.collect();
659663
let staking_transaction =
660664
stake(1, &signers[0], &block_producers[0], TESTING_INIT_STAKE + TESTING_INIT_STAKE / 6);
@@ -715,7 +719,8 @@ fn test_state_sync() {
715719
let block_producers: Vec<_> =
716720
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
717721
let signer =
718-
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref());
722+
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref())
723+
.into();
719724
let staking_transaction = stake(1, &signer, &block_producers[0], TESTING_INIT_STAKE + 1);
720725
env.step_default(vec![staking_transaction]);
721726
env.step_default(vec![]);
@@ -804,7 +809,8 @@ fn test_get_validator_info() {
804809
let block_producers: Vec<_> =
805810
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
806811
let signer =
807-
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref());
812+
InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref())
813+
.into();
808814
let staking_transaction = stake(1, &signer, &block_producers[0], 0);
809815
let mut expected_blocks = [0, 0];
810816
let mut expected_chunks = [0, 0];
@@ -1045,7 +1051,8 @@ fn test_double_sign_challenge_not_all_slashed() {
10451051
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
10461052

10471053
let signer =
1048-
InMemorySigner::from_seed(validators[2].clone(), KeyType::ED25519, validators[2].as_ref());
1054+
InMemorySigner::from_seed(validators[2].clone(), KeyType::ED25519, validators[2].as_ref())
1055+
.into();
10491056
let staking_transaction = stake(1, &signer, &block_producers[2], TESTING_INIT_STAKE / 3);
10501057
env.step(
10511058
vec![vec![staking_transaction]],
@@ -1221,7 +1228,7 @@ fn test_fishermen_stake() {
12211228
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
12221229
let signers: Vec<_> = validators
12231230
.iter()
1224-
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
1231+
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into())
12251232
.collect();
12261233
let fishermen_stake = 3300 * NEAR_BASE + 1;
12271234

@@ -1288,7 +1295,7 @@ fn test_fishermen_unstake() {
12881295
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
12891296
let signers: Vec<_> = validators
12901297
.iter()
1291-
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
1298+
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into())
12921299
.collect();
12931300
let fishermen_stake = 3300 * NEAR_BASE + 1;
12941301

@@ -1365,15 +1372,15 @@ fn test_delete_account_after_unstake() {
13651372
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
13661373
.collect();
13671374

1368-
let staking_transaction1 = stake(1, &signers[1], &block_producers[1], 0);
1375+
let staking_transaction1 = stake(1, &signers[1].clone().into(), &block_producers[1], 0);
13691376
env.step_default(vec![staking_transaction1]);
13701377
let account = env.view_account(block_producers[1].validator_id());
13711378
assert_eq!(account.amount, TESTING_INIT_BALANCE - TESTING_INIT_STAKE);
13721379
assert_eq!(account.locked, TESTING_INIT_STAKE);
13731380
for _ in 2..=5 {
13741381
env.step_default(vec![]);
13751382
}
1376-
let staking_transaction2 = stake(2, &signers[1], &block_producers[1], 1);
1383+
let staking_transaction2 = stake(2, &signers[1].clone().into(), &block_producers[1], 1);
13771384
env.step_default(vec![staking_transaction2]);
13781385
for _ in 7..=13 {
13791386
env.step_default(vec![]);
@@ -1385,7 +1392,7 @@ fn test_delete_account_after_unstake() {
13851392
4,
13861393
signers[1].account_id.clone(),
13871394
signers[1].account_id.clone(),
1388-
&signers[1] as &Signer,
1395+
&signers[1].clone().into(),
13891396
vec![Action::DeleteAccount(DeleteAccountAction {
13901397
beneficiary_id: signers[0].account_id.clone(),
13911398
})],
@@ -1410,7 +1417,7 @@ fn test_proposal_deduped() {
14101417
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
14111418
let signers: Vec<_> = validators
14121419
.iter()
1413-
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
1420+
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into())
14141421
.collect();
14151422

14161423
let staking_transaction1 = stake(1, &signers[1], &block_producers[1], TESTING_INIT_STAKE - 100);
@@ -1431,7 +1438,7 @@ fn test_insufficient_stake() {
14311438
validators.iter().map(|id| create_test_signer(id.as_str())).collect();
14321439
let signers: Vec<_> = validators
14331440
.iter()
1434-
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()))
1441+
.map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into())
14351442
.collect();
14361443

14371444
let staking_transaction1 = stake(1, &signers[1], &block_producers[1], 100);
@@ -1479,7 +1486,7 @@ fn test_trie_and_flat_state_equality() {
14791486
4,
14801487
signers[0].account_id.clone(),
14811488
validators[1].clone(),
1482-
&signers[0] as &Signer,
1489+
&signers[0].clone().into(),
14831490
vec![Action::Transfer(TransferAction { deposit: 10 })],
14841491
// runtime does not validate block history
14851492
CryptoHash::default(),
@@ -1567,7 +1574,7 @@ fn generate_transaction_pool(
15671574
round.try_into().unwrap(),
15681575
signers[i].account_id.clone(),
15691576
signers[(i + round) % signer_count].account_id.clone(),
1570-
&signers[i] as &Signer,
1577+
&signers[i].clone().into(),
15711578
round.try_into().unwrap(),
15721579
block_hash,
15731580
);

chain/chain/src/tests/garbage_collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use near_primitives::merkle::PartialMerkleTree;
2020
use near_primitives::shard_layout::ShardUId;
2121
use near_primitives::test_utils::{create_test_signer, TestBlockBuilder};
2222
use near_primitives::types::{BlockHeight, NumBlocks, StateRoot};
23-
use near_primitives::validator_signer::InMemoryValidatorSigner;
23+
use near_primitives::validator_signer::ValidatorSigner;
2424
use near_store::test_utils::gen_changes;
2525
use near_store::{DBCol, ShardTries, Trie, WrappedTrieChanges};
2626

@@ -730,7 +730,7 @@ fn add_block(
730730
epoch_manager: &dyn EpochManagerAdapter,
731731
prev_block: &mut Block,
732732
blocks: &mut Vec<Block>,
733-
signer: Arc<InMemoryValidatorSigner>,
733+
signer: Arc<ValidatorSigner>,
734734
height: u64,
735735
) {
736736
let next_epoch_id = epoch_manager

chain/chain/src/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ mod tests {
424424
nonce,
425425
account_id,
426426
"bob".parse().unwrap(),
427-
&signer,
427+
&signer.into(),
428428
10,
429429
CryptoHash::default(),
430430
)

chain/chunks/src/chunk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ mod tests {
296296
CryptoHash::default(),
297297
CryptoHash::default(),
298298
vec![],
299-
&signer,
299+
&signer.into(),
300300
))
301301
}
302302

chain/chunks/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod tests {
229229
nonce,
230230
signer_id.clone(),
231231
receiver_id.clone(),
232-
&signer,
232+
&signer.into(),
233233
deposit,
234234
CryptoHash::default(),
235235
);

chain/client/src/chunk_distribution_network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ mod tests {
396396
hash(&[height.to_le_bytes().as_slice(), shard_id.to_le_bytes().as_slice()].concat());
397397
let mut mock_hashes = MockHashes::new(prev_block_hash);
398398

399-
let signer = ValidatorSigner::EmptyValidatorSigner(EmptyValidatorSigner::default());
399+
let signer = EmptyValidatorSigner::default().into();
400400
let header_inner = ShardChunkHeaderInner::V3(ShardChunkHeaderInnerV3 {
401401
prev_block_hash,
402402
prev_state_root: mock_hashes.next().unwrap(),

chain/client/src/client.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ use near_chain::{
3939
BlockProcessingArtifact, BlockStatus, Chain, ChainGenesis, ChainStoreAccess, Doomslug,
4040
DoomslugThresholdMode, Provenance,
4141
};
42-
use near_chain_configs::{ClientConfig, LogSummaryStyle, MutableConfigValue, UpdateableClientConfig};
42+
use near_chain_configs::{
43+
ClientConfig, LogSummaryStyle, MutableConfigValue, UpdateableClientConfig,
44+
};
4345
use near_chunks::adapter::ShardsManagerRequestFromClient;
4446
use near_chunks::client::ShardedTransactionPool;
4547
use near_chunks::logic::{
@@ -592,10 +594,9 @@ impl Client {
592594
height: BlockHeight,
593595
prev_hash: CryptoHash,
594596
) -> Result<Option<Block>, Error> {
595-
let validator_signer = self
596-
.validator_signer
597-
.get()
598-
.ok_or_else(|| Error::BlockProducer("Called without block producer info.".to_string()))?;
597+
let validator_signer = self.validator_signer.get().ok_or_else(|| {
598+
Error::BlockProducer("Called without block producer info.".to_string())
599+
})?;
599600

600601
// Check that we are were called at the block that we are producer for.
601602
let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(&prev_hash).unwrap();
@@ -829,10 +830,9 @@ impl Client {
829830
next_height: BlockHeight,
830831
shard_id: ShardId,
831832
) -> Result<Option<ProduceChunkResult>, Error> {
832-
let validator_signer = self
833-
.validator_signer
834-
.get()
835-
.ok_or_else(|| Error::ChunkProducer("Called without block producer info.".to_string()))?;
833+
let validator_signer = self.validator_signer.get().ok_or_else(|| {
834+
Error::ChunkProducer("Called without block producer info.".to_string())
835+
})?;
836836

837837
let chunk_proposer =
838838
self.epoch_manager.get_chunk_producer(epoch_id, next_height, shard_id).unwrap();
@@ -869,7 +869,7 @@ impl Client {
869869
last_header: ShardChunkHeader,
870870
next_height: BlockHeight,
871871
shard_id: ShardId,
872-
validator_signer: Arc<dyn ValidatorSigner>,
872+
validator_signer: Arc<ValidatorSigner>,
873873
) -> Result<Option<ProduceChunkResult>, Error> {
874874
let span = tracing::Span::current();
875875
let timer = Instant::now();
@@ -2090,7 +2090,8 @@ impl Client {
20902090
Err(_) => false,
20912091
Ok(target_block_producer) => {
20922092
let validator_signer = self.validator_signer.get();
2093-
Some(&target_block_producer) == validator_signer.as_ref().map(|x| x.validator_id())
2093+
Some(&target_block_producer)
2094+
== validator_signer.as_ref().map(|x| x.validator_id())
20942095
}
20952096
};
20962097

chain/client/src/client_actor.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl ClientActorInner {
326326
info!(target: "client", "Starting validator node: {}", vs.validator_id());
327327
}
328328
let info_helper =
329-
InfoHelper::new(clock.clone(), telemetry_sender, &config, validator_signer.clone());
329+
InfoHelper::new(clock.clone(), telemetry_sender, &config, validator_signer);
330330

331331
let now = clock.now_utc();
332332
Ok(ClientActorInner {
@@ -709,7 +709,8 @@ impl Handler<Status> for ClientActorInner {
709709
.into_chain_error()?;
710710

711711
let node_public_key = self.node_id.public_key().clone();
712-
let (validator_account_id, validator_public_key) = match &self.client.validator_signer.get() {
712+
let (validator_account_id, validator_public_key) = match &self.client.validator_signer.get()
713+
{
713714
Some(vs) => (Some(vs.validator_id().clone()), Some(vs.public_key())),
714715
None => (None, None),
715716
};
@@ -1161,11 +1162,9 @@ impl ClientActorInner {
11611162
pub(crate) fn check_triggers(&mut self, ctx: &mut dyn DelayedActionRunner<Self>) -> Duration {
11621163
let _span = tracing::debug_span!(target: "client", "check_triggers").entered();
11631164
if let Some(config_updater) = &mut self.config_updater {
1164-
config_updater.try_update(
1165-
&|updateable_client_config| {
1166-
self.client.update_client_config(updateable_client_config)
1167-
},
1168-
);
1165+
config_updater.try_update(&|updateable_client_config| {
1166+
self.client.update_client_config(updateable_client_config)
1167+
});
11691168
}
11701169

11711170
// Check block height to trigger expected shutdown

chain/client/src/config_updater.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ impl ConfigUpdater {
2121

2222
/// Check if any of the configs were updated.
2323
/// If they did, the receiver (rx_config_update) will contain a clone of the new configs.
24-
pub fn try_update(
25-
&mut self,
26-
update_client_config_fn: &dyn Fn(UpdateableClientConfig),
27-
) {
24+
pub fn try_update(&mut self, update_client_config_fn: &dyn Fn(UpdateableClientConfig)) {
2825
while let Ok(maybe_updateable_configs) = self.rx_config_update.try_recv() {
2926
match maybe_updateable_configs {
3027
Ok(updateable_configs) => {

chain/client/src/stateless_validation/state_witness_producer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Client {
3838
let shard_id = chunk_header.shard_id();
3939
let _span = tracing::debug_span!(target: "client", "send_chunk_state_witness", chunk_hash=?chunk_header.chunk_hash(), ?shard_id).entered();
4040

41-
let my_signer = self.validator_signer.get().ok_or(Error::NotAValidator)?.clone();
41+
let my_signer = self.validator_signer.get().ok_or(Error::NotAValidator)?;
4242
let state_witness = self.create_state_witness(
4343
my_signer.validator_id().clone(),
4444
prev_block_header,

chain/client/src/test_utils/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn create_chunk(
190190
let parity_parts = total_parts - data_parts;
191191
let rs = ReedSolomon::new(data_parts, parity_parts).unwrap();
192192

193-
let signer = client.validator_signer.get().unwrap().clone();
193+
let signer = client.validator_signer.get().unwrap();
194194
let header = chunk.cloned_header();
195195
let (mut encoded_chunk, mut new_merkle_paths) = EncodedShardChunk::new(
196196
*header.prev_block_hash(),
@@ -228,7 +228,7 @@ pub fn create_chunk(
228228
client.chain.chain_store().get_block_merkle_tree(last_block.hash()).unwrap();
229229
let mut block_merkle_tree = PartialMerkleTree::clone(&block_merkle_tree);
230230

231-
let signer = client.validator_signer.get().unwrap().clone();
231+
let signer = client.validator_signer.get().unwrap();
232232
let endorsement = ChunkEndorsement::new(chunk.cloned_header().chunk_hash(), signer.as_ref());
233233
block_merkle_tree.insert(*last_block.hash());
234234
let block = Block::produce(
@@ -249,7 +249,7 @@ pub fn create_chunk(
249249
None,
250250
vec![],
251251
vec![],
252-
&*client.validator_signer.get().unwrap().clone(),
252+
&*client.validator_signer.get().unwrap(),
253253
*last_block.header().next_bp_hash(),
254254
block_merkle_tree.root(),
255255
client.clock.now_utc(),

0 commit comments

Comments
 (0)