Skip to content

Commit

Permalink
Implemented paravalidation notifications. Dependency updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Aug 22, 2022
1 parent 8530e32 commit aa16bb3
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 156 deletions.
58 changes: 30 additions & 28 deletions Cargo.lock

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
Expand Up @@ -21,6 +21,8 @@ INSERT INTO app_notification_type(code) VALUES('chain_validator_set_controller')
INSERT INTO app_notification_type(code) VALUES('chain_validator_session_keys_changed') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('chain_validator_identity_changed') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('chain_validator_payout_stakers') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('chain_validator_started_para_validating') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('chain_validator_stopped_para_validating') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('telemetry_validator_offline') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('telemetry_validator_binary_out_of_date') ON CONFLICT(code) DO NOTHING;
INSERT INTO app_notification_type(code) VALUES('telemetry_validator_peer_count_low') ON CONFLICT(code) DO NOTHING;
Expand Down Expand Up @@ -133,6 +135,8 @@ INSERT INTO app_notification_param_type(
-- chain_validator_session_keys_changed :: no param
-- chain_validator_identity_changed :: no param
-- chain_validator_reward_payout :: no param
-- chain_validator_started_para_validating :: no param
-- chain_validator_stopped_para_validating :: no param
-- telemetry_validator_offline
INSERT INTO app_notification_param_type(
notification_type_code,
Expand Down
2 changes: 2 additions & 0 deletions _template/email/chain_validator_started_para_validating.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<strong>{{ validator_display }}</strong>
⭐ is now a paravalidator.
2 changes: 2 additions & 0 deletions _template/email/chain_validator_started_para_validating.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ validator_display }}
⭐ is now a paravalidator.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ validator_display }} paravalidation status update
2 changes: 2 additions & 0 deletions _template/email/chain_validator_stopped_para_validating.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<strong>{{ validator_display }}</strong>
⭕ is not anymore a paravalidator.
2 changes: 2 additions & 0 deletions _template/email/chain_validator_stopped_para_validating.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ validator_display }}
⭕ is not anymore a paravalidator.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ validator_display }} paravalidation status update
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ validator_display }}
⭐ is now a paravalidator.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ validator_display }}
⭕ is not anymore a paravalidator.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<strong>{{ validator_display }}</strong>
⭐ is now a paravalidator.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<strong>{{ validator_display }}</strong>
⭕ is not anymore a paravalidator.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paravalidation »
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% if is_on %}🟢{% else %}⚪️{% endif %} Started Paravalidating
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% if is_on %}🟢{% else %}⚪️{% endif %} Stopped Paravalidating
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- PARAVALIDATION -
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod identity;
mod inactive;
mod inactive_next_session;
mod nomination;
mod para_validation;
mod session_keys;

impl NotificationGenerator {
Expand Down Expand Up @@ -120,6 +121,8 @@ impl NotificationGenerator {
&current,
)
.await?;
self.inspect_para_validating(app_postgres.clone(), finalized_block_number, last, &current)
.await?;
Ok(Some(current))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::{NotificationGenerator, CONFIG};
use std::sync::Arc;
use subvt_persistence::postgres::app::PostgreSQLAppStorage;
use subvt_types::app::NotificationTypeCode;
use subvt_types::subvt::ValidatorDetails;

impl NotificationGenerator {
pub(crate) async fn inspect_para_validating(
&self,
app_postgres: Arc<PostgreSQLAppStorage>,
finalized_block_number: u64,
last: &ValidatorDetails,
current: &ValidatorDetails,
) -> anyhow::Result<()> {
if current.is_para_validator && !last.is_para_validator {
log::debug!("Started paravalidating: {}", current.account.address);
let rules = app_postgres
.get_notification_rules_for_validator(
&NotificationTypeCode::ChainValidatorStartedParaValidating.to_string(),
CONFIG.substrate.network_id,
&current.account.id,
)
.await?;
self.generate_notifications(
app_postgres,
&rules,
finalized_block_number,
&Some(current.account.id),
None::<&()>,
)
.await?;
} else if !current.is_para_validator && last.is_para_validator {
log::debug!("Stopped paravalidating: {}", current.account.address);
let rules = app_postgres
.get_notification_rules_for_validator(
&NotificationTypeCode::ChainValidatorStoppedParaValidating.to_string(),
CONFIG.substrate.network_id,
&current.account.id,
)
.await?;
self.generate_notifications(
app_postgres,
&rules,
finalized_block_number,
&Some(current.account.id),
None::<&()>,
)
.await?;
}
Ok(())
}
}
2 changes: 2 additions & 0 deletions subvt-notification-processor/src/content/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub(crate) fn get_renderer_context(
NotificationTypeCode::ChainValidatorPayoutStakers => {
set_payout_context(network, notification, &mut context);
}
NotificationTypeCode::ChainValidatorStartedParaValidating => (),
NotificationTypeCode::ChainValidatorStoppedParaValidating => (),
NotificationTypeCode::OneKVValidatorBinaryVersionChange => {
set_onekv_binary_version_changed_context(notification, &mut context);
}
Expand Down
10 changes: 10 additions & 0 deletions subvt-telegram-bot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ lazy_static! {
NotificationPeriodType::Immediate,
0,
),
(
NotificationTypeCode::ChainValidatorStartedParaValidating,
NotificationPeriodType::Off,
0,
),
(
NotificationTypeCode::ChainValidatorStoppedParaValidating,
NotificationPeriodType::Off,
0,
),
(
NotificationTypeCode::OneKVValidatorBinaryVersionChange,
NotificationPeriodType::Immediate,
Expand Down
43 changes: 20 additions & 23 deletions subvt-telegram-bot/src/messenger/button/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,28 @@ pub(crate) fn get_notification_on_off_button(
template_file_name: &str,
edit_type: SettingsEditQueryType,
notification_rules: &[UserNotificationRule],
) -> anyhow::Result<Option<Vec<InlineKeyboardButton>>> {
if let Some(rule) = notification_rules
) -> anyhow::Result<Vec<InlineKeyboardButton>> {
let is_on = notification_rules
.iter()
.find(|rule| rule.notification_type.code == notification_type_code.to_string())
{
let is_on = rule.period_type == NotificationPeriodType::Immediate;
let mut context = Context::new();
context.insert("is_on", &is_on);
Ok(Some(vec![InlineKeyboardButton {
text: renderer.render(template_file_name, &context)?,
url: None,
login_url: None,
callback_data: Some(serde_json::to_string(&Query {
query_type: QueryType::SettingsEdit(edit_type),
parameter: Some(serde_json::to_string(&!is_on)?),
})?),
web_app: None,
switch_inline_query: None,
switch_inline_query_current_chat: None,
callback_game: None,
pay: None,
}]))
} else {
Ok(None)
}
.map(|rule| rule.period_type == NotificationPeriodType::Immediate)
.unwrap_or(false);
let mut context = Context::new();
context.insert("is_on", &is_on);
Ok(vec![InlineKeyboardButton {
text: renderer.render(template_file_name, &context)?,
url: None,
login_url: None,
callback_data: Some(serde_json::to_string(&Query {
query_type: QueryType::SettingsEdit(edit_type),
parameter: Some(serde_json::to_string(&!is_on)?),
})?),
web_app: None,
switch_inline_query: None,
switch_inline_query_current_chat: None,
callback_game: None,
pay: None,
}])
}

pub(crate) fn get_notification_period_button(
Expand Down
Loading

0 comments on commit aa16bb3

Please sign in to comment.