Skip to content

Commit

Permalink
Merge branch 'dev' into breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbochok authored Feb 22, 2022
2 parents 50a2c8d + 986fedb commit ee7b390
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 1,769 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
pull_request:
push:
branches:
- staging
- trying
- staging
- trying

jobs:
lint:
Expand Down Expand Up @@ -121,9 +121,6 @@ jobs:
ci_run zk test i api
ci_run zk test i api-docs
- name: integration-zcli
run: ci_run zk test i zcli

- name: integration-rust-sdk
run: ci_run zk test i rust-sdk

Expand All @@ -147,7 +144,7 @@ jobs:
run: |
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
- name: start-services
run: |
docker-compose -f docker-compose-runner.yml down
Expand Down Expand Up @@ -234,7 +231,6 @@ jobs:
docker-compose -f docker-compose-runner.yml exec -T -e ALLOWED_PERCENT=20 -e RUST_LOG=loadnext=debug -e ZKSYNC_RPC_ADDR=http://127.0.0.2:3030 -e WEB3_URL=http://geth:8545 -e ETH_NETWORK=localhost -e MASTER_WALLET_PK=74d8b3a188f7260f67698eb44da07397a298df5427df681ef68c45b34b61f998 -e ACCOUNTS_AMOUNT=5 -e OPERATIONS_PER_ACCOUNT=5 -e MAIN_TOKEN=DAI zk ./target/release/loadnext
docker-compose -f docker-compose-runner.yml exec -T -e ZKSYNC_REST_ADDR=http://127.0.0.2:3001 zk ts-node core/tests/check-block-root-hahes.ts
- name: stop-server
run: |
ci_run killall zksync_server
Expand All @@ -249,22 +245,20 @@ jobs:
ci_run sleep 30
docker-compose -f docker-compose-runner.yml exec -T -e ZKSYNC_REST_ADDR=http://127.0.0.2:3001 zk ts-node core/tests/check-block-root-hahes.ts
- name: Show logs
if: always()
run: |
ci_run cat server.log
ci_run cat api.log
notify:
if: always()
name: Notify on failures
runs-on: ubuntu-latest
needs: [lint, unit-tests, integration, circuit-tests, testkit, revert-blocks]
needs:
[lint, unit-tests, integration, circuit-tests, testkit, revert-blocks]
steps:
-
if: failure()
- if: failure()
name: Notify to Mattermost (on incidents)
uses: tferreira/matterfy@releases/v1
with:
Expand Down
26 changes: 15 additions & 11 deletions .github/workflows/deploy-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:

build-images:
name: Build and Push Docker Images
runs-on: [self-hosted, MAIN]
needs: [setup]
runs-on: [self-hosted, ci-runner]

steps:
- uses: actions/checkout@v2
Expand All @@ -34,25 +35,28 @@ jobs:
echo CI=1 >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
- name: start-services
run: |
docker-compose -f docker-compose-runner.yml down
docker-compose -f docker-compose-runner.yml up -d zk postgres
- name: init
run: |
cargo sqlx --version || cargo install sqlx-cli
zk
zk run yarn
cp etc/tokens/{test,localhost}.json
zk run verify-keys unpack
zk up
zk db basic-setup
ci_run zk
ci_run zk run yarn
ci_run cp etc/tokens/{test,localhost}.json
ci_run zk run verify-keys unpack
ci_run zk db basic-setup
- name: update-images
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
zk docker push rust
ci_run docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
ci_run zk docker push rust
- name: docker-down
if: always()
run: |
docker-compose down
docker-compose -f docker-compose-runner.yml down
# Reminder: when disabling the deploy stage - comment the whole job out!
deploy:
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ go_to_env.sh

core/lib/storage/.env

.zcli-config.json

# Perf/flamegraph files
perf.data*
flamegraph.svg
9 changes: 0 additions & 9 deletions bin/zcli

This file was deleted.

6 changes: 4 additions & 2 deletions core/bin/zksync_api/src/utils/token_db_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ impl TokenDBCache {
Self::default()
}

/// Performs case-insensitive token search.
pub async fn get_token(
&self,
storage: &mut StorageProcessor<'_>,
token_query: impl Into<TokenLike>,
) -> anyhow::Result<Option<Token>> {
let token_query = token_query.into();
// Just return token from cache.
if let Some((token, update_time)) = self.cache.read().await.get(&token_query) {
if let Some((token, update_time)) = self.cache.read().await.get(&token_query.to_lowercase())
{
if update_time.elapsed() < TOKEN_INVALIDATE_CACHE {
return Ok(Some(token.clone()));
}
Expand All @@ -46,7 +48,7 @@ impl TokenDBCache {
self.cache
.write()
.await
.insert(token_query, (token.clone(), Instant::now()));
.insert(token_query.to_lowercase(), (token.clone(), Instant::now()));
}

Ok(token)
Expand Down
110 changes: 55 additions & 55 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5584,6 +5584,61 @@
"nullable": []
}
},
"ba69c8315c69469b20ca6069708732c6ba2e3acee17dc3bde55622051746250c": {
"query": "\n SELECT id, address, decimals, kind as \"kind: _\", symbol FROM tokens\n WHERE lower(symbol) = lower($1)\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "address",
"type_info": "Text"
},
{
"ordinal": 2,
"name": "decimals",
"type_info": "Int2"
},
{
"ordinal": 3,
"name": "kind: _",
"type_info": {
"Custom": {
"name": "token_kind",
"kind": {
"Enum": [
"ERC20",
"NFT",
"None"
]
}
}
}
},
{
"ordinal": 4,
"name": "symbol",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"baaaff359564c5d1094fcf2650d53cf9dcac5d50fc3a549c6cff53dd472350f7": {
"query": "\n SELECT * FROM ticker_price\n WHERE token_id = $1\n LIMIT 1\n ",
"describe": {
Expand Down Expand Up @@ -6283,61 +6338,6 @@
]
}
},
"c55673eb654deef9816a03d81ac34767003f366ef28a6be49ad3a9509f21aa1a": {
"query": "\n SELECT id, address, decimals, kind as \"kind: _\", symbol FROM tokens\n WHERE symbol = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "address",
"type_info": "Text"
},
{
"ordinal": 2,
"name": "decimals",
"type_info": "Int2"
},
{
"ordinal": 3,
"name": "kind: _",
"type_info": {
"Custom": {
"name": "token_kind",
"kind": {
"Enum": [
"ERC20",
"NFT",
"None"
]
}
}
}
},
{
"ordinal": 4,
"name": "symbol",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false,
false,
false
]
}
},
"c7459e7624c46417d3a91fc39b05128cf3e88097ae114d8aad6e22b9b2cd84e9": {
"query": "\n INSERT INTO accounts ( id, last_block, nonce, address, pubkey_hash )\n VALUES ( $1, $2, $3, $4, $5 )\n ",
"describe": {
Expand Down
8 changes: 8 additions & 0 deletions core/lib/storage/src/tests/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
.expect("token by symbol not found");
assert_eq!(token_b, token_b_by_symbol);

// Try case-insensitive search
let token_b_by_symbol_case_insensitive = TokensSchema(&mut storage)
.get_token(TokenLike::Symbol(token_b.symbol.to_lowercase()))
.await
.expect("get token query failed")
.expect("token by symbol not found");
assert_eq!(token_b, token_b_by_symbol_case_insensitive);

let db_nft_token = TokensSchema(&mut storage)
.get_token(TokenLike::Id(nft.id))
.await
Expand Down
9 changes: 8 additions & 1 deletion core/lib/storage/src/tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl<'a, 'c> TokensSchema<'a, 'c> {
/// Given the numeric token ID, symbol or address, returns token.
pub async fn get_token(&mut self, token_like: TokenLike) -> QueryResult<Option<Token>> {
let start = Instant::now();

let db_token = match token_like {
TokenLike::Id(token_id) => {
sqlx::query_as!(
Expand Down Expand Up @@ -432,11 +433,17 @@ impl<'a, 'c> TokensSchema<'a, 'c> {
.await?
}
TokenLike::Symbol(token_symbol) => {
// Note: for address and symbol queries we use `lower(...) = lower(...)` syntax, which means
// that we need to do a full scan over the table in order to achieve case-insensitive search.
// Luckily, we
// 1) don't have too much tokens.
// 2) most tokens requests will be handled by `TokenDbCache` anyway,
// so it shouldn't be a problem.
sqlx::query_as!(
DbToken,
r#"
SELECT id, address, decimals, kind as "kind: _", symbol FROM tokens
WHERE symbol = $1
WHERE lower(symbol) = lower($1)
LIMIT 1
"#,
token_symbol
Expand Down
44 changes: 41 additions & 3 deletions core/lib/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,25 @@ impl TokenLike {
/// Checks if the token is Ethereum.
pub fn is_eth(&self) -> bool {
match self {
TokenLike::Symbol(symbol) => symbol == "ETH",
TokenLike::Address(address) => *address == Address::zero(),
TokenLike::Id(id) => **id == 0,
Self::Symbol(symbol) => {
// Case-insensitive comparison against `ETH`.
symbol
.chars()
.map(|c| c.to_ascii_lowercase())
.eq("eth".chars())
}
Self::Address(address) => *address == Address::zero(),
Self::Id(id) => **id == 0,
}
}

/// Makes request case-insensitive (lowercase).
/// Used to compare queries against keys in the cache.
pub fn to_lowercase(&self) -> Self {
match self {
Self::Id(id) => Self::Id(*id),
Self::Address(address) => Self::Address(*address),
Self::Symbol(symbol) => Self::Symbol(symbol.to_lowercase()),
}
}
}
Expand Down Expand Up @@ -368,4 +384,26 @@ mod tests {
))
);
}

#[test]
fn token_like_is_eth() {
let tokens = vec![
TokenLike::Address(Address::zero()),
TokenLike::Id(TokenId(0)),
TokenLike::Symbol("ETH".into()),
TokenLike::Symbol("eth".into()),
];

for token in tokens {
assert!(token.is_eth());
}
}

#[test]
fn token_like_to_case_insensitive() {
assert_eq!(
TokenLike::Symbol("ETH".into()).to_lowercase(),
TokenLike::Symbol("eth".into())
);
}
}
1 change: 1 addition & 0 deletions core/tests/ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@types/mocha-steps": "^1.3.0",
"@types/node": "^14.14.5",
"@types/node-fetch": "^2.5.7",
"@types/chai-as-promised": "^7.1.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"ethers": "^5.4.4",
Expand Down
Loading

0 comments on commit ee7b390

Please sign in to comment.