Skip to content

Commit

Permalink
command: backdate_eose()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Mar 20, 2024
1 parent 302750f commit 41baa88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion gossip-bin/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Command {
}
}

const COMMANDS: [Command; 30] = [
const COMMANDS: [Command; 31] = [
Command {
cmd: "oneshot",
usage_params: "{depends}",
Expand All @@ -45,6 +45,11 @@ const COMMANDS: [Command; 30] = [
usage_params: "<listname>",
desc: "add a new person list with the given name",
},
Command {
cmd: "backdate_eose",
usage_params: "",
desc: "backdate last_general_eose_at by 24 hours for every relay",
},
Command {
cmd: "bech32_decode",
usage_params: "<bech32string>",
Expand Down Expand Up @@ -202,6 +207,7 @@ pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Er
"oneshot" => oneshot(command, args)?,
"add_person_relay" => add_person_relay(command, args)?,
"add_person_list" => add_person_list(command, args)?,
"backdate_eose" => backdate_eose()?,
"bech32_decode" => bech32_decode(command, args)?,
"bech32_encode_event_addr" => bech32_encode_event_addr(command, args)?,
"decrypt" => decrypt(command, args)?,
Expand Down Expand Up @@ -307,6 +313,24 @@ pub fn add_person_list(cmd: Command, mut args: env::Args) -> Result<(), Error> {
Ok(())
}

pub fn backdate_eose() -> Result<(), Error> {
let now = Unixtime::now().unwrap();
let ago = (now.0 - 60 * 60 * 24) as u64;

GLOBALS.storage.modify_all_relays(
|relay| {
if let Some(eose) = relay.last_general_eose_at {
if eose > ago {
relay.last_general_eose_at = Some(ago);
}
}
},
None,
)?;

Ok(())
}

pub fn bech32_decode(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let mut param = match args.next() {
Some(s) => s,
Expand Down
2 changes: 1 addition & 1 deletion gossip-lib/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ impl Storage {

//// Modify all relay records
#[inline]
pub(crate) fn modify_all_relays<'a, M>(
pub fn modify_all_relays<'a, M>(
&'a self,
modify: M,
rw_txn: Option<&mut RwTxn<'a>>,
Expand Down

0 comments on commit 41baa88

Please sign in to comment.