diff --git a/Cargo.lock b/Cargo.lock index 6038b410198..2cb3d1efdb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4115,6 +4115,7 @@ dependencies = [ "anyhow", "near-async", "near-chain-configs", + "near-crypto", "near-o11y", "near-primitives", "once_cell", diff --git a/chain/chain/src/doomslug.rs b/chain/chain/src/doomslug.rs index d65a48578b1..20f05a01174 100644 --- a/chain/chain/src/doomslug.rs +++ b/chain/chain/src/doomslug.rs @@ -138,7 +138,7 @@ pub struct Doomslug { endorsement_pending: bool, /// Information to track the timer (see `start_timer` routine in the paper) timer: DoomslugTimer, - signer: Option>, + signer: Option>, /// How many approvals to have before producing a block. In production should be always `HalfStake`, /// but for many tests we use `NoApprovals` to invoke more forkfulness threshold_mode: DoomslugThresholdMode, @@ -362,7 +362,7 @@ impl Doomslug { min_delay: Duration, delay_step: Duration, max_delay: Duration, - signer: Option>, + signer: Option>, threshold_mode: DoomslugThresholdMode, ) -> Self { Doomslug { diff --git a/chain/chain/src/runtime/tests.rs b/chain/chain/src/runtime/tests.rs index 15afc4c7786..31a600a5a84 100644 --- a/chain/chain/src/runtime/tests.rs +++ b/chain/chain/src/runtime/tests.rs @@ -48,8 +48,8 @@ use primitive_types::U256; fn stake( nonce: Nonce, - signer: &dyn Signer, - sender: &dyn ValidatorSigner, + signer: &Signer, + sender: &ValidatorSigner, stake: Balance, ) -> SignedTransaction { SignedTransaction::from_actions( @@ -438,13 +438,15 @@ fn test_validator_rotation() { let block_producers: Vec<_> = validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signer = - InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()); + InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()) + .into(); // test1 doubles stake and the new account stakes the same, so test2 will be kicked out.` let staking_transaction = stake(1, &signer, &block_producers[0], TESTING_INIT_STAKE * 2); let new_account = AccountId::try_from(format!("test{}", num_nodes + 1)).unwrap(); let new_validator = create_test_signer(new_account.as_str()); - let new_signer = - InMemorySigner::from_seed(new_account.clone(), KeyType::ED25519, new_account.as_ref()); + let new_signer: Signer = + InMemorySigner::from_seed(new_account.clone(), KeyType::ED25519, new_account.as_ref()) + .into(); let create_account_transaction = SignedTransaction::create_account( 2, block_producers[0].validator_id().clone(), @@ -462,7 +464,8 @@ fn test_validator_rotation() { validators[1].clone(), KeyType::ED25519, validators[1].as_ref(), - ); + ) + .into(); vec![ staking_transaction, create_account_transaction, @@ -524,7 +527,8 @@ fn test_validator_stake_change() { let block_producers: Vec<_> = validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signer = - InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()); + InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()) + .into(); let desired_stake = 2 * TESTING_INIT_STAKE / 3; let staking_transaction = stake(1, &signer, &block_producers[0], desired_stake); @@ -561,7 +565,7 @@ fn test_validator_stake_change_multiple_times() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signers: Vec<_> = validators .iter() - .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) + .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into()) .collect(); let staking_transaction = stake(1, &signers[0], &block_producers[0], TESTING_INIT_STAKE - 1); @@ -656,7 +660,7 @@ fn test_stake_in_last_block_of_an_epoch() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signers: Vec<_> = validators .iter() - .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) + .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into()) .collect(); let staking_transaction = stake(1, &signers[0], &block_producers[0], TESTING_INIT_STAKE + TESTING_INIT_STAKE / 6); @@ -717,7 +721,8 @@ fn test_state_sync() { let block_producers: Vec<_> = validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signer = - InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()); + InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()) + .into(); let staking_transaction = stake(1, &signer, &block_producers[0], TESTING_INIT_STAKE + 1); env.step_default(vec![staking_transaction]); env.step_default(vec![]); @@ -806,7 +811,8 @@ fn test_get_validator_info() { let block_producers: Vec<_> = validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signer = - InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()); + InMemorySigner::from_seed(validators[0].clone(), KeyType::ED25519, validators[0].as_ref()) + .into(); let staking_transaction = stake(1, &signer, &block_producers[0], 0); let mut expected_blocks = [0, 0]; let mut expected_chunks = [0, 0]; @@ -1047,7 +1053,8 @@ fn test_double_sign_challenge_not_all_slashed() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signer = - InMemorySigner::from_seed(validators[2].clone(), KeyType::ED25519, validators[2].as_ref()); + InMemorySigner::from_seed(validators[2].clone(), KeyType::ED25519, validators[2].as_ref()) + .into(); let staking_transaction = stake(1, &signer, &block_producers[2], TESTING_INIT_STAKE / 3); env.step( vec![vec![staking_transaction]], @@ -1223,7 +1230,7 @@ fn test_fishermen_stake() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signers: Vec<_> = validators .iter() - .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) + .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into()) .collect(); let fishermen_stake = 3300 * NEAR_BASE + 1; @@ -1290,7 +1297,7 @@ fn test_fishermen_unstake() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signers: Vec<_> = validators .iter() - .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) + .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into()) .collect(); let fishermen_stake = 3300 * NEAR_BASE + 1; @@ -1367,7 +1374,7 @@ fn test_delete_account_after_unstake() { .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) .collect(); - let staking_transaction1 = stake(1, &signers[1], &block_producers[1], 0); + let staking_transaction1 = stake(1, &signers[1].clone().into(), &block_producers[1], 0); env.step_default(vec![staking_transaction1]); let account = env.view_account(block_producers[1].validator_id()); assert_eq!(account.amount, TESTING_INIT_BALANCE - TESTING_INIT_STAKE); @@ -1375,7 +1382,7 @@ fn test_delete_account_after_unstake() { for _ in 2..=5 { env.step_default(vec![]); } - let staking_transaction2 = stake(2, &signers[1], &block_producers[1], 1); + let staking_transaction2 = stake(2, &signers[1].clone().into(), &block_producers[1], 1); env.step_default(vec![staking_transaction2]); for _ in 7..=13 { env.step_default(vec![]); @@ -1387,7 +1394,7 @@ fn test_delete_account_after_unstake() { 4, signers[1].account_id.clone(), signers[1].account_id.clone(), - &signers[1] as &dyn Signer, + &signers[1].clone().into(), vec![Action::DeleteAccount(DeleteAccountAction { beneficiary_id: signers[0].account_id.clone(), })], @@ -1412,7 +1419,7 @@ fn test_proposal_deduped() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signers: Vec<_> = validators .iter() - .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) + .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into()) .collect(); let staking_transaction1 = stake(1, &signers[1], &block_producers[1], TESTING_INIT_STAKE - 100); @@ -1433,7 +1440,7 @@ fn test_insufficient_stake() { validators.iter().map(|id| create_test_signer(id.as_str())).collect(); let signers: Vec<_> = validators .iter() - .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref())) + .map(|id| InMemorySigner::from_seed(id.clone(), KeyType::ED25519, id.as_ref()).into()) .collect(); let staking_transaction1 = stake(1, &signers[1], &block_producers[1], 100); @@ -1481,7 +1488,7 @@ fn test_trie_and_flat_state_equality() { 4, signers[0].account_id.clone(), validators[1].clone(), - &signers[0] as &dyn Signer, + &signers[0].clone().into(), vec![Action::Transfer(TransferAction { deposit: 10 })], // runtime does not validate block history CryptoHash::default(), @@ -1569,7 +1576,7 @@ fn generate_transaction_pool( round.try_into().unwrap(), signers[i].account_id.clone(), signers[(i + round) % signer_count].account_id.clone(), - &signers[i] as &dyn Signer, + &signers[i].clone().into(), round.try_into().unwrap(), block_hash, ); diff --git a/chain/chain/src/test_utils.rs b/chain/chain/src/test_utils.rs index 0fe9ffc1387..617dc0dfd5d 100644 --- a/chain/chain/src/test_utils.rs +++ b/chain/chain/src/test_utils.rs @@ -23,7 +23,7 @@ use near_primitives::hash::CryptoHash; use near_primitives::test_utils::create_test_signer; use near_primitives::types::{AccountId, NumBlocks, NumShards}; use near_primitives::utils::MaybeValidated; -use near_primitives::validator_signer::InMemoryValidatorSigner; +use near_primitives::validator_signer::ValidatorSigner; use near_primitives::version::PROTOCOL_VERSION; use near_store::genesis::initialize_genesis_state; use near_store::test_utils::create_test_store; @@ -120,7 +120,7 @@ pub fn process_block_sync( // TODO(#8190) Improve this testing API. pub fn setup( clock: Clock, -) -> (Chain, Arc, Arc, Arc) { +) -> (Chain, Arc, Arc, Arc) { setup_with_tx_validity_period(clock, 100, 1000) } @@ -128,7 +128,7 @@ pub fn setup_with_tx_validity_period( clock: Clock, tx_validity_period: NumBlocks, epoch_length: u64, -) -> (Chain, Arc, Arc, Arc) { +) -> (Chain, Arc, Arc, Arc) { let store = create_test_store(); let mut genesis = Genesis::test_sharded( clock.clone(), diff --git a/chain/chain/src/tests/garbage_collection.rs b/chain/chain/src/tests/garbage_collection.rs index 956ace33a44..2bac715bce9 100644 --- a/chain/chain/src/tests/garbage_collection.rs +++ b/chain/chain/src/tests/garbage_collection.rs @@ -20,7 +20,7 @@ use near_primitives::merkle::PartialMerkleTree; use near_primitives::shard_layout::ShardUId; use near_primitives::test_utils::{create_test_signer, TestBlockBuilder}; use near_primitives::types::{BlockHeight, NumBlocks, StateRoot}; -use near_primitives::validator_signer::InMemoryValidatorSigner; +use near_primitives::validator_signer::ValidatorSigner; use near_store::test_utils::gen_changes; use near_store::{DBCol, ShardTries, Trie, WrappedTrieChanges}; @@ -730,7 +730,7 @@ fn add_block( epoch_manager: &dyn EpochManagerAdapter, prev_block: &mut Block, blocks: &mut Vec, - signer: Arc, + signer: Arc, height: u64, ) { let next_epoch_id = epoch_manager diff --git a/chain/chain/src/validate.rs b/chain/chain/src/validate.rs index 195aea3ae2b..0c0de032186 100644 --- a/chain/chain/src/validate.rs +++ b/chain/chain/src/validate.rs @@ -456,7 +456,7 @@ mod tests { nonce, account_id, "bob".parse().unwrap(), - &signer, + &signer.into(), 10, CryptoHash::default(), ) diff --git a/chain/chunks/src/chunk_cache.rs b/chain/chunks/src/chunk_cache.rs index d910cd62631..2ac1f0b0e70 100644 --- a/chain/chunks/src/chunk_cache.rs +++ b/chain/chunks/src/chunk_cache.rs @@ -296,7 +296,7 @@ mod tests { CryptoHash::default(), CryptoHash::default(), vec![], - &signer, + &signer.into(), )) } diff --git a/chain/chunks/src/client.rs b/chain/chunks/src/client.rs index 30fdecbfe0b..6e0e2052d2f 100644 --- a/chain/chunks/src/client.rs +++ b/chain/chunks/src/client.rs @@ -229,7 +229,7 @@ mod tests { nonce, signer_id.clone(), receiver_id.clone(), - &signer, + &signer.into(), deposit, CryptoHash::default(), ); diff --git a/chain/chunks/src/shards_manager_actor.rs b/chain/chunks/src/shards_manager_actor.rs index 955abdc1837..897a0d07446 100644 --- a/chain/chunks/src/shards_manager_actor.rs +++ b/chain/chunks/src/shards_manager_actor.rs @@ -1977,7 +1977,7 @@ impl ShardsManagerActor { prev_outgoing_receipts_root: CryptoHash, tx_root: CryptoHash, congestion_info: Option, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, rs: &ReedSolomon, protocol_version: ProtocolVersion, ) -> Result<(EncodedShardChunk, Vec), Error> { diff --git a/chain/client/src/chunk_distribution_network.rs b/chain/client/src/chunk_distribution_network.rs index 51b2e973752..baf1ac9e069 100644 --- a/chain/client/src/chunk_distribution_network.rs +++ b/chain/client/src/chunk_distribution_network.rs @@ -396,7 +396,7 @@ mod tests { hash(&[height.to_le_bytes().as_slice(), shard_id.to_le_bytes().as_slice()].concat()); let mut mock_hashes = MockHashes::new(prev_block_hash); - let signer = EmptyValidatorSigner::default(); + let signer = EmptyValidatorSigner::default().into(); let header_inner = ShardChunkHeaderInner::V3(ShardChunkHeaderInnerV3 { prev_block_hash, prev_state_root: mock_hashes.next().unwrap(), diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs index da7cdd15975..b847f06b25d 100644 --- a/chain/client/src/client.rs +++ b/chain/client/src/client.rs @@ -39,7 +39,9 @@ use near_chain::{ BlockProcessingArtifact, BlockStatus, Chain, ChainGenesis, ChainStoreAccess, Doomslug, DoomslugThresholdMode, Provenance, }; -use near_chain_configs::{ClientConfig, LogSummaryStyle, UpdateableClientConfig}; +use near_chain_configs::{ + ClientConfig, LogSummaryStyle, MutableConfigValue, UpdateableClientConfig, +}; use near_chunks::adapter::ShardsManagerRequestFromClient; use near_chunks::client::ShardedTransactionPool; use near_chunks::logic::{ @@ -146,7 +148,7 @@ pub struct Client { /// Network adapter. pub network_adapter: PeerManagerAdapter, /// Signer for block producer (if present). - pub validator_signer: Option>, + pub validator_signer: MutableConfigValue>>, /// Approvals for which we do not have the block yet pub pending_approvals: lru::LruCache>, @@ -249,7 +251,7 @@ impl Client { runtime_adapter: Arc, network_adapter: PeerManagerAdapter, shards_manager_adapter: Sender, - validator_signer: Option>, + validator_signer: Option>, enable_doomslug: bool, rng_seed: RngSeed, snapshot_callbacks: Option, @@ -397,7 +399,7 @@ impl Client { shards_manager_adapter, sharded_tx_pool, network_adapter, - validator_signer, + validator_signer: MutableConfigValue::new(validator_signer, "validator_signer"), pending_approvals: lru::LruCache::new(num_block_producer_seats), catchup_state_syncs: HashMap::new(), epoch_sync, @@ -596,11 +598,9 @@ impl Client { height: BlockHeight, prev_hash: CryptoHash, ) -> Result, Error> { - let validator_signer = self - .validator_signer - .as_ref() - .ok_or_else(|| Error::BlockProducer("Called without block producer info.".to_string()))? - .clone(); + let validator_signer = self.validator_signer.get().ok_or_else(|| { + Error::BlockProducer("Called without block producer info.".to_string()) + })?; // Check that we are were called at the block that we are producer for. let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(&prev_hash).unwrap(); @@ -834,11 +834,9 @@ impl Client { next_height: BlockHeight, shard_id: ShardId, ) -> Result, Error> { - let validator_signer = self - .validator_signer - .as_ref() - .ok_or_else(|| Error::ChunkProducer("Called without block producer info.".to_string()))? - .clone(); + let validator_signer = self.validator_signer.get().ok_or_else(|| { + Error::ChunkProducer("Called without block producer info.".to_string()) + })?; let chunk_proposer = self.epoch_manager.get_chunk_producer(epoch_id, next_height, shard_id).unwrap(); @@ -875,7 +873,7 @@ impl Client { last_header: ShardChunkHeader, next_height: BlockHeight, shard_id: ShardId, - validator_signer: Arc, + validator_signer: Arc, ) -> Result, Error> { let span = tracing::Span::current(); let timer = Instant::now(); @@ -1093,7 +1091,7 @@ impl Client { } pub fn send_challenges(&mut self, challenges: Vec) { - if let Some(validator_signer) = &self.validator_signer { + if let Some(validator_signer) = &self.validator_signer.get() { for body in challenges { let challenge = Challenge::produce(body, &**validator_signer); self.challenges.insert(challenge.hash, challenge.clone()); @@ -1118,7 +1116,7 @@ impl Client { let _span = tracing::debug_span!( target: "client", "receive_block", - me = ?self.validator_signer.as_ref().map(|vs| vs.validator_id()), + me = ?self.validator_signer.get().map(|vs| vs.validator_id().clone()), %prev_hash, %hash, height = block.header().height(), @@ -1306,7 +1304,7 @@ impl Client { let result = { let me = self .validator_signer - .as_ref() + .get() .map(|validator_signer| validator_signer.validator_id().clone()); self.chain.start_process_block_async( &me, @@ -1320,14 +1318,14 @@ impl Client { self.process_block_processing_artifact(block_processing_artifacts); // Send out challenge if the block was found to be invalid. - if let Some(validator_signer) = self.validator_signer.as_ref() { + if let Some(validator_signer) = self.validator_signer.get() { if let Err(e) = &result { match e { near_chain::Error::InvalidChunkProofs(chunk_proofs) => { self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests( NetworkRequests::Challenge(Challenge::produce( ChallengeBody::ChunkProofs(*chunk_proofs.clone()), - &**validator_signer, + &*validator_signer, )), )); } @@ -1335,7 +1333,7 @@ impl Client { self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests( NetworkRequests::Challenge(Challenge::produce( ChallengeBody::ChunkState(*chunk_state.clone()), - &**validator_signer, + &*validator_signer, )), )); } @@ -1358,7 +1356,7 @@ impl Client { .entered(); let me = self .validator_signer - .as_ref() + .get() .map(|validator_signer| validator_signer.validator_id().clone()); let mut block_processing_artifacts = BlockProcessingArtifact::default(); let (accepted_blocks, errors) = self.chain.postprocess_ready_blocks( @@ -1565,7 +1563,9 @@ impl Client { let next_epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(parent_hash)?; let next_block_producer = self.epoch_manager.get_block_producer(&next_epoch_id, approval.target_height)?; - if Some(&next_block_producer) == self.validator_signer.as_ref().map(|x| x.validator_id()) { + let validator_signer = self.validator_signer.get(); + let next_block_producer_id = validator_signer.as_ref().map(|x| x.validator_id()); + if Some(&next_block_producer) == next_block_producer_id { self.collect_block_approval(&approval, ApprovalType::SelfApproval); } else { debug!(target: "client", @@ -1669,7 +1669,7 @@ impl Client { } } - if let Some(validator_signer) = self.validator_signer.clone() { + if let Some(validator_signer) = self.validator_signer.get() { let validator_id = validator_signer.validator_id().clone(); if !self.reconcile_transaction_pool(validator_id.clone(), status, &block) { @@ -1968,8 +1968,8 @@ impl Client { apply_chunks_done_sender: Option>, ) { let _span = debug_span!(target: "client", "process_blocks_with_missing_chunks").entered(); - let me = - self.validator_signer.as_ref().map(|validator_signer| validator_signer.validator_id()); + let validator_signer = self.validator_signer.get(); + let me = validator_signer.as_ref().map(|validator_signer| validator_signer.validator_id()); let mut blocks_processing_artifacts = BlockProcessingArtifact::default(); self.chain.check_blocks_with_missing_chunks( &me.map(|x| x.clone()), @@ -1980,7 +1980,7 @@ impl Client { } pub fn is_validator(&self, epoch_id: &EpochId, block_hash: &CryptoHash) -> bool { - match self.validator_signer.as_ref() { + match self.validator_signer.get() { None => false, Some(signer) => { let account_id = signer.validator_id(); @@ -2130,8 +2130,9 @@ impl Client { match self.epoch_manager.get_block_producer(&next_block_epoch_id, *target_height) { Err(_) => false, Ok(target_block_producer) => { + let validator_signer = self.validator_signer.get(); Some(&target_block_producer) - == self.validator_signer.as_ref().map(|x| x.validator_id()) + == validator_signer.as_ref().map(|x| x.validator_id()) } }; @@ -2192,11 +2193,12 @@ impl Client { } } - if let Some(account_id) = self.validator_signer.as_ref().map(|bp| bp.validator_id()) { + let validator_signer = self.validator_signer.get(); + if let Some(account_id) = validator_signer.as_ref().map(|bp| bp.validator_id()) { validators.remove(account_id); } for validator in validators { - trace!(target: "client", me = ?self.validator_signer.as_ref().map(|bp| bp.validator_id()), ?tx, ?validator, shard_id, "Routing a transaction"); + trace!(target: "client", me = ?validator_signer.as_ref().map(|bp| bp.validator_id()), ?tx, ?validator, shard_id, "Routing a transaction"); // Send message to network to actually forward transaction. self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests( @@ -2219,7 +2221,8 @@ impl Client { check_only: bool, ) -> ProcessTxResponse { unwrap_or_return!(self.process_tx_internal(&tx, is_forwarded, check_only), { - let me = self.validator_signer.as_ref().map(|vs| vs.validator_id()); + let validator_signer = self.validator_signer.get(); + let me = validator_signer.as_ref().map(|vs| vs.validator_id()); warn!(target: "client", ?me, ?tx, "Dropping tx"); ProcessTxResponse::NoResponse }) @@ -2265,7 +2268,8 @@ impl Client { check_only: bool, ) -> Result { let head = self.chain.head()?; - let me = self.validator_signer.as_ref().map(|vs| vs.validator_id()); + let validator_signer = self.validator_signer.get(); + let me = validator_signer.as_ref().map(|vs| vs.validator_id()); let cur_block = self.chain.get_head_block()?; let cur_block_header = cur_block.header(); let transaction_validity_period = self.chain.transaction_validity_period; @@ -2407,8 +2411,9 @@ impl Client { fn active_validator(&self, shard_id: ShardId) -> Result { let head = self.chain.head()?; let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(&head.last_block_hash)?; + let validator_signer = self.validator_signer.get(); - let account_id = if let Some(vs) = self.validator_signer.as_ref() { + let account_id = if let Some(vs) = validator_signer.as_ref() { vs.validator_id() } else { return Ok(false); @@ -2437,7 +2442,7 @@ impl Client { ) -> Result<(), Error> { let _span = debug_span!(target: "sync", "run_catchup").entered(); let mut notify_state_sync = false; - let me = &self.validator_signer.as_ref().map(|x| x.validator_id().clone()); + let me = &self.validator_signer.get().map(|x| x.validator_id().clone()); for (sync_hash, state_sync_info) in self.chain.chain_store().iterate_state_sync_infos()? { assert_eq!(sync_hash, state_sync_info.epoch_tail_hash); diff --git a/chain/client/src/client_actor.rs b/chain/client/src/client_actor.rs index 8315d2e238e..27ec2654819 100644 --- a/chain/client/src/client_actor.rs +++ b/chain/client/src/client_actor.rs @@ -134,7 +134,7 @@ pub fn start_client( state_sync_adapter: Arc>, network_adapter: PeerManagerAdapter, shards_manager_adapter: Sender, - validator_signer: Option>, + validator_signer: Option>, telemetry_sender: Sender, snapshot_callbacks: Option, sender: Option>, @@ -313,7 +313,7 @@ impl ClientActorInner { config: ClientConfig, node_id: PeerId, network_adapter: PeerManagerAdapter, - validator_signer: Option>, + validator_signer: Option>, telemetry_sender: Sender, shutdown_signal: Option>, adv: crate::adversarial::Controls, @@ -325,7 +325,7 @@ impl ClientActorInner { info!(target: "client", "Starting validator node: {}", vs.validator_id()); } let info_helper = - InfoHelper::new(clock.clone(), telemetry_sender, &config, validator_signer.clone()); + InfoHelper::new(clock.clone(), telemetry_sender, &config, validator_signer); let now = clock.now_utc(); Ok(ClientActorInner { @@ -462,7 +462,7 @@ impl Handler for ClientActorInner { let mut genesis = near_chain_configs::GenesisConfig::default(); genesis.genesis_height = self.client.chain.chain_store().get_genesis_height(); let mut store_validator = near_chain::store_validator::StoreValidator::new( - self.client.validator_signer.as_ref().map(|x| x.validator_id().clone()), + self.client.validator_signer.get().map(|x| x.validator_id().clone()), genesis, self.client.epoch_manager.clone(), self.client.shard_tracker.clone(), @@ -708,7 +708,8 @@ impl Handler for ClientActorInner { .into_chain_error()?; let node_public_key = self.node_id.public_key().clone(); - let (validator_account_id, validator_public_key) = match &self.client.validator_signer { + let (validator_account_id, validator_public_key) = match &self.client.validator_signer.get() + { Some(vs) => (Some(vs.validator_id().clone()), Some(vs.public_key())), None => (None, None), }; @@ -890,7 +891,7 @@ impl ClientActorInner { self.start_sync(ctx); // Start block production tracking if have block producer info. - if self.client.validator_signer.is_some() { + if self.client.validator_signer.get().is_some() { self.block_production_started = true; } @@ -915,7 +916,7 @@ impl ClientActorInner { } // First check that we currently have an AccountId - let validator_signer = match self.client.validator_signer.as_ref() { + let validator_signer = match self.client.validator_signer.get() { None => return, Some(signer) => signer, }; @@ -1079,7 +1080,7 @@ impl ClientActorInner { debug!(target: "client", "Cannot produce any block: not enough approvals beyond {}", latest_known.height); } - let me = if let Some(me) = &self.client.validator_signer { + let me = if let Some(me) = &self.client.validator_signer.get() { me.validator_id().clone() } else { return Ok(()); @@ -1540,7 +1541,8 @@ impl ClientActorInner { Some(self.myself_sender.apply_chunks_done.clone()), self.state_parts_future_spawner.as_ref(), ) { - error!(target: "client", "{:?} Error occurred during catchup for the next epoch: {:?}", self.client.validator_signer.as_ref().map(|vs| vs.validator_id()), err); + let validator_signer = self.client.validator_signer.get(); + error!(target: "client", "{:?} Error occurred during catchup for the next epoch: {:?}", validator_signer.as_ref().map(|vs| vs.validator_id()), err); } } @@ -1657,7 +1659,7 @@ impl ClientActorInner { _ => unreachable!("Sync status should have been StateSync!"), }; - let me = self.client.validator_signer.as_ref().map(|x| x.validator_id().clone()); + let me = self.client.validator_signer.get().map(|x| x.validator_id().clone()); let block_header = self.client.chain.get_block_header(&sync_hash); let block_header = unwrap_and_report_state_sync_result!(block_header); let epoch_id = block_header.epoch_id().clone(); diff --git a/chain/client/src/debug.rs b/chain/client/src/debug.rs index 0781b8d1adb..b487f58218a 100644 --- a/chain/client/src/debug.rs +++ b/chain/client/src/debug.rs @@ -340,7 +340,7 @@ impl ClientActorInner { fn get_tracked_shards_view(&self) -> Result { let epoch_id = self.client.chain.header_head()?.epoch_id; let fetch_hash = self.client.chain.header_head()?.last_block_hash; - let me = self.client.validator_signer.as_ref().map(|x| x.validator_id().clone()); + let me = self.client.validator_signer.get().map(|x| x.validator_id().clone()); let shard_ids = self.client.epoch_manager.shard_ids(&epoch_id).unwrap(); let shards_tracked_this_epoch = shard_ids .iter() @@ -538,7 +538,7 @@ impl ClientActorInner { let head = self.client.chain.head()?; let mut productions = vec![]; - if let Some(signer) = &self.client.validator_signer { + if let Some(signer) = &self.client.validator_signer.get() { let validator_id = signer.validator_id().to_string(); // We want to show some older blocks (up to DEBUG_PRODUCTION_OLD_BLOCKS_TO_SHOW in the past) @@ -616,7 +616,7 @@ impl ClientActorInner { validator_name: self .client .validator_signer - .as_ref() + .get() .map(|signer| signer.validator_id().clone()), // TODO: this might not work correctly when we're at the epoch boundary (as it will // just return the validators for the current epoch). We can fix it in the future, if diff --git a/chain/client/src/info.rs b/chain/client/src/info.rs index da4b067b9b8..2682b6dc850 100644 --- a/chain/client/src/info.rs +++ b/chain/client/src/info.rs @@ -59,7 +59,7 @@ pub struct InfoHelper { /// Total gas used during period. gas_used: u64, /// Sign telemetry with block producer key if available. - validator_signer: Option>, + validator_signer: Option>, /// Telemetry event sender. telemetry_sender: Sender, /// Log coloring enabled. @@ -81,7 +81,7 @@ impl InfoHelper { clock: Clock, telemetry_sender: Sender, client_config: &ClientConfig, - validator_signer: Option>, + validator_signer: Option>, ) -> Self { set_open_files_limit(0); metrics::export_version(&client_config.version); @@ -147,7 +147,8 @@ impl InfoHelper { /// Count which shards are tracked by the node in the epoch indicated by head parameter. fn record_tracked_shards(head: &Tip, client: &crate::client::Client) { - let me = client.validator_signer.as_ref().map(|x| x.validator_id()); + let validator_signer = client.validator_signer.get(); + let me = validator_signer.as_ref().map(|x| x.validator_id()); if let Ok(shard_ids) = client.epoch_manager.shard_ids(&head.epoch_id) { for shard_id in shard_ids { let tracked = client.shard_tracker.care_about_shard( @@ -164,7 +165,7 @@ impl InfoHelper { } fn record_block_producers(head: &Tip, client: &crate::client::Client) { - let me = client.validator_signer.as_ref().map(|x| x.validator_id().clone()); + let me = client.validator_signer.get().map(|x| x.validator_id().clone()); if let Some(is_bp) = me.map_or(Some(false), |account_id| { // In rare cases block producer information isn't available. // Don't set the metric in this case. @@ -179,7 +180,7 @@ impl InfoHelper { fn record_chunk_producers(head: &Tip, client: &crate::client::Client) { if let (Some(account_id), Ok(epoch_info)) = ( - client.validator_signer.as_ref().map(|x| x.validator_id().clone()), + client.validator_signer.get().map(|x| x.validator_id().clone()), client.epoch_manager.get_epoch_info(&head.epoch_id), ) { for (shard_id, validators) in epoch_info.chunk_producers_settlement().iter().enumerate() @@ -328,7 +329,8 @@ impl InfoHelper { &head.epoch_id, &head.last_block_hash, ); - let account_id = client.validator_signer.as_ref().map(|x| x.validator_id()); + let validator_signer = client.validator_signer.get(); + let account_id = validator_signer.as_ref().map(|x| x.validator_id()); let is_validator = if let Some(account_id) = account_id { match client.epoch_manager.get_validator_by_account_id( &head.epoch_id, diff --git a/chain/client/src/stateless_validation/chunk_validator/mod.rs b/chain/client/src/stateless_validation/chunk_validator/mod.rs index e6146b40f43..9f3e41713f7 100644 --- a/chain/client/src/stateless_validation/chunk_validator/mod.rs +++ b/chain/client/src/stateless_validation/chunk_validator/mod.rs @@ -37,7 +37,7 @@ const NUM_NEXT_BLOCK_PRODUCERS_TO_SEND_CHUNK_ENDORSEMENT: u64 = 5; /// so that the chunk can be included in the block. pub struct ChunkValidator { /// The signer for our own node, if we are a validator. If not, this is None. - my_signer: Option>, + my_signer: Option>, epoch_manager: Arc, network_sender: Sender, runtime_adapter: Arc, @@ -54,7 +54,7 @@ pub struct ChunkValidator { impl ChunkValidator { pub fn new( - my_signer: Option>, + my_signer: Option>, epoch_manager: Arc, network_sender: Sender, runtime_adapter: Arc, @@ -202,7 +202,7 @@ impl ChunkValidator { pub(crate) fn send_chunk_endorsement_to_block_producers( chunk_header: &ShardChunkHeader, epoch_manager: &dyn EpochManagerAdapter, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, network_sender: &Sender, chunk_endorsement_tracker: &ChunkEndorsementTracker, ) { @@ -285,7 +285,7 @@ impl Client { fn send_state_witness_ack(&self, witness: &ChunkStateWitness) { // Chunk producers should not receive state witness from themselves. log_assert!( - self.validator_signer.is_some(), + self.validator_signer.get().is_some(), "Received a chunk state witness but this is not a validator node. Witness={:?}", witness ); @@ -293,10 +293,10 @@ impl Client { // produced the witness. However some tests bypass PartialWitnessActor, thus when a chunk producer // receives its own state witness, we log a warning instead of panicking. // TODO: Make sure all tests run with "test_features" and panic for non-test builds. - if self.validator_signer.as_ref().unwrap().validator_id() == &witness.chunk_producer { + if self.validator_signer.get().unwrap().validator_id() == &witness.chunk_producer { tracing::warn!( "Validator {:?} received state witness from itself. Witness={:?}", - self.validator_signer.as_ref().unwrap().validator_id(), + self.validator_signer.get().unwrap().validator_id(), witness ); return; diff --git a/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs b/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs index 752571c159d..24f83193534 100644 --- a/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs +++ b/chain/client/src/stateless_validation/partial_witness/partial_witness_actor.rs @@ -33,7 +33,7 @@ pub struct PartialWitnessActor { /// Adapter to send messages to the network. network_adapter: PeerManagerAdapter, /// Validator signer to sign the state witness. - my_signer: Arc, + my_signer: Arc, /// Epoch manager to get the set of chunk validators epoch_manager: Arc, /// Tracks the parts of the state witness sent from chunk producers to chunk validators. @@ -104,7 +104,7 @@ impl PartialWitnessActor { clock: Clock, network_adapter: PeerManagerAdapter, client_sender: ClientSenderForPartialWitness, - my_signer: Arc, + my_signer: Arc, epoch_manager: Arc, store: Store, ) -> Self { diff --git a/chain/client/src/stateless_validation/state_witness_producer.rs b/chain/client/src/stateless_validation/state_witness_producer.rs index 6876472123a..f4b4000b9a4 100644 --- a/chain/client/src/stateless_validation/state_witness_producer.rs +++ b/chain/client/src/stateless_validation/state_witness_producer.rs @@ -38,7 +38,7 @@ impl Client { let shard_id = chunk_header.shard_id(); let _span = tracing::debug_span!(target: "client", "send_chunk_state_witness", chunk_hash=?chunk_header.chunk_hash(), ?shard_id).entered(); - let my_signer = self.validator_signer.as_ref().ok_or(Error::NotAValidator)?.clone(); + let my_signer = self.validator_signer.get().ok_or(Error::NotAValidator)?; let state_witness = self.create_state_witness( my_signer.validator_id().clone(), prev_block_header, diff --git a/chain/client/src/test_utils/client.rs b/chain/client/src/test_utils/client.rs index c31a6cb17eb..588fa80aa74 100644 --- a/chain/client/src/test_utils/client.rs +++ b/chain/client/src/test_utils/client.rs @@ -109,7 +109,7 @@ impl Client { encoded_chunk, merkle_paths, receipts, - self.validator_signer.as_ref().unwrap().validator_id().clone(), + self.validator_signer.get().unwrap().validator_id().clone(), ) .unwrap(); let prev_block = self.chain.get_block(shard_chunk.prev_block()).unwrap(); @@ -201,7 +201,7 @@ pub fn create_chunk( let parity_parts = total_parts - data_parts; let rs = ReedSolomon::new(data_parts, parity_parts).unwrap(); - let signer = client.validator_signer.as_ref().unwrap().clone(); + let signer = client.validator_signer.get().unwrap(); let header = chunk.cloned_header(); let (mut encoded_chunk, mut new_merkle_paths) = EncodedShardChunk::new( *header.prev_block_hash(), @@ -238,7 +238,7 @@ pub fn create_chunk( client.chain.chain_store().get_block_merkle_tree(last_block.hash()).unwrap(); let mut block_merkle_tree = PartialMerkleTree::clone(&block_merkle_tree); - let signer = client.validator_signer.as_ref().unwrap().clone(); + let signer = client.validator_signer.get().unwrap(); let endorsement = ChunkEndorsement::new(chunk.cloned_header().chunk_hash(), signer.as_ref()); block_merkle_tree.insert(*last_block.hash()); let block = Block::produce( @@ -259,7 +259,7 @@ pub fn create_chunk( None, vec![], vec![], - &*client.validator_signer.as_ref().unwrap().clone(), + &*client.validator_signer.get().unwrap(), *last_block.header().next_bp_hash(), block_merkle_tree.root(), client.clock.now_utc(), diff --git a/chain/client/src/test_utils/setup.rs b/chain/client/src/test_utils/setup.rs index 05b933177cb..916929ab724 100644 --- a/chain/client/src/test_utils/setup.rs +++ b/chain/client/src/test_utils/setup.rs @@ -985,7 +985,7 @@ pub fn setup_client_with_runtime( save_trie_changes: bool, snapshot_callbacks: Option, partial_witness_adapter: PartialWitnessSenderForClient, - validator_signer: Arc, + validator_signer: Arc, ) -> Client { let mut config = ClientConfig::test( true, diff --git a/chain/client/src/test_utils/test_env.rs b/chain/client/src/test_utils/test_env.rs index 77df0186680..f2196bf7097 100644 --- a/chain/client/src/test_utils/test_env.rs +++ b/chain/client/src/test_utils/test_env.rs @@ -12,7 +12,7 @@ use near_chain_configs::GenesisConfig; use near_chain_primitives::error::QueryError; use near_chunks::client::ShardsManagerResponse; use near_chunks::test_utils::{MockClientAdapterForShardsManager, SynchronousShardsManagerAdapter}; -use near_crypto::{InMemorySigner, KeyType, Signer}; +use near_crypto::{InMemorySigner, KeyType}; use near_network::client::ProcessTxResponse; use near_network::shards_manager::ShardsManagerRequestFromNetwork; use near_network::test_utils::MockPeerManagerAdapter; @@ -469,8 +469,8 @@ impl TestEnv { let tx = SignedTransaction::send_money( 1, account_id.clone(), - account_id.clone(), - &signer, + account_id, + &signer.into(), 100, self.clients[id].chain.head().unwrap().last_block_hash, ); @@ -608,7 +608,7 @@ impl TestEnv { /// memory caches. /// Though, it seems that it is not necessary for current use cases. pub fn restart(&mut self, idx: usize) { - let account_id = self.get_client_id(idx).clone(); + let account_id = self.get_client_id(idx); let rng_seed = match self.seeds.get(&account_id) { Some(seed) => *seed, None => TEST_SEED, @@ -630,14 +630,15 @@ impl TestEnv { self.save_trie_changes, None, self.clients[idx].partial_witness_adapter.clone(), - self.clients[idx].validator_signer.clone().unwrap(), + self.clients[idx].validator_signer.get().unwrap(), ) } /// Returns an [`AccountId`] used by a client at given index. More /// specifically, returns validator id of the client’s validator signer. - pub fn get_client_id(&self, idx: usize) -> &AccountId { - self.clients[idx].validator_signer.as_ref().unwrap().validator_id() + pub fn get_client_id(&self, idx: usize) -> AccountId { + let validator_signer = self.clients[idx].validator_signer.get(); + validator_signer.unwrap().validator_id().clone() } /// Returns the index of client with the given [`AccoountId`]. @@ -692,7 +693,7 @@ impl TestEnv { tip.height + 1, signer.account_id.clone(), receiver, - signer, + &signer.clone().into(), actions, tip.last_block_hash, 0, @@ -731,7 +732,7 @@ impl TestEnv { relayer_nonce, relayer, sender, - &relayer_signer, + &relayer_signer.into(), vec![Action::Delegate(Box::new(signed_delegate_action))], tip.last_block_hash, 0, diff --git a/chain/client/src/test_utils/test_loop.rs b/chain/client/src/test_utils/test_loop.rs index 354a594c9b1..85afbf68f97 100644 --- a/chain/client/src/test_utils/test_loop.rs +++ b/chain/client/src/test_utils/test_loop.rs @@ -43,7 +43,7 @@ where let head = client.chain.head().unwrap(); tracing::info!("{}Chain HEAD: {:?}", idx_prefix, head); - if let Some(signer) = client.validator_signer.as_ref() { + if let Some(signer) = client.validator_signer.get() { let account_id = signer.validator_id(); let mut tracked_shards = Vec::new(); diff --git a/chain/client/src/tests/bug_repros.rs b/chain/client/src/tests/bug_repros.rs index caac7a6c876..c9a59f87a2d 100644 --- a/chain/client/src/tests/bug_repros.rs +++ b/chain/client/src/tests/bug_repros.rs @@ -122,7 +122,8 @@ fn repro_1183() { from.clone(), KeyType::ED25519, from.as_ref(), - ), + ) + .into(), 1, *block.header().prev_hash(), ), diff --git a/chain/client/src/tests/catching_up.rs b/chain/client/src/tests/catching_up.rs index 3befb5c0118..ff727cc523f 100644 --- a/chain/client/src/tests/catching_up.rs +++ b/chain/client/src/tests/catching_up.rs @@ -75,7 +75,12 @@ fn send_tx( connector.do_send( ProcessTxRequest { transaction: SignedTransaction::send_money( - nonce, from, to, &signer, amount, block_hash, + nonce, + from, + to, + &signer.into(), + amount, + block_hash, ), is_forwarded: false, check_only: false, diff --git a/chain/client/src/tests/cross_shard_tx.rs b/chain/client/src/tests/cross_shard_tx.rs index 423b66c2096..809be505b1c 100644 --- a/chain/client/src/tests/cross_shard_tx.rs +++ b/chain/client/src/tests/cross_shard_tx.rs @@ -115,7 +115,7 @@ fn send_tx( nonce, from.clone(), to.clone(), - &signer, + &signer.into(), amount, block_hash, ), diff --git a/chain/client/src/tests/doomslug.rs b/chain/client/src/tests/doomslug.rs index f49b155c9c3..9bae9a719c1 100644 --- a/chain/client/src/tests/doomslug.rs +++ b/chain/client/src/tests/doomslug.rs @@ -31,7 +31,7 @@ fn test_processing_skips_on_forks() { env.process_block(1, b2, Provenance::NONE); let validator_signer = InMemoryValidatorSigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); - let approval = Approval::new(CryptoHash::default(), 1, 3, &validator_signer); + let approval = Approval::new(CryptoHash::default(), 1, 3, &validator_signer.into()); env.clients[1].collect_block_approval(&approval, ApprovalType::SelfApproval); assert!(!env.clients[1].doomslug.approval_status_at_height(&3).approvals.is_empty()); } diff --git a/chain/client/src/tests/query_client.rs b/chain/client/src/tests/query_client.rs index ed4cdae3bf2..9a5e153a750 100644 --- a/chain/client/src/tests/query_client.rs +++ b/chain/client/src/tests/query_client.rs @@ -167,7 +167,7 @@ fn test_execution_outcome_for_chunk() { 1, "test".parse().unwrap(), "near".parse().unwrap(), - &signer, + &signer.into(), 10, block_hash, ); diff --git a/chain/epoch-manager/src/tests/mod.rs b/chain/epoch-manager/src/tests/mod.rs index 904a608e9b3..f0d0663fcbd 100644 --- a/chain/epoch-manager/src/tests/mod.rs +++ b/chain/epoch-manager/src/tests/mod.rs @@ -2760,7 +2760,7 @@ fn test_max_kickout_stake_ratio() { assert_eq!(validator_stats, wanted_validator_stats,); } -fn test_chunk_header(h: &[CryptoHash], signer: &dyn ValidatorSigner) -> ShardChunkHeader { +fn test_chunk_header(h: &[CryptoHash], signer: &ValidatorSigner) -> ShardChunkHeader { let congestion_info = ProtocolFeature::CongestionControl .enabled(PROTOCOL_VERSION) .then_some(CongestionInfo::default()); diff --git a/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs b/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs index 855d2f359fb..6cb02647bb0 100644 --- a/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs +++ b/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs @@ -42,7 +42,7 @@ fn test_send_tx_async() { 1, signer_account_id.parse().unwrap(), "test2".parse().unwrap(), - &signer, + &signer.into(), 100, block_hash, ); @@ -97,7 +97,7 @@ fn test_send_tx_commit() { 1, "test1".parse().unwrap(), "test2".parse().unwrap(), - &signer, + &signer.into(), 100, block_hash, ); @@ -146,7 +146,8 @@ fn test_expired_tx() { "test1".parse().unwrap(), KeyType::ED25519, "test1", - ); + ) + .into(); let tx = SignedTransaction::send_money( 1, "test1".parse().unwrap(), @@ -190,7 +191,8 @@ fn test_expired_tx() { #[test] fn test_replay_protection() { test_with_client!(test_utils::NodeType::Validator, client, async move { - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::send_money( 1, "test1".parse().unwrap(), @@ -236,7 +238,7 @@ fn test_check_invalid_tx() { 1, "test1".parse().unwrap(), "test2".parse().unwrap(), - &signer, + &signer.into(), 100, hash(&[1]), )), diff --git a/chain/network/src/accounts_data/mod.rs b/chain/network/src/accounts_data/mod.rs index 9d962dc1532..923cfb7ae99 100644 --- a/chain/network/src/accounts_data/mod.rs +++ b/chain/network/src/accounts_data/mod.rs @@ -55,7 +55,7 @@ pub(crate) enum AccountDataError { /// for more details. #[derive(Clone)] pub struct LocalAccountData { - pub signer: Arc, + pub signer: Arc, pub data: Arc, } diff --git a/chain/network/src/accounts_data/tests.rs b/chain/network/src/accounts_data/tests.rs index 9c5d57a4337..7f43c38cbdd 100644 --- a/chain/network/src/accounts_data/tests.rs +++ b/chain/network/src/accounts_data/tests.rs @@ -17,7 +17,7 @@ fn make_account_data( ) -> SignedAccountData { let peer_id = data::make_peer_id(rng); data::make_account_data(rng, version, clock.now_utc(), signer.public_key(), peer_id) - .sign(signer) + .sign(&signer.clone().into()) .unwrap() } @@ -225,7 +225,7 @@ async fn set_local() { // Set local while local.signer is in cache.keys. // A new AccountData should be signed. let local = LocalAccountData { - signer: Arc::new(signers[0].clone()), + signer: Arc::new(signers[0].clone().into()), data: Arc::new(make_account_data(rng, &clock.clock(), 1, &signers[0]).data.clone()), }; let got = cache.set_local(&clock.clock(), local.clone()).unwrap(); @@ -266,7 +266,7 @@ async fn set_local() { // Update local data to a signer in cache.keys. let local = LocalAccountData { - signer: Arc::new(signers[2].clone()), + signer: Arc::new(signers[2].clone().into()), data: Arc::new(make_account_data(rng, &clock.clock(), 1, &signers[2]).data.clone()), }; let got = cache.set_local(&clock.clock(), local.clone()).unwrap(); @@ -276,7 +276,7 @@ async fn set_local() { // Update local data to a signer outside of cache.keys. let local = LocalAccountData { - signer: Arc::new(signers[0].clone()), + signer: Arc::new(signers[0].clone().into()), data: Arc::new(make_account_data(rng, &clock.clock(), 1, &signers[0]).data.clone()), }; assert_eq!(None, cache.set_local(&clock.clock(), local)); diff --git a/chain/network/src/config.rs b/chain/network/src/config.rs index c64ec4524bc..d7a8b5fc5a5 100644 --- a/chain/network/src/config.rs +++ b/chain/network/src/config.rs @@ -56,7 +56,7 @@ pub enum ValidatorProxies { #[derive(Clone)] pub struct ValidatorConfig { - pub signer: Arc, + pub signer: Arc, pub proxies: ValidatorProxies, } @@ -213,7 +213,7 @@ impl NetworkConfig { pub fn new( cfg: crate::config_json::Config, node_key: SecretKey, - validator_signer: Option>, + validator_signer: Option>, archive: bool, ) -> anyhow::Result { if cfg.public_addrs.len() > MAX_PEER_ADDRS { @@ -636,7 +636,7 @@ mod test { version: 0, timestamp: clock.now_utc(), }; - let sad = ad.sign(&signer).unwrap(); + let sad = ad.sign(&signer.into()).unwrap(); assert!(sad.payload().len() <= network_protocol::MAX_ACCOUNT_DATA_SIZE_BYTES); } } diff --git a/chain/network/src/network_protocol/mod.rs b/chain/network/src/network_protocol/mod.rs index 80acf1c767d..e8ed2fc9cef 100644 --- a/chain/network/src/network_protocol/mod.rs +++ b/chain/network/src/network_protocol/mod.rs @@ -170,7 +170,7 @@ impl VersionedAccountData { /// due to account_id mismatch. Then instead of panicking we could return an error /// and the caller (who constructs the arguments) would do an unwrap(). This would /// consistute a cleaner never-panicking interface. - pub fn sign(self, signer: &dyn ValidatorSigner) -> anyhow::Result { + pub fn sign(self, signer: &ValidatorSigner) -> anyhow::Result { assert_eq!( self.account_key, signer.public_key(), @@ -256,7 +256,7 @@ impl OwnedAccount { /// Serializes OwnedAccount to proto and signs it using `signer`. /// Panics if OwnedAccount.account_key doesn't match signer.public_key(), /// as this would likely be a bug. - pub fn sign(self, signer: &dyn ValidatorSigner) -> SignedOwnedAccount { + pub fn sign(self, signer: &ValidatorSigner) -> SignedOwnedAccount { assert_eq!( self.account_key, signer.public_key(), diff --git a/chain/network/src/network_protocol/testonly.rs b/chain/network/src/network_protocol/testonly.rs index 44b9435005a..23983de6cd4 100644 --- a/chain/network/src/network_protocol/testonly.rs +++ b/chain/network/src/network_protocol/testonly.rs @@ -42,7 +42,7 @@ pub fn make_genesis_block(clock: &time::Clock, chunks: Vec) -> Block pub fn make_block( clock: &time::Clock, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, prev: &Block, chunks: Vec, ) -> Block { @@ -160,7 +160,7 @@ pub fn make_signed_transaction(rng: &mut R) -> SignedTransaction { rng.gen(), sender.account_id.clone(), receiver, - &sender, + &sender.into(), 15, CryptoHash::default(), ) @@ -172,7 +172,7 @@ pub fn make_challenge(rng: &mut R) -> Challenge { left_block_header: rng.sample_iter(&Standard).take(65).collect(), right_block_header: rng.sample_iter(&Standard).take(34).collect(), }), - &make_validator_signer(rng), + &make_validator_signer(rng).into(), ) } @@ -247,7 +247,12 @@ impl Chain { let signer = make_validator_signer(rng); for _ in 1..block_count { clock.advance(time::Duration::seconds(15)); - blocks.push(make_block(&clock.clock(), &signer, blocks.last().unwrap(), chunks.make())); + blocks.push(make_block( + &clock.clock(), + &signer.clone().into(), + blocks.last().unwrap(), + chunks.make(), + )); } Chain { genesis_id: GenesisId { @@ -314,7 +319,7 @@ impl Chain { let peer_id = make_peer_id(rng); Arc::new( make_account_data(rng, 1, clock.now_utc(), v.public_key(), peer_id) - .sign(v) + .sign(&v.clone().into()) .unwrap(), ) }) @@ -400,7 +405,9 @@ pub fn make_account_data( pub fn make_signed_account_data(rng: &mut impl Rng, clock: &time::Clock) -> SignedAccountData { let signer = make_validator_signer(rng); let peer_id = make_peer_id(rng); - make_account_data(rng, 1, clock.now_utc(), signer.public_key(), peer_id).sign(&signer).unwrap() + make_account_data(rng, 1, clock.now_utc(), signer.public_key(), peer_id) + .sign(&signer.into()) + .unwrap() } // Accessors for creating malformed SignedAccountData diff --git a/chain/network/src/network_protocol/tests.rs b/chain/network/src/network_protocol/tests.rs index 2d339b1b2cc..7a27e49fea7 100644 --- a/chain/network/src/network_protocol/tests.rs +++ b/chain/network/src/network_protocol/tests.rs @@ -53,7 +53,7 @@ fn bad_account_data_size() { version: rng.gen(), timestamp: clock.now_utc(), }; - assert!(ad.sign(&signer).is_err()); + assert!(ad.sign(&signer.into()).is_err()); } #[test] diff --git a/chain/network/src/peer_manager/tests/tier1.rs b/chain/network/src/peer_manager/tests/tier1.rs index 24c2ca6f859..7cb1b03bb6d 100644 --- a/chain/network/src/peer_manager/tests/tier1.rs +++ b/chain/network/src/peer_manager/tests/tier1.rs @@ -18,7 +18,7 @@ use std::collections::HashSet; use std::sync::Arc; /// Constructs a random TIER1 message. -fn make_block_approval(rng: &mut Rng, signer: &dyn ValidatorSigner) -> Approval { +fn make_block_approval(rng: &mut Rng, signer: &ValidatorSigner) -> Approval { let inner = ApprovalInner::Endorsement(data::make_hash(rng)); let target_height = rng.gen_range(0..100000); Approval { diff --git a/chain/pool/src/lib.rs b/chain/pool/src/lib.rs index 9a28a374502..968be3dd90f 100644 --- a/chain/pool/src/lib.rs +++ b/chain/pool/src/lib.rs @@ -351,8 +351,9 @@ mod tests { end_nonce: u64, ) -> Vec { let signer_id: AccountId = signer_id.parse().unwrap(); - let signer = - Arc::new(InMemorySigner::from_seed(signer_id.clone(), KeyType::ED25519, signer_seed)); + let signer = Arc::new( + InMemorySigner::from_seed(signer_id.clone(), KeyType::ED25519, signer_seed).into(), + ); (starting_nonce..=end_nonce) .map(|i| { SignedTransaction::send_money( @@ -466,11 +467,10 @@ mod tests { .map(|i| { let signer_id = AccountId::try_from(format!("user_{}", i % 5)).unwrap(); let signer_seed = format!("user_{}", i % 3); - let signer = Arc::new(InMemorySigner::from_seed( - signer_id.clone(), - KeyType::ED25519, - &signer_seed, - )); + let signer = Arc::new( + InMemorySigner::from_seed(signer_id.clone(), KeyType::ED25519, &signer_seed) + .into(), + ); SignedTransaction::send_money( i, signer_id, @@ -561,11 +561,10 @@ mod tests { .map(|i| { let signer_id = AccountId::try_from(format!("user_{}", i)).unwrap(); let signer_seed = signer_id.as_ref(); - let signer = Arc::new(InMemorySigner::from_seed( - signer_id.clone(), - KeyType::ED25519, - signer_seed, - )); + let signer = Arc::new( + InMemorySigner::from_seed(signer_id.clone(), KeyType::ED25519, signer_seed) + .into(), + ); SignedTransaction::send_money( i, signer_id, diff --git a/core/chain-configs/src/test_genesis.rs b/core/chain-configs/src/test_genesis.rs index 16db80c2965..8174c2b8f59 100644 --- a/core/chain-configs/src/test_genesis.rs +++ b/core/chain-configs/src/test_genesis.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use near_async::time::Clock; -use near_crypto::{PublicKey, Signer}; +use near_crypto::PublicKey; use near_primitives::account::{AccessKey, Account}; use near_primitives::hash::CryptoHash; use near_primitives::shard_layout::ShardLayout; diff --git a/core/chain-configs/src/updateable_config.rs b/core/chain-configs/src/updateable_config.rs index 9178b8552aa..2b6b64cb9f6 100644 --- a/core/chain-configs/src/updateable_config.rs +++ b/core/chain-configs/src/updateable_config.rs @@ -40,12 +40,12 @@ impl Serialize for MutableConfigValue { } } -impl MutableConfigValue { +impl MutableConfigValue { /// Initializes a value. /// `field_name` is needed to export the config value as a prometheus metric. pub fn new(val: T, field_name: &str) -> Self { let res = Self { - value: Arc::new(Mutex::new(val)), + value: Arc::new(Mutex::new(val.clone())), field_name: field_name.to_string(), #[cfg(feature = "metrics")] last_update: Clock::real().now_utc(), @@ -55,15 +55,15 @@ impl MutableConfigValue { } pub fn get(&self) -> T { - *self.value.lock().unwrap() + self.value.lock().unwrap().clone() } pub fn update(&self, val: T) { let mut lock = self.value.lock().unwrap(); if *lock != val { tracing::info!(target: "config", "Updated config field '{}' from {:?} to {:?}", self.field_name, *lock, val); - self.set_metric_value(*lock, 0); - *lock = val; + self.set_metric_value(lock.clone(), 0); + *lock = val.clone(); self.set_metric_value(val, 1); } else { tracing::info!(target: "config", "Mutable config field '{}' remains the same: {:?}", self.field_name, val); diff --git a/core/crypto/src/signer.rs b/core/crypto/src/signer.rs index 25175594aa3..f3f46ca24d1 100644 --- a/core/crypto/src/signer.rs +++ b/core/crypto/src/signer.rs @@ -2,41 +2,83 @@ use crate::key_conversion::convert_secret_key; use crate::key_file::KeyFile; use crate::{KeyType, PublicKey, SecretKey, Signature}; use near_account_id::AccountId; +use std::fmt::{self, Debug}; use std::io; use std::path::Path; use std::sync::Arc; -/// Generic signer trait, that can sign with some subset of supported curves. -pub trait Signer: Sync + Send { - fn public_key(&self) -> PublicKey; - fn sign(&self, data: &[u8]) -> Signature; +/// Enum for Signer, that can sign with some subset of supported curves. +#[derive(Debug, PartialEq)] +pub enum Signer { + /// Dummy signer, does not hold a key. Use for tests only! + Empty(EmptySigner), + /// Default signer that holds data in memory. + InMemory(InMemorySigner), +} + +/// Enum for Signer, that can sign with some subset of supported curves. +impl Signer { + pub fn public_key(&self) -> PublicKey { + match self { + Signer::Empty(signer) => signer.public_key(), + Signer::InMemory(signer) => signer.public_key(), + } + } + + pub fn sign(&self, data: &[u8]) -> Signature { + match self { + Signer::Empty(signer) => signer.sign(data), + Signer::InMemory(signer) => signer.sign(data), + } + } - fn verify(&self, data: &[u8], signature: &Signature) -> bool { + pub fn verify(&self, data: &[u8], signature: &Signature) -> bool { signature.verify(data, &self.public_key()) } - fn compute_vrf_with_proof(&self, _data: &[u8]) -> (crate::vrf::Value, crate::vrf::Proof); + pub fn compute_vrf_with_proof(&self, data: &[u8]) -> (crate::vrf::Value, crate::vrf::Proof) { + match self { + Signer::Empty(_) => unimplemented!(), + Signer::InMemory(signer) => signer.compute_vrf_with_proof(data), + } + } /// Used by test infrastructure, only implement if make sense for testing otherwise raise `unimplemented`. - fn write_to_file(&self, _path: &Path) -> io::Result<()> { - unimplemented!(); + pub fn write_to_file(&self, path: &Path) -> io::Result<()> { + match self { + Signer::Empty(_) => unimplemented!(), + Signer::InMemory(signer) => signer.write_to_file(path), + } + } +} + +impl From for Signer { + fn from(signer: EmptySigner) -> Self { + Signer::Empty(signer) + } +} + +impl From for Signer { + fn from(signer: InMemorySigner) -> Self { + Signer::InMemory(signer) } } // Signer that returns empty signature. Used for transaction testing. +#[derive(Debug, PartialEq)] pub struct EmptySigner {} -impl Signer for EmptySigner { - fn public_key(&self) -> PublicKey { - PublicKey::empty(KeyType::ED25519) +impl EmptySigner { + pub fn new() -> Self { + Self {} } - fn sign(&self, _data: &[u8]) -> Signature { - Signature::empty(KeyType::ED25519) + pub fn public_key(&self) -> PublicKey { + PublicKey::empty(KeyType::ED25519) } - fn compute_vrf_with_proof(&self, _data: &[u8]) -> (crate::vrf::Value, crate::vrf::Proof) { - unimplemented!() + pub fn sign(&self, _data: &[u8]) -> Signature { + Signature::empty(KeyType::ED25519) } } @@ -61,27 +103,35 @@ impl InMemorySigner { pub fn from_file(path: &Path) -> io::Result { KeyFile::from_file(path).map(Self::from) } -} -impl Signer for InMemorySigner { - fn public_key(&self) -> PublicKey { + pub fn public_key(&self) -> PublicKey { self.public_key.clone() } - fn sign(&self, data: &[u8]) -> Signature { + pub fn sign(&self, data: &[u8]) -> Signature { self.secret_key.sign(data) } - fn compute_vrf_with_proof(&self, data: &[u8]) -> (crate::vrf::Value, crate::vrf::Proof) { + pub fn compute_vrf_with_proof(&self, data: &[u8]) -> (crate::vrf::Value, crate::vrf::Proof) { let secret_key = convert_secret_key(self.secret_key.unwrap_as_ed25519()); secret_key.compute_vrf_with_proof(&data) } - fn write_to_file(&self, path: &Path) -> io::Result<()> { + pub fn write_to_file(&self, path: &Path) -> io::Result<()> { KeyFile::from(self).write_to_file(path) } } +impl fmt::Debug for InMemorySigner { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "InMemorySigner(account_id: {}, public_key: {})", + self.account_id, self.public_key + ) + } +} + impl From for InMemorySigner { fn from(key_file: KeyFile) -> Self { Self { diff --git a/core/dyn-configs/Cargo.toml b/core/dyn-configs/Cargo.toml index c2b311b0964..36ca12db087 100644 --- a/core/dyn-configs/Cargo.toml +++ b/core/dyn-configs/Cargo.toml @@ -23,6 +23,7 @@ tracing.workspace = true near-async.workspace = true near-chain-configs.workspace = true +near-crypto.workspace = true near-o11y.workspace = true near-primitives.workspace = true diff --git a/core/primitives/benches/serialization.rs b/core/primitives/benches/serialization.rs index af23e2592da..8d3103b9399 100644 --- a/core/primitives/benches/serialization.rs +++ b/core/primitives/benches/serialization.rs @@ -68,7 +68,7 @@ fn create_block() -> Block { Some(0), vec![], vec![], - &signer, + &signer.into(), CryptoHash::default(), CryptoHash::default(), Clock::real().now_utc(), diff --git a/core/primitives/src/block.rs b/core/primitives/src/block.rs index 728267d1707..a8cda59f18e 100644 --- a/core/primitives/src/block.rs +++ b/core/primitives/src/block.rs @@ -130,7 +130,7 @@ pub fn genesis_chunks( &[], CryptoHash::default(), congestion_info, - &EmptyValidatorSigner::default(), + &EmptyValidatorSigner::default().into(), genesis_protocol_version, ) .expect("Failed to decode genesis chunk"); @@ -267,7 +267,7 @@ impl Block { minted_amount: Option, challenges_result: ChallengesResult, challenges: Challenges, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, next_bp_hash: CryptoHash, block_merkle_root: CryptoHash, timestamp: Utc, diff --git a/core/primitives/src/block_header.rs b/core/primitives/src/block_header.rs index b9df32a3657..cc5f793b9b9 100644 --- a/core/primitives/src/block_header.rs +++ b/core/primitives/src/block_header.rs @@ -248,7 +248,7 @@ impl Approval { parent_hash: CryptoHash, parent_height: BlockHeight, target_height: BlockHeight, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, ) -> Self { let inner = ApprovalInner::new(&parent_hash, parent_height, target_height); let signature = signer.sign_approval(&inner, target_height); @@ -429,7 +429,7 @@ impl BlockHeader { next_gas_price: Balance, total_supply: Balance, challenges_result: ChallengesResult, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, last_final_block: CryptoHash, last_ds_final_block: CryptoHash, epoch_sync_data_hash: Option, diff --git a/core/primitives/src/challenge.rs b/core/primitives/src/challenge.rs index 571fcd15571..dcd296dfea7 100644 --- a/core/primitives/src/challenge.rs +++ b/core/primitives/src/challenge.rs @@ -122,7 +122,7 @@ impl Challenge { self.hash = CryptoHash::hash_borsh(&self.body); } - pub fn produce(body: ChallengeBody, signer: &dyn ValidatorSigner) -> Self { + pub fn produce(body: ChallengeBody, signer: &ValidatorSigner) -> Self { let (hash, signature) = signer.sign_challenge(&body); Self { body, account_id: signer.validator_id().clone(), signature, hash } } diff --git a/core/primitives/src/sharding.rs b/core/primitives/src/sharding.rs index b41e4bf0c0a..b162d960855 100644 --- a/core/primitives/src/sharding.rs +++ b/core/primitives/src/sharding.rs @@ -128,7 +128,7 @@ impl ShardChunkHeaderV2 { prev_outgoing_receipts_root: CryptoHash, tx_root: CryptoHash, prev_validator_proposals: Vec, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, ) -> Self { let inner = ShardChunkHeaderInnerV1 { prev_block_hash, @@ -194,7 +194,7 @@ impl ShardChunkHeaderV3 { tx_root: CryptoHash, prev_validator_proposals: Vec, congestion_info: Option, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, ) -> Self { let inner = if let Some(congestion_info) = congestion_info { assert!(ProtocolFeature::CongestionControl.enabled(protocol_version)); @@ -234,7 +234,7 @@ impl ShardChunkHeaderV3 { Self::from_inner(inner, signer) } - pub fn from_inner(inner: ShardChunkHeaderInner, signer: &dyn ValidatorSigner) -> Self { + pub fn from_inner(inner: ShardChunkHeaderInner, signer: &ValidatorSigner) -> Self { let hash = Self::compute_hash(&inner); let signature = signer.sign_chunk_hash(&hash); Self { inner, height_included: 0, signature, hash } @@ -506,7 +506,7 @@ impl ShardChunkHeaderV1 { prev_outgoing_receipts_root: CryptoHash, tx_root: CryptoHash, prev_validator_proposals: Vec, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, ) -> Self { let inner = ShardChunkHeaderInnerV1 { prev_block_hash, @@ -1037,7 +1037,7 @@ impl EncodedShardChunk { prev_outgoing_receipts: &[Receipt], prev_outgoing_receipts_root: CryptoHash, congestion_info: Option, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, protocol_version: ProtocolVersion, ) -> Result<(Self, Vec), std::io::Error> { let (transaction_receipts_parts, encoded_length) = reed_solomon_encode( diff --git a/core/primitives/src/signable_message.rs b/core/primitives/src/signable_message.rs index f7f1f6b7965..59ee8415f02 100644 --- a/core/primitives/src/signable_message.rs +++ b/core/primitives/src/signable_message.rs @@ -94,7 +94,7 @@ impl<'a, T: BorshSerialize> SignableMessage<'a, T> { Self { discriminant, msg } } - pub fn sign(&self, signer: &dyn Signer) -> Signature { + pub fn sign(&self, signer: &Signer) -> Signature { let bytes = borsh::to_vec(&self).expect("Failed to deserialize"); let hash = hash(&bytes); signer.sign(hash.as_bytes()) @@ -241,7 +241,8 @@ mod tests { let delegate_action = delegate_action(sender_id, receiver_id, signer.public_key()); let signable = SignableMessage::new(&delegate_action, SignableMessageType::DelegateAction); - let signed = SignedDelegateAction { signature: signable.sign(&signer), delegate_action }; + let signed = + SignedDelegateAction { signature: signable.sign(&signer.into()), delegate_action }; assert!(signed.verify()); } @@ -259,7 +260,8 @@ mod tests { discriminant: MessageDiscriminant::new_on_chain(wrong_nep).unwrap(), msg: &delegate_action, }; - let signed = SignedDelegateAction { signature: signable.sign(&signer), delegate_action }; + let signed = + SignedDelegateAction { signature: signable.sign(&signer.into()), delegate_action }; assert!(!signed.verify()); } @@ -276,7 +278,8 @@ mod tests { // here we use it as an off-chain only signature let wrong_discriminant = MessageDiscriminant::new_off_chain(correct_nep).unwrap(); let signable = SignableMessage { discriminant: wrong_discriminant, msg: &delegate_action }; - let signed = SignedDelegateAction { signature: signable.sign(&signer), delegate_action }; + let signed = + SignedDelegateAction { signature: signable.sign(&signer.into()), delegate_action }; assert!(!signed.verify()); } diff --git a/core/primitives/src/stateless_validation.rs b/core/primitives/src/stateless_validation.rs index bd867df1aeb..fa57200773e 100644 --- a/core/primitives/src/stateless_validation.rs +++ b/core/primitives/src/stateless_validation.rs @@ -60,7 +60,7 @@ impl PartialEncodedStateWitness { part_ord: usize, part: Vec, encoded_length: usize, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, ) -> Self { let inner = PartialEncodedStateWitnessInner::new( epoch_id, @@ -378,7 +378,7 @@ impl ChunkStateWitness { Default::default(), Default::default(), congestion_info, - &EmptyValidatorSigner::default(), + &EmptyValidatorSigner::default().into(), )); Self::new( "alice.near".parse().unwrap(), @@ -423,7 +423,7 @@ pub struct ChunkEndorsement { } impl ChunkEndorsement { - pub fn new(chunk_hash: ChunkHash, signer: &dyn ValidatorSigner) -> ChunkEndorsement { + pub fn new(chunk_hash: ChunkHash, signer: &ValidatorSigner) -> ChunkEndorsement { let inner = ChunkEndorsementInner::new(chunk_hash); let account_id = signer.validator_id().clone(); let signature = signer.sign_chunk_endorsement(&inner); diff --git a/core/primitives/src/test_utils.rs b/core/primitives/src/test_utils.rs index 2252608ad7d..4956937d85b 100644 --- a/core/primitives/src/test_utils.rs +++ b/core/primitives/src/test_utils.rs @@ -80,7 +80,7 @@ impl Transaction { } } - pub fn sign(self, signer: &dyn Signer) -> SignedTransaction { + pub fn sign(self, signer: &Signer) -> SignedTransaction { let signature = signer.sign(self.get_hash_and_size().0.as_ref()); SignedTransaction::new(signature, self) } @@ -144,7 +144,7 @@ impl SignedTransaction { nonce: Nonce, signer_id: AccountId, receiver_id: AccountId, - signer: &dyn Signer, + signer: &Signer, actions: Vec, block_hash: CryptoHash, _priority_fee: u64, @@ -165,7 +165,7 @@ impl SignedTransaction { nonce: Nonce, signer_id: AccountId, receiver_id: AccountId, - signer: &dyn Signer, + signer: &Signer, actions: Vec, block_hash: CryptoHash, priority_fee: u64, @@ -186,7 +186,7 @@ impl SignedTransaction { nonce: Nonce, signer_id: AccountId, receiver_id: AccountId, - signer: &dyn Signer, + signer: &Signer, deposit: Balance, block_hash: CryptoHash, ) -> Self { @@ -204,7 +204,7 @@ impl SignedTransaction { pub fn stake( nonce: Nonce, signer_id: AccountId, - signer: &dyn Signer, + signer: &Signer, stake: Balance, public_key: PublicKey, block_hash: CryptoHash, @@ -226,7 +226,7 @@ impl SignedTransaction { new_account_id: AccountId, amount: Balance, public_key: PublicKey, - signer: &dyn Signer, + signer: &Signer, block_hash: CryptoHash, ) -> Self { Self::from_actions( @@ -254,7 +254,7 @@ impl SignedTransaction { code: Vec, amount: Balance, public_key: PublicKey, - signer: &dyn Signer, + signer: &Signer, block_hash: CryptoHash, ) -> Self { Self::from_actions( @@ -280,7 +280,7 @@ impl SignedTransaction { nonce: Nonce, signer_id: AccountId, receiver_id: AccountId, - signer: &dyn Signer, + signer: &Signer, deposit: Balance, method_name: String, args: Vec, @@ -308,7 +308,7 @@ impl SignedTransaction { signer_id: AccountId, receiver_id: AccountId, beneficiary_id: AccountId, - signer: &dyn Signer, + signer: &Signer, block_hash: CryptoHash, ) -> Self { Self::from_actions( @@ -327,7 +327,7 @@ impl SignedTransaction { 0, "test".parse().unwrap(), "test".parse().unwrap(), - &EmptySigner {}, + &EmptySigner::new().into(), vec![], block_hash, 0, @@ -368,7 +368,7 @@ impl BlockHeader { } } - pub fn resign(&mut self, signer: &dyn ValidatorSigner) { + pub fn resign(&mut self, signer: &ValidatorSigner) { let (hash, signature) = signer.sign_block_header_parts( *self.prev_hash(), &self.inner_lite_bytes(), @@ -451,12 +451,12 @@ impl BlockBody { /// # Examples /// /// // TODO(mm-near): change it to doc-tested code once we have easy way to create a genesis block. -/// let signer = EmptyValidatorSigner::default(); +/// let signer = EmptyValidatorSigner::default().into(); /// let test_block = test_utils::TestBlockBuilder::new(prev, signer).height(33).build(); pub struct TestBlockBuilder { clock: Clock, prev: Block, - signer: Arc, + signer: Arc, height: u64, epoch_id: EpochId, next_epoch_id: EpochId, @@ -466,14 +466,14 @@ pub struct TestBlockBuilder { } impl TestBlockBuilder { - pub fn new(clock: Clock, prev: &Block, signer: Arc) -> Self { + pub fn new(clock: Clock, prev: &Block, signer: Arc) -> Self { let mut tree = PartialMerkleTree::default(); tree.insert(*prev.hash()); Self { clock, prev: prev.clone(), - signer: signer.clone(), + signer, height: prev.header().height() + 1, epoch_id: prev.header().epoch_id().clone(), next_epoch_id: if prev.header().is_genesis() { @@ -715,12 +715,13 @@ pub fn encode(xs: &[u64]) -> Vec { // Helper function that creates a new signer for a given account, that uses the account name as seed. // Should be used only in tests. -pub fn create_test_signer(account_name: &str) -> InMemoryValidatorSigner { +pub fn create_test_signer(account_name: &str) -> ValidatorSigner { InMemoryValidatorSigner::from_seed( account_name.parse().unwrap(), KeyType::ED25519, account_name, ) + .into() } /// Helper function that creates a new signer for a given account, that uses the account name as seed. diff --git a/core/primitives/src/transaction.rs b/core/primitives/src/transaction.rs index c0a1b15c13f..6ea92703b99 100644 --- a/core/primitives/src/transaction.rs +++ b/core/primitives/src/transaction.rs @@ -480,7 +480,8 @@ mod tests { #[test] fn test_verify_transaction() { - let signer = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer: Signer = + InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); let transaction = Transaction::V0(TransactionV0 { signer_id: "test".parse().unwrap(), public_key: signer.public_key(), diff --git a/core/primitives/src/validator_signer.rs b/core/primitives/src/validator_signer.rs index 69fd3e41b43..1f1f269e303 100644 --- a/core/primitives/src/validator_signer.rs +++ b/core/primitives/src/validator_signer.rs @@ -1,3 +1,4 @@ +use std::fmt::Debug; use std::path::Path; use std::sync::Arc; @@ -14,53 +15,125 @@ use crate::stateless_validation::{ use crate::telemetry::TelemetryInfo; use crate::types::{AccountId, BlockHeight, EpochId}; +/// Enum for validator signer, that holds validator id and key used for signing data. +#[derive(Clone, Debug, PartialEq)] +pub enum ValidatorSigner { + /// Dummy validator signer, does not hold a key. Use for tests only! + Empty(EmptyValidatorSigner), + /// Default validator signer that holds data in memory. + InMemory(InMemoryValidatorSigner), +} + /// Validator signer that is used to sign blocks and approvals. -pub trait ValidatorSigner: Sync + Send { +impl ValidatorSigner { /// Account id of the given validator. - fn validator_id(&self) -> &AccountId; + pub fn validator_id(&self) -> &AccountId { + match self { + ValidatorSigner::Empty(signer) => signer.validator_id(), + ValidatorSigner::InMemory(signer) => signer.validator_id(), + } + } /// Public key that identifies this validator. - fn public_key(&self) -> PublicKey; + pub fn public_key(&self) -> PublicKey { + match self { + ValidatorSigner::Empty(signer) => signer.public_key(), + ValidatorSigner::InMemory(signer) => signer.public_key(), + } + } /// Serializes telemetry info to JSON and signs it, returning JSON with "signature" field. - fn sign_telemetry(&self, info: &TelemetryInfo) -> serde_json::Value; + pub fn sign_telemetry(&self, info: &TelemetryInfo) -> serde_json::Value { + match self { + ValidatorSigner::Empty(signer) => signer.sign_telemetry(info), + ValidatorSigner::InMemory(signer) => signer.sign_telemetry(info), + } + } /// Signs given parts of the header. - fn sign_block_header_parts( + pub fn sign_block_header_parts( &self, prev_hash: CryptoHash, inner_lite: &[u8], inner_rest: &[u8], - ) -> (CryptoHash, Signature); + ) -> (CryptoHash, Signature) { + match self { + ValidatorSigner::Empty(signer) => { + signer.sign_block_header_parts(prev_hash, inner_lite, inner_rest) + } + ValidatorSigner::InMemory(signer) => { + signer.sign_block_header_parts(prev_hash, inner_lite, inner_rest) + } + } + } /// Signs given inner of the chunk header. - fn sign_chunk_hash(&self, chunk_hash: &ChunkHash) -> Signature; + pub fn sign_chunk_hash(&self, chunk_hash: &ChunkHash) -> Signature { + match self { + ValidatorSigner::Empty(signer) => signer.sign_chunk_hash(chunk_hash), + ValidatorSigner::InMemory(signer) => signer.sign_chunk_hash(chunk_hash), + } + } /// Signs approval of given parent hash and reference hash. - fn sign_approval(&self, inner: &ApprovalInner, target_height: BlockHeight) -> Signature; + pub fn sign_approval(&self, inner: &ApprovalInner, target_height: BlockHeight) -> Signature { + match self { + ValidatorSigner::Empty(signer) => signer.sign_approval(inner, target_height), + ValidatorSigner::InMemory(signer) => signer.sign_approval(inner, target_height), + } + } /// Signs chunk endorsement to be sent to block producer. - fn sign_chunk_endorsement(&self, inner: &ChunkEndorsementInner) -> Signature; + pub fn sign_chunk_endorsement(&self, inner: &ChunkEndorsementInner) -> Signature { + match self { + ValidatorSigner::Empty(signer) => signer.sign_chunk_endorsement(inner), + ValidatorSigner::InMemory(signer) => signer.sign_chunk_endorsement(inner), + } + } /// Signs chunk state witness to be sent to all validators. - fn sign_chunk_state_witness(&self, witness_bytes: &EncodedChunkStateWitness) -> Signature; + pub fn sign_chunk_state_witness(&self, witness_bytes: &EncodedChunkStateWitness) -> Signature { + match self { + ValidatorSigner::Empty(signer) => signer.sign_chunk_state_witness(witness_bytes), + ValidatorSigner::InMemory(signer) => signer.sign_chunk_state_witness(witness_bytes), + } + } /// Signs partial encoded state witness to be sent and forwarded to all validators. - fn sign_partial_encoded_state_witness( + pub fn sign_partial_encoded_state_witness( &self, part: &PartialEncodedStateWitnessInner, - ) -> Signature; + ) -> Signature { + match self { + ValidatorSigner::Empty(signer) => signer.sign_partial_encoded_state_witness(part), + ValidatorSigner::InMemory(signer) => signer.sign_partial_encoded_state_witness(part), + } + } /// Signs challenge body. - fn sign_challenge(&self, challenge_body: &ChallengeBody) -> (CryptoHash, Signature); + pub fn sign_challenge(&self, challenge_body: &ChallengeBody) -> (CryptoHash, Signature) { + match self { + ValidatorSigner::Empty(signer) => signer.sign_challenge(challenge_body), + ValidatorSigner::InMemory(signer) => signer.sign_challenge(challenge_body), + } + } /// Signs account announce. - fn sign_account_announce( + pub fn sign_account_announce( &self, account_id: &AccountId, peer_id: &PeerId, epoch_id: &EpochId, - ) -> Signature; + ) -> Signature { + match self { + ValidatorSigner::Empty(signer) => { + signer.sign_account_announce(account_id, peer_id, epoch_id) + } + ValidatorSigner::InMemory(signer) => { + signer.sign_account_announce(account_id, peer_id, epoch_id) + } + } + } /// Signs a proto-serialized AccountKeyPayload (see /// chain/network/src/network_protocol/network.proto). @@ -73,26 +146,53 @@ pub trait ValidatorSigner: Sync + Send { /// used only for networking purposes and are not persisted on chain. /// Moving to proto serialization for stuff stored on chain would be way /// harder. - fn sign_account_key_payload(&self, proto_bytes: &[u8]) -> Signature; + pub fn sign_account_key_payload(&self, proto_bytes: &[u8]) -> Signature { + match self { + ValidatorSigner::Empty(signer) => signer.sign_account_key_payload(proto_bytes), + ValidatorSigner::InMemory(signer) => signer.sign_account_key_payload(proto_bytes), + } + } - fn compute_vrf_with_proof( + pub fn compute_vrf_with_proof( &self, data: &[u8], - ) -> (near_crypto::vrf::Value, near_crypto::vrf::Proof); + ) -> (near_crypto::vrf::Value, near_crypto::vrf::Proof) { + match self { + ValidatorSigner::Empty(_) => unimplemented!(), + ValidatorSigner::InMemory(signer) => signer.compute_vrf_with_proof(data), + } + } /// Used by test infrastructure, only implement if make sense for testing otherwise raise `unimplemented`. - fn write_to_file(&self, path: &Path) -> std::io::Result<()>; + pub fn write_to_file(&self, path: &Path) -> std::io::Result<()> { + match self { + ValidatorSigner::Empty(_) => unimplemented!(), + ValidatorSigner::InMemory(signer) => signer.write_to_file(path), + } + } +} + +impl From for ValidatorSigner { + fn from(signer: EmptyValidatorSigner) -> Self { + ValidatorSigner::Empty(signer) + } +} + +impl From for ValidatorSigner { + fn from(signer: InMemoryValidatorSigner) -> Self { + ValidatorSigner::InMemory(signer) + } } /// Test-only signer that "signs" everything with 0s. /// Don't use in any production or code that requires signature verification. -#[derive(smart_default::SmartDefault)] +#[derive(smart_default::SmartDefault, Clone, Debug, PartialEq)] pub struct EmptyValidatorSigner { #[default("test".parse().unwrap())] account_id: AccountId, } -impl ValidatorSigner for EmptyValidatorSigner { +impl EmptyValidatorSigner { fn validator_id(&self) -> &AccountId { &self.account_id } @@ -154,34 +254,23 @@ impl ValidatorSigner for EmptyValidatorSigner { fn sign_account_key_payload(&self, _proto_bytes: &[u8]) -> Signature { Signature::default() } - - fn compute_vrf_with_proof( - &self, - _data: &[u8], - ) -> (near_crypto::vrf::Value, near_crypto::vrf::Proof) { - unimplemented!() - } - - fn write_to_file(&self, _path: &Path) -> std::io::Result<()> { - unimplemented!() - } } /// Signer that keeps secret key in memory and signs locally. -#[derive(Clone)] +#[derive(Clone, Debug, PartialEq)] pub struct InMemoryValidatorSigner { account_id: AccountId, - signer: Arc, + signer: Arc, } impl InMemoryValidatorSigner { pub fn from_random(account_id: AccountId, key_type: KeyType) -> Self { - let signer = Arc::new(InMemorySigner::from_random(account_id.clone(), key_type)); + let signer = Arc::new(InMemorySigner::from_random(account_id.clone(), key_type).into()); Self { account_id, signer } } pub fn from_seed(account_id: AccountId, key_type: KeyType, seed: &str) -> Self { - let signer = Arc::new(InMemorySigner::from_seed(account_id.clone(), key_type, seed)); + let signer = Arc::new(InMemorySigner::from_seed(account_id.clone(), key_type, seed).into()); Self { account_id, signer } } @@ -189,21 +278,19 @@ impl InMemoryValidatorSigner { self.signer.public_key() } + pub fn from_signer(signer: InMemorySigner) -> Self { + Self { account_id: signer.account_id.clone(), signer: Arc::new(signer.into()) } + } + pub fn from_file(path: &Path) -> std::io::Result { let signer = InMemorySigner::from_file(path)?; - Ok(Self { account_id: signer.account_id.clone(), signer: Arc::new(signer) }) + Ok(Self::from_signer(signer)) } -} -impl ValidatorSigner for InMemoryValidatorSigner { - fn validator_id(&self) -> &AccountId { + pub fn validator_id(&self) -> &AccountId { &self.account_id } - fn public_key(&self) -> PublicKey { - self.signer.public_key() - } - fn sign_telemetry(&self, info: &TelemetryInfo) -> serde_json::Value { let mut value = serde_json::to_value(info).expect("Telemetry must serialize to JSON"); let content = serde_json::to_string(&value).expect("Telemetry must serialize to JSON"); @@ -250,7 +337,7 @@ impl ValidatorSigner for InMemoryValidatorSigner { (hash, signature) } - fn sign_account_announce( + pub fn sign_account_announce( &self, account_id: &AccountId, peer_id: &PeerId, diff --git a/core/store/benches/finalize_bench.rs b/core/store/benches/finalize_bench.rs index 2f2c5cc6ffa..aedce9232ec 100644 --- a/core/store/benches/finalize_bench.rs +++ b/core/store/benches/finalize_bench.rs @@ -18,7 +18,7 @@ use bencher::{black_box, Bencher}; use borsh::BorshSerialize; use near_chain::Chain; use near_chunks::shards_manager_actor::ShardsManagerActor; -use near_crypto::{InMemorySigner, KeyType, Signer}; +use near_crypto::{InMemorySigner, KeyType}; use near_primitives::congestion_info::CongestionInfo; use near_primitives::hash::CryptoHash; use near_primitives::merkle::{merklize, MerklePathItem}; @@ -136,7 +136,7 @@ fn create_chunk_header(height: u64, shard_id: u64) -> ShardChunkHeader { CryptoHash::default(), vec![], congestion_info, - &validator_signer(), + &validator_signer().into(), )) } @@ -208,7 +208,7 @@ fn create_encoded_shard_chunk( Default::default(), Default::default(), congestion_info, - &validator_signer(), + &validator_signer().into(), &rs, 100, ) diff --git a/docs/practices/style.md b/docs/practices/style.md index 6d55daaa9f8..a584a0a1542 100644 --- a/docs/practices/style.md +++ b/docs/practices/style.md @@ -352,7 +352,7 @@ When emitting events and spans with `tracing` prefer adding variable data via // GOOD debug!( target: "client", - validator_id = self.client.validator_signer.as_ref().map(|vs| { + validator_id = self.client.validator_signer.get().map(|vs| { tracing::field::display(vs.validator_id()) }), %hash, @@ -372,7 +372,7 @@ form of formatting, as seen in the following example: debug!( target: "client", "{:?} Received block {} <- {} at {} from {}, requested: {}", - self.client.validator_signer.as_ref().map(|vs| vs.validator_id()), + self.client.validator_signer.get().map(|vs| vs.validator_id()), hash, block.header().prev_hash(), block.header().height(), diff --git a/genesis-tools/keypair-generator/src/main.rs b/genesis-tools/keypair-generator/src/main.rs index ea281201833..96ebd234087 100644 --- a/genesis-tools/keypair-generator/src/main.rs +++ b/genesis-tools/keypair-generator/src/main.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use clap::{Arg, Command}; -use near_crypto::{InMemorySigner, KeyType, SecretKey, Signer}; +use near_crypto::{InMemorySigner, KeyType, SecretKey}; use nearcore::get_default_home; fn generate_key_to_file(account_id: &str, key: SecretKey, path: &PathBuf) -> std::io::Result<()> { diff --git a/integration-tests/src/nearcore_utils.rs b/integration-tests/src/nearcore_utils.rs index 05b094489b4..dee4fb01459 100644 --- a/integration-tests/src/nearcore_utils.rs +++ b/integration-tests/src/nearcore_utils.rs @@ -26,7 +26,7 @@ pub fn add_blocks( client: Addr, num: usize, epoch_length: BlockHeightDelta, - signer: &dyn ValidatorSigner, + signer: &ValidatorSigner, ) -> Vec { let mut prev = &blocks[blocks.len() - 1]; let mut block_merkle_tree = PartialMerkleTree::default(); diff --git a/integration-tests/src/node/mod.rs b/integration-tests/src/node/mod.rs index 3b7439323da..65d53f7660e 100644 --- a/integration-tests/src/node/mod.rs +++ b/integration-tests/src/node/mod.rs @@ -12,7 +12,7 @@ use near_primitives::num_rational::Ratio; use near_primitives::state_record::StateRecord; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{AccountId, Balance, NumSeats}; -use near_primitives::validator_signer::InMemoryValidatorSigner; +use near_primitives::validator_signer::ValidatorSigner; use near_primitives::views::AccountView; use near_vm_runner::ContractCode; use nearcore::config::{create_testnet_configs, create_testnet_configs_from_seeds, Config}; @@ -39,7 +39,7 @@ pub enum NodeConfig { /// Should be the default choice for the tests, since it provides the most control through the /// internal access. Thread(NearConfig), - /// A complete noe running in a subprocess. Can be started and stopped, but besides that all + /// A complete node running in a subprocess. Can be started and stopped, but besides that all /// interactions are limited to what is exposed through RPC. Process(NearConfig), } @@ -69,9 +69,9 @@ pub trait Node: Send + Sync { self.user().add_transaction(transaction) } - fn signer(&self) -> Arc; + fn signer(&self) -> Arc; - fn block_signer(&self) -> Arc { + fn block_signer(&self) -> Arc { unimplemented!() } @@ -122,7 +122,7 @@ impl dyn Node { fn near_configs_to_node_configs( configs: Vec, - validator_signers: Vec, + validator_signers: Vec, network_signers: Vec, genesis: Genesis, ) -> Vec { diff --git a/integration-tests/src/node/process_node.rs b/integration-tests/src/node/process_node.rs index 85d21d12d9b..b5fd308d111 100644 --- a/integration-tests/src/node/process_node.rs +++ b/integration-tests/src/node/process_node.rs @@ -29,7 +29,8 @@ pub struct ProcessNode { pub work_dir: PathBuf, pub config: NearConfig, pub state: ProcessNodeState, - pub signer: Arc, + pub signer: Arc, + account_id: AccountId, } impl Node for ProcessNode { @@ -78,7 +79,7 @@ impl Node for ProcessNode { } } - fn signer(&self) -> Arc { + fn signer(&self) -> Arc { self.signer.clone() } @@ -90,8 +91,11 @@ impl Node for ProcessNode { } fn user(&self) -> Box { - let account_id = self.signer.account_id.clone(); - Box::new(RpcUser::new(&self.config.rpc_addr().unwrap(), account_id, self.signer.clone())) + Box::new(RpcUser::new( + &self.config.rpc_addr().unwrap(), + self.account_id.clone(), + self.signer.clone(), + )) } fn as_process_ref(&self) -> &ProcessNode { @@ -108,12 +112,13 @@ impl ProcessNode { pub fn new(config: NearConfig) -> ProcessNode { let mut rng = rand::thread_rng(); let work_dir = env::temp_dir().join(format!("process_node_{}", rng.gen::())); - let signer = Arc::new(InMemorySigner::from_seed( - config.validator_signer.as_ref().unwrap().validator_id().clone(), - KeyType::ED25519, - config.validator_signer.as_ref().unwrap().validator_id().as_ref(), - )); - let result = ProcessNode { config, work_dir, state: ProcessNodeState::Stopped, signer }; + let account_id = config.validator_signer.as_ref().unwrap().validator_id().clone(); + let signer = Arc::new( + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()) + .into(), + ); + let result = + ProcessNode { config, work_dir, state: ProcessNodeState::Stopped, signer, account_id }; result.reset_storage(); result } diff --git a/integration-tests/src/node/runtime_node.rs b/integration-tests/src/node/runtime_node.rs index 41d50c68224..d024cef7890 100644 --- a/integration-tests/src/node/runtime_node.rs +++ b/integration-tests/src/node/runtime_node.rs @@ -13,8 +13,9 @@ use crate::user::{RuntimeUser, User}; pub struct RuntimeNode { pub client: Arc>, - pub signer: Arc, + pub signer: Arc, pub genesis: Genesis, + account_id: AccountId, } impl RuntimeNode { @@ -31,11 +32,10 @@ impl RuntimeNode { genesis: Genesis, runtime_config: RuntimeConfig, ) -> Self { - let signer = Arc::new(InMemorySigner::from_seed( - account_id.clone(), - KeyType::ED25519, - account_id.as_ref(), - )); + let signer = Arc::new( + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()) + .into(), + ); let (runtime, tries, root) = get_runtime_and_trie_from_genesis(&genesis); let client = Arc::new(RwLock::new(MockClient { runtime, @@ -44,7 +44,7 @@ impl RuntimeNode { epoch_length: genesis.config.epoch_length, runtime_config, })); - RuntimeNode { signer, client, genesis } + RuntimeNode { signer, client, genesis, account_id: account_id.clone() } } pub fn new_from_genesis(account_id: &AccountId, genesis: Genesis) -> Self { @@ -80,18 +80,18 @@ impl Node for RuntimeNode { } fn account_id(&self) -> Option { - Some(self.signer.account_id.clone()) + Some(self.account_id.clone()) } fn start(&mut self) {} fn kill(&mut self) {} - fn signer(&self) -> Arc { + fn signer(&self) -> Arc { self.signer.clone() } - fn block_signer(&self) -> Arc { + fn block_signer(&self) -> Arc { self.signer.clone() } @@ -101,7 +101,7 @@ impl Node for RuntimeNode { fn user(&self) -> Box { Box::new(RuntimeUser::new( - self.signer.account_id.clone(), + self.account_id.clone(), self.signer.clone(), self.client.clone(), )) diff --git a/integration-tests/src/node/thread_node.rs b/integration-tests/src/node/thread_node.rs index 1435aa1ca0b..60329c0a941 100644 --- a/integration-tests/src/node/thread_node.rs +++ b/integration-tests/src/node/thread_node.rs @@ -19,8 +19,9 @@ pub enum ThreadNodeState { pub struct ThreadNode { pub config: NearConfig, pub state: ThreadNodeState, - pub signer: Arc, + pub signer: Arc, pub dir: tempfile::TempDir, + account_id: AccountId, } fn start_thread(config: NearConfig, path: PathBuf) -> ShutdownableThread { @@ -54,7 +55,7 @@ impl Node for ThreadNode { } } - fn signer(&self) -> Arc { + fn signer(&self) -> Arc { self.signer.clone() } @@ -66,8 +67,11 @@ impl Node for ThreadNode { } fn user(&self) -> Box { - let account_id = self.signer.account_id.clone(); - Box::new(RpcUser::new(&self.config.rpc_addr().unwrap(), account_id, self.signer.clone())) + Box::new(RpcUser::new( + &self.config.rpc_addr().unwrap(), + self.account_id.clone(), + self.signer.clone(), + )) } fn as_thread_ref(&self) -> &ThreadNode { @@ -82,16 +86,15 @@ impl Node for ThreadNode { impl ThreadNode { /// Side effects: create storage, open database, lock database pub fn new(config: NearConfig) -> ThreadNode { - let signer = Arc::new(InMemorySigner::from_seed( - config.validator_signer.as_ref().unwrap().validator_id().clone(), - KeyType::ED25519, - config.validator_signer.as_ref().unwrap().validator_id().as_ref(), - )); + let account_id = config.validator_signer.as_ref().unwrap().validator_id().clone(); + let signer = + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()); ThreadNode { config, state: ThreadNodeState::Stopped, - signer, + signer: Arc::new(signer.into()), dir: tempfile::Builder::new().prefix("thread_node").tempdir().unwrap(), + account_id, } } } diff --git a/integration-tests/src/tests/client/benchmarks.rs b/integration-tests/src/tests/client/benchmarks.rs index 0f9cde0c7ec..79185b1b25e 100644 --- a/integration-tests/src/tests/client/benchmarks.rs +++ b/integration-tests/src/tests/client/benchmarks.rs @@ -35,9 +35,9 @@ fn benchmark_large_chunk_production_time() { let genesis = Genesis::test(vec!["test0".parse().unwrap(), "test1".parse().unwrap()], 1); let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); - let account_id = env.get_client_id(0).clone(); + let account_id = env.get_client_id(0); let signer = - InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()); + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()).into(); let last_block_hash = env.clients[0].chain.head().unwrap().last_block_hash; for i in 0..n_txes { let tx = SignedTransaction::from_actions( diff --git a/integration-tests/src/tests/client/block_corruption.rs b/integration-tests/src/tests/client/block_corruption.rs index 6ab17c3c33d..b0ab6e9b546 100644 --- a/integration-tests/src/tests/client/block_corruption.rs +++ b/integration-tests/src/tests/client/block_corruption.rs @@ -21,7 +21,7 @@ fn create_tx_load(height: BlockHeight, last_block: &Block) -> Vec AccountId { "test1".parse().unwrap() } -fn create_tx_send_money( - nonce: u64, - signer: &InMemorySigner, - block_hash: CryptoHash, -) -> SignedTransaction { +fn create_tx_send_money(nonce: u64, signer: &Signer, block_hash: CryptoHash) -> SignedTransaction { SignedTransaction::send_money(nonce, test0(), test1(), signer, 1, block_hash) } fn create_tx_deploy_contract( height: u64, - signer: &InMemorySigner, + signer: &Signer, block_hash: CryptoHash, ) -> SignedTransaction { let code = near_test_contracts::rs_contract().to_vec(); @@ -92,7 +88,7 @@ fn create_tx_deploy_contract( fn create_tx_function_call( nonce: u64, - signer: &InMemorySigner, + signer: &Signer, block_hash: CryptoHash, ) -> SignedTransaction { let action = Action::FunctionCall(Box::new(FunctionCallAction { @@ -131,7 +127,7 @@ fn test_storage_after_commit_of_cold_update() { let mut last_hash = *env.clients[0].chain.genesis().hash(); for height in 1..max_height { - let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0"); + let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0").into(); if height == 1 { let tx = create_tx_deploy_contract(height, &signer, last_hash); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -273,7 +269,7 @@ fn test_cold_db_copy_with_height_skips() { let mut last_hash = *env.clients[0].chain.genesis().hash(); for height in 1..max_height { - let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0"); + let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0").into(); // It is still painful to filter out transactions in last two blocks. // So, as block 19 is skipped, blocks 17 and 18 shouldn't contain any transactions. // So, we shouldn't send any transactions between block 17 and the previous block. @@ -364,7 +360,7 @@ fn test_initial_copy_to_cold(batch_size: usize) { let mut last_hash = *env.clients[0].chain.genesis().hash(); for height in 1..max_height { - let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0"); + let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0").into(); for i in 0..5 { let tx = create_tx_send_money(height * 10 + i, &signer, last_hash); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -448,7 +444,7 @@ fn test_cold_loop_on_gc_boundary() { let mut last_hash = *env.clients[0].chain.genesis().hash(); for height in 1..height_delta { - let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0"); + let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0").into(); for i in 0..5 { let tx = create_tx_send_money(height * 10 + i, &signer, last_hash); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -467,7 +463,7 @@ fn test_cold_loop_on_gc_boundary() { update_cold_head(cold_db, &hot_store, &(height_delta - 1)).unwrap(); for height in height_delta..height_delta * 2 { - let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0"); + let signer = InMemorySigner::from_seed(test0(), KeyType::ED25519, "test0").into(); for i in 0..5 { let tx = create_tx_send_money(height * 10 + i, &signer, last_hash); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); diff --git a/integration-tests/src/tests/client/epoch_sync.rs b/integration-tests/src/tests/client/epoch_sync.rs index 1b5c1f18d2c..84fcd1ab91b 100644 --- a/integration-tests/src/tests/client/epoch_sync.rs +++ b/integration-tests/src/tests/client/epoch_sync.rs @@ -37,7 +37,8 @@ use std::sync::{Arc, RwLock}; fn generate_transactions(last_hash: &CryptoHash, h: BlockHeight) -> Vec { let mut txs = vec![]; - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); if h == 1 { txs.push(SignedTransaction::from_actions( h, diff --git a/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs b/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs index 412ea881ebc..6e4275a0a9f 100644 --- a/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs +++ b/integration-tests/src/tests/client/features/access_key_nonce_for_implicit_accounts.rs @@ -7,7 +7,7 @@ use near_chain_configs::{Genesis, NEAR_BASE}; use near_chunks::metrics::PARTIAL_ENCODED_CHUNK_FORWARD_CACHED_WITHOUT_HEADER; use near_client::test_utils::{create_chunk_with_transactions, TestEnv}; use near_client::{ProcessTxResponse, ProduceChunkResult}; -use near_crypto::{InMemorySigner, KeyType, SecretKey, Signer}; +use near_crypto::{InMemorySigner, KeyType, SecretKey}; use near_network::shards_manager::ShardsManagerRequestFromNetwork; use near_network::types::{NetworkRequests, PeerManagerMessageRequest}; use near_o11y::testonly::init_test_logger; @@ -53,7 +53,8 @@ fn test_transaction_hash_collision() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let signer0 = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); - let signer1 = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer1 = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let send_money_tx = SignedTransaction::send_money( 1, "test1".parse().unwrap(), @@ -90,7 +91,7 @@ fn test_transaction_hash_collision() { "test1".parse().unwrap(), NEAR_BASE, signer1.public_key(), - &signer0, + &signer0.into(), *genesis_block.hash(), ); assert_eq!( @@ -124,8 +125,10 @@ fn get_status_of_tx_hash_collision_for_near_implicit_account( let deposit_for_account_creation = 10u128.pow(23); let mut height = 1; let blocks_number = 5; - let signer1 = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer1 = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let near_implicit_account_id = near_implicit_account_signer.account_id.clone(); + let near_implicit_account_signer = near_implicit_account_signer.into(); // Send money to NEAR-implicit account, invoking its creation. let send_money_tx = SignedTransaction::send_money( @@ -241,7 +244,7 @@ fn test_chunk_transaction_validity() { 1, "test1".parse().unwrap(), "test0".parse().unwrap(), - &signer, + &signer.into(), 100, *genesis_block.hash(), ); @@ -252,7 +255,7 @@ fn test_chunk_transaction_validity() { ProduceChunkResult { chunk, encoded_chunk_parts_paths: merkle_paths, receipts, .. }, block, ) = create_chunk_with_transactions(&mut env.clients[0], vec![tx]); - let validator_id = env.clients[0].validator_signer.as_ref().unwrap().validator_id().clone(); + let validator_id = env.clients[0].validator_signer.get().unwrap().validator_id().clone(); env.clients[0] .persist_and_distribute_encoded_chunk(chunk, merkle_paths, receipts, validator_id) .unwrap(); @@ -273,7 +276,7 @@ fn test_transaction_nonce_too_large() { large_nonce, "test1".parse().unwrap(), "test0".parse().unwrap(), - &signer, + &signer.into(), 100, *genesis_block.hash(), ); diff --git a/integration-tests/src/tests/client/features/account_id_in_function_call_permission.rs b/integration-tests/src/tests/client/features/account_id_in_function_call_permission.rs index 205c841286f..538bbf5c327 100644 --- a/integration-tests/src/tests/client/features/account_id_in_function_call_permission.rs +++ b/integration-tests/src/tests/client/features/account_id_in_function_call_permission.rs @@ -35,7 +35,8 @@ fn test_account_id_in_function_call_permission_upgrade() { .build() }; - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer: Signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx = TransactionV0 { signer_id: "test0".parse().unwrap(), receiver_id: "test0".parse().unwrap(), @@ -122,7 +123,7 @@ fn test_very_long_account_id() { nonce: 0, block_hash: tip.last_block_hash, }) - .sign(&signer); + .sign(&signer.into()); assert_eq!( env.clients[0].process_tx(tx, false, false), diff --git a/integration-tests/src/tests/client/features/adversarial_behaviors.rs b/integration-tests/src/tests/client/features/adversarial_behaviors.rs index 8f4b8073f21..7803708eb0b 100644 --- a/integration-tests/src/tests/client/features/adversarial_behaviors.rs +++ b/integration-tests/src/tests/client/features/adversarial_behaviors.rs @@ -222,7 +222,7 @@ fn test_banning_chunk_producer_when_seeing_invalid_chunk_base( checked_feature!("stable", StatelessValidationV0, PROTOCOL_VERSION); let epoch_manager = test.env.clients[0].epoch_manager.clone(); let bad_chunk_producer = - test.env.clients[7].validator_signer.as_ref().unwrap().validator_id().clone(); + test.env.clients[7].validator_signer.get().unwrap().validator_id().clone(); let mut epochs_seen_invalid_chunk: HashSet = HashSet::new(); let mut last_block_skipped = false; for height in 1..=EPOCH_LENGTH * 4 + 5 { diff --git a/integration-tests/src/tests/client/features/chunk_nodes_cache.rs b/integration-tests/src/tests/client/features/chunk_nodes_cache.rs index 274e3e06a72..dc42a9c0444 100644 --- a/integration-tests/src/tests/client/features/chunk_nodes_cache.rs +++ b/integration-tests/src/tests/client/features/chunk_nodes_cache.rs @@ -19,7 +19,7 @@ use nearcore::test_utils::TestEnvNightshadeSetupExt; fn process_transaction( env: &mut TestEnv, - signer: &dyn Signer, + signer: &Signer, num_blocks: BlockHeightDelta, protocol_version: ProtocolVersion, ) -> CryptoHash { @@ -105,7 +105,8 @@ fn compare_node_counts() { 1, ); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx_node_counts: Vec = (0..4) .map(|i| { let touching_trie_node_cost: Gas = 16_101_955_926; diff --git a/integration-tests/src/tests/client/features/congestion_control.rs b/integration-tests/src/tests/client/features/congestion_control.rs index 4792e3dac83..11c4ff37ca0 100644 --- a/integration-tests/src/tests/client/features/congestion_control.rs +++ b/integration-tests/src/tests/client/features/congestion_control.rs @@ -57,12 +57,12 @@ fn setup_contract(env: &mut TestEnv) { let mut nonce = 1; let create_contract_tx = SignedTransaction::create_contract( nonce, - signer_id.clone(), + signer_id, CONTRACT_ID.parse().unwrap(), contract.to_vec(), 10 * 10u128.pow(24), PublicKey::from_seed(KeyType::ED25519, CONTRACT_ID), - &signer, + &signer.clone().into(), *block.hash(), ); // this adds the tx to the pool and then produces blocks until the tx result is available @@ -336,7 +336,7 @@ fn new_fn_call_100tgas( nonce, signer.account_id.clone(), CONTRACT_ID.parse().unwrap(), - signer, + &signer.clone().into(), deposit, // easy way to burn all attached gas "loop_forever".to_owned(), @@ -362,7 +362,7 @@ fn new_cheap_fn_call( nonce, signer.account_id.clone(), receiver, - signer, + &signer.clone().into(), deposit, "foo_does_not_exists".to_owned(), vec![], diff --git a/integration-tests/src/tests/client/features/delegate_action.rs b/integration-tests/src/tests/client/features/delegate_action.rs index ad195dbf587..9078ad7c36e 100644 --- a/integration-tests/src/tests/client/features/delegate_action.rs +++ b/integration-tests/src/tests/client/features/delegate_action.rs @@ -7,7 +7,7 @@ use crate::node::{Node, RuntimeNode}; use crate::tests::standard_cases::fee_helper; use near_chain_configs::{Genesis, NEAR_BASE}; use near_client::test_utils::TestEnv; -use near_crypto::{KeyType, PublicKey, Signer}; +use near_crypto::{KeyType, PublicKey}; use near_parameters::ActionCosts; use near_primitives::account::{ id::AccountType, AccessKey, AccessKeyPermission, FunctionCallPermission, diff --git a/integration-tests/src/tests/client/features/flat_storage.rs b/integration-tests/src/tests/client/features/flat_storage.rs index 27cdd55c029..488cd07310e 100644 --- a/integration-tests/src/tests/client/features/flat_storage.rs +++ b/integration-tests/src/tests/client/features/flat_storage.rs @@ -51,7 +51,8 @@ fn test_flat_storage_upgrade() { old_protocol_version, ); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer: Signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let gas = 20_000_000_000_000; let tx = TransactionV0 { signer_id: "test0".parse().unwrap(), diff --git a/integration-tests/src/tests/client/features/in_memory_tries.rs b/integration-tests/src/tests/client/features/in_memory_tries.rs index 13af8b8c72a..2269b8f2184 100644 --- a/integration-tests/src/tests/client/features/in_memory_tries.rs +++ b/integration-tests/src/tests/client/features/in_memory_tries.rs @@ -277,7 +277,7 @@ fn run_chain_for_some_blocks_while_sending_money_around( *nonce, sender.clone(), receiver.clone(), - &create_user_test_signer(&sender), + &create_user_test_signer(&sender).into(), ONE_NEAR, tip.last_block_hash, ); diff --git a/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs b/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs index b319e4ab3fe..d7d7c9dbd1f 100644 --- a/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs +++ b/integration-tests/src/tests/client/features/increase_storage_compute_cost.rs @@ -13,7 +13,7 @@ use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; use near_client::ProcessTxResponse; -use near_crypto::{InMemorySigner, KeyType}; +use near_crypto::{InMemorySigner, KeyType, Signer}; use near_parameters::RuntimeConfigStore; use near_parameters::{ActionCosts, RuntimeConfig}; use near_primitives::sharding::ShardChunk; @@ -301,14 +301,15 @@ fn produce_saturated_chunk( gas, deposit: 0, }))]; - let signer = - InMemorySigner::from_seed(user_account.clone(), KeyType::ED25519, user_account.as_ref()); + let signer: Signer = + InMemorySigner::from_seed(user_account.clone(), KeyType::ED25519, user_account.as_ref()) + .into(); let tip = env.clients[0].chain.head().unwrap(); let mut tx_factory = || { let tx = SignedTransaction::from_actions( *nonce, - signer.account_id.clone(), + user_account.clone(), contract_account.clone(), &signer, actions.clone(), diff --git a/integration-tests/src/tests/client/features/lower_storage_key_limit.rs b/integration-tests/src/tests/client/features/lower_storage_key_limit.rs index 9e065624cb5..aa136534bf2 100644 --- a/integration-tests/src/tests/client/features/lower_storage_key_limit.rs +++ b/integration-tests/src/tests/client/features/lower_storage_key_limit.rs @@ -60,7 +60,8 @@ fn protocol_upgrade() { env }; - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer: Signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx = TransactionV0 { signer_id: "test0".parse().unwrap(), receiver_id: "test0".parse().unwrap(), diff --git a/integration-tests/src/tests/client/features/multinode_stateless_validators.rs b/integration-tests/src/tests/client/features/multinode_stateless_validators.rs index c42a9adfcbb..483e3c2e56f 100644 --- a/integration-tests/src/tests/client/features/multinode_stateless_validators.rs +++ b/integration-tests/src/tests/client/features/multinode_stateless_validators.rs @@ -549,7 +549,7 @@ fn test_stateless_validators_with_multi_test_loop() { 1, accounts[i].clone(), accounts[(i + 1) % NUM_ACCOUNTS].clone(), - &create_user_test_signer(&accounts[i]), + &create_user_test_signer(&accounts[i]).into(), amount, anchor_hash, ); diff --git a/integration-tests/src/tests/client/features/multinode_test_loop_example.rs b/integration-tests/src/tests/client/features/multinode_test_loop_example.rs index ab1c725b85d..91d79f4ef89 100644 --- a/integration-tests/src/tests/client/features/multinode_test_loop_example.rs +++ b/integration-tests/src/tests/client/features/multinode_test_loop_example.rs @@ -526,7 +526,7 @@ fn test_client_with_multi_test_loop() { 1, accounts[i].clone(), accounts[(i + 1) % accounts.len()].clone(), - &create_user_test_signer(&accounts[i]), + &create_user_test_signer(&accounts[i]).into(), amount, anchor_hash, ); diff --git a/integration-tests/src/tests/client/features/nearvm.rs b/integration-tests/src/tests/client/features/nearvm.rs index f1b56bbb77a..93e2f4ae74c 100644 --- a/integration-tests/src/tests/client/features/nearvm.rs +++ b/integration-tests/src/tests/client/features/nearvm.rs @@ -42,7 +42,8 @@ fn test_nearvm_upgrade() { env }; - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer: Signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx = TransactionV0 { signer_id: "test0".parse().unwrap(), receiver_id: "test0".parse().unwrap(), diff --git a/integration-tests/src/tests/client/features/nonrefundable_transfer.rs b/integration-tests/src/tests/client/features/nonrefundable_transfer.rs index b0e8104a235..8b844d4cbb5 100644 --- a/integration-tests/src/tests/client/features/nonrefundable_transfer.rs +++ b/integration-tests/src/tests/client/features/nonrefundable_transfer.rs @@ -133,7 +133,7 @@ fn execute_transaction_from_actions( nonce + 1, signer.account_id.clone(), receiver, - signer, + &signer.clone().into(), actions, tip.last_block_hash, 0, diff --git a/integration-tests/src/tests/client/features/stateless_validation.rs b/integration-tests/src/tests/client/features/stateless_validation.rs index c8979680b0b..244378e3250 100644 --- a/integration-tests/src/tests/client/features/stateless_validation.rs +++ b/integration-tests/src/tests/client/features/stateless_validation.rs @@ -166,7 +166,7 @@ fn run_chunk_validation_test( round as u64, sender_account, receiver_account, - &signer, + &signer.into(), ONE_NEAR, tip.last_block_hash, ); @@ -406,7 +406,7 @@ fn test_invalid_transactions() { 1, sender_account.clone(), receiver_account.clone(), - &signers[0], + &signers[0].clone().into(), u128::MAX, tip.last_block_hash, ), @@ -415,7 +415,7 @@ fn test_invalid_transactions() { 0, sender_account.clone(), receiver_account.clone(), - &signers[0], + &signers[0].clone().into(), ONE_NEAR, tip.last_block_hash, ), @@ -424,7 +424,7 @@ fn test_invalid_transactions() { 2, "test3".parse().unwrap(), receiver_account.clone(), - &new_signer, + &new_signer.into(), ONE_NEAR, tip.last_block_hash, ), @@ -434,7 +434,7 @@ fn test_invalid_transactions() { 1, sender_account, receiver_account, - &signers[0], + &signers[0].clone().into(), ONE_NEAR, tip.last_block_hash, ); @@ -467,7 +467,7 @@ fn test_invalid_transactions() { chunk, encoded_chunk_parts_paths, receipts, - client.validator_signer.as_ref().unwrap().validator_id().clone(), + client.validator_signer.get().unwrap().validator_id().clone(), ) .unwrap(); let prev_block = client.chain.get_block(shard_chunk.prev_block()).unwrap(); diff --git a/integration-tests/src/tests/client/features/storage_proof_size_limit.rs b/integration-tests/src/tests/client/features/storage_proof_size_limit.rs index 294e8ab9e5c..5f192be4f13 100644 --- a/integration-tests/src/tests/client/features/storage_proof_size_limit.rs +++ b/integration-tests/src/tests/client/features/storage_proof_size_limit.rs @@ -3,7 +3,7 @@ use near_chain::Provenance; use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; use near_client::ProcessTxResponse; -use near_crypto::{InMemorySigner, KeyType}; +use near_crypto::{InMemorySigner, KeyType, Signer}; use near_parameters::RuntimeConfigStore; use near_primitives::action::{Action, DeployContractAction, FunctionCallAction}; use near_primitives::checked_feature; @@ -54,8 +54,9 @@ fn test_storage_proof_size_limit() { // query the access key of the user. It's easier to keep a shared counter // that starts at 1 and increases monotonically. let mut nonce = 1; - let signer = - InMemorySigner::from_seed(user_account.clone(), KeyType::ED25519, user_account.as_ref()); + let signer: Signer = + InMemorySigner::from_seed(user_account.clone(), KeyType::ED25519, user_account.as_ref()) + .into(); // Write 1MB values under keys 0, 1, 2, 3, ..., 23. // 24MB of data in total @@ -69,7 +70,7 @@ fn test_storage_proof_size_limit() { let tx = SignedTransaction::from_actions( nonce, - signer.account_id.clone(), + user_account.clone(), contract_account.clone(), &signer, vec![action], @@ -92,7 +93,7 @@ fn test_storage_proof_size_limit() { })); let tx = SignedTransaction::from_actions( nonce, - signer.account_id.clone(), + user_account.clone(), contract_account.clone(), &signer, vec![action], diff --git a/integration-tests/src/tests/client/features/wallet_contract.rs b/integration-tests/src/tests/client/features/wallet_contract.rs index da5f7a605a6..342af8cef7c 100644 --- a/integration-tests/src/tests/client/features/wallet_contract.rs +++ b/integration-tests/src/tests/client/features/wallet_contract.rs @@ -100,7 +100,7 @@ fn test_eth_implicit_account_creation() { 1, signer.account_id.clone(), eth_implicit_account_id.clone(), - &signer, + &signer.into(), 0, *genesis_block.hash(), ); @@ -154,14 +154,14 @@ fn test_transaction_from_eth_implicit_account_fail() { let public_key = secret_key.public_key(); let eth_implicit_account_id = derive_eth_implicit_account_id(public_key.unwrap_as_secp256k1()); let eth_implicit_account_signer = - InMemorySigner::from_secret_key(eth_implicit_account_id.clone(), secret_key); + InMemorySigner::from_secret_key(eth_implicit_account_id.clone(), secret_key).into(); // Send money to ETH-implicit account, invoking its creation. let send_money_tx = SignedTransaction::send_money( 1, "test1".parse().unwrap(), eth_implicit_account_id.clone(), - &signer1, + &signer1.into(), deposit_for_account_creation, *genesis_block.hash(), ); @@ -272,7 +272,7 @@ fn test_wallet_contract_interaction() { nonce, relayer.clone(), eth_implicit_account.clone(), - &relayer_signer.signer, + &relayer_signer.signer.clone().into(), actions, block_hash, 0, @@ -395,7 +395,7 @@ fn create_rlp_execute_tx( nonce, near_signer.account_id.into(), eth_implicit_account.into(), - &near_signer.signer, + &near_signer.signer.clone().into(), actions, block_hash, 0, diff --git a/integration-tests/src/tests/client/features/yield_timeouts.rs b/integration-tests/src/tests/client/features/yield_timeouts.rs index 21495a9bef5..39368229423 100644 --- a/integration-tests/src/tests/client/features/yield_timeouts.rs +++ b/integration-tests/src/tests/client/features/yield_timeouts.rs @@ -65,7 +65,8 @@ fn prepare_env_with_yield( } let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); // Submit transaction deploying contract to test0 let tx = SignedTransaction::from_actions( @@ -139,7 +140,7 @@ fn invoke_yield_resume( 200, "test0".parse().unwrap(), "test0".parse().unwrap(), - &signer, + &signer.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_yield_resume".to_string(), args: yield_payload.into_iter().chain(data_id.as_bytes().iter().cloned()).collect(), @@ -162,7 +163,8 @@ fn invoke_yield_resume( /// Note that these transactions start to be processed in the *second* block produced after they are /// inserted to client 0's mempool. fn create_congestion(env: &mut TestEnv) { - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let mut tx_hashes = vec![]; diff --git a/integration-tests/src/tests/client/features/zero_balance_account.rs b/integration-tests/src/tests/client/features/zero_balance_account.rs index 102fd353baa..b5ea8458c8e 100644 --- a/integration-tests/src/tests/client/features/zero_balance_account.rs +++ b/integration-tests/src/tests/client/features/zero_balance_account.rs @@ -2,7 +2,7 @@ use assert_matches::assert_matches; use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; -use near_crypto::{InMemorySigner, KeyType, PublicKey}; +use near_crypto::{InMemorySigner, KeyType, PublicKey, Signer}; use near_network::client::ProcessTxResponse; use near_parameters::{ExtCostsConfig, RuntimeConfig, RuntimeConfigStore, StorageUsageConfig}; use near_primitives::account::id::AccountId; @@ -54,14 +54,16 @@ fn test_zero_balance_account_creation() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let new_account_id: AccountId = "hello.test0".parse().unwrap(); - let signer0 = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer0_account_id: AccountId = "test0".parse().unwrap(); + let signer0 = + InMemorySigner::from_seed(signer0_account_id.clone(), KeyType::ED25519, "test0").into(); let new_signer = InMemorySigner::from_seed(new_account_id.clone(), KeyType::ED25519, "hello.test0"); // create a valid zero balance account. Transaction should succeed let create_account_tx = SignedTransaction::create_account( 1, - signer0.account_id.clone(), + signer0_account_id.clone(), new_account_id.clone(), 0, new_signer.public_key.clone(), @@ -83,7 +85,7 @@ fn test_zero_balance_account_creation() { let contract = near_test_contracts::sized_contract(ZERO_BALANCE_ACCOUNT_STORAGE_LIMIT as usize); let create_account_tx = SignedTransaction::create_contract( 2, - signer0.account_id.clone(), + signer0_account_id, new_account_id, contract.to_vec(), 0, @@ -134,17 +136,19 @@ fn test_zero_balance_account_add_key() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let new_account_id: AccountId = "hello.test0".parse().unwrap(); - let signer0 = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); - let new_signer = - InMemorySigner::from_seed(new_account_id.clone(), KeyType::ED25519, "hello.test0"); + let signer0_account_id: AccountId = "test0".parse().unwrap(); + let signer0 = + InMemorySigner::from_seed(signer0_account_id.clone(), KeyType::ED25519, "test0").into(); + let new_signer: Signer = + InMemorySigner::from_seed(new_account_id.clone(), KeyType::ED25519, "hello.test0").into(); let amount = 10u128.pow(24); let create_account_tx = SignedTransaction::create_account( 1, - signer0.account_id.clone(), + signer0_account_id.clone(), new_account_id.clone(), amount, - new_signer.public_key.clone(), + new_signer.public_key(), &signer0, *genesis_block.hash(), ); @@ -204,7 +208,7 @@ fn test_zero_balance_account_add_key() { let send_money_tx = SignedTransaction::send_money( nonce + 10, new_account_id.clone(), - signer0.account_id, + signer0_account_id, &new_signer, amount, *genesis_block.hash(), @@ -252,14 +256,16 @@ fn test_zero_balance_account_upgrade() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let new_account_id: AccountId = "hello.test0".parse().unwrap(); - let signer0 = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer0_account_id: AccountId = "test0".parse().unwrap(); + let signer0: Signer = + InMemorySigner::from_seed(signer0_account_id.clone(), KeyType::ED25519, "test0").into(); let new_signer = InMemorySigner::from_seed(new_account_id.clone(), KeyType::ED25519, "hello.test0"); // before protocol upgrade, should not be possible to create a zero balance account let first_create_account_tx = SignedTransaction::create_account( 1, - signer0.account_id.clone(), + signer0_account_id.clone(), new_account_id.clone(), 0, new_signer.public_key.clone(), @@ -285,7 +291,7 @@ fn test_zero_balance_account_upgrade() { let second_create_account_tx = SignedTransaction::create_account( 2, - signer0.account_id.clone(), + signer0_account_id, new_account_id, 0, new_signer.public_key, diff --git a/integration-tests/src/tests/client/flat_storage.rs b/integration-tests/src/tests/client/flat_storage.rs index fa5f7208b17..fd3d30e114a 100644 --- a/integration-tests/src/tests/client/flat_storage.rs +++ b/integration-tests/src/tests/client/flat_storage.rs @@ -127,7 +127,8 @@ fn test_flat_storage_creation_sanity() { // Process some blocks with flat storage. Then remove flat storage data from disk. { let mut env = setup_env(&genesis, store.clone()); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let genesis_hash = *env.clients[0].chain.genesis().hash(); for height in 1..START_HEIGHT { env.produce_block(0, height); @@ -250,7 +251,8 @@ fn test_flat_storage_creation_two_shards() { // Process some blocks with flat storages for two shards. Then remove flat storage data from disk for shard 0. { let mut env = setup_env(&genesis, store.clone()); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let genesis_hash = *env.clients[0].chain.genesis().hash(); for height in 1..START_HEIGHT { env.produce_block(0, height); @@ -511,7 +513,8 @@ fn test_not_supported_block() { let store = create_test_store(); let mut env = setup_env(&genesis, store); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let genesis_hash = *env.clients[0].chain.genesis().hash(); // Produce blocks up to `START_HEIGHT`. diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 3fb03ec0424..abaa1df0a08 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -25,7 +25,7 @@ use near_client::{ BlockApproval, BlockResponse, GetBlockWithMerkleTree, ProcessTxResponse, ProduceChunkResult, SetNetworkInfo, }; -use near_crypto::{InMemorySigner, KeyType, PublicKey, Signature, Signer}; +use near_crypto::{InMemorySigner, KeyType, PublicKey, Signature}; use near_network::test_utils::{wait_or_panic, MockPeerManagerAdapter}; use near_network::types::{ BlockInfo, ConnectedPeerInfo, HighestHeightPeerInfo, NetworkInfo, PeerChainInfo, @@ -58,7 +58,6 @@ use near_primitives::transaction::{ use near_primitives::trie_key::TrieKey; use near_primitives::types::validator_stake::ValidatorStake; use near_primitives::types::{AccountId, BlockHeight, EpochId, NumBlocks, ProtocolVersion}; -use near_primitives::validator_signer::ValidatorSigner; use near_primitives::version::{ProtocolFeature, PROTOCOL_VERSION}; use near_primitives::views::{ BlockHeaderView, FinalExecutionStatus, QueryRequest, QueryResponseKind, @@ -135,7 +134,7 @@ pub(crate) fn create_account( new_account_id, 10u128.pow(24), signer.public_key(), - &signer, + &signer.into(), *block.hash(), ); let tx_hash = tx.get_hash(); @@ -160,7 +159,7 @@ pub(crate) fn deploy_test_contract_with_protocol_version( height, account_id.clone(), account_id, - &signer, + &signer.into(), vec![Action::DeployContract(DeployContractAction { code: wasm_code.to_vec() })], *block.hash(), 0, @@ -203,7 +202,8 @@ pub(crate) fn prepare_env_with_congestion( } let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); // Deploy contract to test0. let tx = SignedTransaction::from_actions( @@ -1067,7 +1067,7 @@ fn test_time_attack() { init_test_logger(); let mut env = TestEnv::default_builder().clients_count(1).mock_epoch_managers().build(); let client = &mut env.clients[0]; - let signer = client.validator_signer.as_ref().unwrap(); + let signer = client.validator_signer.get().unwrap(); let genesis = client.chain.get_block_by_height(0).unwrap(); let mut b1 = TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build(); b1.mut_header().get_mut().inner_lite.timestamp = @@ -1095,7 +1095,7 @@ fn test_invalid_gas_price() { genesis_config.min_gas_price = 100; let mut env = TestEnv::builder(&genesis_config).clients_count(1).mock_epoch_managers().build(); let client = &mut env.clients[0]; - let signer = client.validator_signer.as_ref().unwrap(); + let signer = client.validator_signer.get().unwrap(); let genesis = client.chain.get_block_by_height(0).unwrap(); let mut b1 = TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build(); @@ -1139,7 +1139,7 @@ fn test_bad_orphan() { env.produce_block(0, i); } let block = env.clients[0].produce_block(5).unwrap().unwrap(); - let signer = env.clients[0].validator_signer.as_ref().unwrap().clone(); + let signer = env.clients[0].validator_signer.get().unwrap(); { // Orphan block with unknown epoch let mut block = env.clients[0].produce_block(6).unwrap().unwrap(); @@ -1283,7 +1283,7 @@ fn test_bad_chunk_mask() { } block .mut_header() - .resign(&*env.client(&block_producer).validator_signer.as_ref().unwrap().clone()); + .resign(&*env.client(&block_producer).validator_signer.get().unwrap().clone()); for client in env.clients.iter_mut() { let res = client @@ -1600,7 +1600,8 @@ fn test_gc_execution_outcome() { genesis.config.epoch_length = epoch_length; let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx = SignedTransaction::send_money( 1, "test0".parse().unwrap(), @@ -1789,13 +1790,14 @@ fn test_tx_forward_around_epoch_boundary() { .nightshade_runtimes(&genesis) .build(); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -1918,7 +1920,8 @@ fn test_gas_price_change() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let genesis_hash = *genesis_block.hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::send_money( 1, "test1".parse().unwrap(), @@ -1962,7 +1965,8 @@ fn test_gas_price_overflow() { let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let genesis_hash = *genesis_block.hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); for i in 1..100 { let tx = SignedTransaction::send_money( i, @@ -2093,7 +2097,7 @@ fn test_data_reset_before_state_sync() { "test_account".parse().unwrap(), NEAR_BASE, signer.public_key(), - &signer, + &signer.into(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -2186,7 +2190,8 @@ fn test_validate_chunk_extra() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let genesis_height = genesis_block.header().height(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx = SignedTransaction::from_actions( 1, "test0".parse().unwrap(), @@ -2285,7 +2290,7 @@ fn test_validate_chunk_extra() { let mut chain_store = ChainStore::new(env.clients[0].chain.chain_store().store().clone(), genesis_height, true); let chunk_header = encoded_chunk.cloned_header(); - let validator_id = env.clients[0].validator_signer.as_ref().unwrap().validator_id().clone(); + let validator_id = env.clients[0].validator_signer.get().unwrap().validator_id().clone(); env.clients[0] .persist_and_distribute_encoded_chunk(encoded_chunk, merkle_paths, receipts, validator_id) .unwrap(); @@ -2355,7 +2360,8 @@ fn test_catchup_gas_price_change() { env.process_block(0, block.clone(), Provenance::PRODUCED); env.process_block(1, block, Provenance::NONE); } - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); for i in 0..3 { let tx = SignedTransaction::send_money( i + 1, @@ -2447,7 +2453,8 @@ fn test_block_execution_outcomes() { genesis.config.gas_limit = 1000000000000; let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let mut tx_hashes = vec![]; for i in 0..3 { // send transaction to the same account to generate local receipts @@ -2535,7 +2542,8 @@ fn test_refund_receipts_processing() { genesis.config.gas_limit = 100_000_000; let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let mut tx_hashes = vec![]; // Send transactions to a non-existing account to generate refunds. for i in 0..3 { @@ -2615,7 +2623,8 @@ fn test_delayed_receipt_count_limit() { let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); // Send enough transactions to saturate delayed receipts capacity. let total_tx_count = 200usize; for i in 0..total_tx_count { @@ -2968,7 +2977,7 @@ fn produce_chunks(env: &mut TestEnv, epoch_id: &EpochId, height: u64) { produce_chunk_result; for client in &mut env.clients { - let validator_id = client.validator_signer.as_ref().unwrap().validator_id().clone(); + let validator_id = client.validator_signer.get().unwrap().validator_id().clone(); client .persist_and_distribute_encoded_chunk( chunk.clone(), @@ -3060,7 +3069,7 @@ fn test_query_final_state() { 1, "test0".parse().unwrap(), "test1".parse().unwrap(), - &signer, + &signer.into(), 100, *genesis_block.hash(), ); @@ -3258,7 +3267,7 @@ fn prepare_env_with_transaction() -> (TestEnv, CryptoHash) { 1, "test0".parse().unwrap(), "test1".parse().unwrap(), - &signer, + &signer.into(), 100, *genesis_block.hash(), ); @@ -3483,7 +3492,7 @@ fn test_validator_stake_host_function() { 10, "test0".parse().unwrap(), "test0".parse().unwrap(), - &signer, + &signer.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "ext_validator_stake".to_string(), args: b"test0".to_vec(), @@ -3814,7 +3823,7 @@ mod contract_precompilation_tests { "test2".parse().unwrap(), "test2".parse().unwrap(), "test0".parse().unwrap(), - &signer, + &signer.into(), *block.hash(), ); assert_eq!( diff --git a/integration-tests/src/tests/client/resharding.rs b/integration-tests/src/tests/client/resharding.rs index a922368ef76..aa1ac7f78f0 100644 --- a/integration-tests/src/tests/client/resharding.rs +++ b/integration-tests/src/tests/client/resharding.rs @@ -6,7 +6,7 @@ use near_chain::{ChainStoreAccess, Provenance}; use near_chain_configs::{Genesis, NEAR_BASE}; use near_client::test_utils::{run_catchup, TestEnv}; use near_client::{Client, ProcessTxResponse}; -use near_crypto::{InMemorySigner, KeyType, Signer}; +use near_crypto::{InMemorySigner, KeyType}; use near_o11y::testonly::init_test_logger; use near_primitives::account::id::AccountId; use near_primitives::block::{Block, Tip}; @@ -341,7 +341,7 @@ impl TestReshardingEnv { let _span = tracing::debug_span!(target: "test", "process block", client=j).entered(); let shard_ids = chunk_producer_to_shard_id - .get(client.validator_signer.as_ref().unwrap().validator_id()) + .get(client.validator_signer.get().unwrap().validator_id()) .cloned() .unwrap_or_default(); let should_produce_chunk = @@ -974,7 +974,7 @@ fn generate_create_accounts_txs( account_id.clone(), NEAR_BASE, signer.public_key(), - &signer0, + &signer0.into(), genesis_hash, ); if check_accounts { @@ -1283,7 +1283,7 @@ fn setup_test_env_with_cross_contract_txs( 1, account_id.clone(), account_id.clone(), - &signer, + &signer.into(), actions, genesis_hash, 0, @@ -1452,7 +1452,7 @@ fn gen_cross_contract_tx_impl( nonce, account0.clone(), account1.clone(), - &signer0, + &signer0.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -1598,7 +1598,7 @@ fn generate_yield_create_tx( nonce, account_id.clone(), account_id.clone(), - &signer, + &signer.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: callback_method_name, args: vec![], @@ -1632,7 +1632,7 @@ fn setup_test_env_with_promise_yield_txs( 1, account_id.clone(), account_id.clone(), - &signer, + &signer.into(), actions, genesis_hash, 0, diff --git a/integration-tests/src/tests/client/runtimes.rs b/integration-tests/src/tests/client/runtimes.rs index ece190ae587..5f09f98ab0e 100644 --- a/integration-tests/src/tests/client/runtimes.rs +++ b/integration-tests/src/tests/client/runtimes.rs @@ -49,7 +49,8 @@ fn test_invalid_approvals() { assert_eq!(env.clients[0].pending_approvals.len(), 0); // Approval with invalid signature. Should be dropped let signer = - InMemoryValidatorSigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "random"); + InMemoryValidatorSigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "random") + .into(); let genesis_hash = *env.clients[0].chain.genesis().hash(); let approval = Approval::new(genesis_hash, 0, 1, &signer); env.clients[0].collect_block_approval(&approval, ApprovalType::PeerApproval(peer_id)); diff --git a/integration-tests/src/tests/client/sandbox.rs b/integration-tests/src/tests/client/sandbox.rs index 2545e1f3b8b..f21572674b4 100644 --- a/integration-tests/src/tests/client/sandbox.rs +++ b/integration-tests/src/tests/client/sandbox.rs @@ -2,7 +2,7 @@ use near_chain::Provenance; use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; use near_client::ProcessTxResponse; -use near_crypto::{InMemorySigner, KeyType}; +use near_crypto::{InMemorySigner, KeyType, Signer}; use near_primitives::account::Account; use near_primitives::sandbox::state_patch::SandboxStatePatch; use near_primitives::state_record::StateRecord; @@ -12,12 +12,13 @@ use near_primitives::transaction::{ use near_primitives::types::{AccountId, BlockHeight, Nonce}; use nearcore::test_utils::TestEnvNightshadeSetupExt; -fn test_setup() -> (TestEnv, InMemorySigner) { +fn test_setup() -> (TestEnv, Signer) { let epoch_length = 5; let mut genesis = Genesis::test(vec!["test0".parse().unwrap(), "test1".parse().unwrap()], 1); genesis.config.epoch_length = epoch_length; let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); assert_eq!( send_tx( &mut env, @@ -65,7 +66,7 @@ fn send_tx( nonce: Nonce, signer_id: AccountId, receiver_id: AccountId, - signer: &InMemorySigner, + signer: &Signer, actions: Vec, ) -> ProcessTxResponse { let hash = env.clients[0].chain.head().unwrap().last_block_hash; diff --git a/integration-tests/src/tests/client/state_dump.rs b/integration-tests/src/tests/client/state_dump.rs index 93f8f7d5000..ff71c7c0963 100644 --- a/integration-tests/src/tests/client/state_dump.rs +++ b/integration-tests/src/tests/client/state_dump.rs @@ -144,7 +144,8 @@ fn run_state_sync_with_dumped_parts( .nightshade_runtimes(&genesis) .build(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer: Signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let genesis_hash = *genesis_block.hash(); diff --git a/integration-tests/src/tests/client/state_snapshot.rs b/integration-tests/src/tests/client/state_snapshot.rs index 8f8d78cd9f6..6d1e6b7f85b 100644 --- a/integration-tests/src/tests/client/state_snapshot.rs +++ b/integration-tests/src/tests/client/state_snapshot.rs @@ -194,7 +194,8 @@ fn test_make_state_snapshot() { .nightshade_runtimes(&genesis) .build(); - let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let signer: Signer = + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let genesis_hash = *genesis_block.hash(); diff --git a/integration-tests/src/tests/client/sync_state_nodes.rs b/integration-tests/src/tests/client/sync_state_nodes.rs index d42b028d7ed..2dbc35b5ade 100644 --- a/integration-tests/src/tests/client/sync_state_nodes.rs +++ b/integration-tests/src/tests/client/sync_state_nodes.rs @@ -576,7 +576,8 @@ fn test_dump_epoch_missing_chunk_in_last_block() { let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); let mut blocks = vec![genesis_block.clone()]; let signer = - InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0") + .into(); let target_height = epoch_length + 1; for i in 1..=target_height { tracing::info!( diff --git a/integration-tests/src/tests/nearcore/rpc_error_structs.rs b/integration-tests/src/tests/nearcore/rpc_error_structs.rs index b361cda6700..9547f72b0d7 100644 --- a/integration-tests/src/tests/nearcore/rpc_error_structs.rs +++ b/integration-tests/src/tests/nearcore/rpc_error_structs.rs @@ -369,7 +369,7 @@ fn test_tx_invalid_tx_error() { 1, "near.5".parse().unwrap(), "near.2".parse().unwrap(), - &signer, + &signer.into(), 10000, genesis_hash, ); diff --git a/integration-tests/src/tests/nearcore/rpc_nodes.rs b/integration-tests/src/tests/nearcore/rpc_nodes.rs index 4a9063d055d..5669d6ef326 100644 --- a/integration-tests/src/tests/nearcore/rpc_nodes.rs +++ b/integration-tests/src/tests/nearcore/rpc_nodes.rs @@ -113,7 +113,7 @@ fn test_get_execution_outcome(is_tx_successful: bool) { 1, "near.0".parse().unwrap(), "near.1".parse().unwrap(), - &signer, + &signer.into(), 10000, genesis_hash, ) @@ -124,7 +124,7 @@ fn test_get_execution_outcome(is_tx_successful: bool) { "near.1".parse().unwrap(), 10, signer.public_key.clone(), - &signer, + &signer.into(), genesis_hash, ) }; @@ -372,7 +372,7 @@ fn test_tx_not_enough_balance_must_return_error() { 1, "near.0".parse().unwrap(), "near.1".parse().unwrap(), - &signer, + &signer.into(), 1100000000000000000000000000000000, genesis_hash, ); @@ -436,7 +436,7 @@ fn test_check_unknown_tx_must_return_error() { 1, "near.0".parse().unwrap(), "near.0".parse().unwrap(), - &signer, + &signer.into(), 10000, genesis_hash, ); @@ -500,7 +500,7 @@ fn test_tx_status_on_lightclient_must_return_does_not_track_shard() { 1, "near.1".parse().unwrap(), "near.1".parse().unwrap(), - &signer, + &signer.into(), 10000, genesis_hash, ); diff --git a/integration-tests/src/tests/nearcore/stake_nodes.rs b/integration-tests/src/tests/nearcore/stake_nodes.rs index a3189e41fe8..9c7ba0437ee 100644 --- a/integration-tests/src/tests/nearcore/stake_nodes.rs +++ b/integration-tests/src/tests/nearcore/stake_nodes.rs @@ -129,7 +129,7 @@ fn test_stake_nodes() { 1, test_nodes[1].account_id.clone(), // &*test_nodes[1].config.block_producer.as_ref().unwrap().signer, - &*test_nodes[1].signer, + &(*test_nodes[1].signer).clone().into(), TESTING_INIT_STAKE, test_nodes[1].config.validator_signer.as_ref().unwrap().public_key(), test_nodes[1].genesis_hash, @@ -214,11 +214,14 @@ fn test_validator_kickout() { let stakes = (0..num_nodes / 2).map(|_| NEAR_BASE + rng.gen_range(1..100)); let stake_transactions = stakes.enumerate().map(|(i, stake)| { let test_node = &test_nodes[i]; - let signer = Arc::new(InMemorySigner::from_seed( - test_node.account_id.clone(), - KeyType::ED25519, - test_node.account_id.as_ref(), - )); + let signer = Arc::new( + InMemorySigner::from_seed( + test_node.account_id.clone(), + KeyType::ED25519, + test_node.account_id.as_ref(), + ) + .into(), + ); SignedTransaction::stake( 1, test_node.account_id.clone(), @@ -365,11 +368,14 @@ fn test_validator_join() { false, true, ); - let signer = Arc::new(InMemorySigner::from_seed( - test_nodes[1].account_id.clone(), - KeyType::ED25519, - test_nodes[1].account_id.as_ref(), - )); + let signer = Arc::new( + InMemorySigner::from_seed( + test_nodes[1].account_id.clone(), + KeyType::ED25519, + test_nodes[1].account_id.as_ref(), + ) + .into(), + ); let unstake_transaction = SignedTransaction::stake( 1, test_nodes[1].account_id.clone(), @@ -379,11 +385,14 @@ fn test_validator_join() { test_nodes[1].genesis_hash, ); - let signer = Arc::new(InMemorySigner::from_seed( - test_nodes[2].account_id.clone(), - KeyType::ED25519, - test_nodes[2].account_id.as_ref(), - )); + let signer = Arc::new( + InMemorySigner::from_seed( + test_nodes[2].account_id.clone(), + KeyType::ED25519, + test_nodes[2].account_id.as_ref(), + ) + .into(), + ); let stake_transaction = SignedTransaction::stake( 1, test_nodes[2].account_id.clone(), diff --git a/integration-tests/src/tests/nearcore/sync_nodes.rs b/integration-tests/src/tests/nearcore/sync_nodes.rs index e8b065ffa0b..57af970d277 100644 --- a/integration-tests/src/tests/nearcore/sync_nodes.rs +++ b/integration-tests/src/tests/nearcore/sync_nodes.rs @@ -170,17 +170,16 @@ fn sync_state_stake_change() { start_with_config(dir1.path(), near1.clone()).expect("start_with_config"); let genesis_hash = *genesis_block(&genesis).hash(); - let signer = Arc::new(InMemorySigner::from_seed( - "test1".parse().unwrap(), - KeyType::ED25519, - "test1", - )); + let signer = Arc::new( + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1") + .into(), + ); let unstake_transaction = SignedTransaction::stake( 1, "test1".parse().unwrap(), &*signer, TESTING_INIT_STAKE / 2, - near1.validator_signer.as_ref().unwrap().public_key(), + near1.validator_signer.unwrap().public_key(), genesis_hash, ); actix::spawn( diff --git a/integration-tests/src/tests/network/runner.rs b/integration-tests/src/tests/network/runner.rs index fab4aa79be4..d228255f6a5 100644 --- a/integration-tests/src/tests/network/runner.rs +++ b/integration-tests/src/tests/network/runner.rs @@ -27,7 +27,6 @@ use near_primitives::block::GenesisId; use near_primitives::network::PeerId; use near_primitives::test_utils::create_test_signer; use near_primitives::types::{AccountId, ValidatorId}; -use near_primitives::validator_signer::ValidatorSigner; use near_store::genesis::initialize_genesis_state; use near_telemetry::{TelemetryActor, TelemetryConfig}; use nearcore::NightshadeRuntime; diff --git a/integration-tests/src/tests/standard_cases/mod.rs b/integration-tests/src/tests/standard_cases/mod.rs index 4f66a885e89..6c070daf79d 100644 --- a/integration-tests/src/tests/standard_cases/mod.rs +++ b/integration-tests/src/tests/standard_cases/mod.rs @@ -4,7 +4,7 @@ mod runtime; use assert_matches::assert_matches; use near_chain_configs::test_utils::{TESTING_INIT_BALANCE, TESTING_INIT_STAKE}; use near_chain_configs::NEAR_BASE; -use near_crypto::{InMemorySigner, KeyType, PublicKey}; +use near_crypto::{InMemorySigner, KeyType, PublicKey, Signer}; use near_jsonrpc_primitives::errors::ServerError; use near_parameters::{ActionCosts, ExtCosts}; use near_primitives::account::{ @@ -47,13 +47,12 @@ fn add_access_key( node: &impl Node, node_user: &dyn User, access_key: &AccessKey, - signer2: &InMemorySigner, + signer2: &Signer, ) -> FinalExecutionOutcomeView { let root = node_user.get_state_root(); let account_id = &node.account_id().unwrap(); - let transaction_result = node_user - .add_key(account_id.clone(), signer2.public_key.clone(), access_key.clone()) - .unwrap(); + let transaction_result = + node_user.add_key(account_id.clone(), signer2.public_key(), access_key.clone()).unwrap(); assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); assert_eq!(transaction_result.receipts_outcome.len(), 1); let new_root = node_user.get_state_root(); @@ -737,13 +736,13 @@ pub fn test_swap_key(node: impl Node) { pub fn test_add_key(node: impl Node) { let account_id = &node.account_id().unwrap(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); let node_user = node.user(); add_access_key(&node, node_user.as_ref(), &AccessKey::full_access(), &signer2); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_ok()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_ok()); } pub fn test_add_existing_key(node: impl Node) { @@ -775,12 +774,12 @@ pub fn test_add_existing_key(node: impl Node) { pub fn test_delete_key(node: impl Node) { let account_id = &node.account_id().unwrap(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); let node_user = node.user(); add_access_key(&node, node_user.as_ref(), &AccessKey::full_access(), &signer2); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_ok()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_ok()); let root = node_user.get_state_root(); let transaction_result = @@ -791,7 +790,7 @@ pub fn test_delete_key(node: impl Node) { assert_ne!(new_root, root); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_err()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_ok()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_ok()); } pub fn test_delete_key_not_owned(node: impl Node) { @@ -890,12 +889,12 @@ pub fn test_add_access_key_function_call(node: impl Node) { method_names: vec![], }), }; - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); let result = add_access_key(&node, node_user.as_ref(), &access_key, &signer2); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - let view_access_key = node_user.get_access_key(account_id, &signer2.public_key).unwrap(); + let view_access_key = node_user.get_access_key(account_id, &signer2.public_key()).unwrap(); assert_access_key(&access_key, view_access_key, &result, node_user.as_ref()); } @@ -910,22 +909,22 @@ pub fn test_delete_access_key(node: impl Node) { method_names: vec![], }), }; - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); add_access_key(&node, node_user.as_ref(), &access_key, &signer2); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_ok()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_ok()); let root = node_user.get_state_root(); let transaction_result = - node_user.delete_key(account_id.clone(), signer2.public_key.clone()).unwrap(); + node_user.delete_key(account_id.clone(), signer2.public_key()).unwrap(); assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); assert_eq!(transaction_result.receipts_outcome.len(), 1); let new_root = node_user.get_state_root(); assert_ne!(new_root, root); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_err()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_err()); } pub fn test_add_access_key_with_allowance(node: impl Node) { @@ -939,7 +938,7 @@ pub fn test_add_access_key_with_allowance(node: impl Node) { }), }; let node_user = node.user(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); let account = node_user.view_account(account_id).unwrap(); let initial_balance = account.amount; let fee_helper = fee_helper(&node); @@ -950,7 +949,7 @@ pub fn test_add_access_key_with_allowance(node: impl Node) { assert_eq!(account.amount, initial_balance - add_access_key_cost); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - let view_access_key = node_user.get_access_key(account_id, &signer2.public_key).unwrap(); + let view_access_key = node_user.get_access_key(account_id, &signer2.public_key()).unwrap(); assert_access_key(&access_key, view_access_key, &result, node_user.as_ref()); } @@ -965,7 +964,7 @@ pub fn test_delete_access_key_with_allowance(node: impl Node) { }), }; let node_user = node.user(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); let account = node_user.view_account(account_id).unwrap(); let initial_balance = account.amount; let fee_helper = fee_helper(&node); @@ -973,12 +972,12 @@ pub fn test_delete_access_key_with_allowance(node: impl Node) { add_access_key(&node, node_user.as_ref(), &access_key, &signer2); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_ok()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_ok()); let root = node_user.get_state_root(); let delete_access_key_cost = fee_helper.delete_key_cost(); let transaction_result = - node_user.delete_key(account_id.clone(), signer2.public_key.clone()).unwrap(); + node_user.delete_key(account_id.clone(), signer2.public_key()).unwrap(); assert_eq!(transaction_result.status, FinalExecutionStatus::SuccessValue(Vec::new())); assert_eq!(transaction_result.receipts_outcome.len(), 1); let new_root = node_user.get_state_root(); @@ -988,7 +987,7 @@ pub fn test_delete_access_key_with_allowance(node: impl Node) { assert_eq!(account.amount, initial_balance - add_access_key_cost - delete_access_key_cost); assert!(node_user.get_access_key(account_id, &node.signer().public_key()).is_ok()); - assert!(node_user.get_access_key(account_id, &signer2.public_key).is_err()); + assert!(node_user.get_access_key(account_id, &signer2.public_key()).is_err()); } pub fn test_access_key_smart_contract(node: impl Node) { @@ -1002,7 +1001,8 @@ pub fn test_access_key_smart_contract(node: impl Node) { }; let mut node_user = node.user(); let account_id = &node.account_id().unwrap(); - let signer2 = Arc::new(InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519)); + let signer2 = + Arc::new(InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into()); add_access_key(&node, node_user.as_ref(), &access_key, &signer2); node_user.set_signer(signer2.clone()); @@ -1029,7 +1029,7 @@ pub fn test_access_key_smart_contract(node: impl Node) { let new_root = node_user.get_state_root(); assert_ne!(root, new_root); - let view_access_key = node_user.get_access_key(account_id, &signer2.public_key).unwrap(); + let view_access_key = node_user.get_access_key(account_id, &signer2.public_key()).unwrap(); assert_eq!( view_access_key, AccessKey { @@ -1055,7 +1055,7 @@ pub fn test_access_key_smart_contract_reject_method_name(node: impl Node) { }; let mut node_user = node.user(); let account_id = &node.account_id().unwrap(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); add_access_key(&node, node_user.as_ref(), &access_key, &signer2); node_user.set_signer(Arc::new(signer2)); @@ -1083,7 +1083,7 @@ pub fn test_access_key_smart_contract_reject_contract_id(node: impl Node) { }; let mut node_user = node.user(); let account_id = &node.account_id().unwrap(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); add_access_key(&node, node_user.as_ref(), &access_key, &signer2); node_user.set_signer(Arc::new(signer2)); @@ -1119,7 +1119,7 @@ pub fn test_access_key_reject_non_function_call(node: impl Node) { }), }; let mut node_user = node.user(); - let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519); + let signer2 = InMemorySigner::from_random("test".parse().unwrap(), KeyType::ED25519).into(); add_access_key(&node, node_user.as_ref(), &access_key, &signer2); node_user.set_signer(Arc::new(signer2)); @@ -1205,11 +1205,9 @@ pub fn test_unstake_while_not_staked(node: impl Node) { pub fn test_fail_not_enough_balance_for_storage(node: impl Node) { let mut node_user = node.user(); let account_id = bob_account(); - let signer = Arc::new(InMemorySigner::from_seed( - account_id.clone(), - KeyType::ED25519, - account_id.as_ref(), - )); + let signer = Arc::new( + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()).into(), + ); node_user.set_signer(signer); node_user.send_money(account_id, alice_account(), 10).unwrap_err(); } diff --git a/integration-tests/src/tests/test_errors.rs b/integration-tests/src/tests/test_errors.rs index 9fbd1d67f8a..c3dfda51e63 100644 --- a/integration-tests/src/tests/test_errors.rs +++ b/integration-tests/src/tests/test_errors.rs @@ -33,7 +33,7 @@ fn start_node() -> ThreadNode { fn test_check_tx_error_log() { let node = start_node(); let signer = - Arc::new(InMemorySigner::from_seed(alice_account(), KeyType::ED25519, "alice.near")); + Arc::new(InMemorySigner::from_seed(alice_account(), KeyType::ED25519, "alice.near").into()); let block_hash = node.user().get_best_block_hash().unwrap(); let tx = SignedTransaction::from_actions( 1, @@ -44,7 +44,7 @@ fn test_check_tx_error_log() { Action::CreateAccount(CreateAccountAction {}), Action::Transfer(TransferAction { deposit: 1_000 }), Action::AddKey(Box::new(AddKeyAction { - public_key: signer.public_key.clone(), + public_key: signer.public_key(), access_key: AccessKey::full_access(), })), ], @@ -57,7 +57,7 @@ fn test_check_tx_error_log() { tx_result, InvalidTxError::InvalidAccessKeyError(InvalidAccessKeyError::AccessKeyNotFound { account_id: bob_account(), - public_key: signer.public_key.clone().into() + public_key: Box::new(signer.public_key()), }) .rpc_into() ); @@ -73,19 +73,19 @@ fn test_deliver_tx_error_log() { node.genesis().config.min_gas_price, ); let signer = - Arc::new(InMemorySigner::from_seed(alice_account(), KeyType::ED25519, "alice.near")); + Arc::new(InMemorySigner::from_seed(alice_account(), KeyType::ED25519, "alice.near").into()); let block_hash = node.user().get_best_block_hash().unwrap(); let cost = fee_helper.create_account_transfer_full_key_cost_no_reward(); let tx = SignedTransaction::from_actions( 1, alice_account(), "test.near".parse().unwrap(), - &*signer, + &signer, vec![ Action::CreateAccount(CreateAccountAction {}), Action::Transfer(TransferAction { deposit: TESTING_INIT_BALANCE + 1 }), Action::AddKey(Box::new(AddKeyAction { - public_key: signer.public_key.clone(), + public_key: signer.public_key(), access_key: AccessKey::full_access(), })), ], diff --git a/integration-tests/src/user/mod.rs b/integration-tests/src/user/mod.rs index e489aa4887d..e0b65ca549d 100644 --- a/integration-tests/src/user/mod.rs +++ b/integration-tests/src/user/mod.rs @@ -88,9 +88,9 @@ pub trait User { public_key: &PublicKey, ) -> Result; - fn signer(&self) -> Arc; + fn signer(&self) -> Arc; - fn set_signer(&mut self, signer: Arc); + fn set_signer(&mut self, signer: Arc); fn sign_and_commit_actions( &self, diff --git a/integration-tests/src/user/rpc_user.rs b/integration-tests/src/user/rpc_user.rs index 151a29dc650..6b0a445976c 100644 --- a/integration-tests/src/user/rpc_user.rs +++ b/integration-tests/src/user/rpc_user.rs @@ -28,7 +28,7 @@ use crate::user::User; pub struct RpcUser { account_id: AccountId, - signer: Arc, + signer: Arc, addr: String, } @@ -43,7 +43,7 @@ impl RpcUser { .block_on(async move { f(new_client(&format!("http://{}", addr))).await }) } - pub fn new(addr: &str, account_id: AccountId, signer: Arc) -> RpcUser { + pub fn new(addr: &str, account_id: AccountId, signer: Arc) -> RpcUser { RpcUser { account_id, addr: addr.to_owned(), signer } } @@ -222,11 +222,11 @@ impl User for RpcUser { } } - fn signer(&self) -> Arc { + fn signer(&self) -> Arc { self.signer.clone() } - fn set_signer(&mut self, signer: Arc) { + fn set_signer(&mut self, signer: Arc) { self.signer = signer; } } diff --git a/integration-tests/src/user/runtime_user.rs b/integration-tests/src/user/runtime_user.rs index b10663c96d6..51aa8f5a04c 100644 --- a/integration-tests/src/user/runtime_user.rs +++ b/integration-tests/src/user/runtime_user.rs @@ -44,7 +44,7 @@ impl MockClient { pub struct RuntimeUser { pub account_id: AccountId, - pub signer: Arc, + pub signer: Arc, pub trie_viewer: TrieViewer, pub client: Arc>, // Store results of applying transactions/receipts @@ -59,7 +59,7 @@ pub struct RuntimeUser { impl RuntimeUser { pub fn new( account_id: AccountId, - signer: Arc, + signer: Arc, client: Arc>, ) -> Self { let runtime_config = Arc::new(client.read().unwrap().runtime_config.clone()); @@ -390,11 +390,11 @@ impl User for RuntimeUser { .map_err(|err| err.to_string()) } - fn signer(&self) -> Arc { + fn signer(&self) -> Arc { self.signer.clone() } - fn set_signer(&mut self, signer: Arc) { + fn set_signer(&mut self, signer: Arc) { self.signer = signer; } } diff --git a/nearcore/src/config.rs b/nearcore/src/config.rs index 7c2830579de..f8a2abe1e42 100644 --- a/nearcore/src/config.rs +++ b/nearcore/src/config.rs @@ -28,7 +28,7 @@ use near_chain_configs::{ PROTOCOL_UPGRADE_STAKE_THRESHOLD, TRANSACTION_VALIDITY_PERIOD, }; use near_config_utils::{ValidationError, ValidationErrors}; -use near_crypto::{InMemorySigner, KeyFile, KeyType, PublicKey, Signer}; +use near_crypto::{InMemorySigner, KeyFile, KeyType, PublicKey}; use near_epoch_manager::EpochManagerHandle; #[cfg(feature = "json_rpc")] use near_jsonrpc::RpcConfig; @@ -504,7 +504,7 @@ pub struct NearConfig { pub rosetta_rpc_config: Option, pub telemetry_config: TelemetryConfig, pub genesis: Genesis, - pub validator_signer: Option>, + pub validator_signer: Option>, } impl NearConfig { @@ -512,7 +512,7 @@ impl NearConfig { config: Config, genesis: Genesis, network_key_pair: KeyFile, - validator_signer: Option>, + validator_signer: Option>, ) -> anyhow::Result { Ok(NearConfig { config: config.clone(), @@ -1016,7 +1016,7 @@ pub fn create_testnet_configs_from_seeds( local_ports: bool, archive: bool, tracked_shards: Vec, -) -> (Vec, Vec, Vec, Genesis) { +) -> (Vec, Vec, Vec, Genesis) { let num_validator_seats = (seeds.len() - num_non_validator_seats as usize) as NumSeats; let validator_signers = seeds.iter().map(|seed| create_test_signer(seed.as_str())).collect::>(); @@ -1076,8 +1076,7 @@ pub fn create_testnet_configs( local_ports: bool, archive: bool, tracked_shards: Vec, -) -> (Vec, Vec, Vec, Genesis, Vec) -{ +) -> (Vec, Vec, Vec, Genesis, Vec) { let shard_keys = vec![]; let (configs, validator_signers, network_signers, genesis) = create_testnet_configs_from_seeds( (0..(num_validator_seats + num_non_validator_seats)) @@ -1238,7 +1237,7 @@ pub fn load_config( let validator_file = dir.join(&config.validator_key_file); let validator_signer = if validator_file.exists() { match InMemoryValidatorSigner::from_file(&validator_file) { - Ok(signer) => Some(Arc::new(signer) as Arc), + Ok(signer) => Some(Arc::new(signer.into())), Err(_) => { let error_message = format!( "Failed initializing validator signer from {}", @@ -1330,7 +1329,7 @@ pub fn load_test_config(seed: &str, addr: tcp::ListenerAddr, genesis: Genesis) - } else { let signer = Arc::new(InMemorySigner::from_seed(seed.parse().unwrap(), KeyType::ED25519, seed)); - let validator_signer = Arc::new(create_test_signer(seed)) as Arc; + let validator_signer = Arc::new(create_test_signer(seed)) as Arc; (signer, Some(validator_signer)) }; NearConfig::new(config, genesis, signer.into(), validator_signer).unwrap() diff --git a/nearcore/src/lib.rs b/nearcore/src/lib.rs index ada0ac8baaf..266b94482e5 100644 --- a/nearcore/src/lib.rs +++ b/nearcore/src/lib.rs @@ -439,7 +439,7 @@ pub fn start_with_config_and_synchronization( epoch_manager, shard_tracker, runtime, - account_id: config.validator_signer.as_ref().map(|signer| signer.validator_id().clone()), + account_id: config.validator_signer.map(|signer| signer.validator_id().clone()), dump_future_runner: StateSyncDumper::arbiter_dump_future_runner(), handle: None, }; diff --git a/nearcore/tests/economics.rs b/nearcore/tests/economics.rs index ca9b2dfe74f..ee529a12a61 100644 --- a/nearcore/tests/economics.rs +++ b/nearcore/tests/economics.rs @@ -80,7 +80,7 @@ fn test_burn_mint() { 1, "test0".parse().unwrap(), "test1".parse().unwrap(), - &signer, + &signer.into(), 1000, genesis_hash, ), diff --git a/runtime/runtime-params-estimator/src/action_costs.rs b/runtime/runtime-params-estimator/src/action_costs.rs index d886dd701df..51c5e8b291a 100644 --- a/runtime/runtime-params-estimator/src/action_costs.rs +++ b/runtime/runtime-params-estimator/src/action_costs.rs @@ -770,8 +770,8 @@ pub(crate) fn empty_delegate_action( max_block_height: 1000, public_key: signer.public_key.clone(), }; - let signature = - SignableMessage::new(&delegate_action, SignableMessageType::DelegateAction).sign(&signer); + let signature = SignableMessage::new(&delegate_action, SignableMessageType::DelegateAction) + .sign(&signer.into()); Action::Delegate(Box::new(near_primitives::action::delegate::SignedDelegateAction { delegate_action, signature, diff --git a/runtime/runtime-params-estimator/src/transaction_builder.rs b/runtime/runtime-params-estimator/src/transaction_builder.rs index 412fea0d5cd..c72d765716e 100644 --- a/runtime/runtime-params-estimator/src/transaction_builder.rs +++ b/runtime/runtime-params-estimator/src/transaction_builder.rs @@ -59,7 +59,7 @@ impl TransactionBuilder { nonce as u64, sender.clone(), receiver, - &signer, + &signer.into(), actions, CryptoHash::default(), 0, diff --git a/runtime/runtime/src/balance_checker.rs b/runtime/runtime/src/balance_checker.rs index 05ee2ac1042..61dbe56525e 100644 --- a/runtime/runtime/src/balance_checker.rs +++ b/runtime/runtime/src/balance_checker.rs @@ -569,7 +569,7 @@ mod tests { 0, sender, receiver, - &signer, + &signer.into(), deposit, CryptoHash::default(), ); diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 58ea83a9f3c..48b530d25ae 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -2308,7 +2308,7 @@ mod tests { fn create_receipt_with_actions( account_id: AccountId, - signer: Arc, + signer: Arc, actions: Vec, ) -> Receipt { Receipt::V0(ReceiptV0 { @@ -2364,8 +2364,7 @@ mod tests { initial_balance: Balance, initial_locked: Balance, gas_limit: Gas, - ) -> (Runtime, ShardTries, CryptoHash, ApplyState, Arc, impl EpochInfoProvider) - { + ) -> (Runtime, ShardTries, CryptoHash, ApplyState, Arc, impl EpochInfoProvider) { setup_runtime_for_shard( initial_balance, initial_locked, @@ -2379,17 +2378,15 @@ mod tests { initial_locked: Balance, gas_limit: Gas, shard_uid: ShardUId, - ) -> (Runtime, ShardTries, CryptoHash, ApplyState, Arc, impl EpochInfoProvider) - { + ) -> (Runtime, ShardTries, CryptoHash, ApplyState, Arc, impl EpochInfoProvider) { let tries = TestTriesBuilder::new().build(); let root = MerkleHash::default(); let runtime = Runtime::new(); let account_id = alice_account(); - let signer = Arc::new(InMemorySigner::from_seed( - account_id.clone(), - KeyType::ED25519, - account_id.as_ref(), - )); + let signer: Arc = Arc::new( + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()) + .into(), + ); let mut initial_state = tries.new_trie_update(shard_uid, root); let mut initial_account = account_new(initial_balance, hash(&[])); diff --git a/runtime/runtime/src/verifier.rs b/runtime/runtime/src/verifier.rs index 236f93d3a19..81dd2133856 100644 --- a/runtime/runtime/src/verifier.rs +++ b/runtime/runtime/src/verifier.rs @@ -619,7 +619,7 @@ mod tests { initial_balance: Balance, initial_locked: Balance, access_key: Option, - ) -> (Arc, TrieUpdate, Balance) { + ) -> (Arc, TrieUpdate, Balance) { let access_keys = if let Some(key) = access_key { vec![key] } else { vec![] }; setup_accounts(vec![( alice_account(), @@ -635,16 +635,15 @@ mod tests { // two bools: first one is whether the account has a contract, second one is whether the // account has data accounts: Vec<(AccountId, Balance, Balance, Vec, bool, bool)>, - ) -> (Arc, TrieUpdate, Balance) { + ) -> (Arc, TrieUpdate, Balance) { let tries = TestTriesBuilder::new().build(); let root = MerkleHash::default(); let account_id = alice_account(); - let signer = Arc::new(InMemorySigner::from_seed( - account_id.clone(), - KeyType::ED25519, - account_id.as_ref(), - )); + let signer: Arc = Arc::new( + InMemorySigner::from_seed(account_id.clone(), KeyType::ED25519, account_id.as_ref()) + .into(), + ); let mut initial_state = tries.new_trie_update(ShardUId::single_shard(), root); for (account_id, initial_balance, initial_locked, access_keys, has_contract, has_data) in diff --git a/runtime/runtime/tests/test_async_calls.rs b/runtime/runtime/tests/test_async_calls.rs index d849cefd239..7ddaa5b4d9a 100644 --- a/runtime/runtime/tests/test_async_calls.rs +++ b/runtime/runtime/tests/test_async_calls.rs @@ -29,7 +29,7 @@ fn test_simple_func_call() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "sum_n".to_string(), args: 10u64.to_le_bytes().to_vec(), @@ -76,7 +76,7 @@ fn test_single_promise_no_callback() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -143,7 +143,7 @@ fn test_single_promise_with_callback() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -228,7 +228,7 @@ fn test_two_promises_no_callbacks() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -323,7 +323,7 @@ fn test_two_promises_with_two_callbacks() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -415,7 +415,7 @@ fn test_single_promise_no_callback_batch() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -488,7 +488,7 @@ fn test_single_promise_with_callback_batch() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -563,7 +563,7 @@ fn test_simple_transfer() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -631,7 +631,7 @@ fn test_create_account_with_transfer_and_full_key() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -744,7 +744,7 @@ fn test_account_factory() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -891,7 +891,7 @@ fn test_create_account_add_key_call_delete_key_delete_account() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -986,7 +986,7 @@ fn test_transfer_64len_hex() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), @@ -1053,7 +1053,7 @@ fn test_create_transfer_64len_hex_fail() { 1, signer_sender.account_id.clone(), signer_receiver.account_id, - &signer_sender, + &signer_sender.into(), vec![Action::FunctionCall(Box::new(FunctionCallAction { method_name: "call_promise".to_string(), args: serde_json::to_vec(&data).unwrap(), diff --git a/test-utils/runtime-tester/src/run_test.rs b/test-utils/runtime-tester/src/run_test.rs index 56540ba0b06..12ff6b5602e 100644 --- a/test-utils/runtime-tester/src/run_test.rs +++ b/test-utils/runtime-tester/src/run_test.rs @@ -182,7 +182,7 @@ impl TransactionConfig { self.nonce, self.signer_id.clone(), self.receiver_id.clone(), - &self.signer, + &self.signer.clone().into(), self.actions.clone(), *last_block.hash(), 0, diff --git a/tools/mock-node/src/setup.rs b/tools/mock-node/src/setup.rs index 4d7d972befa..36de5dc4e38 100644 --- a/tools/mock-node/src/setup.rs +++ b/tools/mock-node/src/setup.rs @@ -351,7 +351,7 @@ mod tests { gen_account_from_alphabet(&mut rng, b"abcdefghijklmn"), 5 * NEAR_BASE, signer0.public_key.clone(), - &signer0, + &signer0.into(), block.header.hash, ); spawn_interruptible( diff --git a/tools/restaked/src/main.rs b/tools/restaked/src/main.rs index 6a5de2b11ee..0f18636b531 100644 --- a/tools/restaked/src/main.rs +++ b/tools/restaked/src/main.rs @@ -86,8 +86,9 @@ fn main() { signer.account_id, key_file.account_id, "Only can stake for the same account as given signer key" ); + let signer = Arc::new(signer.into()); - let user = RpcUser::new(rpc_url, account_id.clone(), Arc::new(signer)); + let user = RpcUser::new(rpc_url, account_id.clone(), signer); loop { let validators = user.validators(None).unwrap(); // Check: diff --git a/tools/state-viewer/src/apply_chain_range.rs b/tools/state-viewer/src/apply_chain_range.rs index 54b5e8bace2..8e24857d2ef 100644 --- a/tools/state-viewer/src/apply_chain_range.rs +++ b/tools/state-viewer/src/apply_chain_range.rs @@ -607,13 +607,14 @@ mod test { let epoch_length = 4; let (store, genesis, mut env) = setup(epoch_length); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -649,13 +650,14 @@ mod test { let epoch_length = 4; let (store, genesis, mut env) = setup(epoch_length); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); diff --git a/tools/state-viewer/src/apply_chunk.rs b/tools/state-viewer/src/apply_chunk.rs index 9f12d4c66fb..6c35fb50e0d 100644 --- a/tools/state-viewer/src/apply_chunk.rs +++ b/tools/state-viewer/src/apply_chunk.rs @@ -508,7 +508,7 @@ mod test { height, from.parse().unwrap(), to.parse().unwrap(), - signer, + &signer.clone().into(), 100, hash, ); diff --git a/tools/state-viewer/src/contract_accounts.rs b/tools/state-viewer/src/contract_accounts.rs index dabc88dcf0a..11d109fc570 100644 --- a/tools/state-viewer/src/contract_accounts.rs +++ b/tools/state-viewer/src/contract_accounts.rs @@ -492,7 +492,7 @@ impl ContractAccountFilter { mod tests { use super::{ContractAccount, ContractAccountFilter, Summary}; use borsh::BorshSerialize; - use near_crypto::{InMemorySigner, Signer}; + use near_crypto::InMemorySigner; use near_primitives::hash::CryptoHash; use near_primitives::receipt::{ActionReceipt, Receipt, ReceiptEnum, ReceiptV0}; use near_primitives::transaction::{ diff --git a/tools/state-viewer/src/state_dump.rs b/tools/state-viewer/src/state_dump.rs index e79a6bcc23b..9df1dda58a9 100644 --- a/tools/state-viewer/src/state_dump.rs +++ b/tools/state-viewer/src/state_dump.rs @@ -356,10 +356,10 @@ mod test { public_key: PublicKey::empty(KeyType::ED25519), secret_key: SecretKey::from_random(KeyType::ED25519), }, - Some(Arc::new(InMemoryValidatorSigner::from_random( - "test".parse().unwrap(), - KeyType::ED25519, - ))), + Some(Arc::new( + InMemoryValidatorSigner::from_random("test".parse().unwrap(), KeyType::ED25519) + .into(), + )), ) .unwrap(); @@ -394,13 +394,14 @@ mod test { let epoch_length = 4; let (store, genesis, mut env, near_config) = setup(epoch_length, PROTOCOL_VERSION, false); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -448,7 +449,7 @@ mod test { let genesis_hash = *env.clients[0].chain.genesis().hash(); let signer0 = - InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0").into(); let tx00 = SignedTransaction::from_actions( 1, "test0".parse().unwrap(), @@ -465,20 +466,20 @@ mod test { "test0".parse().unwrap(), &signer0, TESTING_INIT_STAKE, - signer0.public_key.clone(), + signer0.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx00, false, false), ProcessTxResponse::ValidTx); assert_eq!(env.clients[0].process_tx(tx01, false, false), ProcessTxResponse::ValidTx); let signer1 = - InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx1 = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer1, TESTING_INIT_STAKE, - signer1.public_key.clone(), + signer1.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx1, false, false), ProcessTxResponse::ValidTx); @@ -535,13 +536,14 @@ mod test { let epoch_length = 4; let (store, genesis, mut env, near_config) = setup(epoch_length, PROTOCOL_VERSION, false); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -586,13 +588,14 @@ mod test { let epoch_length = 4; let (store, genesis, mut env, near_config) = setup(epoch_length, PROTOCOL_VERSION, false); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -720,7 +723,7 @@ mod test { 1, "test1".parse().unwrap(), "test0".parse().unwrap(), - &signer, + &signer.into(), 1, genesis_hash, ); @@ -744,10 +747,10 @@ mod test { public_key: PublicKey::empty(KeyType::ED25519), secret_key: SecretKey::from_random(KeyType::ED25519), }, - Some(Arc::new(InMemoryValidatorSigner::from_random( - "test".parse().unwrap(), - KeyType::ED25519, - ))), + Some(Arc::new( + InMemoryValidatorSigner::from_random("test".parse().unwrap(), KeyType::ED25519) + .into(), + )), ) .unwrap(); @@ -791,13 +794,14 @@ mod test { .runtimes(vec![nightshade_runtime]) .build(); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); @@ -812,10 +816,10 @@ mod test { public_key: PublicKey::empty(KeyType::ED25519), secret_key: SecretKey::from_random(KeyType::ED25519), }, - Some(Arc::new(InMemoryValidatorSigner::from_random( - "test".parse().unwrap(), - KeyType::ED25519, - ))), + Some(Arc::new( + InMemoryValidatorSigner::from_random("test".parse().unwrap(), KeyType::ED25519) + .into(), + )), ) .unwrap(); let head = env.clients[0].chain.head().unwrap(); @@ -858,13 +862,14 @@ mod test { let (store, genesis, mut env, near_config) = setup(epoch_length, PROTOCOL_VERSION, false); let genesis_hash = *env.clients[0].chain.genesis().hash(); - let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1"); + let signer = + InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1").into(); let tx = SignedTransaction::stake( 1, "test1".parse().unwrap(), &signer, TESTING_INIT_STAKE, - signer.public_key.clone(), + signer.public_key(), genesis_hash, ); assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx);