Skip to content

Commit

Permalink
Pow check of events incoming (#341)
Browse files Browse the repository at this point in the history
* Pow check of events incoming

* pow tag to lowercase
  • Loading branch information
arkanoider authored Aug 8, 2024
1 parent 7bcc480 commit 12f14bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions settings.tpl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ expiration_seconds = 900
user_rates_sent_interval_seconds = 3600
# Relay list event time interval
publish_relays_interval = 60
# Requested POW
pow = 0



Expand Down
10 changes: 9 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::app::release::release_action;
use crate::app::take_buy::take_buy_action;
use crate::app::take_sell::take_sell_action;
use crate::lightning::LndConnector;
use crate::Settings;

use anyhow::Result;
use mostro_core::message::{Action, Message};
Expand All @@ -49,9 +50,16 @@ pub async fn run(
) -> Result<()> {
loop {
let mut notifications = client.notifications();

// Get pow from config
let pow = Settings::get_mostro().pow;
while let Ok(notification) = notifications.recv().await {
if let RelayPoolNotification::Event { event, .. } = notification {
// Verify pow
if !event.check_pow(pow) {
//Discard
info!("Not POW verified event!");
continue;
}
if let Kind::EncryptedDirectMessage = event.kind {
// We validates if the event is correctly signed
if event.verify().is_err() {
Expand Down
1 change: 1 addition & 0 deletions src/cli/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct Mostro {
pub user_rates_sent_interval_seconds: u32,
pub max_expiration_days: u32,
pub publish_relays_interval: u32,
pub pow: u8,
}

impl TryFrom<Settings> for Mostro {
Expand Down
4 changes: 4 additions & 0 deletions src/nip33.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ pub fn info_to_tags(mostro_pubkey: &PublicKey) -> Vec<Tag> {
TagKind::Custom(std::borrow::Cow::Borrowed("fee")),
vec![mostro_settings.fee.to_string()],
),
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("pow")),
vec![mostro_settings.pow.to_string()],
),
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("hold_invoice_expiration_window")),
vec![ln_settings.hold_invoice_expiration_window.to_string()],
Expand Down

0 comments on commit 12f14bb

Please sign in to comment.