Skip to content

Commit

Permalink
fix backward compat for some batches
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Feb 6, 2021
1 parent 2dd3ef3 commit e5c0cba
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
8 changes: 4 additions & 4 deletions core/bin/zksync_api/src/api_server/rest/v1/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async fn submit_tx_batch(
let signatures = body.signature;
let tx_hashes = data
.tx_sender
.submit_txs_batch(txs, signatures)
.submit_txs_batch(txs, Some(signatures))
.await
.map_err(ApiError::from)?;

Expand Down Expand Up @@ -643,7 +643,7 @@ mod tests {
let batch_signature = {
let batch_message = EthBatchSignData::get_batch_sign_message(txs);
let eth_sig = PackedEthSignature::sign(&acc.eth_private_key, &batch_message).unwrap();
let single_signature = Some(TxEthSignature::EthereumSignature(eth_sig));
let single_signature = TxEthSignature::EthereumSignature(eth_sig);

EthBatchSignatures::Single(single_signature)
};
Expand Down Expand Up @@ -709,7 +709,7 @@ mod tests {
let batch_signature = {
let batch_message = EthBatchSignData::get_batch_sign_message(txs);
let eth_sig = PackedEthSignature::sign(&from.eth_private_key, &batch_message).unwrap();
let single_signature = Some(TxEthSignature::EthereumSignature(eth_sig));
let single_signature = TxEthSignature::EthereumSignature(eth_sig);

EthBatchSignatures::Single(single_signature)
};
Expand Down Expand Up @@ -758,7 +758,7 @@ mod tests {
let batch_signature = {
let batch_message = EthBatchSignData::get_batch_sign_message(txs);
let eth_sig = PackedEthSignature::sign(&from.eth_private_key, &batch_message).unwrap();
let single_signature = Some(TxEthSignature::EthereumSignature(eth_sig));
let single_signature = TxEthSignature::EthereumSignature(eth_sig);

EthBatchSignatures::Single(single_signature)
};
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/api_server/rpc_server/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl RpcApp {
pub async fn _impl_submit_txs_batch(
self,
txs: Vec<TxWithSignature>,
eth_signatures: EthBatchSignatures,
eth_signatures: Option<EthBatchSignatures>,
) -> Result<Vec<TxHash>> {
let start = Instant::now();
let result = self
Expand Down
4 changes: 2 additions & 2 deletions core/bin/zksync_api/src/api_server/rpc_server/rpc_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait Rpc {
fn submit_txs_batch(
&self,
txs: Vec<TxWithSignature>,
eth_signatures: EthBatchSignatures,
eth_signatures: Option<EthBatchSignatures>,
) -> FutureResp<Vec<TxHash>>;

#[rpc(name = "contract_address", returns = "ContractAddressResp")]
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Rpc for RpcApp {
fn submit_txs_batch(
&self,
txs: Vec<TxWithSignature>,
eth_signatures: EthBatchSignatures,
eth_signatures: Option<EthBatchSignatures>,
) -> FutureResp<Vec<TxHash>> {
let handle = self.runtime_handle.clone();
let self_ = self.clone();
Expand Down
4 changes: 2 additions & 2 deletions core/bin/zksync_api/src/api_server/tx_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ impl TxSender {
pub async fn submit_txs_batch(
&self,
txs: Vec<TxWithSignature>,
eth_signatures: EthBatchSignatures,
eth_signatures: Option<EthBatchSignatures>,
) -> Result<Vec<TxHash>, SubmitError> {
// Bring the received signatures into a vector for simplified work.
let eth_signatures: Vec<_> = eth_signatures.into();
let eth_signatures = EthBatchSignatures::api_arg_to_vec(eth_signatures);

if txs.is_empty() {
return Err(SubmitError::TxAdd(TxAddError::EmptyBatch));
Expand Down
4 changes: 3 additions & 1 deletion core/bin/zksync_core/src/committer/aggregated_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ fn create_new_create_proof_operation(
let aggregate_proof_size = available_aggregate_proof_sizes
.iter()
.rev()
.find(|aggregate_size| *aggregate_size >= &new_blocks_with_proofs.len())
.find(|aggregate_size| {
*aggregate_size >= &std::cmp::min(new_blocks_with_proofs.len(), max_aggregate_size)
})
.cloned()
.expect("failed to find correct aggregate proof size");

Expand Down
19 changes: 8 additions & 11 deletions core/lib/types/src/tx/primitives/eth_batch_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ use serde::{Deserialize, Serialize};
#[serde(untagged)]
pub enum EthBatchSignatures {
/// Old version of the batch signature, represents a maximum of one signature for one batch.
Single(Option<TxEthSignature>),
Single(TxEthSignature),
/// New version of the batch signature, represents multiple signatures for one batch.
Multi(Vec<TxEthSignature>),
}

impl Into<Vec<TxEthSignature>> for EthBatchSignatures {
fn into(self) -> Vec<TxEthSignature> {
match self {
impl EthBatchSignatures {
pub fn api_arg_to_vec(api_argument: Option<EthBatchSignatures>) -> Vec<TxEthSignature> {
match api_argument {
// If the signature is one, then just wrap it around the vector
EthBatchSignatures::Single(single_signature) => {
if let Some(signature) = single_signature {
vec![signature]
} else {
Vec::new()
}
Some(EthBatchSignatures::Single(single_signature)) => {
vec![single_signature]
}
EthBatchSignatures::Multi(signatures) => signatures,
Some(EthBatchSignatures::Multi(signatures)) => signatures,
None => Vec::new(),
}
}
}

0 comments on commit e5c0cba

Please sign in to comment.