Skip to content

Commit

Permalink
Merge branch 'dev' into dvush-new-sc
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Dec 15, 2020
2 parents 9d678d6 + 52d8979 commit 596adc6
Show file tree
Hide file tree
Showing 59 changed files with 2,574 additions and 273 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
ci-all:
# We currently have two self-hosted runners, one of which is marked "DEV-CI" and other one is marder "MAIN".
# "MAIN" is the current CI runner, "DEV-CI" is currently used to experiment with CI optimizing.
runs-on: [self-hosted, MAIN]
runs-on: self-hosted

steps:
- uses: actions/checkout@v2
Expand All @@ -23,10 +23,30 @@ jobs:
echo CI=1 >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
- name: cache-contracts
uses: actions/cache@v2
with:
path: |
contracts/build
contracts/node_modules
contracts/dev-contracts/generated
key: ${{ runner.os }}-contracts-${{ hashFiles('contracts/contracts/*.sol') }}

- name: cache-rust
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: update-deps
# Upstream version of sqlx-cli has some incompatibilities with the sqlx version used zksync_storage.
run: |
rustup update stable
cargo sqlx --version || cargo install --version=0.2.0 sqlx-cli
cargo install sqlx-cli --git https://github.com/alekseysidorov/sqlx.git
cargo install diesel_cli --no-default-features --features postgres
docker pull matterlabs/ci-integration-test:zk-latest
- name: zk
Expand All @@ -46,7 +66,7 @@ jobs:
cargo clippy --all --tests --benches -- -D warnings
env:
SQLX_OFFLINE: "true"

- name: generic-init
run: |
# Unpack keys to build dev contracts
Expand Down
2 changes: 1 addition & 1 deletion core/bin/data_restore/src/inmemory_storage_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl InMemoryStorageInteractor {
.get_mut(id)
.expect("In tests this account should be stored");
account.nonce = max(account.nonce, *new_nonce);
account.pub_key_hash = new_pub_key_hash.clone();
account.pub_key_hash = *new_pub_key_hash;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/bin/data_restore/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async fn test_run_state_update(mut storage: StorageProcessor<'_>) {

// Check that it's stores some account, created by deposit
let (_, account) = AccountSchema(interactor.storage())
.account_state_by_address(&Default::default())
.account_state_by_address(Address::default())
.await
.unwrap()
.verified
Expand Down
4 changes: 2 additions & 2 deletions core/bin/data_restore/src/tree_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ mod test {
let tx5 = ChangePubKey::new(
0,
[7u8; 20].into(),
pub_key_hash_7.clone(),
pub_key_hash_7,
1,
BigUint::from(1u32),
2,
Expand Down Expand Up @@ -734,7 +734,7 @@ mod test {
let tx5 = ChangePubKey::new(
0,
[7u8; 20].into(),
pub_key_hash_7.clone(),
pub_key_hash_7,
1,
BigUint::from(1u32),
2,
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/api_server/event_notify/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl NotifierState {
let account_state = storage
.chain()
.account_schema()
.account_state_by_address(&address)
.account_state_by_address(address)
.await?;

let account_id = if let Some(id) = account_state.committed.as_ref().map(|(id, _)| id) {
Expand Down
44 changes: 44 additions & 0 deletions core/bin/zksync_api/src/api_server/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Helpers collection shared between the different API implementations.
// Built-in uses

// External uses

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

// Local uses

pub fn remove_prefix(query: &str) -> &str {
if let Some(query) = query.strip_prefix("0x") {
query
} else if let Some(query) = query.strip_prefix("sync-bl:") {
query
} else if let Some(query) = query.strip_prefix("sync-tx:") {
query
} else {
query
}
}

pub fn try_parse_hash(query: &str) -> Result<H256, 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(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())
}
1 change: 1 addition & 0 deletions core/bin/zksync_api/src/api_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::signature_checker;

mod admin_server;
mod event_notify;
mod helpers;
mod loggers;
mod rest;
pub mod rpc_server;
Expand Down
34 changes: 1 addition & 33 deletions core/bin/zksync_api/src/api_server/rest/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,7 @@ use zksync_storage::chain::{
operations_ext::records::{TransactionsHistoryItem, TxByHashResponse},
};
use zksync_storage::StorageProcessor;
use zksync_types::{tx::TxHash, PriorityOp, Token, TokenId, ZkSyncPriorityOp, H256};

pub fn remove_prefix(query: &str) -> &str {
if let Some(query) = query.strip_prefix("0x") {
query
} else if let Some(query) = query.strip_prefix("sync-bl:") {
query
} else if let Some(query) = query.strip_prefix("sync-tx:") {
query
} else {
query
}
}

pub fn try_parse_hash(query: &str) -> Option<H256> {
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()?;
Some(H256::from_slice(&slice))
}

pub fn try_parse_tx_hash(query: &str) -> Option<TxHash> {
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)
}
use zksync_types::{PriorityOp, Token, TokenId, ZkSyncPriorityOp};

/// Checks if block is finalized, meaning that
/// both Verify operation is performed for it, and this
Expand Down
14 changes: 9 additions & 5 deletions core/bin/zksync_api/src/api_server/rest/v01/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
//! scope configuration. This is done by the `ApiV01::into_scope` method.
use crate::api_server::{
helpers::try_parse_hash,
rest::{
helpers::*,
helpers::{deposit_op_to_tx_by_hash, parse_tx_id, priority_op_to_tx_history},
v01::{api_decl::ApiV01, types::*},
},
rpc_server::get_ongoing_priority_ops,
};
use actix_web::{web, HttpResponse, Result as ActixResult};
use std::time::Instant;
Expand Down Expand Up @@ -82,7 +82,9 @@ impl ApiV01 {
})?;

// Fetch ongoing deposits, since they must be reported within the transactions history.
let mut ongoing_ops = get_ongoing_priority_ops(&self_.api_client, address)
let mut ongoing_ops = self_
.api_client
.get_unconfirmed_deposits(address)
.await
.map_err(|err| {
vlog::warn!(
Expand Down Expand Up @@ -231,7 +233,9 @@ impl ApiV01 {
// fill the rest of the limit.

// Fetch ongoing deposits, since they must be reported within the transactions history.
let mut ongoing_ops = get_ongoing_priority_ops(&self_.api_client, address)
let mut ongoing_ops = self_
.api_client
.get_unconfirmed_deposits(address)
.await
.map_err(|err| {
vlog::warn!(
Expand Down Expand Up @@ -304,7 +308,7 @@ impl ApiV01 {
) -> ActixResult<HttpResponse> {
let start = Instant::now();
let hash = try_parse_hash(&hash_hex_with_prefix)
.ok_or_else(|| HttpResponse::BadRequest().finish())?;
.map_err(|_| HttpResponse::BadRequest().finish())?;

let mut res = self_
.access_storage()
Expand Down
53 changes: 53 additions & 0 deletions core/bin/zksync_api/src/api_server/rest/v1/accounts/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Accounts API client implementation
// Built-in uses

// External uses

// Workspace uses

// Local uses
use crate::api_server::v1::client::{Client, ClientError};

use super::types::{
AccountInfo, AccountQuery, AccountReceipts, AccountReceiptsQuery, AccountTxReceipt,
PendingAccountTxReceipt,
};

/// Accounts API part.
impl Client {
/// Gets account information
pub async fn account_info(
&self,
account: impl Into<AccountQuery>,
) -> Result<Option<AccountInfo>, ClientError> {
let account = account.into();

self.get(&format!("accounts/{}", account)).send().await
}

pub async fn account_receipts(
&self,
account: impl Into<AccountQuery>,
from: AccountReceipts,
limit: u32,
) -> Result<Vec<AccountTxReceipt>, ClientError> {
let account = account.into();

self.get(&format!("accounts/{}/receipts", account))
.query(&AccountReceiptsQuery::new(from, limit))
.send()
.await
}

pub async fn account_pending_receipts(
&self,
account: impl Into<AccountQuery>,
) -> Result<Vec<PendingAccountTxReceipt>, ClientError> {
let account = account.into();

self.get(&format!("accounts/{}/receipts/pending", account))
.send()
.await
}
}
Loading

0 comments on commit 596adc6

Please sign in to comment.