Skip to content

Commit

Permalink
rusk: add [vm] config section
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jan 29, 2025
1 parent 93b5619 commit 6407802
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 66 deletions.
10 changes: 9 additions & 1 deletion rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `[chain].public_sender_start_height` config [#3341]
- Add `abi::public_sender` [#3341]
- Add `[vm]` config section [#3341]

### Changed

- Deprecate `[chain].gas_per_deploy_byte` config [#3341]
- Deprecate `[chain].min_deployment_gas_price` config [#3341]
- Deprecate `[chain].generation_timeout` config [#3341]
- Deprecate `[chain].min_deploy_points` config [#3341]
- Deprecate `[chain].block_gas_limit` config [#3341]

### Removed

Expand Down
19 changes: 13 additions & 6 deletions rusk/default.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@
[chain]
#db_path = '/home/user/.dusk/rusk'
#consensus_keys_path = '/home/user/.dusk/rusk/consensus.keys'
#generation_timeout = '3s'
# Note: changing the gas per deploy byte parameter is equivalent to forking the chain.
#gas_per_deploy_byte = 100
#min_deployment_gas_price = 2000
#min_gas_limit = 75000
#min_deploy_points = 5000000

# Note: changing the vm settings is equivalent to forking the chain.
[vm]
generation_timeout = '3s'
gas_per_deploy_byte = 100
min_deployment_gas_price = 2000
min_gas_limit = 75000
min_deploy_points = 5000000

[vm.features]
# key = activation_height
# key = activation_height
# key = activation_height

[databroker]
max_inv_entries = 100
Expand Down
7 changes: 7 additions & 0 deletions rusk/src/bin/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use self::{
mempool::MempoolConfig, telemetry::TelemetryConfig,
};

#[cfg(feature = "chain")]
use rusk::node::RuskVmConfig;

use serde::{Deserialize, Serialize};

use crate::args::Args;
Expand All @@ -50,6 +53,10 @@ pub(crate) struct Config {
#[serde(default = "ChainConfig::default")]
pub(crate) chain: ChainConfig,

#[cfg(feature = "chain")]
#[serde(default = "RuskVmConfig::default")]
pub(crate) vm: RuskVmConfig,

#[serde(default = "HttpConfig::default")]
pub(crate) http: HttpConfig,

Expand Down
5 changes: 0 additions & 5 deletions rusk/src/bin/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub(crate) struct ChainConfig {
min_deploy_points: Option<u64>,
min_gas_limit: Option<u64>,
block_gas_limit: Option<u64>,
public_sender_start_height: Option<u64>,

#[serde(with = "humantime_serde")]
#[serde(default)]
Expand Down Expand Up @@ -97,10 +96,6 @@ impl ChainConfig {
self.min_deploy_points
}

pub(crate) fn public_sender_start_height(&self) -> Option<u64> {
self.public_sender_start_height
}

pub(crate) fn min_gas_limit(&self) -> Option<u64> {
self.min_gas_limit
}
Expand Down
40 changes: 28 additions & 12 deletions rusk/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod ephemeral;
mod log;

#[cfg(feature = "chain")]
use tracing::info;
use tracing::{info, warn};

use clap::Parser;

Expand Down Expand Up @@ -69,6 +69,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db_path = config.chain.db_path();

node_builder = node_builder
.with_vm_config(config.vm)
.with_feeder_call_gas(config.http.feeder_call_gas)
.with_db_path(db_path)
.with_db_options(config.chain.db_options())
Expand All @@ -80,17 +81,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_genesis_timestamp(config.chain.genesis_timestamp())
.with_mempool(config.mempool.into())
.with_state_dir(state_dir)
.with_generation_timeout(config.chain.generation_timeout())
.with_gas_per_deploy_byte(config.chain.gas_per_deploy_byte())
.with_min_deployment_gas_price(
config.chain.min_deployment_gas_price(),
)
.with_min_deploy_points(config.chain.min_deploy_points())
.with_public_sender_start_height(
config.chain.public_sender_start_height(),
)
.with_min_gas_limit(config.chain.min_gas_limit())
.with_block_gas_limit(config.chain.block_gas_limit());
.with_min_gas_limit(config.chain.min_gas_limit());

#[allow(deprecated)]
{
if let Some(gas_byte) = config.chain.gas_per_deploy_byte() {
warn!("[chain].gas_per_deploy_byte is deprecated, use [vm].gas_per_deploy_byte");
node_builder = node_builder.with_gas_per_deploy_byte(gas_byte);
}
if let Some(price) = config.chain.min_deployment_gas_price() {
warn!("[chain].min_deployment_gas_price is deprecated, use [vm].min_deployment_gas_price");
node_builder =
node_builder.with_min_deployment_gas_price(price);
}
if let Some(timeout) = config.chain.generation_timeout() {
warn!("[chain].generation_timeout is deprecated, use [vm].generation_timeout");
node_builder = node_builder.with_generation_timeout(timeout);
}
if let Some(min) = config.chain.min_deploy_points() {
warn!("[chain].min_deploy_points is deprecated, use [vm].min_deploy_points");
node_builder = node_builder.with_min_deploy_points(min);
}
if let Some(limit) = config.chain.block_gas_limit() {
warn!("[chain].block_gas_limit is deprecated, use [vm].block_gas_limit");
node_builder = node_builder.with_block_gas_limit(limit);
}
}
};

if config.http.listen {
Expand Down
51 changes: 25 additions & 26 deletions rusk/src/lib/builder/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,32 @@ impl RuskNodeBuilder {
self
}

pub fn with_generation_timeout(
#[deprecated(since = "1.0.3", note = "please use `with_vm_config` instead")]
pub fn with_generation_timeout<O: Into<Option<Duration>>>(
mut self,
generation_timeout: Option<Duration>,
generation_timeout: O,
) -> Self {
self.vm_config.generation_timeout = generation_timeout;
self.vm_config.generation_timeout = generation_timeout.into();
self
}

pub fn with_gas_per_deploy_byte(
#[deprecated(since = "1.0.3", note = "please use `with_vm_config` instead")]
pub fn with_gas_per_deploy_byte<O: Into<Option<u64>>>(
mut self,
gas_per_deploy_byte: Option<u64>,
gas_per_deploy_byte: O,
) -> Self {
if let Some(gas_per_deploy_byte) = gas_per_deploy_byte {
if let Some(gas_per_deploy_byte) = gas_per_deploy_byte.into() {
self.vm_config.gas_per_deploy_byte = gas_per_deploy_byte;
}
self
}

pub fn with_min_deployment_gas_price(
#[deprecated(since = "1.0.3", note = "please use `with_vm_config` instead")]
pub fn with_min_deployment_gas_price<O: Into<Option<u64>>>(
mut self,
min_deployment_gas_price: Option<u64>,
min_deployment_gas_price: O,
) -> Self {
if let Some(min_deploy_gas_price) = min_deployment_gas_price {
if let Some(min_deploy_gas_price) = min_deployment_gas_price.into() {
self.vm_config.min_deploy_gas_price = min_deploy_gas_price;
}
self
Expand All @@ -139,37 +142,28 @@ impl RuskNodeBuilder {
self
}

pub fn with_min_deploy_points(
#[deprecated(since = "1.0.3", note = "please use `with_vm_config` instead")]
pub fn with_min_deploy_points<O: Into<Option<u64>>>(
mut self,
min_deploy_points: Option<u64>,
min_deploy_points: O,
) -> Self {
if let Some(min_deploy_points) = min_deploy_points {
if let Some(min_deploy_points) = min_deploy_points.into() {
self.vm_config.min_deploy_points = min_deploy_points;
}
self
}

pub fn with_block_gas_limit(
#[deprecated(since = "1.0.3", note = "please use `with_vm_config` instead")]
pub fn with_block_gas_limit<O: Into<Option<u64>>>(
mut self,
block_gas_limit: Option<u64>,
block_gas_limit: O,
) -> Self {
if let Some(block_gas_limit) = block_gas_limit {
if let Some(block_gas_limit) = block_gas_limit.into() {
self.vm_config.block_gas_limit = block_gas_limit;
}
self
}

pub fn with_public_sender_start_height(
mut self,
public_sender_start_height: Option<u64>,
) -> Self {
if let Some(public_sender_start_height) = public_sender_start_height {
self.vm_config.public_sender_start_height =
public_sender_start_height;
}
self
}

pub fn with_feeder_call_gas(mut self, feeder_call_gas: u64) -> Self {
self.feeder_call_gas = feeder_call_gas;
self
Expand All @@ -190,6 +184,11 @@ impl RuskNodeBuilder {
self
}

pub fn with_vm_config(mut self, vm_config: RuskVmConfig) -> Self {
self.vm_config = vm_config;
self
}

/// Build the RuskNode and corresponding services
pub async fn build_and_run(self) -> anyhow::Result<()> {
let channel_cap = self
Expand Down
60 changes: 44 additions & 16 deletions rusk/src/lib/node/vm/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,52 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::collections::HashMap;
use std::time::Duration;

use dusk_vm::ExecutionConfig;
use serde::{Deserialize, Serialize};

const DEFAULT_GAS_PER_DEPLOY_BYTE: u64 = 100;
const DEFAULT_MIN_DEPLOYMENT_GAS_PRICE: u64 = 2000;
const DEFAULT_MIN_DEPLOY_POINTS: u64 = 5_000_000;
const DEFAULT_BLOCK_GAS_LIMIT: u64 = 3 * 1_000_000_000;
const fn default_gas_per_deploy_byte() -> u64 {
100
}
const fn default_min_deploy_points() -> u64 {
5_000_000
}
const fn default_min_deployment_gas_price() -> u64 {
2_000
}
const fn default_block_gas_limit() -> u64 {
3 * 1_000_000_000
}

/// Configuration for the execution of a transaction.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
/// The amount of gas points charged for each byte in a contract-deployment
/// bytecode.
#[serde(default = "default_gas_per_deploy_byte")]
pub gas_per_deploy_byte: u64,

/// The minimum gas points charged for a contract deployment.
#[serde(default = "default_min_deploy_points")]
pub min_deploy_points: u64,

/// The minimum gas price set for a contract deployment
#[serde(default = "default_min_deployment_gas_price")]
pub min_deploy_gas_price: u64,

/// The maximum amount of gas points that can be used in a block.
#[serde(default = "default_block_gas_limit")]
pub block_gas_limit: u64,

/// The timeout for a candidate block generation.
#[serde(with = "humantime_serde")]
#[serde(default)]
pub generation_timeout: Option<Duration>,
/// The height at which the public sender starts to be injected in the
/// block metadata
pub public_sender_start_height: u64,

/// Set of features to activate
pub features: HashMap<String, u64>,
}

impl Default for Config {
Expand All @@ -41,13 +61,12 @@ impl Default for Config {
impl Config {
pub fn new() -> Self {
Self {
gas_per_deploy_byte: DEFAULT_GAS_PER_DEPLOY_BYTE,
min_deploy_gas_price: DEFAULT_MIN_DEPLOYMENT_GAS_PRICE,
min_deploy_points: DEFAULT_MIN_DEPLOY_POINTS,
block_gas_limit: DEFAULT_BLOCK_GAS_LIMIT,
gas_per_deploy_byte: default_gas_per_deploy_byte(),
min_deploy_gas_price: default_min_deployment_gas_price(),
min_deploy_points: default_min_deploy_points(),
block_gas_limit: default_block_gas_limit(),
generation_timeout: None,
// Disabled by default
public_sender_start_height: u64::MAX,
features: HashMap::new(),
}
}

Expand Down Expand Up @@ -96,13 +115,22 @@ impl Config {

/// Create a new `Config` with the given parameters.
pub fn to_execution_config(&self, block_height: u64) -> ExecutionConfig {
let with_public_sender =
block_height >= self.public_sender_start_height;
let with_public_sender = self
.feature("ABI_PUBLIC_SENDER")
.map(|activation| activation >= block_height)
.unwrap_or_default();
ExecutionConfig {
gas_per_deploy_byte: self.gas_per_deploy_byte,
min_deploy_points: self.min_deploy_points,
min_deploy_gas_price: self.min_deploy_gas_price,
with_public_sender,
}
}

pub fn feature(&self, feature: &str) -> Option<u64> {
self.features
.iter()
.find(|(k, _)| k.eq_ignore_ascii_case(feature))
.map(|(_, &v)| v)
}
}

0 comments on commit 6407802

Please sign in to comment.