|
|
@@ -354,8 +354,30 @@ impl ConsensusState {
|
|
|
Self::pid_error(self.extend_leaders_history())
|
|
|
}
|
|
|
|
|
|
+ fn max_windowed_forks(&self) -> Float10 {
|
|
|
+ let mut max : u64= 5;
|
|
|
+ let window_size = 10;
|
|
|
+ let len = self.leaders_history.len();
|
|
|
+ let window_begining = if len <= (window_size+1) {
|
|
|
+ 0
|
|
|
+ } else {
|
|
|
+ len - (window_size +1)
|
|
|
+ };
|
|
|
+ for item in &self.leaders_history[window_begining..] {
|
|
|
+ if *item>max {
|
|
|
+ max = *item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Float10::try_from(max as i64).unwrap().with_precision(constants::RADIX_BITS).value()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn tuned_kp(&self) -> Float10 {
|
|
|
+ (constants::KP.clone() * constants::FLOAT10_FIVE.clone())/self.max_windowed_forks()
|
|
|
+ }
|
|
|
+
|
|
|
fn weighted_f_dif(&mut self) -> Float10 {
|
|
|
- constants::KP.clone() * self.f_dif()
|
|
|
+ self.tuned_kp() * self.f_dif()
|
|
|
}
|
|
|
|
|
|
fn f_der(&self) -> Float10 {
|
|
|
@@ -375,6 +397,7 @@ impl ConsensusState {
|
|
|
der
|
|
|
}
|
|
|
|
|
|
+
|
|
|
fn weighted_f_der(&self) -> Float10 {
|
|
|
constants::KD.clone() * self.f_der()
|
|
|
}
|
|
|
@@ -390,6 +413,10 @@ impl ConsensusState {
|
|
|
sum
|
|
|
}
|
|
|
|
|
|
+ fn tuned_ki(&self) -> Float10 {
|
|
|
+ (constants::KI.clone() * constants::FLOAT10_FIVE.clone())/self.max_windowed_forks()
|
|
|
+ }
|
|
|
+
|
|
|
fn weighted_f_int(&self) -> Float10 {
|
|
|
constants::KI.clone() * self.f_int()
|
|
|
}
|