Skip to content

Commit

Permalink
Merge branch 'dev' into alekseysidorov-919-stable-api-operations
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseysidorov authored Dec 9, 2020
2 parents 0f26f05 + 9a4f775 commit 6ed3b03
Show file tree
Hide file tree
Showing 45 changed files with 373 additions and 188 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: update-deps
run: |
rustup update stable
cargo sqlx --version || cargo install --version=0.1.0-beta.1 sqlx-cli
cargo sqlx --version || cargo install --version=0.2.0 sqlx-cli
docker pull matterlabs/ci-integration-test:zk-latest
- name: zk
Expand All @@ -38,15 +38,14 @@ jobs:
zk fmt --check
yarn lint:md
yarn lint:sol
# So database will be created for compilation.
zk db setup
zk dummy-prover ensure-disabled
cargo fmt --all -- --check
# For some reason, `cargo clippy` currently doesn't work in sqlx offline mod. So, we're checking it in online mode.
zk f cargo clippy --tests --benches -- -D warnings
pushd sdk/zksync-crypto
cargo fmt -- --check
cargo clippy --all --tests --benches -- -D warnings
env:
SQLX_OFFLINE: "true"

- name: generic-init
run: |
Expand All @@ -61,6 +60,8 @@ jobs:

- name: integration-testkit
run: zk test integration testkit
env:
SQLX_OFFLINE: "true"

- name: contracts-unit-tests
run: zk test contracts
Expand All @@ -69,7 +70,10 @@ jobs:
run: zk test js

- name: rust-unit-tests
run: zk test rust
run: |
# Api tests require database setup
zk db setup
zk test rust
- name: zksync-crypto-tests
run: pushd sdk/zksync-crypto && zk f cargo test --release
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ chrono = { version = "0.4", features = ["serde", "rustc-serialize"] }
ctrlc = { version = "3.1", features = ["termination"] }
anyhow = "1.0"
thiserror = "1.0"
# TODO: should be removed after json rpc deps are updated is updated, current version (14.0) (#1107).
# TODO: should be removed after json rpc deps are updated is updated, current version (14.0) (ZKS-98).
futures01 = { package = "futures", version = "0.1" }
reqwest = { version = "0.10", features = ["blocking", "json"] }
tiny-keccak = "1.4.2"
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/api_server/rest/v1/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async fn blocks_range(
.await
.map_err(ApiError::internal)?;
// Handle edge case when "after + limit" greater than the total blocks count.
// TODO Handle this case directly in the `storage` crate. (#1151)
// TODO Handle this case directly in the `storage` crate. (ZKS-124)
let range = if let Pagination::After(after) = pagination {
range
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/api_server/rest/v1/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use thiserror::Error;

pub type Result<T> = std::result::Result<T, ClientError>;

// TODO Make error handling as correct as possible. (#1152)
// TODO Make error handling as correct as possible. (ZKS-125)
#[derive(Debug, Error)]
pub enum ClientError {
#[error("Bad request: {0}")]
Expand Down
10 changes: 10 additions & 0 deletions core/bin/zksync_api/src/api_server/rest/v1/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ impl TestServerConfig {
18,
))
.await?;
// Insert Golem token with old symbol (from rinkeby).
storage
.tokens_schema()
.store_token(Token::new(
16,
Address::from_str("d94e3dc39d4cad1dad634e7eb585a57a19dc7efe ").unwrap(),
"GNT",
18,
))
.await?;

let mut accounts = AccountMap::default();

Expand Down
35 changes: 34 additions & 1 deletion core/bin/zksync_api/src/api_server/rest/v1/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
.await?,
None
);
// TODO Check error (#1152)
// TODO Check error (ZKS-125)
client
.token_price(&TokenLike::Id(2), TokenPriceKind::Token)
.await
Expand Down Expand Up @@ -303,4 +303,37 @@ mod tests {
server.stop().await;
Ok(())
}

// Test special case for Golem: GLM token name should be alias for the GNT.
// By the way, since `TokenDBCache` is shared between this API implementation
// and the old RPC code, there is no need to write a test for the old implementation.
//
// TODO: Remove this case after Golem update [ZKS-173]
#[actix_rt::test]
async fn gnt_as_glm_alias() -> anyhow::Result<()> {
let cfg = TestServerConfig::default();
cfg.fill_database().await?;

let fee_ticker = dummy_fee_ticker(&[]);
let (client, server) = cfg.start_server(move |cfg| {
api_scope(TokenDBCache::new(cfg.pool.clone()), fee_ticker.clone())
});

// Get Golem token as GNT.
let golem_gnt = client
.token_by_id(&TokenLike::from("GNT"))
.await?
.expect("Golem token should be exist");
// Get Golem token as GMT.
let golem_glm = client
.token_by_id(&TokenLike::from("GLM"))
.await?
.expect("Golem token should be exist");
// Check that GNT is alias to GMT.
assert_eq!(golem_gnt, golem_glm);
assert_eq!(golem_gnt.id, 16);

server.stop().await;
Ok(())
}
}
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/fee_ticker/ticker_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<T: TokenPriceAPI + Send + Sync> FeeTickerAPI for TickerApi<T> {
.await?
.ok_or_else(|| format_err!("Token not found: {:?}", token))?;

// TODO: remove hardcode for Matter Labs Trial Token (#1036).
// TODO: remove hardcode for Matter Labs Trial Token (ZKS-63).
if token.symbol == "MLTT" {
return Ok(TokenPrice {
usd_price: Ratio::from_integer(1u32.into()),
Expand Down
25 changes: 24 additions & 1 deletion core/bin/zksync_api/src/utils/token_db_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zksync_types::{Token, TokenLike};
#[derive(Debug, Clone)]
pub struct TokenDBCache {
pub db: ConnectionPool,
// TODO: handle stale entries, edge case when we rename token after adding it (#1097)
// TODO: handle stale entries, edge case when we rename token after adding it (ZKS-97)
cache: Arc<RwLock<HashMap<TokenLike, Token>>>,
}

Expand All @@ -25,6 +25,29 @@ impl TokenDBCache {
token_query: impl Into<TokenLike>,
) -> anyhow::Result<Option<Token>> {
let token_query = token_query.into();
// HACK: Special case for the Golem:
//
// Currently, their token on Rinkeby is called GNT, but it's being renamed to the GLM.
// So, for some period of time, we should consider GLM token name as an alias to the GNT token.
//
// TODO: Remove this case after Golem update [ZKS-173]
match token_query {
TokenLike::Symbol(symbol) if symbol == "GLM" => {
// Try to lookup Golem token as "GLM".
if let Some(token) = self.get_token_impl(TokenLike::Symbol(symbol)).await? {
// If such token exists, use it.
Ok(Some(token))
} else {
// Otherwise to lookup Golem token as "GNT".
self.get_token_impl(TokenLike::Symbol("GNT".to_string()))
.await
}
}
other => self.get_token_impl(other).await,
}
}

async fn get_token_impl(&self, token_query: TokenLike) -> anyhow::Result<Option<Token>> {
// Just return token from cache.
if let Some(token) = self.cache.read().await.get(&token_query) {
return Ok(Some(token.clone()));
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl ZkSyncStateKeeper {
mut updates,
executed_op,
}) => {
self.pending_block.chunks_left -= chunks_needed;
self.pending_block.chunks_left -= executed_op.chunks();
self.pending_block.account_updates.append(&mut updates);
if let Some(fee) = fee {
self.pending_block.collected_fees.push(fee);
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_eth_sender/src/gas_adjuster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<ETH: EthereumInterface, DB: DatabaseInterface> GasAdjuster<ETH, DB> {
}

// TODO: Currently instead of using sent txs as samples, we use the gas prices suggested by
// the Ethereum node (#1130).
// the Ethereum node (ZKS-118).
// // Report used price to be gathered by the statistics module.
// self.statistics.add_sample(price);

Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_eth_sender/src/gas_adjuster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async fn gas_price_limit_scaling() {
/// Checks that if the price suggested by the Ethereum client is below the price limit,
/// the limit is calculated as (average of samples) * scale_factor.
#[tokio::test]
#[ignore] // TODO: Disabled as currently the limit is calculated based on the network price rather than used txs samples (#1130).
#[ignore] // TODO: Disabled as currently the limit is calculated based on the network price rather than used txs samples (ZKS-118).
async fn gas_price_limit_average_basis() {
// Increases the gas price value by 15%.
fn increase_gas_price(value: u64) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_witness_generator/tests/prover_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn connect_to_db() -> zksync_storage::ConnectionPool {
}

async fn spawn_server(prover_timeout: time::Duration, rounds_interval: time::Duration) -> String {
// TODO: make single server spawn for all tests (#1108).
// TODO: make single server spawn for all tests (ZKS-99).
let bind_to = "127.0.0.1:8088";

let mut prover_options = ProverOptions::from_env();
Expand Down
6 changes: 3 additions & 3 deletions core/lib/circuit/src/allocated_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<E: RescueEngine> AllocatedOperationData<E> {

let third_sig_msg = CircuitElement::unsafe_empty_of_some_length(
zero_element.clone(),
franklin_constants::MAX_CIRCUIT_MSG_HASH_BITS - (2 * E::Fr::CAPACITY as usize), //TODO: think of more consistent constant flow (#971).
franklin_constants::MAX_CIRCUIT_MSG_HASH_BITS - (2 * E::Fr::CAPACITY as usize), //TODO: think of more consistent constant flow (ZKS-54).
);

let new_pubkey_hash = CircuitElement::unsafe_empty_of_some_length(
Expand Down Expand Up @@ -257,13 +257,13 @@ impl<E: RescueEngine> AllocatedOperationData<E> {
let second_sig_msg = CircuitElement::from_fe_with_known_length(
cs.namespace(|| "second_part_signature_message"),
|| op.second_sig_msg.grab(),
E::Fr::CAPACITY as usize, //TODO: think of more consistent constant flow (#971).
E::Fr::CAPACITY as usize, //TODO: think of more consistent constant flow (ZKS-54).
)?;

let third_sig_msg = CircuitElement::from_fe_with_known_length(
cs.namespace(|| "third_part_signature_message"),
|| op.third_sig_msg.grab(),
franklin_constants::MAX_CIRCUIT_MSG_HASH_BITS - (2 * E::Fr::CAPACITY as usize), //TODO: think of more consistent constant flow (#971).
franklin_constants::MAX_CIRCUIT_MSG_HASH_BITS - (2 * E::Fr::CAPACITY as usize), //TODO: think of more consistent constant flow (ZKS-54).
)?;

let new_pubkey_hash = CircuitElement::from_fe_with_known_length(
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
&rhs_valid,
)?;
cur.balance
.enforce_length(cs.namespace(|| "mutated balance is still correct length"))?; // TODO: this is actually redundant, cause they are both enforced to be of appropriate length (#1118).
.enforce_length(cs.namespace(|| "mutated balance is still correct length"))?; // TODO: this is actually redundant, cause they are both enforced to be of appropriate length (ZKS-106).

cur.account.address = CircuitElement::conditionally_select(
cs.namespace(|| "mutated_pubkey"),
Expand Down
4 changes: 2 additions & 2 deletions core/lib/circuit/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
let pk = PublicKey::from_private(&private_key, p_g, params);
let _is_valid_signature = pk.verify_musig_sha256(&message_bytes, &signature, p_g, params);

// TODO: handle the case where it is not valid (#1113)
// TODO: handle the case where it is not valid (ZKS-101)
// if !is_valid_signature {
// return None;
// }
Expand Down Expand Up @@ -88,7 +88,7 @@ where
jubjub_params,
);

// TODO: handle the case where it is not valid (#1113)
// TODO: handle the case where it is not valid (ZKS-101)
// if !is_valid_signature {
// return None;
// }
Expand Down
2 changes: 1 addition & 1 deletion core/lib/crypto/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type SparseMerkleTree<T, H, HH> = parallel_smt::SparseMerkleTree<T, H, HH>;
/// Default hasher used in the zkSync network for state hash calculations.
pub type RescueHasher<T> = rescue_hasher::RescueHasher<T>;

// TODO: return the code below and uncomment asserts (#1119)
// TODO: return the code below and uncomment asserts (ZKS-107)

// pub fn verify_proof<E: Account>(&self, index: u32, item: Account, proof: Vec<(E::Fr, bool)>) -> bool {
// use crate::sparse_merkle_tree::hasher::Hasher;
Expand Down
88 changes: 44 additions & 44 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,50 @@
]
}
},
"59c4e0d8255c2e4dd6eece1b24245daf3414d4f15b6cba7b369dc1ac32bed018": {
"query": "\n SELECT * FROM accounts\n WHERE id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "last_block",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "nonce",
"type_info": "Int8"
},
{
"ordinal": 3,
"name": "address",
"type_info": "Bytea"
},
{
"ordinal": 4,
"name": "pubkey_hash",
"type_info": "Bytea"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"5de811d61e00fd7b93311aa825d17e2b2f0ee46ee762f5064e842f5d0f2b5ad7": {
"query": "UPDATE eth_parameters\n SET commit_ops = $1, verify_ops = $2, withdraw_ops = $3\n WHERE id = true",
"describe": {
Expand Down Expand Up @@ -3155,50 +3199,6 @@
"nullable": []
}
},
"ddf29a55c76cb7c56286ef5a7095e44b350cf9b6dcf88b67f399483f76b8f36f": {
"query": "\n SELECT * FROM accounts\n WHERE id = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "last_block",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "nonce",
"type_info": "Int8"
},
{
"ordinal": 3,
"name": "address",
"type_info": "Bytea"
},
{
"ordinal": 4,
"name": "pubkey_hash",
"type_info": "Bytea"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"debbe23f0c730c331482c798387d1739911923edcafc2bd80463464ff98f3b71": {
"query": "SELECT * from mempool_txs\n WHERE tx_hash = $1",
"describe": {
Expand Down
Loading

0 comments on commit 6ed3b03

Please sign in to comment.