Skip to content

Commit

Permalink
Initial merge
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Jun 22, 2021
2 parents 8ab2150 + 706670c commit c5fd07f
Show file tree
Hide file tree
Showing 171 changed files with 10,008 additions and 6,310 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ jobs:
run: ci_run zk test i server

- name: integration-api
run: ci_run zk test i api
run: |
ci_run zk test i api
ci_run zk test i api-docs
- name: integration-zcli
run: ci_run zk test i zcli
Expand Down
23 changes: 23 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"core/lib/contracts",
"core/lib/api_client",
"core/lib/notifier",
"core/lib/api_types",
"core/lib/balancer",

# Test infrastructure
Expand Down
9 changes: 9 additions & 0 deletions bin/api_docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [ -z "$1" ]; then
cd $ZKSYNC_HOME
yarn && yarn api-docs build
else
# can't start this with yarn since it has quirks with `--` as an argument
node -- $ZKSYNC_HOME/infrastructure/api-docs/build/index.js "$@"
fi
8 changes: 8 additions & 0 deletions changelog/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to the core components will be documented in this file.

### Removed

- (`api_server`): REST API v1.0.

### Changed

- (`loadtest`): `zksync_fee` has been moved to `[main_wallet]` section from the `[network]` section.
Expand All @@ -16,6 +18,7 @@ All notable changes to the core components will be documented in this file.
- (`api_server`): Make `submit_txs_batch` send only one signature request.
- Fast withdrawals now can trigger aggregated block execution.
- Replaced `anyhow` errors with typed errors in `lib/state`, `lib/crypto` and `lib/types`.
- (`fee-ticker`): Batch fee now includes `zkp_fee` and `gas_fee`.

### Added

Expand All @@ -30,6 +33,11 @@ All notable changes to the core components will be documented in this file.
- (`api_server`): Support for accounts that don't have to pay fees (e.g. network service accounts) was added.
- Added `BlockMetadata` structure and corresponding table to track block data that is not related to protocol.
- (`block_revert`): CLI that calls `revertBlocks` smart contract function and updates the database respectively.
- (`api_server`): Added REST API v0.2.
- (`api_client`): Client for REST API v0.2.
- (`api_types`): Crate for storing types that are used in API.
- Added hashes for batches and additional hashes for priority operations.
- Added `ForcedExit` fee type to REST API v0.2 and JSON RPC API.

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion changelog/infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ components, the logs will have the following format:
### Added

- (`token_list_manager`): CLI for updating to new version of a previously saved list of trusted tokens.

- (`loadnext`): Crate, a new implementation of the loadtest for zkSync.
- (`api-docs`): tool for generating and testing API documentation. Docs are generated from a bunch of .apib files where
API endpoints and their inputs/outputs are defined.

### Fixed

Expand Down
5 changes: 5 additions & 0 deletions changelog/js-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ All notable changes to `zksync.js` will be documented in this file.

- Methods for working with NFTs. You can read more [here](https://zksync.io/dev/nfts.html).
- Methods for working with atomic swaps/limit orders. You can read more [here](https://zksync.io/dev/swaps.html).
- `RestProvider` class, that is used for querying REST API v0.2.
- `SyncProvider` interface: common interface for API v0.2 `RestProvider` and JSON RPC `Provider`.
- Types for REST API v0.2.

### Changed

- Changed type of `provider` field in `Wallet` class from `Provider` to `SyncProvider`.
- `ForcedExit` fee type is used for `ForcedExit` transactions instead of `Withdraw` fee type.
- `zksync-crypto` to support atomic swaps/limit orders functionality.

## Version 0.10.9 (13.04.2021)
Expand Down
1 change: 1 addition & 0 deletions core/bin/data_restore/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fn create_deposit(from: Address, to: Address, amount: u32) -> ExecutedOperations
deadline_block: 0,
eth_hash: H256::zero(),
eth_block: 0,
eth_block_index: None,
};
let executed_deposit_op = ExecutedPriorityOp {
priority_op: priority_operation,
Expand Down
1 change: 1 addition & 0 deletions core/bin/data_restore/src/tree_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ impl TreeState {
deadline_block: 0,
eth_hash: H256::zero(),
eth_block: 0,
eth_block_index: None,
},
block_index,
created_at: chrono::Utc::now(),
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ zksync_contracts = { path = "../../lib/contracts", version = "1.0" }
zksync_eth_client = { path = "../../lib/eth_client", version = "1.0" }
zksync_eth_signer = { path = "../../lib/eth_signer", version = "1.0" }
zksync_api_client = { path = "../../lib/api_client", version = "0.1" }
zksync_api_types = { path = "../../lib/api_types", version = "1.0" }
zksync_prometheus_exporter = { path = "../../lib/prometheus_exporter", version = "1.0" }
zksync_balancer = { path = "../../lib/balancer", version = "1.0" }
zksync_gateway_watcher = { path = "../../lib/gateway_watcher", version = "1.0" }
Expand Down
40 changes: 21 additions & 19 deletions core/bin/zksync_api/benches/criterion/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,43 @@ use criterion::{criterion_group, criterion_main, Criterion};
use ethabi::Address;
use reqwest::{blocking::Client, StatusCode};

use zksync_api_client::rest::v1::{IncomingTxBatchForFee, IncomingTxForFee};
use zksync_types::{TokenLike, TxFeeTypes};
use zksync_api_types::v02::fee::{
ApiTxFeeTypes, BatchFeeRequest, TxFeeRequest, TxInBatchFeeRequest,
};
use zksync_types::{TokenId, TokenLike};

fn generate_transactions(number: usize) -> IncomingTxBatchForFee {
let mut tx_types = vec![];
let mut addresses = vec![];
fn generate_transactions(number: usize) -> BatchFeeRequest {
let mut transactions = Vec::new();
for _ in 0..number {
tx_types.push(TxFeeTypes::Withdraw);
addresses.push(Address::random());
transactions.push(TxInBatchFeeRequest {
tx_type: ApiTxFeeTypes::Withdraw,
address: Address::random(),
});
}
IncomingTxBatchForFee {
tx_types,
addresses,
token_like: TokenLike::Symbol("wBTC".to_string()),
BatchFeeRequest {
transactions,
token_like: TokenLike::Id(TokenId(2)), // id of wBTC on localhost
}
}

fn get_txs_batch_fee(client: Client, url: String, transaction: IncomingTxBatchForFee) {
fn get_txs_batch_fee(client: Client, url: String, batch_fee_request: BatchFeeRequest) {
let res = client
.post(format!("{}/api/v1/transactions/fee/batch", url).as_str())
.json(&transaction)
.post(format!("{}/api/v0.2/fee/batch", url).as_str())
.json(&batch_fee_request)
.send()
.unwrap();
assert_eq!(res.status(), StatusCode::OK)
}

fn get_txs_fee(client: Client, url: String) {
let transaction = IncomingTxForFee {
tx_type: TxFeeTypes::Withdraw,
let transaction = TxFeeRequest {
tx_type: ApiTxFeeTypes::Withdraw,
address: Address::random(),
token_like: TokenLike::Symbol("wBTC".to_string()),
token_like: TokenLike::Id(TokenId(2)), // id of wBTC on localhost
};

let res = client
.post(format!("{}/api/v1/transactions/fee", url).as_str())
.post(format!("{}/api/v0.2/fee", url).as_str())
.json(&transaction)
.send()
.unwrap();
Expand All @@ -47,7 +49,7 @@ fn bench_fee(c: &mut Criterion) {
let url = std::env::var("API_REST_URL").unwrap();
let client = reqwest::blocking::Client::new();
let transaction = generate_transactions(100);
c.bench_function("get_txs_batch_fee_new_version", |b| {
c.bench_function("get_txs_batch_fee", |b| {
b.iter(|| get_txs_batch_fee(client.clone(), url.clone(), transaction.clone()))
});
c.bench_function("get_txs_fee", |b| {
Expand Down
13 changes: 1 addition & 12 deletions core/bin/zksync_api/src/api_server/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// External uses

// Workspace uses
use zksync_types::{tx::TxHash, H256};
use zksync_types::H256;
use zksync_utils::remove_prefix;

// Local uses
Expand All @@ -20,14 +20,3 @@ pub fn try_parse_hash(query: &str) -> Result<H256, hex::FromHexError> {

Ok(H256::from_slice(&slice))
}

pub fn try_parse_tx_hash(query: &str) -> Result<TxHash, hex::FromHexError> {
const HASH_SIZE: usize = 32; // 32 bytes

let mut slice = [0_u8; HASH_SIZE];

let tx_hex = remove_prefix(query);
hex::decode_to_slice(&tx_hex, &mut slice)?;

Ok(TxHash::from_slice(&slice).unwrap())
}
3 changes: 0 additions & 3 deletions core/bin/zksync_api/src/api_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
//! `mod rpc_server` - JSON rpc via HTTP (for request reply functions)
//! `mod rpc_subscriptions` - JSON rpc via WebSocket (for request reply functions and subscriptions)
// Public uses
pub use rest::v1;

// External uses
use futures::channel::mpsc;
// Workspace uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ use actix_web::{dev::Body, http::HeaderValue, HttpResponse, ResponseError};
use reqwest::{header::CONTENT_TYPE, StatusCode};

// Workspace uses
pub use zksync_api_client::rest::v1::ErrorBody;

use zksync_api_client::rest::error::ErrorBody;
// Local uses
use crate::api_server::tx_sender::SubmitError;

/// An HTTP error structure.
#[derive(Debug)]
pub struct Error {
pub struct ApiError {
/// HTTP error code.
pub http_code: StatusCode,
/// HTTP error content serialized into JSON.
pub body: ErrorBody,
}

impl Error {
impl ApiError {
/// Creates a new Error with the BAD_REQUEST (400) status code.
pub fn bad_request(title: impl Display) -> Self {
Self::with_code(StatusCode::BAD_REQUEST, title)
Expand All @@ -30,11 +30,6 @@ impl Error {
Self::with_code(StatusCode::INTERNAL_SERVER_ERROR, title)
}

/// Creates a new Error with the NOT_IMPLEMENTED (501) status code.
pub fn not_implemented(title: impl Display) -> Self {
Self::with_code(StatusCode::NOT_IMPLEMENTED, title)
}

/// Creates a new Error with the NOT_FOUND (404) status code.
pub fn not_found(title: impl Display) -> Self {
Self::with_code(StatusCode::NOT_FOUND, title)
Expand All @@ -50,32 +45,20 @@ impl Error {
}
}

/// Sets error title.
pub fn title(mut self, title: impl Display) -> Self {
self.body.title = title.to_string();
self
}

/// Sets error details.
pub fn detail(mut self, detail: impl Display) -> Self {
self.body.detail = detail.to_string();
self
}

/// Sets error specific code.
pub fn code(mut self, code: u64) -> Self {
self.body.code = Some(code);
self
}
}

impl Display for Error {
impl Display for ApiError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} ({})", self.body, self.http_code)
}
}

impl ResponseError for Error {
impl ResponseError for ApiError {
fn status_code(&self) -> reqwest::StatusCode {
self.http_code
}
Expand All @@ -94,3 +77,50 @@ impl ResponseError for Error {
}
}
}

#[derive(Debug, Clone, Copy)]
pub enum SumbitErrorCode {
AccountCloseDisabled = 101,
InvalidParams = 102,
UnsupportedFastProcessing = 103,
IncorrectTx = 104,
TxAdd = 105,
InappropriateFeeToken = 106,

Internal = 110,
CommunicationCoreServer = 111,
Other = 112,
}

impl SumbitErrorCode {
fn from_err(err: &SubmitError) -> Self {
match err {
SubmitError::AccountCloseDisabled => Self::AccountCloseDisabled,
SubmitError::InvalidParams(_) => Self::InvalidParams,
SubmitError::UnsupportedFastProcessing => Self::UnsupportedFastProcessing,
SubmitError::IncorrectTx(_) => Self::IncorrectTx,
SubmitError::TxAdd(_) => Self::TxAdd,
SubmitError::InappropriateFeeToken => Self::InappropriateFeeToken,
SubmitError::CommunicationCoreServer(_) => Self::CommunicationCoreServer,
SubmitError::Internal(_) => Self::Internal,
SubmitError::Other(_) => Self::Other,
}
}

fn as_code(self) -> u64 {
self as u64
}
}

impl From<SubmitError> for ApiError {
fn from(inner: SubmitError) -> Self {
let internal_code = SumbitErrorCode::from_err(&inner).as_code();

if let SubmitError::Internal(err) = &inner {
ApiError::internal(err)
} else {
ApiError::bad_request(inner)
}
.code(internal_code)
}
}
Loading

0 comments on commit c5fd07f

Please sign in to comment.