add warning if calculated event id != requested event id
parent
afca61fe7c
commit
1601027605
|
@ -93,9 +93,8 @@ impl Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
|
pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
|
||||||
// We use autocheckpoints
|
self.write_lock()
|
||||||
//self.write_lock()
|
.pragma_update(Some(Main), "wal_checkpoint", &"TRUNCATE")?;
|
||||||
//.pragma_update(Some(Main), "wal_checkpoint", &"TRUNCATE")?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1544,6 +1544,66 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"parse_pdu" => {
|
||||||
|
if body.len() > 2
|
||||||
|
&& body[0].trim() == "```"
|
||||||
|
&& body.last().unwrap().trim() == "```"
|
||||||
|
{
|
||||||
|
let string = body[1..body.len() - 1].join("\n");
|
||||||
|
match serde_json::from_str(&string) {
|
||||||
|
Ok(value) => {
|
||||||
|
let event_id = EventId::try_from(&*format!(
|
||||||
|
"${}",
|
||||||
|
// Anything higher than version3 behaves the same
|
||||||
|
ruma::signatures::reference_hash(
|
||||||
|
&value,
|
||||||
|
&RoomVersionId::Version6
|
||||||
|
)
|
||||||
|
.expect("ruma can calculate reference hashes")
|
||||||
|
))
|
||||||
|
.expect(
|
||||||
|
"ruma's reference hashes are valid event ids",
|
||||||
|
);
|
||||||
|
|
||||||
|
match serde_json::from_value::<PduEvent>(
|
||||||
|
serde_json::to_value(value)
|
||||||
|
.expect("value is json"),
|
||||||
|
) {
|
||||||
|
Ok(pdu) => {
|
||||||
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
|
message::MessageEventContent::text_plain(
|
||||||
|
format!("EventId: {:?}\n{:#?}", event_id, pdu),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
|
message::MessageEventContent::text_plain(
|
||||||
|
format!("EventId: {:?}\nCould not parse event: {}", event_id, e),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
|
message::MessageEventContent::text_plain(
|
||||||
|
format!(
|
||||||
|
"Invalid json in command body: {}",
|
||||||
|
e
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
|
message::MessageEventContent::text_plain(
|
||||||
|
"Expected code block in command body.",
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
"get_pdu" => {
|
"get_pdu" => {
|
||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
if let Ok(event_id) = EventId::try_from(args[0]) {
|
if let Ok(event_id) = EventId::try_from(args[0]) {
|
||||||
|
|
|
@ -1184,13 +1184,13 @@ fn handle_outlier_pdu<'a>(
|
||||||
// Build map of auth events
|
// Build map of auth events
|
||||||
let mut auth_events = HashMap::new();
|
let mut auth_events = HashMap::new();
|
||||||
for id in &incoming_pdu.auth_events {
|
for id in &incoming_pdu.auth_events {
|
||||||
let auth_event = db
|
let auth_event = match db.rooms.get_pdu(id).map_err(|e| e.to_string())? {
|
||||||
.rooms
|
Some(e) => e,
|
||||||
.get_pdu(id)
|
None => {
|
||||||
.map_err(|e| e.to_string())?
|
warn!("Could not find auth event {}", id);
|
||||||
.ok_or_else(|| {
|
continue;
|
||||||
"Auth event not found, event failed recursive auth checks.".to_string()
|
}
|
||||||
})?;
|
};
|
||||||
|
|
||||||
match auth_events.entry((
|
match auth_events.entry((
|
||||||
auth_event.kind.clone(),
|
auth_event.kind.clone(),
|
||||||
|
@ -1767,7 +1767,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
||||||
{
|
{
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
warn!("Got {} over federation", id);
|
warn!("Got {} over federation", id);
|
||||||
let (event_id, value) =
|
let (calculated_event_id, value) =
|
||||||
match crate::pdu::gen_event_id_canonical_json(&res.pdu) {
|
match crate::pdu::gen_event_id_canonical_json(&res.pdu) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -1776,11 +1776,16 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if calculated_event_id != **id {
|
||||||
|
warn!("Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}",
|
||||||
|
id, calculated_event_id, &res.pdu);
|
||||||
|
}
|
||||||
|
|
||||||
// This will also fetch the auth chain
|
// This will also fetch the auth chain
|
||||||
match handle_outlier_pdu(
|
match handle_outlier_pdu(
|
||||||
origin,
|
origin,
|
||||||
create_event,
|
create_event,
|
||||||
&event_id,
|
&id,
|
||||||
&room_id,
|
&room_id,
|
||||||
value.clone(),
|
value.clone(),
|
||||||
db,
|
db,
|
||||||
|
|
Loading…
Reference in New Issue