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 Fundamentals #2204

Merged
merged 54 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e40eb73
node framework + config flow
shahar4 Jun 10, 2024
476addc
migration + dal
shahar4 Jun 11, 2024
8967d86
use dal
shahar4 Jun 12, 2024
7e19e94
fmt
shahar4 Jun 12, 2024
4ab267e
fmt
shahar4 Jun 12, 2024
876a6e1
fix compilation
ischasny Jun 12, 2024
3eb58d1
wired base token adjuster into the fee model
ischasny Jun 13, 2024
e6c2686
Wired base token price to fee calculator
ischasny Jun 13, 2024
63777b0
add sqlx queries
ischasny Jun 13, 2024
d3ba4c7
Lint fixes
ischasny Jun 13, 2024
9b9fdf6
update cargo lock
ischasny Jun 13, 2024
6f4cce6
Adjusted interface
ischasny Jun 14, 2024
a2b45e1
add fee model tests
ischasny Jun 14, 2024
62d54dd
rename base_token_ratio
ischasny Jun 14, 2024
09aa927
flow seems complete
shahar4 Jun 19, 2024
bbd9f7c
working sqlx + converting params themselves
shahar4 Jun 20, 2024
313444f
real working sqlx
shahar4 Jun 20, 2024
9160131
flow through updating params
shahar4 Jun 21, 2024
cce90e1
one happy test
shahar4 Jun 21, 2024
92ce099
self CR and unit test. i tests out
shahar4 Jun 23, 2024
3adef45
merge main
shahar4 Jun 23, 2024
adba682
cargo lock
shahar4 Jun 23, 2024
681735a
retry fetching price and some self CR to make CI happy
shahar4 Jun 23, 2024
34f7252
cleanup: trait, config, running locally
shahar4 Jun 24, 2024
686ace0
fmt and todo
shahar4 Jun 24, 2024
d1ac367
merge main
shahar4 Jun 25, 2024
554c901
base token cfg non optional. nume+deno again. conversion in params. u…
shahar4 Jun 25, 2024
cd7befa
merge main
shahar4 Jun 25, 2024
58fea32
zk db prepare
shahar4 Jun 25, 2024
2909d4a
revert unwanted contract changes. run adjuster in ci
shahar4 Jun 26, 2024
66f8aea
self review nits
shahar4 Jun 26, 2024
06a4c1e
use constructor instead of deleted new
shahar4 Jun 26, 2024
2a54ef1
separate the adjuster to two
shahar4 Jun 28, 2024
0415900
merge main
shahar4 Jun 28, 2024
c044dcd
happy tests
shahar4 Jun 28, 2024
5f8dac7
remove gas adjuster abstraction
shahar4 Jun 29, 2024
f732804
added config for initial values
shahar4 Jun 30, 2024
50a3764
fmt
shahar4 Jun 30, 2024
5067528
always init fetcher with new
shahar4 Jun 30, 2024
7ad6300
removing initial config. abstracting BaseTokenFetcher
shahar4 Jul 1, 2024
334a1be
start the adjuster from the l1 gas layer
shahar4 Jul 1, 2024
6fba96c
Merge main.
shahar4 Jul 1, 2024
430aac0
adjusting to framework changes
shahar4 Jul 1, 2024
ac0bc96
adjuster constructer async and inserts an initial ratio
shahar4 Jul 1, 2024
9647fc2
rely on db ratio wout retry. start adjuster layer not from l1 gas layer
shahar4 Jul 2, 2024
7a9614d
move match into get_latest_price
shahar4 Jul 2, 2024
9344f9b
PR review
shahar4 Jul 2, 2024
8f45299
changed names
shahar4 Jul 2, 2024
4462253
merge main
shahar4 Jul 2, 2024
2b5d92c
precision and scale to NUMERIC
shahar4 Jul 2, 2024
91a5a60
remove contracts change from bad main merge
shahar4 Jul 2, 2024
cfdeb10
pass ci
shahar4 Jul 2, 2024
c35a035
default_interval not public and comments
shahar4 Jul 3, 2024
11b9fed
nits
shahar4 Jul 3, 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-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
base_token: ["Eth", "Custom"]
deployment_mode: ["Rollup", "Validium"]
env:
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,da_dispatcher${{ matrix.consensus && ',consensus' || '' }}"
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,da_dispatcher,base_token_ratio_persister${{ matrix.consensus && ',consensus' || '' }}"

runs-on: [matterlabs-ci-runner]
steps:
Expand Down Expand Up @@ -309,7 +309,7 @@ jobs:
runs-on: [matterlabs-ci-runner]

env:
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,da_dispatcher${{ matrix.consensus && ',consensus' || '' }}"
SERVER_COMPONENTS: "api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,da_dispatcher,base_token_ratio_persister${{ matrix.consensus && ',consensus' || '' }}"
EXT_NODE_FLAGS: "${{ matrix.consensus && '-- --enable-consensus' || '' }}"

steps:
Expand Down
31 changes: 31 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"core/node/contract_verification_server",
"core/node/api_server",
"core/node/tee_verifier_input_producer",
"core/node/base_token_adjuster",
# Libraries
"core/lib/db_connection",
"core/lib/zksync_core_leftovers",
Expand Down Expand Up @@ -69,6 +70,7 @@ members = [
"core/lib/web3_decl",
"core/lib/snapshots_applier",
"core/lib/crypto_primitives",
"core/lib/external_price_api",
popzxc marked this conversation as resolved.
Show resolved Hide resolved
# Test infrastructure
"core/tests/test_account",
"core/tests/loadnext",
Expand Down Expand Up @@ -248,6 +250,7 @@ zksync_types = { path = "core/lib/types" }
zksync_utils = { path = "core/lib/utils" }
zksync_web3_decl = { path = "core/lib/web3_decl" }
zksync_crypto_primitives = { path = "core/lib/crypto_primitives" }
zksync_external_price_api = { path = "core/lib/external_price_api" }

# Framework and components
zksync_node_framework = { path = "core/node/node_framework" }
Expand All @@ -274,3 +277,4 @@ zksync_node_consensus = { path = "core/node/consensus" }
zksync_contract_verification_server = { path = "core/node/contract_verification_server" }
zksync_node_api_server = { path = "core/node/api_server" }
zksync_tee_verifier_input_producer = { path = "core/node/tee_verifier_input_producer" }
zksync_base_token_adjuster = {path = "core/node/base_token_adjuster"}
8 changes: 5 additions & 3 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use zksync_config::{
L1Secrets, ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig,
ProtectiveReadsWriterConfig, Secrets,
},
ApiConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig,
GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig,
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig,
EthConfig, EthWatchConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig,
SnapshotsCreatorConfig,
};
use zksync_core_leftovers::{
genesis_init, is_genesis_needed,
Expand Down Expand Up @@ -47,7 +48,7 @@ struct Cli {
/// Comma-separated list of components to launch.
#[arg(
long,
default_value = "api,tree,eth,state_keeper,housekeeper,tee_verifier_input_producer,commitment_generator,da_dispatcher"
default_value = "api,tree,eth,state_keeper,housekeeper,tee_verifier_input_producer,commitment_generator,da_dispatcher,base_token_ratio_persister"
)]
components: ComponentsToRun,
/// Path to the yaml config. If set, it will be used instead of env vars.
Expand Down Expand Up @@ -271,6 +272,7 @@ fn load_env_config() -> anyhow::Result<TempConfigStore> {
da_dispatcher_config: DADispatcherConfig::from_env().ok(),
protective_reads_writer_config: ProtectiveReadsWriterConfig::from_env().ok(),
core_object_store: ObjectStoreConfig::from_env().ok(),
base_token_adjuster_config: BaseTokenAdjusterConfig::from_env().ok(),
commitment_generator: None,
pruning: None,
snapshot_recovery: None,
Expand Down
19 changes: 19 additions & 0 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use zksync_node_api_server::{
};
use zksync_node_framework::{
implementations::layers::{
base_token_ratio_persister::BaseTokenRatioPersisterLayer,
base_token_ratio_provider::BaseTokenRatioProviderLayer,
circuit_breaker_checker::CircuitBreakerCheckerLayer,
commitment_generator::CommitmentGeneratorLayer,
consensus::{ConsensusLayer, Mode as ConsensusMode},
Expand Down Expand Up @@ -57,6 +59,7 @@ use zksync_node_framework::{
},
service::{ZkStackService, ZkStackServiceBuilder},
};
use zksync_types::SHARED_BRIDGE_ETHER_TOKEN_ADDRESS;
use zksync_vlog::prometheus::PrometheusExporterConfig;

/// Macro that looks into a path to fetch an optional config,
Expand Down Expand Up @@ -148,6 +151,11 @@ impl MainNodeBuilder {
}

fn add_sequencer_l1_gas_layer(mut self) -> anyhow::Result<Self> {
// Ensure the BaseTokenRatioProviderResource is inserted if the base token is not ETH.
if self.contracts_config.base_token_addr != Some(SHARED_BRIDGE_ETHER_TOKEN_ADDRESS) {
self.node.add_layer(BaseTokenRatioProviderLayer {});
}

let gas_adjuster_config = try_load_config!(self.configs.eth)
.gas_adjuster
.context("Gas adjuster")?;
Expand Down Expand Up @@ -495,6 +503,14 @@ impl MainNodeBuilder {
Ok(self)
}

fn add_base_token_ratio_persister_layer(mut self) -> anyhow::Result<Self> {
let config = try_load_config!(self.configs.base_token_adjuster);
self.node
.add_layer(BaseTokenRatioPersisterLayer::new(config));

Ok(self)
}

pub fn build(mut self, mut components: Vec<Component>) -> anyhow::Result<ZkStackService> {
// Add "base" layers (resources and helper tasks).
self = self
Expand Down Expand Up @@ -585,6 +601,9 @@ impl MainNodeBuilder {
Component::VmRunnerProtectiveReads => {
self = self.add_vm_runner_protective_reads_layer()?;
}
Component::BaseTokenRatioPersister => {
self = self.add_base_token_ratio_persister_layer()?;
}
}
}
Ok(self.node.build()?)
Expand Down
31 changes: 31 additions & 0 deletions core/lib/config/src/configs/base_token_adjuster.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::time::Duration;

use serde::Deserialize;

/// By default the ratio persister will run every 30 seconds.
pub const DEFAULT_INTERVAL_MS: u64 = 30_000;

#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct BaseTokenAdjusterConfig {
/// How often to spark a new cycle of the ratio persister to fetch external prices and persis ratios.
#[serde(default = "BaseTokenAdjusterConfig::default_interval")]
pub price_polling_interval_ms: u64,
}

impl Default for BaseTokenAdjusterConfig {
fn default() -> Self {
Self {
price_polling_interval_ms: Self::default_interval(),
}
}
}

impl BaseTokenAdjusterConfig {
fn default_interval() -> u64 {
DEFAULT_INTERVAL_MS
}

pub fn price_polling_interval(&self) -> Duration {
Duration::from_millis(self.price_polling_interval_ms)
}
}
1 change: 1 addition & 0 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct ContractsConfig {
pub l2_testnet_paymaster_addr: Option<Address>,
pub l1_multicall3_addr: Address,
pub ecosystem_contracts: Option<EcosystemContracts>,
// Used by the RPC API and by the node builder in wiring the BaseTokenRatioProvider layer.
pub base_token_addr: Option<Address>,
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl SenderConfig {
}
}

#[derive(Debug, Deserialize, Copy, Clone, PartialEq)]
#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Default)]
pub struct GasAdjusterConfig {
/// Priority Fee to be used by GasAdjuster
pub default_priority_fee_per_gas: u64,
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
configs::{
base_token_adjuster::BaseTokenAdjusterConfig,
chain::{CircuitBreakerConfig, MempoolConfig, OperationsManagerConfig, StateKeeperConfig},
da_dispatcher::DADispatcherConfig,
fri_prover_group::FriProverGroupConfig,
Expand Down Expand Up @@ -43,4 +44,5 @@ pub struct GeneralConfig {
pub snapshot_recovery: Option<SnapshotRecoveryConfig>,
pub pruning: Option<PruningConfig>,
pub core_object_store: Option<ObjectStoreConfig>,
pub base_token_adjuster: Option<BaseTokenAdjusterConfig>,
}
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Public re-exports
pub use self::{
api::ApiConfig,
base_token_adjuster::BaseTokenAdjusterConfig,
commitment_generator::CommitmentGeneratorConfig,
contract_verifier::ContractVerifierConfig,
contracts::{ContractsConfig, EcosystemContracts},
Expand Down Expand Up @@ -28,6 +29,7 @@ pub use self::{
};

pub mod api;
pub mod base_token_adjuster;
pub mod chain;
mod commitment_generator;
pub mod consensus;
Expand Down
6 changes: 3 additions & 3 deletions core/lib/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)]

pub use crate::configs::{
ApiConfig, ContractVerifierConfig, ContractsConfig, DADispatcherConfig, DBConfig, EthConfig,
EthWatchConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig,
SnapshotsCreatorConfig,
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, ContractsConfig,
DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, GasAdjusterConfig, GenesisConfig,
ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig,
};

pub mod configs;
Expand Down

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS base_token_ratios;
Loading
Loading