Skip to content

Commit

Permalink
feat(models): add new consensus config
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Oct 18, 2024
1 parent 9f46bfd commit b65137e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
74 changes: 73 additions & 1 deletion src/models/config/params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::borrow::Cow;
use std::num::{NonZeroU16, NonZeroU32, NonZeroU8};
use std::num::{NonZeroU16, NonZeroU32};

use everscale_crypto::ed25519;

Expand Down Expand Up @@ -500,7 +500,74 @@ impl<'a> Load<'a> for CatchainConfig {
}
}

/// DAG Consensus configuration params
///
/// ```tlb
/// consensus_config_tycho#d8
/// clock_skew_millis:uint16
/// payload_batch_bytes:uint32
/// commit_history_rounds:uint8
/// deduplicate_rounds:uint16
/// max_consensus_lag_rounds:uint16
/// payload_buffer_bytes:uint32
/// broadcast_retry_millis:uint8
/// download_retry_millis:uint8
/// download_peers:uint8
/// download_tasks:uint16
/// sync_support_rounds:uint16
/// = ConsensusConfig;
/// ```
#[cfg(feature = "tycho")]
#[derive(Debug, Clone, Eq, PartialEq, Store, Load)]
#[tlb(tag = "#d8")]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConsensusConfig {
/// TODO: Add docs.
///
/// **NOTE: Affects overlay id.**
pub clock_skew_millis: u16,

/// TODO: Add docs.
///
/// **NOTE: Affects overlay id.**
pub payload_batch_bytes: u32,

/// TODO: Add docs.
///
/// **NOTE: Affects overlay id.**
pub commit_history_rounds: u8,

/// TODO: Add docs.
///
/// **NOTE: Affects overlay id.**
pub deduplicate_rounds: u16,

/// TODO: Add docs.
///
/// **NOTE: Affects overlay id.**
pub max_consensus_lag_rounds: u16,

/// TODO: Add docs.
pub payload_buffer_bytes: u32,

/// TODO: Add docs.
pub broadcast_retry_millis: u8,

/// TODO: Add docs.
pub download_retry_millis: u8,

/// TODO: Add docs.
pub download_peers: u8,

/// TODO: Add docs.
pub download_tasks: u16,

/// TODO: Add docs.
pub sync_support_rounds: u16,
}

/// Consensus configuration params.
#[cfg(not(feature = "tycho"))]
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConsensusConfig {
Expand All @@ -524,11 +591,13 @@ pub struct ConsensusConfig {
pub max_collated_bytes: u32,
}

#[cfg(not(feature = "tycho"))]
impl ConsensusConfig {
const TAG_V1: u8 = 0xd6;
const TAG_V2: u8 = 0xd7;
}

#[cfg(not(feature = "tycho"))]
impl Store for ConsensusConfig {
fn store_into(&self, builder: &mut CellBuilder, _: &mut dyn CellContext) -> Result<(), Error> {
let flags = self.new_catchain_ids as u8;
Expand All @@ -546,8 +615,11 @@ impl Store for ConsensusConfig {
}
}

#[cfg(not(feature = "tycho"))]
impl<'a> Load<'a> for ConsensusConfig {
fn load_from(slice: &mut CellSlice<'a>) -> Result<Self, Error> {
use std::num::NonZeroU8;

let (flags, round_candidates) = match slice.load_u8() {
Ok(Self::TAG_V1) => (0, ok!(NonZeroU32::load_from(slice))),
Ok(Self::TAG_V2) => {
Expand Down
5 changes: 3 additions & 2 deletions src/models/config/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::num::NonZeroU32;

use super::*;
use crate::boc::BocRepr;
use crate::models::{ShardIdent, ShardStateUnsplit};
use crate::prelude::Boc;

#[cfg(not(feature = "tycho"))]
#[test]
fn simple_config() {
use std::num::NonZeroU32;

let data = Boc::decode(include_bytes!("simple_config.boc")).unwrap();
let blockchain_config = data.parse::<BlockchainConfig>().unwrap();

Expand Down

0 comments on commit b65137e

Please sign in to comment.