Skip to content

Commit

Permalink
loadtest
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Nov 20, 2020
1 parent f1ab61e commit 7c16c2c
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 183 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ members = [
]

[patch.crates-io]
ethabi = { path = "../ethabi/ethabi", version = "12.0.0" }
ethabi = { git = "https://github.com/dvush/ethabi.git" }
19 changes: 8 additions & 11 deletions contracts/contracts/ZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
}

// Check onchain operations
(bytes32 pendingOnchainOpsHash, uint64 priorityReqCommitted, bytes32 onchainOpsOffsetCommitment) = collectOnchainOps(_newBlock);
(bytes32 pendingOnchainOpsHash, uint64 priorityReqCommitted, bytes memory onchainOpsOffsetCommitment) = collectOnchainOps(_newBlock);

// Create block commitment for verification proof
bytes32 commitment = createBlockCommitment(_previousBlock, _newBlock, onchainOpsOffsetCommitment);
Expand Down Expand Up @@ -331,7 +331,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
// Ensure block was committed
require(hashStoredBlockInfo(_blockExecuteData.storedBlock) == storedBlockHashes[_blockExecuteData.storedBlock.blockNumber], "exe10"); // incorrect previous block data
require(_blockExecuteData.storedBlock.blockNumber == totalBlocksVerified + _executedBlockIdx + 1, "exe11"); // Execute blocks in order
require(_blockExecuteData.storedBlock.blockNumber < totalBlocksVerified, "exe03"); // Can't execute blocks more then committed currently.
require(_blockExecuteData.storedBlock.blockNumber <= totalBlocksCommitted, "exe03"); // Can't execute blocks more then committed currently.
// Ensure block was verified
require(openAndCheckCommitmentInSlot(_blockExecuteData.storedBlock.commitment, _blockExecuteData.commitmentsInSlot, _blockExecuteData.commitmentIdx), "exe12"); // block is verified

Expand Down Expand Up @@ -531,22 +531,22 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
/// @dev priorityOperationsProcessed - number of priority operations processed in this block (Deposits, FullExits)
/// @dev offsetsCommitment - array where 1 is stored in chunk where onchainOperation begins and other are 0 (used in commitments)
function collectOnchainOps(CommitBlockInfo memory _newBlockData)
internal returns (bytes32 processableOperationsHash, uint64 priorityOperationsProcessed, bytes32 offsetsCommitment) {
internal returns (bytes32 processableOperationsHash, uint64 priorityOperationsProcessed, bytes memory offsetsCommitment) {
bytes memory pubData = _newBlockData.publicData;

require(pubData.length % CHUNK_BYTES == 0, "fcs11"); // pubdata length must be a multiple of CHUNK_BYTES

uint64 uncommittedPriorityRequestsOffset = firstPriorityRequestId + totalCommittedPriorityRequests;
priorityOperationsProcessed = 0;
processableOperationsHash = EMPTY_STRING_KECCAK;

bytes memory priorityChunks = new bytes(_newBlockData.publicData.length / CHUNK_BYTES);
require(pubData.length % CHUNK_BYTES == 0, "fcs11"); // pubdata length must be a multiple of CHUNK_BYTES
offsetsCommitment = new bytes(pubData.length / CHUNK_BYTES);
for (uint32 i = 0; i < _newBlockData.onchainOperations.length; ++i) {
OnchainOperationData memory onchainOpData = _newBlockData.onchainOperations[i];

uint pubdataOffset = onchainOpData.publicDataOffset;
require(pubdataOffset % CHUNK_BYTES == 0, "fcso2"); // offsets should be on chunks boundaries
priorityChunks[pubdataOffset / CHUNK_BYTES] = byte(0x01);
offsetsCommitment[pubdataOffset / CHUNK_BYTES] = byte(0x01);

Operations.OpType opType = Operations.OpType(uint8(pubData[pubdataOffset]));

Expand Down Expand Up @@ -602,8 +602,6 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
revert("fpp14"); // unsupported op
}
}

offsetsCommitment = sha256(abi.encodePacked(priorityChunks));
}

/// @notice Checks that change operation is correct
Expand Down Expand Up @@ -653,17 +651,16 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
function createBlockCommitment(
StoredBlockInfo memory _previousBlock,
CommitBlockInfo memory _newBlockData,
bytes32 _offsetCommitment
bytes memory _offsetCommitment
) internal view returns (bytes32 commitment) {
bytes32 hash = sha256(
abi.encodePacked(uint256(_newBlockData.blockNumber), uint256(_newBlockData.feeAccount))
);
hash = sha256(abi.encodePacked(hash, _previousBlock.stateHash));
hash = sha256(abi.encodePacked(hash, _newBlockData.newStateHash));
hash = sha256(abi.encodePacked(hash, _offsetCommitment));
hash = sha256(abi.encodePacked(hash, uint256(_newBlockData.timestamp)));

bytes memory pubdata = _newBlockData.publicData;
bytes memory pubdata = abi.encodePacked(_newBlockData.publicData, _offsetCommitment);

/// The code below is equivalent to `commitment = sha256(abi.encodePacked(hash, _publicData))`

Expand Down
1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"scripts": {
"build": "hardhat compile",
"build-dev": "hardhat compile",
"test": "yarn build && zk f mocha -r ts-node/register test/**/*.ts",
"itest": "yarn build && mocha -r ts-node/register test/unit_tests/**/*.js test/fails_tests.ts",
"unit-test": "yarn build && mocha -r ts-node/register test/unit_tests/**/*",
Expand Down
2 changes: 1 addition & 1 deletion contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Deployer {
const verifierContract = await deployContract(
this.deployWallet,
this.contracts.verifier, [],
{gasLimit: 4000000, ...ethTxOptions},
{gasLimit: 8000000, ...ethTxOptions},
);
const verRec = await verifierContract.deployTransaction.wait();
const verGasUsed = verRec.gasUsed;
Expand Down
1 change: 1 addition & 0 deletions core/bin/key_generator/src/zksync_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fn zksync_circuit(block_chunks: usize) -> impl Circuit<Engine> + Clone {
initial_used_subtree_root: None,
validator_address: None,
block_number: None,
block_timestamp: None,
pub_data_commitment: None,
validator_balances: vec![None; params::total_tokens()],
validator_audit_path: vec![None; params::account_tree_depth()],
Expand Down
45 changes: 0 additions & 45 deletions core/bin/zksync_core/src/eth_watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ pub enum EthWatchRequest {
eth_hash: Vec<u8>,
resp: oneshot::Sender<Option<(EthBlockId, PriorityOp)>>,
},
GetPendingWithdrawalsQueueIndex {
resp: oneshot::Sender<Result<u32, anyhow::Error>>,
},
}

pub struct EthWatch<T: Transport> {
Expand Down Expand Up @@ -420,41 +417,6 @@ impl<T: Transport> EthWatch<T> {
Ok(auth_fact.as_slice() == tiny_keccak::keccak256(&pub_key_hash.data[..]))
}

async fn pending_withdrawals_queue_index(&self) -> Result<u32, anyhow::Error> {
let first_pending_withdrawal_index: u32 = self
.zksync_contract
.1
.query(
"firstPendingWithdrawalIndex",
(),
None,
Options::default(),
None,
)
.await
.map_err(|e| {
format_err!(
"Failed to query contract firstPendingWithdrawalIndex: {}",
e
)
})?;
let number_of_pending_withdrawals: u32 = self
.zksync_contract
.1
.query(
"numberOfPendingWithdrawals",
(),
None,
Options::default(),
None,
)
.await
.map_err(|e| {
format_err!("Failed to query contract numberOfPendingWithdrawals: {}", e)
})?;
Ok(first_pending_withdrawal_index + number_of_pending_withdrawals)
}

fn find_ongoing_op_by_hash(&self, eth_hash: &[u8]) -> Option<(EthBlockId, PriorityOp)> {
self.eth_state
.unconfirmed_queue()
Expand Down Expand Up @@ -596,13 +558,6 @@ impl<T: Transport> EthWatch<T> {
.unwrap_or(false);
resp.send(authorized).unwrap_or_default();
}
EthWatchRequest::GetPendingWithdrawalsQueueIndex { resp } => {
let pending_withdrawals_queue_index =
self.pending_withdrawals_queue_index().await;

resp.send(pending_withdrawals_queue_index)
.unwrap_or_default();
}
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions core/bin/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,6 @@ pub mod mempool;
pub mod private_api;
pub mod state_keeper;

pub async fn insert_pending_withdrawals(
storage: &mut StorageProcessor<'_>,
eth_watch_req_sender: mpsc::Sender<EthWatchRequest>,
) {
// Check if the pending withdrawals table is empty
let no_stored_pending_withdrawals = storage
.chain()
.operations_schema()
.no_stored_pending_withdrawals()
.await
.expect("failed to call no_stored_pending_withdrawals function");
if no_stored_pending_withdrawals {
let eth_watcher_channel = oneshot::channel();

eth_watch_req_sender
.clone()
.send(EthWatchRequest::GetPendingWithdrawalsQueueIndex {
resp: eth_watcher_channel.0,
})
.await
.expect("EthWatchRequest::GetPendingWithdrawalsQueueIndex request sending failed");

let pending_withdrawals_queue_index = eth_watcher_channel
.1
.await
.expect("EthWatchRequest::GetPendingWithdrawalsQueueIndex response error")
.expect("Err as result of EthWatchRequest::GetPendingWithdrawalsQueueIndex");

// Let's add to the db one 'fake' pending withdrawal with
// id equals to (pending_withdrawals_queue_index-1)
// Next withdrawals will be added to the db with correct
// corresponding indexes in contract's pending withdrawals queue
storage
.chain()
.operations_schema()
.add_pending_withdrawal(
&TxHash::default(),
Some(pending_withdrawals_queue_index as i64 - 1),
)
.await
.expect("can't save fake pending withdrawal in the db");
}
}

/// Waits for *any* of the tokio tasks to be finished.
/// Since the main tokio tasks are used as actors which should live as long
/// as application runs, any possible outcome (either `Ok` or `Err`) is considered
Expand Down Expand Up @@ -158,7 +114,6 @@ pub async fn run_core(

// Insert pending withdrawals into database (if required)
let mut storage_processor = connection_pool.access_storage().await?;
insert_pending_withdrawals(&mut storage_processor, eth_watch_req_sender.clone()).await;

// Start State Keeper.
let state_keeper_init = ZkSyncStateInitParams::restore_from_db(&mut storage_processor).await?;
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_eth_sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl<ETH: EthereumInterface, DB: DatabaseInterface> ETHSender<ETH, DB> {
/// Calculates the gas limit for transaction to be send, depending on the type of operation.
fn gas_limit_for_op(op: &ETHOperation) -> U256 {
// TODO:
U256::from(1_000_000)
U256::from(5_000_000)
// match op.op_type {
// OperationType::Commit => {
// op.op
Expand Down
Loading

0 comments on commit 7c16c2c

Please sign in to comment.