Skip to content

Commit

Permalink
Reverse some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Jul 21, 2021
1 parent c733e45 commit 9ef9e01
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 83 deletions.
16 changes: 8 additions & 8 deletions core/bin/prover/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl ApiClient {
#[async_trait::async_trait]
impl crate::ApiClient for ApiClient {
async fn get_job(&self, req: ProverInputRequest) -> anyhow::Result<ProverInputResponse> {
let operation = (|| async {
let operation = || async {
vlog::trace!("get prover job");

let response = self
Expand All @@ -116,13 +116,13 @@ impl crate::ApiClient for ApiClient {
.json()
.await
.map_err(|e| Transient(format_err!("failed parse json on get job request: {}", e)))
});
};

self.with_retries(operation).await
}

async fn working_on(&self, job_id: i32, prover_name: &str) -> anyhow::Result<()> {
let operation = (|| async {
let operation = || async {
log::trace!(
"sending working_on job_id: {}, prover_name: {}",
job_id,
Expand All @@ -146,13 +146,13 @@ impl crate::ApiClient for ApiClient {
}

Ok(())
});
};

self.with_retries(operation).await
}

async fn publish(&self, data: ProverOutputRequest) -> anyhow::Result<()> {
let operation = (|| async {
let operation = || async {
log::trace!("Trying publish proof: {:?}", data);

let response = self
Expand All @@ -169,13 +169,13 @@ impl crate::ApiClient for ApiClient {
}

Ok(())
});
};

self.with_retries(operation).await
}

async fn prover_stopped(&self, prover_name: String) -> anyhow::Result<()> {
let operation = (|| async {
let operation = || async {
let response = self
.http_client
.post(self.stopped_url.clone())
Expand All @@ -194,7 +194,7 @@ impl crate::ApiClient for ApiClient {
}

Ok(())
});
};

self.with_retries(operation).await
}
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/eth_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
.await
.expect("Check failed");

assert_eq!(result, true, "Signature is incorrect");
assert!(result, "Signature is incorrect");
}

/// This test checks that the actual signature data taken from
Expand Down
6 changes: 3 additions & 3 deletions core/bin/zksync_api/src/fee_ticker/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ mod tests {
.token_allowed(TokenLike::Address(eth_address))
.await
.unwrap();
assert_eq!(dai_allowed, true);
assert_eq!(phnx_allowed, false);
assert_eq!(eth_allowed, true);
assert!(dai_allowed);
assert!(!phnx_allowed);
assert!(eth_allowed);
assert!(validator.tokens.get(&dai_token_address).unwrap().allowed);
assert!(!validator.tokens.get(&phnx_token_address).unwrap().allowed);
}
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_core/src/committer/aggregated_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async fn is_fast_processing_requested(
break;
}
}
return Ok(fast_processing);
Ok(fast_processing)
}

async fn create_aggregated_commits_storage(
Expand Down
6 changes: 3 additions & 3 deletions core/bin/zksync_core/src/state_keeper/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn create_account_and_fast_withdrawal<B: Into<BigUint>>(
)
}

#[allow(clippy::clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments)]
fn create_account_and_withdrawal_impl<B: Into<BigUint>>(
tester: &mut StateKeeperTester,
token_id: TokenId,
Expand Down Expand Up @@ -337,8 +337,8 @@ mod apply_tx {
let pending_block = tester.state_keeper.pending_block;

assert!(result.is_ok());
assert_eq!(old_pending_block.fast_processing_required, false);
assert_eq!(pending_block.fast_processing_required, true);
assert!(!old_pending_block.fast_processing_required);
assert!(pending_block.fast_processing_required);
}

/// Checks if withdrawal that will fail is processed correctly
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_eth_sender/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl DatabaseInterface for MockDatabase {
let eth_operations = self.eth_operations.read().await.clone();

// Consider an operation that affects sequential blocks.
let maybe_operation = eth_operations.iter().find(|(eth_operation)| {
let maybe_operation = eth_operations.iter().find(|eth_operation| {
let op_block_range = eth_operation.op.as_ref().unwrap().1.get_block_range();

op_block_range.1 == first_block - 1
Expand Down
5 changes: 2 additions & 3 deletions core/bin/zksync_witness_generator/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,9 @@ impl DatabaseInterface for MockDatabase {
) -> anyhow::Result<()> {
let witness_str = serde_json::to_string(&witness).expect("Failed to serialize witness");
let mut block_witness = self.block_witness.write().await;
let is_block_not_saved_yet = block_witness
let is_block_not_saved_yet = !block_witness
.iter()
.find(|witness| witness.block == *block as i64)
.is_none();
.any(|witness| witness.block == *block as i64);

if is_block_not_saved_yet {
block_witness.push(StorageBlockWitness {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/change_pubkey_offchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Witness for ChangePubkeyOffChainWitness<Bn256> {
let change_pubkey_data = ChangePubkeyOffChainData {
account_id: *change_pubkey_offchain.account_id,
address: eth_address_to_fr(&change_pubkey_offchain.tx.account),
new_pubkey_hash: change_pubkey_offchain.tx.new_pk_hash.to_fr(),
new_pubkey_hash: change_pubkey_offchain.tx.new_pk_hash.as_fr(),
fee_token: *change_pubkey_offchain.tx.fee_token as u32,
fee: change_pubkey_offchain.tx.fee.to_u128().unwrap(),
nonce: fr_from(change_pubkey_offchain.tx.nonce),
Expand Down
3 changes: 1 addition & 2 deletions core/lib/storage/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ impl<'a, 'c> EventSchema<'a, 'c> {
},
)
})
.filter(|x| x.is_some())
.map(|x| x.unwrap())
.flatten()
.collect();

transaction
Expand Down
10 changes: 2 additions & 8 deletions core/lib/storage/src/tests/chain/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ async fn contains_and_get_tx(mut storage: StorageProcessor<'_>) -> QueryResult<(
for tx in &txs {
let tx_hash = tx.hash();

assert_eq!(
MempoolSchema(&mut storage).contains_tx(tx_hash).await?,
false
);
assert!(!MempoolSchema(&mut storage).contains_tx(tx_hash).await?);
assert!(MempoolSchema(&mut storage).get_tx(tx_hash).await?.is_none());
}

Expand All @@ -338,10 +335,7 @@ async fn contains_and_get_tx(mut storage: StorageProcessor<'_>) -> QueryResult<(
for tx in &txs {
let tx_hash = tx.hash();

assert_eq!(
MempoolSchema(&mut storage).contains_tx(tx_hash).await?,
true
);
assert!(MempoolSchema(&mut storage).contains_tx(tx_hash).await?);
assert_eq!(
MempoolSchema(&mut storage)
.get_tx(tx_hash)
Expand Down
6 changes: 3 additions & 3 deletions core/lib/storage/src/tests/chain/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn aggregated_operations(mut storage: StorageProcessor<'_>) -> QueryResult
assert_eq!(stored_operation.from_block, 1);
assert_eq!(stored_operation.to_block, 1);
assert_eq!(stored_operation.action_type, action_type.to_string());
assert_eq!(stored_operation.confirmed, false);
assert!(!stored_operation.confirmed);

Ok(())
}
Expand Down Expand Up @@ -248,7 +248,7 @@ async fn transaction_resent(mut storage: StorageProcessor<'_>) -> QueryResult<()
.await?
.unwrap();
assert_eq!(loaded_tx.tx_hash, executed_tx.tx_hash);
assert_eq!(loaded_tx.success, true);
assert!(loaded_tx.success);

// Get the block transactions and check if there is exactly 1 tx (failed tx not copied but replaced).
let block_txs = BlockSchema(&mut storage)
Expand All @@ -268,7 +268,7 @@ async fn transaction_resent(mut storage: StorageProcessor<'_>) -> QueryResult<()
.await?
.unwrap();
assert_eq!(loaded_tx.tx_hash, executed_tx.tx_hash);
assert_eq!(loaded_tx.success, true);
assert!(loaded_tx.success);

// ...and there still must be one operation.
let block_txs = BlockSchema(&mut storage)
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl From<Account> for CircuitAccount<super::Engine> {
}

circuit_account.nonce = Fr::from_str(&acc.nonce.to_string()).unwrap();
circuit_account.pub_key_hash = acc.pub_key_hash.to_fr();
circuit_account.pub_key_hash = acc.pub_key_hash.as_fr();
circuit_account.address = eth_address_to_fr(&acc.address);
circuit_account
}
Expand Down
10 changes: 5 additions & 5 deletions core/lib/types/src/account/pubkey_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct PubKeyHash {

impl std::fmt::Debug for PubKeyHash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_hex())
write!(f, "{}", self.as_hex())
}
}

Expand All @@ -47,9 +47,9 @@ impl PubKeyHash {
/// use zksync_types::account::PubKeyHash;
///
/// let pubkey_hash = PubKeyHash::zero();
/// assert_eq!(pubkey_hash.to_hex(), "sync:0000000000000000000000000000000000000000");
/// assert_eq!(pubkey_hash.as_hex(), "sync:0000000000000000000000000000000000000000");
/// ```
pub fn to_hex(&self) -> String {
pub fn as_hex(&self) -> String {
format!("sync:{}", hex::encode(&self.data))
}

Expand Down Expand Up @@ -92,7 +92,7 @@ impl PubKeyHash {
}

/// Converts the `PubKeyhash` into the field element.
pub fn to_fr(&self) -> Fr {
pub fn as_fr(&self) -> Fr {
ff::from_hex(&format!("0x{}", hex::encode(&self.data))).unwrap()
}

Expand All @@ -108,7 +108,7 @@ impl Serialize for PubKeyHash {
where
S: Serializer,
{
serializer.serialize_str(&self.to_hex())
serializer.serialize_str(&self.as_hex())
}
}

Expand Down
22 changes: 5 additions & 17 deletions core/lib/types/src/operations/full_exit_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,10 @@ impl FullExitOp {
.unwrap()
.to_be_bytes(),
);
data.extend_from_slice(
&self
.creator_account_id
.clone()
.unwrap_or_default()
.to_be_bytes(),
);
data.extend_from_slice(&self.creator_address.clone().unwrap_or_default().as_bytes());
data.extend_from_slice(&self.serial_id.clone().unwrap_or_default().to_be_bytes());
data.extend_from_slice(&self.content_hash.clone().unwrap_or_default().as_bytes());
data.extend_from_slice(&self.creator_account_id.unwrap_or_default().to_be_bytes());
data.extend_from_slice(&self.creator_address.unwrap_or_default().as_bytes());
data.extend_from_slice(&self.serial_id.unwrap_or_default().to_be_bytes());
data.extend_from_slice(&self.content_hash.unwrap_or_default().as_bytes());
data.resize(Self::CHUNKS * CHUNK_BYTES, 0x00);
data
}
Expand All @@ -77,13 +71,7 @@ impl FullExitOp {
.unwrap_or(0)
.to_be_bytes(),
);
data.extend_from_slice(
&self
.creator_account_id
.clone()
.unwrap_or_default()
.to_be_bytes(),
);
data.extend_from_slice(&self.creator_account_id.unwrap_or_default().to_be_bytes());
data
}

Expand Down
4 changes: 2 additions & 2 deletions core/lib/types/src/tx/change_pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl ChangePubKey {
out.extend_from_slice(&pack_fee_amount(&self.fee));
out.extend_from_slice(&self.nonce.to_be_bytes());
if let Some(time_range) = &self.time_range {
out.extend_from_slice(&time_range.to_be_bytes());
out.extend_from_slice(&time_range.as_be_bytes());
}
out
}
Expand All @@ -287,7 +287,7 @@ impl ChangePubKey {
out.extend_from_slice(&pack_fee_amount(&self.fee));
out.extend_from_slice(&self.nonce.to_be_bytes());
if let Some(time_range) = &self.time_range {
out.extend_from_slice(&time_range.to_be_bytes());
out.extend_from_slice(&time_range.as_be_bytes());
}
out
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/tx/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Close {
out.extend_from_slice(&[Self::TX_TYPE]);
out.extend_from_slice(&self.account.as_bytes());
out.extend_from_slice(&self.nonce.to_be_bytes());
out.extend_from_slice(&self.time_range.to_be_bytes());
out.extend_from_slice(&self.time_range.as_be_bytes());
out
}

Expand Down
4 changes: 2 additions & 2 deletions core/lib/types/src/tx/forced_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl ForcedExit {
out.extend_from_slice(&(self.token.0 as u16).to_be_bytes());
out.extend_from_slice(&pack_fee_amount(&self.fee));
out.extend_from_slice(&self.nonce.to_be_bytes());
out.extend_from_slice(&self.time_range.to_be_bytes());
out.extend_from_slice(&self.time_range.as_be_bytes());
out
}

Expand All @@ -138,7 +138,7 @@ impl ForcedExit {
out.extend_from_slice(&self.token.to_be_bytes());
out.extend_from_slice(&pack_fee_amount(&self.fee));
out.extend_from_slice(&self.nonce.to_be_bytes());
out.extend_from_slice(&self.time_range.to_be_bytes());
out.extend_from_slice(&self.time_range.as_be_bytes());
out
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/tx/primitives/time_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl TimeRange {
}
}

pub fn to_be_bytes(&self) -> [u8; 16] {
pub fn as_be_bytes(&self) -> [u8; 16] {
[
self.valid_from.to_be_bytes(),
self.valid_until.to_be_bytes(),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/tx/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Order {
out.extend_from_slice(&pad_front(&self.price.0.to_bytes_be(), PRICE_BIT_WIDTH / 8));
out.extend_from_slice(&pad_front(&self.price.1.to_bytes_be(), PRICE_BIT_WIDTH / 8));
out.extend_from_slice(&pack_token_amount(&self.amount));
out.extend_from_slice(&self.time_range.to_be_bytes());
out.extend_from_slice(&self.time_range.as_be_bytes());
out
}

Expand Down
8 changes: 4 additions & 4 deletions core/lib/types/src/tx/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn test_print_transfer_for_protocol() {
transfer
.time_range
.expect("no time range on transfer")
.to_be_bytes()
.as_be_bytes()
.to_vec(),
),
];
Expand Down Expand Up @@ -141,7 +141,7 @@ fn test_print_change_pub_key_for_protocol() {
transfer
.time_range
.expect("no time range on transfer")
.to_be_bytes()
.as_be_bytes()
.to_vec(),
),
];
Expand Down Expand Up @@ -204,7 +204,7 @@ fn test_print_withdraw_for_protocol() {
withdraw
.time_range
.expect("no time range on withdraw")
.to_be_bytes()
.as_be_bytes()
.to_vec(),
),
];
Expand Down Expand Up @@ -259,7 +259,7 @@ fn test_print_withdraw_nft_for_protocol() {
("fee_token", withdraw.fee_token.to_be_bytes().to_vec()),
("fee", pack_fee_amount(&withdraw.fee)),
("nonce", withdraw.nonce.to_be_bytes().to_vec()),
("time_range", withdraw.time_range.to_be_bytes().to_vec()),
("time_range", withdraw.time_range.as_be_bytes().to_vec()),
];
println!("Signed transaction fields:");
let mut field_concat = Vec::new();
Expand Down
Loading

0 comments on commit 9ef9e01

Please sign in to comment.