Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: base token integration tests #2509

Open
wants to merge 91 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
87fc80f
Use forced price api client by default
cytadela8 Jul 26, 2024
0d8b455
fix: smoothed ForcedPriceClient
cytadela8 Jul 29, 2024
0ca2b5e
feat: Integration test gas price incl calculation
cytadela8 Jul 29, 2024
f15bade
fix: Fetch base ratio immediately on start
cytadela8 Jul 30, 2024
ee7800b
fix: enable all fees tests
cytadela8 Jul 30, 2024
6112552
fix: increase alice wallet balance in fees.test.ts
cytadela8 Jul 31, 2024
e3e1356
fix: style
cytadela8 Jul 31, 2024
fd5fa8b
fix(tests): Kill with sigint
cytadela8 Jul 31, 2024
7592dfd
tmp: remove randomness in base token price
cytadela8 Jul 31, 2024
a656770
Try upgrade zksync-ethers to 6.11.0
cytadela8 Jul 31, 2024
ce0d00f
debug
cytadela8 Jul 31, 2024
73cebec
Revert "Try upgrade zksync-ethers to 6.11.0"
cytadela8 Jul 31, 2024
ecf18a4
fix: properly kill server after fees test
cytadela8 Aug 1, 2024
cb76faa
Avoid gasEstimate in fees test
cytadela8 Aug 1, 2024
04b023a
fix: style
cytadela8 Aug 1, 2024
79e691f
debug: more logs
cytadela8 Aug 1, 2024
8e554a2
debug: log addresses
cytadela8 Aug 1, 2024
50fcd67
fix: increase test ETH per account due to large gas price test and re…
cytadela8 Aug 1, 2024
baa5261
Revert "fix: increase test ETH per account due to large gas price tes…
cytadela8 Aug 1, 2024
c5213b1
fix(test): Increase fees.test.ts alice account balance
cytadela8 Aug 1, 2024
644c230
fix(test): Lower l1 gas price in expected gas price test
cytadela8 Aug 1, 2024
0a9676b
fix(test): Lower l1 gas price in expected gas price test even more
cytadela8 Aug 2, 2024
46d5414
Revert "Avoid gasEstimate in fees test"
cytadela8 Aug 2, 2024
c902dc2
Revert "tmp: remove randomness in base token price"
cytadela8 Aug 2, 2024
93126b5
fix: add validium compute overhead
cytadela8 Aug 2, 2024
358769d
fix tests
ischasny Aug 15, 2024
6c1f1af
reduce variation range
ischasny Aug 16, 2024
068a7aa
fix: actually use fluctuation
cytadela8 Aug 26, 2024
b443cfa
Revert "fix tests"
cytadela8 Aug 27, 2024
af9332c
Revert "reduce variation range"
cytadela8 Aug 27, 2024
452ea58
Remove BumpUpFeeWallet leftovers
cytadela8 Aug 27, 2024
90b345a
feat: do not display Obtained receipt... debug logs by default
cytadela8 Aug 27, 2024
f171a46
Remove gas price debug log
cytadela8 Aug 27, 2024
e8115ad
fix: adjust base token test expected ratio
cytadela8 Aug 27, 2024
06abea9
feat: reenable forced client price fluctuation
cytadela8 Aug 28, 2024
64bf3bc
fix: lower forced ratio value by /10
cytadela8 Aug 28, 2024
33ca127
feat: add reason of setTokenMultiplier failure
cytadela8 Aug 28, 2024
9d454c4
feat: check changing base token ratio
cytadela8 Aug 29, 2024
83dfbea
fix: remove fluctuation in base token ratio
cytadela8 Aug 29, 2024
cbe672f
feat: add fluctuations test
cytadela8 Aug 30, 2024
390c0d1
fix: undo timer.tick reorder
cytadela8 Aug 30, 2024
f38102b
fix: typescript
cytadela8 Aug 30, 2024
6cc1f2b
Merge remote-tracking branch 'origin/main' into apu-base-token-integr…
cytadela8 Aug 30, 2024
4b00cab
feat: (re)add reason of setTokenMultiplier tx failure
cytadela8 Aug 30, 2024
86c74b6
fix: restore debug levels
cytadela8 Aug 30, 2024
157aaab
fix
cytadela8 Aug 30, 2024
d322e6e
fix test
cytadela8 Aug 30, 2024
02f13c0
fix: update config for zk_toolbox
cytadela8 Sep 2, 2024
a625f17
fix: allow more time for L1 update
cytadela8 Sep 2, 2024
a9d6d44
fix: lower base ratio l1 update minimal deviation in tests
cytadela8 Sep 2, 2024
d406c8f
fix: typo
cytadela8 Sep 2, 2024
fa62583
fix: properly set l1 update deviation percentage
cytadela8 Sep 2, 2024
6f9e6ba
fix: zk_toolbox env for tests
cytadela8 Sep 2, 2024
eeea10c
feat: remove unnecessery transfer of extra funds in fees.test.ts
cytadela8 Sep 2, 2024
d5512cd
fix: lint
cytadela8 Sep 2, 2024
e4fe076
fix: properly set zk_toolbox base token price
cytadela8 Sep 2, 2024
ea7a3b7
Revert "feat: remove unnecessery transfer of extra funds in fees.test…
cytadela8 Sep 3, 2024
2722b79
fix: missing import, remove extra logs
cytadela8 Sep 3, 2024
d212602
feat: add config option for fluctuation
cytadela8 Sep 3, 2024
88154fe
fix: config test
cytadela8 Sep 3, 2024
3ad4d86
feat: properly perform fluctuations on low numerator
cytadela8 Sep 3, 2024
7e1997d
fix: typo
cytadela8 Sep 6, 2024
2384d62
fix: only deposit extra funds in custom base token test
cytadela8 Sep 6, 2024
8680ed8
fix: naming and docs in fees.test.ts
cytadela8 Sep 6, 2024
034f720
fix: comments
cytadela8 Sep 11, 2024
8bee1d8
fix: RwLock->Mutex
cytadela8 Sep 11, 2024
8963d0b
fix: new line
cytadela8 Sep 11, 2024
ca0ee75
fix: rename
cytadela8 Sep 11, 2024
3826469
fix: spell
cytadela8 Sep 11, 2024
8cee2b6
fix: avoid hardcoding gas price in test
cytadela8 Sep 12, 2024
da45a29
fix: cleaner application of conversion ratio. Proper check of value
cytadela8 Sep 12, 2024
1f6a54d
fix: update overhead calculation logic, some bigint improvements
cytadela8 Sep 12, 2024
45e720a
fix: remove less useful test
cytadela8 Sep 13, 2024
3fd86a5
Merge remote-tracking branch 'origin/main' into apu-base-token-integr…
cytadela8 Sep 23, 2024
b3a2472
fix: remove empty file
cytadela8 Sep 23, 2024
6654d28
fix: proper base token values in toolbox run tests
cytadela8 Sep 23, 2024
5360744
Merge remote-tracking branch 'origin/main' into apu-base-token-integr…
cytadela8 Oct 1, 2024
f11a099
feat: migrated to new way of starting server in fees test
cytadela8 Oct 1, 2024
70fae20
fix: import issues, missing kill, format
cytadela8 Oct 2, 2024
64c7240
debug: debug logs
cytadela8 Oct 9, 2024
ef3c924
Merge remote-tracking branch 'origin/main' into apu-base-token-integr…
cytadela8 Oct 9, 2024
e8c087e
Merge remote-tracking branch 'origin/main' into apu-base-token-integr…
cytadela8 Oct 9, 2024
1c6de49
fix: node spawning bug
cytadela8 Oct 9, 2024
b03433b
feat: simplify node spawning to avoid forgotten nodes
cytadela8 Oct 11, 2024
7ca8434
Merge remote-tracking branch 'origin/main' into apu-base-token-integr…
cytadela8 Oct 14, 2024
ef0e4ed
lint
cytadela8 Oct 14, 2024
7026fa1
feat: nonce stable deposit of token sin integration test context-owne…
cytadela8 Oct 15, 2024
5148250
Revert "feat: nonce stable deposit of token sin integration test cont…
cytadela8 Oct 15, 2024
f05a21a
feat: less stupid yaml config override code
cytadela8 Oct 16, 2024
9ebfc33
fix: distribute eth to token_multplier_setter
cytadela8 Oct 16, 2024
509dab3
fix: Add 1 block wait to gas price test
cytadela8 Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci-zk-toolbox-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address ${{ env.address }} \
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--base-token-price-nominator 314 \
--base-token-price-denominator 1000 \
--set-as-default false \
--ignore-prerequisites

Expand Down
14 changes: 12 additions & 2 deletions core/lib/config/src/configs/external_price_api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ use serde::Deserialize;

pub const DEFAULT_TIMEOUT_MS: u64 = 10_000;

pub const DEFAULT_FORCED_NEXT_VALUE_FLUCTUATION: u32 = 3;

#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct ForcedPriceClientConfig {
/// Forced conversion ratio
pub numerator: Option<u64>,
pub denominator: Option<u64>,
/// Forced fluctuation. It defines how much percent numerator /
/// denominator should fluctuate from their forced values. If it's None or 0, then ForcedPriceClient
/// Forced fluctuation. It defines how much percent the ratio
/// should fluctuate from their forced values. If it's None or 0, then ForcedPriceClient
cytadela8 marked this conversation as resolved.
Show resolved Hide resolved
/// will return the same quote every time it's called. Otherwise, ForcedPriceClient will return
/// forced_quote +/- forced_fluctuation % from its values.
pub fluctuation: Option<u32>,
/// In order to smooth out fluctuation consecutive values returned by forced client will not
/// differ more than next_value_fluctuation percent. If it's None, a default of 3% will be applied.
#[serde(default = "ExternalPriceApiClientConfig::default_forced_next_value_fluctuation")]
pub next_value_fluctuation: u32,
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
Expand All @@ -31,6 +37,10 @@ impl ExternalPriceApiClientConfig {
DEFAULT_TIMEOUT_MS
}

fn default_forced_next_value_fluctuation() -> u32 {
DEFAULT_FORCED_NEXT_VALUE_FLUCTUATION
}

pub fn client_timeout(&self) -> Duration {
Duration::from_millis(self.client_timeout_ms)
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ impl Distribution<configs::external_price_api_client::ExternalPriceApiClientConf
numerator: self.sample(rng),
denominator: self.sample(rng),
fluctuation: self.sample(rng),
next_value_fluctuation: self.sample(rng),
}),
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/env_config/src/external_price_api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod tests {
numerator: Some(100),
denominator: Some(1),
fluctuation: Some(10),
next_value_fluctuation: 1,
}),
}
}
Expand All @@ -57,6 +58,7 @@ mod tests {
EXTERNAL_PRICE_API_CLIENT_FORCED_NUMERATOR=100
EXTERNAL_PRICE_API_CLIENT_FORCED_DENOMINATOR=1
EXTERNAL_PRICE_API_CLIENT_FORCED_FLUCTUATION=10
EXTERNAL_PRICE_API_CLIENT_FORCED_NEXT_VALUE_FLUCTUATION=1
"#;
lock.set_env(config);

Expand Down
87 changes: 61 additions & 26 deletions core/lib/external_price_api/src/forced_price_client.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use std::num::NonZeroU64;
use std::{
cmp::{max, min},
num::NonZeroU64,
};

use async_trait::async_trait;
use rand::Rng;
use tokio::sync::RwLock;
use zksync_config::configs::ExternalPriceApiClientConfig;
use zksync_types::{base_token_ratio::BaseTokenAPIRatio, Address};

use crate::PriceAPIClient;

// Struct for a a forced price "client" (conversion ratio is always a configured "forced" ratio).
#[derive(Debug, Clone)]
// Struct for a forced price "client" (conversion ratio is always a configured "forced" ratio).
#[derive(Debug)]
pub struct ForcedPriceClient {
ratio: BaseTokenAPIRatio,
previous_numerator: RwLock<NonZeroU64>,
fluctuation: Option<u32>,
next_value_fluctuation: u32,
}

impl ForcedPriceClient {
Expand All @@ -29,42 +35,71 @@ impl ForcedPriceClient {
let fluctuation = forced_price_client_config
.fluctuation
.map(|x| x.clamp(0, 100));
let next_value_fluctuation = forced_price_client_config
.next_value_fluctuation
.clamp(0, 100);

Self {
ratio: BaseTokenAPIRatio {
let ratio = if numerator < 100 && fluctuation.is_some_and(|f| f > 0) {
// If numerator is too small we need to multiply by 100 to make sure fluctuations can be applied
BaseTokenAPIRatio {
numerator: NonZeroU64::new(numerator * 100).unwrap(),
denominator: NonZeroU64::new(denominator * 100).unwrap(),
ratio_timestamp: chrono::Utc::now(),
}
} else {
BaseTokenAPIRatio {
numerator: NonZeroU64::new(numerator).unwrap(),
denominator: NonZeroU64::new(denominator).unwrap(),
ratio_timestamp: chrono::Utc::now(),
},
}
};

Self {
ratio,
previous_numerator: RwLock::new(NonZeroU64::new(numerator).unwrap()),
fluctuation,
next_value_fluctuation,
}
}
}

#[async_trait]
impl PriceAPIClient for ForcedPriceClient {
// Returns a ratio which is 10% higher or lower than the configured forced ratio.
/// Returns a ratio which is 10% higher or lower than the configured forced ratio,
/// but not different more than 3% than the last value
async fn fetch_ratio(&self, _token_address: Address) -> anyhow::Result<BaseTokenAPIRatio> {
cytadela8 marked this conversation as resolved.
Show resolved Hide resolved
if let Some(x) = self.fluctuation {
if x != 0 {
let mut rng = rand::thread_rng();

let mut adjust_range = |value: NonZeroU64| {
let value_f64 = value.get() as f64;
let min = (value_f64 * (1.0 - x as f64 / 100.0)).round() as u64;
let max = (value_f64 * (1.0 + x as f64 / 100.0)).round() as u64;
rng.gen_range(min..=max)
};
let new_numerator = adjust_range(self.ratio.numerator);
let new_denominator = adjust_range(self.ratio.denominator);
if let Some(fluctation) = self.fluctuation {
let mut previous_numerator = self.previous_numerator.write().await;
let mut rng = rand::thread_rng();
cytadela8 marked this conversation as resolved.
Show resolved Hide resolved
let numerator_range = (
max(
cytadela8 marked this conversation as resolved.
Show resolved Hide resolved
(self.ratio.numerator.get() as f64 * (1.0 - (fluctation as f64 / 100.0)))
.round() as u64,
(previous_numerator.get() as f64
* (1.0 - (self.next_value_fluctuation as f64 / 100.0)))
.round() as u64,
),
min(
(self.ratio.numerator.get() as f64 * (1.0 + (fluctation as f64 / 100.0)))
.round() as u64,
(previous_numerator.get() as f64
* (1.0 + (self.next_value_fluctuation as f64 / 100.0)))
.round() as u64,
),
);

return Ok(BaseTokenAPIRatio {
numerator: NonZeroU64::new(new_numerator).unwrap_or(self.ratio.numerator),
denominator: NonZeroU64::new(new_denominator).unwrap_or(self.ratio.denominator),
ratio_timestamp: chrono::Utc::now(),
});
}
let new_numerator =
NonZeroU64::new(rng.gen_range(numerator_range.0..=numerator_range.1))
.unwrap_or(self.ratio.numerator);
let adjusted_ratio = BaseTokenAPIRatio {
numerator: new_numerator,
denominator: self.ratio.denominator,
ratio_timestamp: chrono::Utc::now(),
};
*previous_numerator = new_numerator;
Ok(adjusted_ratio)
} else {
Ok(self.ratio)
}
Ok(self.ratio)
}
}
5 changes: 5 additions & 0 deletions core/lib/protobuf_config/src/external_price_api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ impl ProtoRepr for proto::ExternalPriceApiClient {
numerator: self.forced_numerator,
denominator: self.forced_denominator,
fluctuation: self.forced_fluctuation,
next_value_fluctuation: self.forced_next_value_fluctuation.unwrap_or(
configs::external_price_api_client::DEFAULT_FORCED_NEXT_VALUE_FLUCTUATION,
),
}),
},
)
Expand All @@ -26,6 +29,7 @@ impl ProtoRepr for proto::ExternalPriceApiClient {
let numerator = this.forced.as_ref().and_then(|x| x.numerator);
let denominator = this.forced.as_ref().and_then(|x| x.denominator);
let fluctuation = this.forced.as_ref().and_then(|x| x.fluctuation);
let next_value_fluctuation = this.forced.as_ref().map(|x| x.next_value_fluctuation);

Self {
source: Some(this.source.clone()),
Expand All @@ -35,6 +39,7 @@ impl ProtoRepr for proto::ExternalPriceApiClient {
forced_numerator: numerator,
forced_denominator: denominator,
forced_fluctuation: fluctuation,
forced_next_value_fluctuation: next_value_fluctuation,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ message ExternalPriceApiClient {
optional uint64 forced_numerator = 5;
optional uint64 forced_denominator = 6;
optional uint32 forced_fluctuation = 7;
optional uint32 forced_next_value_fluctuation = 8;
}
10 changes: 8 additions & 2 deletions core/node/base_token_adjuster/src/base_token_l1_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ impl BaseTokenL1Behaviour {
if receipt.status == Some(1.into()) {
return Ok(receipt.gas_used);
}
let reason = (*l1_params.eth_client)
.as_ref()
.failure_reason(hash)
.await
.context("failed getting failure reason of `setTokenMultiplier` transaction")?;
return Err(anyhow::Error::msg(format!(
"`setTokenMultiplier` transaction {:?} failed with status {:?}",
"`setTokenMultiplier` transaction {:?} failed with status {:?}, reason: {:?}",
hex::encode(hash),
receipt.status
receipt.status,
reason
)));
} else {
tokio::time::sleep(sleep_duration).await;
Expand Down
3 changes: 1 addition & 2 deletions core/node/external_proof_integration_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ mod middleware;
mod processor;
mod types;

pub use crate::processor::Processor;

cytadela8 marked this conversation as resolved.
Show resolved Hide resolved
use std::net::SocketAddr;

use anyhow::Context;
Expand All @@ -20,6 +18,7 @@ use tokio::sync::watch;
use types::{ExternalProof, ProofGenerationDataResponse};
use zksync_basic_types::L1BatchNumber;

pub use crate::processor::Processor;
use crate::{
metrics::{CallOutcome, Method},
middleware::MetricsMiddleware,
Expand Down
7 changes: 4 additions & 3 deletions core/tests/ts-integration/src/retry-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export class RetryProvider extends zksync.Provider {

override _wrapTransactionReceipt(receipt: any): zksync.types.TransactionReceipt {
const wrapped = super._wrapTransactionReceipt(receipt);
this.reporter.debug(
`Obtained receipt for transaction ${receipt.transactionHash}: blockNumber=${receipt.blockNumber}, status=${receipt.status}`
);
if (process.env.ZKSYNC_DEBUG_TX_RECEIPT)
this.reporter.debug(
`Obtained receipt for transaction ${receipt.transactionHash}: blockNumber=${receipt.blockNumber}, status=${receipt.status}`
);
perekopskiy marked this conversation as resolved.
Show resolved Hide resolved
return wrapped;
}
}
Expand Down
5 changes: 2 additions & 3 deletions core/tests/ts-integration/tests/base-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ describe('base ERC20 contract checks', () => {
const numerator = Number(await zksyncContract.baseTokenGasPriceMultiplierNominator());
const denominator = Number(await zksyncContract.baseTokenGasPriceMultiplierDenominator());

// checking that the numerator and denominator don't have their default values
expect(numerator).toBe(3);
expect(denominator).toBe(2);
expect(numerator).toBe(314);
expect(denominator).toBe(1000);
});

test('Can perform a deposit', async () => {
Expand Down
Loading
Loading