2020-09-16 03:56:31 +02:00
|
|
|
// The Construct
|
2019-08-27 00:12:43 +02:00
|
|
|
//
|
2020-09-16 03:56:31 +02:00
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
|
2019-08-27 00:12:43 +02:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
namespace ircd::m::vm::fetch
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
static void prev_check(const event &, vm::eval &);
|
2020-04-17 23:01:58 +02:00
|
|
|
static bool prev_wait(const event &, vm::eval &);
|
2019-09-06 01:30:51 +02:00
|
|
|
static std::forward_list<ctx::future<m::fetch::result>> prev_fetch(const event &, vm::eval &, const room &);
|
2023-03-17 04:39:17 +01:00
|
|
|
static void prev_eval(const event &, vm::eval &, ctx::future<m::fetch::result> &, const system_point &);
|
2019-09-06 01:30:51 +02:00
|
|
|
static void prev(const event &, vm::eval &, const room &);
|
2019-09-06 22:29:54 +02:00
|
|
|
static std::forward_list<ctx::future<m::fetch::result>> state_fetch(const event &, vm::eval &, const room &);
|
|
|
|
static void state(const event &, vm::eval &, const room &);
|
2020-11-22 02:13:18 +01:00
|
|
|
static void auth_chain_eval(const event &, vm::eval &, const room &, const json::array &, const string_view &);
|
2019-09-06 01:30:51 +02:00
|
|
|
static void auth_chain(const event &, vm::eval &, const room &);
|
|
|
|
static void auth(const event &, vm::eval &, const room &);
|
|
|
|
static void handle(const event &, vm::eval &);
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
extern conf::item<milliseconds> prev_preempt_time;
|
2020-04-17 23:01:58 +02:00
|
|
|
extern conf::item<milliseconds> prev_wait_time;
|
2019-09-06 01:30:51 +02:00
|
|
|
extern conf::item<size_t> prev_backfill_limit;
|
2020-03-04 19:09:01 +01:00
|
|
|
extern conf::item<seconds> event_timeout;
|
|
|
|
extern conf::item<seconds> state_timeout;
|
2019-08-28 04:34:46 +02:00
|
|
|
extern conf::item<seconds> auth_timeout;
|
2019-08-27 00:12:43 +02:00
|
|
|
extern conf::item<bool> enable;
|
2020-05-12 05:24:54 +02:00
|
|
|
extern hookfn<vm::eval &> auth_hook;
|
|
|
|
extern hookfn<vm::eval &> prev_hook;
|
|
|
|
extern hookfn<vm::eval &> state_hook;
|
2019-08-27 00:12:43 +02:00
|
|
|
extern log::log log;
|
|
|
|
}
|
|
|
|
|
2023-03-17 05:24:40 +01:00
|
|
|
namespace ircd::m::vm::fetch::stats
|
|
|
|
{
|
|
|
|
using ircd::stats::item;
|
|
|
|
|
|
|
|
extern item<uint64_t> prev_noempts;
|
|
|
|
extern item<uint64_t> prev_preempts;
|
|
|
|
extern item<uint64_t> prev_evals;
|
|
|
|
extern item<uint64_t> prev_fetched;
|
|
|
|
extern item<uint64_t> prev_fetches;
|
|
|
|
extern item<uint64_t> auth_evals;
|
|
|
|
extern item<uint64_t> auth_fetched;
|
|
|
|
extern item<uint64_t> auth_fetches;
|
|
|
|
extern item<uint64_t> state_evals;
|
|
|
|
extern item<uint64_t> state_fetched;
|
|
|
|
extern item<uint64_t> state_fetches;
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
decltype(ircd::m::vm::fetch::log)
|
|
|
|
ircd::m::vm::fetch::log
|
|
|
|
{
|
|
|
|
"m.vm.fetch"
|
|
|
|
};
|
|
|
|
|
2020-05-12 05:24:54 +02:00
|
|
|
decltype(ircd::m::vm::fetch::auth_hook)
|
|
|
|
ircd::m::vm::fetch::auth_hook
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
|
|
|
handle,
|
|
|
|
{
|
2020-05-12 05:24:54 +02:00
|
|
|
{ "_site", "vm.fetch.auth" }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::prev_hook)
|
|
|
|
ircd::m::vm::fetch::prev_hook
|
|
|
|
{
|
|
|
|
handle,
|
|
|
|
{
|
|
|
|
{ "_site", "vm.fetch.prev" }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::state_hook)
|
|
|
|
ircd::m::vm::fetch::state_hook
|
|
|
|
{
|
|
|
|
handle,
|
|
|
|
{
|
|
|
|
{ "_site", "vm.fetch.state" }
|
2019-09-06 01:30:51 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
decltype(ircd::m::vm::fetch::enable)
|
|
|
|
ircd::m::vm::fetch::enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.enable" },
|
|
|
|
{ "default", true },
|
|
|
|
};
|
|
|
|
|
2019-08-28 04:34:46 +02:00
|
|
|
decltype(ircd::m::vm::fetch::auth_timeout)
|
|
|
|
ircd::m::vm::fetch::auth_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.auth.timeout" },
|
|
|
|
{ "default", 15L },
|
|
|
|
};
|
|
|
|
|
2020-03-04 19:09:01 +01:00
|
|
|
decltype(ircd::m::vm::fetch::state_timeout)
|
|
|
|
ircd::m::vm::fetch::state_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.state.timeout" },
|
|
|
|
{ "default", 20L },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::event_timeout)
|
|
|
|
ircd::m::vm::fetch::event_timeout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.event.timeout" },
|
|
|
|
{ "default", 10L },
|
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
decltype(ircd::m::vm::fetch::prev_backfill_limit)
|
|
|
|
ircd::m::vm::fetch::prev_backfill_limit
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
{ "name", "ircd.m.vm.fetch.prev.backfill.limit" },
|
|
|
|
{ "default", 128L },
|
2019-08-27 00:12:43 +02:00
|
|
|
};
|
|
|
|
|
2020-04-17 23:01:58 +02:00
|
|
|
decltype(ircd::m::vm::fetch::prev_wait_time)
|
|
|
|
ircd::m::vm::fetch::prev_wait_time
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.prev.wait.time" },
|
2023-03-17 04:39:17 +01:00
|
|
|
{ "default", 750L },
|
2020-04-17 23:01:58 +02:00
|
|
|
};
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
decltype(ircd::m::vm::fetch::prev_preempt_time)
|
|
|
|
ircd::m::vm::fetch::prev_preempt_time
|
2020-04-17 23:08:32 +02:00
|
|
|
{
|
2023-03-17 04:39:17 +01:00
|
|
|
{ "name", "ircd.m.vm.fetch.prev.preempt.time" },
|
|
|
|
{ "default", 5000L },
|
2020-04-17 23:08:32 +02:00
|
|
|
};
|
|
|
|
|
2023-03-17 05:24:40 +01:00
|
|
|
decltype(ircd::m::vm::fetch::stats::state_fetches)
|
|
|
|
ircd::m::vm::fetch::stats::state_fetches
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.state.fetches" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::state_fetched)
|
|
|
|
ircd::m::vm::fetch::stats::state_fetched
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.state.fetched" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::state_evals)
|
|
|
|
ircd::m::vm::fetch::stats::state_evals
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.state.evals" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::auth_fetches)
|
|
|
|
ircd::m::vm::fetch::stats::auth_fetches
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.auth.fetches" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::auth_fetched)
|
|
|
|
ircd::m::vm::fetch::stats::auth_fetched
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.auth.fetched" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::auth_evals)
|
|
|
|
ircd::m::vm::fetch::stats::auth_evals
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.auth.evals" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::prev_fetches)
|
|
|
|
ircd::m::vm::fetch::stats::prev_fetches
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.prev.fetches" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::prev_fetched)
|
|
|
|
ircd::m::vm::fetch::stats::prev_fetched
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.prev.fetched" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::prev_evals)
|
|
|
|
ircd::m::vm::fetch::stats::prev_evals
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.prev.evals" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::prev_preempts)
|
|
|
|
ircd::m::vm::fetch::stats::prev_preempts
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.prev.preempts" },
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::vm::fetch::stats::prev_noempts)
|
|
|
|
ircd::m::vm::fetch::stats::prev_noempts
|
|
|
|
{
|
|
|
|
{ "name", "ircd.m.vm.fetch.prev.noempts" },
|
|
|
|
};
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
//
|
|
|
|
// fetch_phase
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
2019-09-06 01:30:51 +02:00
|
|
|
ircd::m::vm::fetch::handle(const event &event,
|
|
|
|
vm::eval &eval)
|
2019-08-27 00:12:43 +02:00
|
|
|
try
|
|
|
|
{
|
2020-05-25 05:29:49 +02:00
|
|
|
if(eval.room_internal)
|
|
|
|
return;
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
assert(eval.opts);
|
2019-09-06 01:30:51 +02:00
|
|
|
const auto &opts
|
|
|
|
{
|
|
|
|
*eval.opts
|
|
|
|
};
|
2019-08-27 00:12:43 +02:00
|
|
|
|
|
|
|
const auto &type
|
|
|
|
{
|
|
|
|
at<"type"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(type == "m.room.create")
|
|
|
|
return;
|
|
|
|
|
|
|
|
const m::event::id &event_id
|
|
|
|
{
|
|
|
|
event.event_id
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::id &room_id
|
|
|
|
{
|
|
|
|
at<"room_id"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Can't construct m::room with the event_id argument because it
|
|
|
|
// won't be found (we're evaluating that event here!) so we just set
|
|
|
|
// the member manually to make further use of the room struct.
|
|
|
|
m::room room{room_id};
|
|
|
|
room.event_id = event_id;
|
|
|
|
|
2020-05-12 05:24:54 +02:00
|
|
|
if(eval.phase == phase::FETCH_AUTH)
|
|
|
|
return auth(event, eval, room);
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2020-05-12 05:24:54 +02:00
|
|
|
if(eval.phase == phase::FETCH_PREV)
|
|
|
|
return prev(event, eval, room);
|
2019-09-06 22:29:54 +02:00
|
|
|
|
2020-05-12 05:24:54 +02:00
|
|
|
if(eval.phase == phase::FETCH_STATE)
|
|
|
|
return state(event, eval, room);
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "%s :%s",
|
|
|
|
loghead(eval),
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
//
|
|
|
|
// auth_events handler stack
|
|
|
|
//
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
void
|
2019-09-06 01:30:51 +02:00
|
|
|
ircd::m::vm::fetch::auth(const event &event,
|
|
|
|
vm::eval &eval,
|
|
|
|
const room &room)
|
2019-08-27 00:12:43 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
// Count how many of the auth_events provided exist locally.
|
|
|
|
const auto &opts{*eval.opts};
|
2020-12-17 00:55:12 +01:00
|
|
|
const event::auth prev
|
|
|
|
{
|
|
|
|
event
|
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
const size_t auth_count
|
|
|
|
{
|
|
|
|
prev.auth_events_count()
|
|
|
|
};
|
2019-09-05 04:26:46 +02:00
|
|
|
|
2020-06-15 12:10:42 +02:00
|
|
|
const size_t auth_exists
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2020-06-15 12:10:42 +02:00
|
|
|
prev.auth_events_exist()
|
|
|
|
};
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
assert(auth_exists <= auth_count);
|
2020-12-16 00:47:58 +01:00
|
|
|
if(auth_exists != auth_count) try
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2020-12-16 00:47:58 +01:00
|
|
|
log::dwarning
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
2020-12-16 00:47:58 +01:00
|
|
|
log, "%s auth_events:%zu miss:%zu",
|
|
|
|
loghead(eval),
|
|
|
|
auth_count,
|
|
|
|
auth_count - auth_exists,
|
2019-09-06 01:30:51 +02:00
|
|
|
};
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2020-12-16 00:47:58 +01:00
|
|
|
if(!bool(m::vm::fetch::enable))
|
|
|
|
throw vm::error
|
|
|
|
{
|
|
|
|
vm::fault::AUTH, "Fetching auth_events disabled by configuration",
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is a blocking call to recursively fetch and evaluate the auth_chain
|
|
|
|
// for this event. Upon return all of the auth_events for this event will
|
|
|
|
// have themselves been fetched and auth'ed recursively.
|
|
|
|
auth_chain(event, eval, room);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
2022-06-18 02:53:39 +02:00
|
|
|
const ctx::exception_handler eh;
|
2020-12-16 00:47:58 +01:00
|
|
|
throw vm::error
|
|
|
|
{
|
|
|
|
vm::fault::AUTH, "Failed to fetch %zu of %zu auth_events :%s",
|
|
|
|
auth_count - prev.auth_events_exist(),
|
|
|
|
auth_count,
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
|
|
|
|
2019-08-28 04:34:46 +02:00
|
|
|
void
|
2019-09-06 01:30:51 +02:00
|
|
|
ircd::m::vm::fetch::auth_chain(const event &event,
|
|
|
|
vm::eval &eval,
|
|
|
|
const room &room)
|
2019-08-28 04:34:46 +02:00
|
|
|
try
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
assert(eval.opts);
|
|
|
|
|
|
|
|
// Figure out a remote hint as the primary target to request the missing
|
|
|
|
// auth events from; if provided, m::fetch will ask this remote first. We
|
|
|
|
// try to use the eval.node_id, which is set to a server that is conducting
|
|
|
|
// the eval (i.e in a /send/ or when processing some response data from
|
|
|
|
// them); next we try the origin of the event itself. These remotes are
|
|
|
|
// most likely to provide a satisfying response.
|
2022-07-03 08:43:12 +02:00
|
|
|
const string_view hint
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
2020-12-01 11:36:40 +01:00
|
|
|
eval.opts->node_id && !my_host(eval.opts->node_id)?
|
2019-09-06 01:30:51 +02:00
|
|
|
eval.opts->node_id:
|
2020-11-21 07:10:02 +01:00
|
|
|
|
|
|
|
event.event_id.host() && !my_host(event.event_id.host())?
|
|
|
|
event.event_id.host():
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
!my_host(json::get<"origin"_>(event))?
|
|
|
|
string_view(json::get<"origin"_>(event)):
|
2020-11-21 07:10:02 +01:00
|
|
|
|
|
|
|
room.room_id.host() && !my_host(room.room_id.host())?
|
|
|
|
room.room_id.host():
|
|
|
|
|
|
|
|
string_view{}
|
2019-09-06 01:30:51 +02:00
|
|
|
};
|
|
|
|
|
2019-08-28 04:34:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
log, "Fetching auth chain for %s in %s hint:%s",
|
2019-08-28 04:34:46 +02:00
|
|
|
string_view{room.event_id},
|
|
|
|
string_view{room.room_id},
|
2022-07-03 08:43:12 +02:00
|
|
|
hint,
|
2019-08-30 04:38:53 +02:00
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
// send
|
2019-08-30 04:38:53 +02:00
|
|
|
auto future
|
|
|
|
{
|
2022-07-03 08:43:12 +02:00
|
|
|
m::fetch::start(
|
|
|
|
{
|
|
|
|
.op = m::fetch::op::auth,
|
|
|
|
.room_id = room.room_id,
|
|
|
|
.event_id = room.event_id,
|
|
|
|
.hint = hint,
|
|
|
|
.check_hashes = false,
|
|
|
|
})
|
2019-08-28 04:34:46 +02:00
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
// recv
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::auth_fetches++;
|
2019-08-30 04:38:53 +02:00
|
|
|
const auto result
|
2019-08-28 04:34:46 +02:00
|
|
|
{
|
2019-08-30 04:38:53 +02:00
|
|
|
future.get(seconds(auth_timeout))
|
2019-08-28 04:34:46 +02:00
|
|
|
};
|
|
|
|
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::auth_fetched++;
|
2019-08-30 04:38:53 +02:00
|
|
|
const json::object response
|
2019-08-28 04:34:46 +02:00
|
|
|
{
|
2019-08-30 04:38:53 +02:00
|
|
|
result
|
2019-08-28 04:34:46 +02:00
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
// parse
|
2019-08-30 04:38:53 +02:00
|
|
|
const json::array &auth_chain
|
2019-08-28 04:34:46 +02:00
|
|
|
{
|
2019-08-30 04:38:53 +02:00
|
|
|
response["auth_chain"]
|
2019-08-28 04:34:46 +02:00
|
|
|
};
|
|
|
|
|
2020-11-22 02:13:18 +01:00
|
|
|
auth_chain_eval(event, eval, room, auth_chain, result.origin);
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::auth_evals++;
|
2019-09-06 01:30:51 +02:00
|
|
|
}
|
|
|
|
catch(const vm::error &e)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2023-02-13 03:52:42 +01:00
|
|
|
log::logf
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
2023-02-13 03:52:42 +01:00
|
|
|
log, eval.opts->auth? log::ERROR: log::DERROR,
|
|
|
|
"Fetching auth chain for %s in %s :%s",
|
2019-09-06 01:30:51 +02:00
|
|
|
string_view{room.event_id},
|
|
|
|
string_view{room.room_id},
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
2023-02-13 03:52:42 +01:00
|
|
|
// Stop propagation if auth not required but fetch attempted anyway
|
|
|
|
if(!eval.opts->auth)
|
|
|
|
return;
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::vm::fetch::auth_chain_eval(const event &event,
|
|
|
|
vm::eval &eval,
|
|
|
|
const room &room,
|
2020-12-07 23:14:58 +01:00
|
|
|
const json::array &auth_chain_,
|
2020-11-22 02:13:18 +01:00
|
|
|
const string_view &origin)
|
2019-09-06 01:30:51 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
assert(eval.opts);
|
2019-09-13 22:27:50 +02:00
|
|
|
auto opts(*eval.opts);
|
2020-05-12 05:24:54 +02:00
|
|
|
opts.fetch = false;
|
2019-09-06 01:30:51 +02:00
|
|
|
opts.infolog_accept = true;
|
|
|
|
opts.warnlog &= ~vm::fault::EXISTS;
|
2020-04-27 22:12:28 +02:00
|
|
|
opts.notify_servers = false;
|
2020-11-22 02:13:18 +01:00
|
|
|
opts.node_id = origin;
|
2020-12-07 23:14:58 +01:00
|
|
|
|
|
|
|
std::vector<m::event> auth_chain
|
|
|
|
(
|
|
|
|
std::begin(auth_chain_), std::end(auth_chain_)
|
|
|
|
);
|
|
|
|
|
|
|
|
// pre-sort here and indicate that to eval.
|
|
|
|
std::sort(begin(auth_chain), end(auth_chain));
|
|
|
|
opts.ordered = true;
|
|
|
|
|
2019-08-28 04:34:46 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
log, "Evaluating auth chain for %s in %s events:%zu",
|
2019-08-28 04:34:46 +02:00
|
|
|
string_view{room.event_id},
|
|
|
|
string_view{room.room_id},
|
2019-09-06 01:30:51 +02:00
|
|
|
auth_chain.size(),
|
2019-08-28 04:34:46 +02:00
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
// eval
|
2019-08-28 04:34:46 +02:00
|
|
|
m::vm::eval
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
auth_chain, opts
|
2019-08-28 04:34:46 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
log, "Evaluating auth chain for %s in %s :%s",
|
2019-08-28 04:34:46 +02:00
|
|
|
string_view{room.event_id},
|
|
|
|
string_view{room.room_id},
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2019-09-06 22:29:54 +02:00
|
|
|
//
|
|
|
|
// state handler stack
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::vm::fetch::state(const event &event,
|
|
|
|
vm::eval &eval,
|
|
|
|
const room &room)
|
2020-03-28 20:10:51 +01:00
|
|
|
try
|
2019-09-06 22:29:54 +02:00
|
|
|
{
|
2020-11-20 22:46:37 +01:00
|
|
|
const auto &opts{*eval.opts};
|
|
|
|
const event::prev prev
|
|
|
|
{
|
|
|
|
event
|
|
|
|
};
|
2019-09-06 22:29:54 +02:00
|
|
|
|
2020-11-20 22:46:37 +01:00
|
|
|
const bool prev_exist
|
2019-09-06 22:29:54 +02:00
|
|
|
{
|
2020-11-20 22:46:37 +01:00
|
|
|
prev.prev_exist()
|
2019-09-06 22:29:54 +02:00
|
|
|
};
|
|
|
|
|
2020-11-20 22:46:37 +01:00
|
|
|
if(opts.fetch_state_any)
|
|
|
|
if(prev_exist && prev.prev_events_count() == prev.prev_events_exist())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(likely(!opts.fetch_state_any))
|
|
|
|
if(prev_exist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(likely(!opts.fetch_state_shallow))
|
|
|
|
{
|
|
|
|
const auto &[sounding_depth, sounding_idx]
|
|
|
|
{
|
|
|
|
m::sounding(room.room_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(at<"depth"_>(event) > sounding_depth)
|
|
|
|
return;
|
|
|
|
}
|
2019-09-06 22:29:54 +02:00
|
|
|
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::state_fetches++;
|
2020-03-04 01:21:38 +01:00
|
|
|
log::dwarning
|
|
|
|
{
|
|
|
|
log, "%s fetching possible missing state in %s",
|
|
|
|
loghead(eval),
|
|
|
|
string_view{room.room_id},
|
|
|
|
};
|
|
|
|
|
2020-12-05 08:53:53 +01:00
|
|
|
struct m::acquire::opts acq_opts;
|
|
|
|
acq_opts.room = room;
|
|
|
|
acq_opts.head = false;
|
|
|
|
acq_opts.history = false;
|
|
|
|
acq_opts.state = true;
|
|
|
|
acq_opts.hint = opts.node_id;
|
|
|
|
m::acquire acq
|
|
|
|
{
|
|
|
|
acq_opts
|
2020-03-04 19:09:01 +01:00
|
|
|
};
|
2019-09-06 22:29:54 +02:00
|
|
|
|
2020-12-05 08:53:53 +01:00
|
|
|
//TODO: XXX
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::state_fetched++;
|
2019-09-06 22:29:54 +02:00
|
|
|
log::info
|
|
|
|
{
|
2020-12-05 08:53:53 +01:00
|
|
|
log, "%s evaluated missing state in %s fetched:-- good:-- fail:--",
|
2019-09-06 22:29:54 +02:00
|
|
|
loghead(eval),
|
|
|
|
string_view{room.room_id},
|
2020-12-05 08:53:53 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2019-09-06 22:29:54 +02:00
|
|
|
};
|
|
|
|
}
|
2020-03-28 20:10:51 +01:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
log, "%s state fetch in %s :%s",
|
|
|
|
loghead(eval),
|
|
|
|
string_view{room.room_id},
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2019-09-06 22:29:54 +02:00
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
//
|
|
|
|
// prev_events handler stack
|
|
|
|
//
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
void
|
2019-09-06 01:30:51 +02:00
|
|
|
ircd::m::vm::fetch::prev(const event &event,
|
|
|
|
vm::eval &eval,
|
|
|
|
const room &room)
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
|
|
|
const auto &opts{*eval.opts};
|
|
|
|
const event::prev prev{event};
|
2019-09-05 04:26:46 +02:00
|
|
|
const size_t prev_count
|
|
|
|
{
|
|
|
|
prev.prev_events_count()
|
|
|
|
};
|
2019-08-31 10:38:20 +02:00
|
|
|
|
2020-04-17 23:01:58 +02:00
|
|
|
const size_t prev_exists
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
prev.prev_events_exist()
|
|
|
|
};
|
2019-08-31 10:38:20 +02:00
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
assert(prev_exists <= prev_count);
|
|
|
|
if(prev_count == prev_exists)
|
|
|
|
return;
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2020-04-17 23:01:58 +02:00
|
|
|
// Attempt to wait for missing prev_events without issuing fetches here.
|
|
|
|
if(prev_wait(event, eval))
|
2023-03-17 05:24:40 +01:00
|
|
|
{
|
|
|
|
stats::prev_noempts += prev_count;
|
2020-04-17 23:01:58 +02:00
|
|
|
return;
|
2023-03-17 05:24:40 +01:00
|
|
|
}
|
2020-04-17 23:01:58 +02:00
|
|
|
|
2020-05-12 05:24:54 +02:00
|
|
|
if(!m::vm::fetch::enable)
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
2023-03-17 04:39:17 +01:00
|
|
|
// No fetches will take place; only check if satisfied.
|
2019-09-06 01:30:51 +02:00
|
|
|
prev_check(event, eval);
|
|
|
|
return;
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
// Launch fetches for missing prev events
|
|
|
|
auto fetching
|
2019-09-06 01:30:51 +02:00
|
|
|
{
|
|
|
|
prev_fetch(event, eval, room)
|
|
|
|
};
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2023-03-17 05:24:40 +01:00
|
|
|
const auto fetching_count
|
|
|
|
{
|
|
|
|
std::distance(begin(fetching), end(fetching))
|
|
|
|
};
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
// At this point one or more prev_events are missing; the fetches were
|
|
|
|
// launched asynchronously if the options allowed for it.
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::prev_fetches += fetching_count;
|
2019-08-27 00:12:43 +02:00
|
|
|
log::dwarning
|
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
log, "%s depth:%ld prev_events:%zu miss:%zu fetching:%zu fetching ...",
|
2019-08-27 00:12:43 +02:00
|
|
|
loghead(eval),
|
2019-09-06 01:30:51 +02:00
|
|
|
at<"depth"_>(event),
|
2019-09-05 04:26:46 +02:00
|
|
|
prev_count,
|
|
|
|
prev_count - prev_exists,
|
2023-03-17 05:24:40 +01:00
|
|
|
fetching_count,
|
2019-08-27 00:12:43 +02:00
|
|
|
};
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
// Rather than waiting for all of the events to arrive or for the entire
|
|
|
|
// timeout to expire, we check if the sought events made it to the server
|
|
|
|
// in the meantime. If so we can drop these fetches and bail.
|
|
|
|
std::optional<vm::notify::future> evaling[prev_count];
|
|
|
|
for(size_t i(0); i < prev_count; ++i)
|
|
|
|
evaling[i].emplace(prev.prev_event(i));
|
|
|
|
|
|
|
|
// Either all of the fetches are done and we can start evaluating or all
|
|
|
|
// of the events arrived elsehow and we don't need any of the fetches.
|
|
|
|
// XXX: Ideally this could be refactored with mix-and-match granularity
|
|
|
|
// but at this time it's unknown if there's practical benefit.
|
|
|
|
ctx::future<> when[]
|
|
|
|
{
|
|
|
|
ctx::when_all(begin(fetching), end(fetching)),
|
|
|
|
ctx::when_all(evaling, evaling + prev_count, []
|
|
|
|
(auto &optional) -> ctx::future<> &
|
|
|
|
{
|
|
|
|
return optional->value();
|
|
|
|
}),
|
2019-08-31 10:38:20 +02:00
|
|
|
};
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
// Represents one of the two outcomes.
|
|
|
|
auto future
|
2020-03-04 19:09:01 +01:00
|
|
|
{
|
2023-03-17 04:39:17 +01:00
|
|
|
ctx::when_any(begin(when), end(when))
|
2020-03-04 19:09:01 +01:00
|
|
|
};
|
2019-09-06 01:30:51 +02:00
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
const auto prev_wait_until
|
2020-04-17 23:08:32 +02:00
|
|
|
{
|
2023-03-17 04:39:17 +01:00
|
|
|
now<system_point>() + milliseconds(prev_preempt_time)
|
2020-04-17 23:08:32 +02:00
|
|
|
};
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
// Wait for one of the two outcomes.
|
|
|
|
const bool finished
|
2020-04-17 03:53:29 +02:00
|
|
|
{
|
2023-03-17 04:39:17 +01:00
|
|
|
future.wait_until(prev_wait_until, std::nothrow)
|
|
|
|
};
|
2020-04-17 03:53:29 +02:00
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
// Check for satisfaction.
|
|
|
|
if(prev.prev_events_exist() == prev_count)
|
|
|
|
{
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::prev_preempts += prev_count;
|
2023-03-17 04:39:17 +01:00
|
|
|
assert(finished);
|
|
|
|
return;
|
2020-04-17 03:53:29 +02:00
|
|
|
}
|
|
|
|
|
2023-03-17 04:39:17 +01:00
|
|
|
const auto event_wait_until
|
|
|
|
{
|
|
|
|
now<system_point>() + seconds(event_timeout)
|
|
|
|
};
|
|
|
|
|
|
|
|
// If we're not satisfied we commit to evaluating the fetches.
|
|
|
|
for(auto &fetch : fetching)
|
|
|
|
prev_eval(event, eval, fetch, event_wait_until);
|
2019-08-31 10:38:20 +02:00
|
|
|
|
2023-02-05 05:14:29 +01:00
|
|
|
// check if result evals have satisfied this eval now; or throw
|
|
|
|
prev_check(event, eval);
|
|
|
|
}
|
2020-04-17 03:53:18 +02:00
|
|
|
|
2023-02-05 05:14:29 +01:00
|
|
|
void
|
|
|
|
ircd::m::vm::fetch::prev_eval(const event &event,
|
|
|
|
vm::eval &eval,
|
2023-03-17 04:39:17 +01:00
|
|
|
ctx::future<m::fetch::result> &future,
|
|
|
|
const system_point &until)
|
2023-02-05 05:14:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m::fetch::result result
|
|
|
|
{
|
2023-03-17 04:39:17 +01:00
|
|
|
future.get_until(until)
|
2023-02-05 05:14:29 +01:00
|
|
|
};
|
2019-08-31 10:38:20 +02:00
|
|
|
|
2023-03-17 05:24:40 +01:00
|
|
|
stats::prev_fetched++;
|
2023-02-05 05:14:29 +01:00
|
|
|
const json::object content
|
|
|
|
{
|
|
|
|
result
|
|
|
|
};
|
2019-08-31 10:38:20 +02:00
|
|
|
|
2023-02-05 05:14:29 +01:00
|
|
|
const json::array &pdus
|
2020-04-04 02:37:34 +02:00
|
|
|
{
|
2023-02-05 05:14:29 +01:00
|
|
|
content["pdus"]
|
|
|
|
};
|
|
|
|
|
|
|
|
auto opts(*eval.opts);
|
|
|
|
opts.phase.set(m::vm::phase::FETCH_PREV, false);
|
|
|
|
opts.phase.set(m::vm::phase::FETCH_STATE, false);
|
|
|
|
opts.notify_servers = false;
|
|
|
|
opts.node_id = result.origin;
|
|
|
|
log::debug
|
2019-08-31 10:38:20 +02:00
|
|
|
{
|
2023-02-05 05:14:29 +01:00
|
|
|
log, "%s fetched %zu pdus; evaluating...",
|
|
|
|
loghead(eval),
|
|
|
|
pdus.size(),
|
|
|
|
};
|
2019-08-31 10:38:20 +02:00
|
|
|
|
2023-02-05 05:14:29 +01:00
|
|
|
vm::eval
|
|
|
|
{
|
|
|
|
pdus, opts
|
|
|
|
};
|
2023-03-17 05:24:40 +01:00
|
|
|
|
|
|
|
stats::prev_evals++;
|
2023-02-05 05:14:29 +01:00
|
|
|
}
|
|
|
|
catch(const ctx::interrupted &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "%s prev fetch/eval :%s",
|
|
|
|
loghead(eval),
|
|
|
|
e.what(),
|
|
|
|
};
|
2019-09-06 01:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::forward_list
|
|
|
|
<
|
|
|
|
ircd::ctx::future<ircd::m::fetch::result>
|
|
|
|
>
|
|
|
|
ircd::m::vm::fetch::prev_fetch(const event &event,
|
|
|
|
vm::eval &eval,
|
|
|
|
const room &room)
|
|
|
|
{
|
|
|
|
const long room_depth
|
|
|
|
{
|
|
|
|
m::depth(std::nothrow, room)
|
|
|
|
};
|
|
|
|
|
|
|
|
const long viewport_depth
|
2019-08-27 00:12:43 +02:00
|
|
|
{
|
2019-09-06 02:31:54 +02:00
|
|
|
room_depth - room::events::viewport_size
|
2019-09-05 04:26:46 +02:00
|
|
|
};
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
std::forward_list
|
|
|
|
<
|
|
|
|
ctx::future<m::fetch::result>
|
|
|
|
>
|
|
|
|
ret;
|
|
|
|
const event::prev prev{event};
|
2020-03-28 20:10:51 +01:00
|
|
|
for(size_t i(0); i < prev.prev_events_count(); ++i) try
|
2019-09-05 04:26:46 +02:00
|
|
|
{
|
2019-09-06 01:30:51 +02:00
|
|
|
const auto &prev_id
|
|
|
|
{
|
|
|
|
prev.prev_event(i)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(m::exists(prev_id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const long depth_gap
|
|
|
|
{
|
|
|
|
std::max(std::abs(at<"depth"_>(event) - room_depth), 1L)
|
|
|
|
};
|
|
|
|
|
2022-07-03 08:43:12 +02:00
|
|
|
const auto backfill_max
|
|
|
|
{
|
|
|
|
std::min(size_t(prev_backfill_limit), eval.opts->fetch_prev_limit)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto backfill_limit
|
|
|
|
{
|
|
|
|
std::min(size_t(depth_gap), backfill_max)
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view hint
|
2020-12-01 11:36:40 +01:00
|
|
|
{
|
|
|
|
eval.opts->node_id && !my_host(eval.opts->node_id)?
|
|
|
|
eval.opts->node_id:
|
|
|
|
|
|
|
|
prev_id.host() && !my_host(prev_id.host())?
|
|
|
|
prev_id.host():
|
|
|
|
|
|
|
|
!my_host(json::get<"origin"_>(event))?
|
|
|
|
string_view(json::get<"origin"_>(event)):
|
|
|
|
|
|
|
|
room.room_id.host() && !my_host(room.room_id.host())?
|
|
|
|
room.room_id.host():
|
|
|
|
|
|
|
|
string_view{}
|
|
|
|
};
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
log::debug
|
|
|
|
{
|
2022-07-03 08:43:12 +02:00
|
|
|
log, "%s requesting backfill off %s; "
|
|
|
|
"depth:%ld viewport:%ld room:%ld gap:%ld limit:%zu hint:%s",
|
2019-09-06 01:30:51 +02:00
|
|
|
loghead(eval),
|
|
|
|
string_view{prev_id},
|
|
|
|
at<"depth"_>(event),
|
|
|
|
viewport_depth,
|
|
|
|
room_depth,
|
|
|
|
depth_gap,
|
2022-07-03 08:43:12 +02:00
|
|
|
backfill_limit,
|
|
|
|
hint,
|
2019-09-06 01:30:51 +02:00
|
|
|
};
|
|
|
|
|
2022-07-03 08:43:12 +02:00
|
|
|
ret.emplace_front(m::fetch::start(
|
|
|
|
{
|
|
|
|
.op = m::fetch::op::backfill,
|
|
|
|
.room_id = room.room_id,
|
|
|
|
.event_id = prev_id,
|
|
|
|
.hint = hint,
|
|
|
|
.backfill_limit = backfill_limit,
|
|
|
|
}));
|
2019-08-27 00:12:43 +02:00
|
|
|
}
|
2020-03-28 20:10:51 +01:00
|
|
|
catch(const ctx::interrupted &)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::derror
|
|
|
|
{
|
|
|
|
log, "%s requesting backfill off prev %s; depth:%ld :%s",
|
|
|
|
loghead(eval),
|
|
|
|
string_view{prev.prev_event(i)},
|
|
|
|
json::get<"depth"_>(event),
|
|
|
|
e.what(),
|
|
|
|
};
|
|
|
|
}
|
2019-08-27 00:12:43 +02:00
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-17 23:01:58 +02:00
|
|
|
bool
|
|
|
|
ircd::m::vm::fetch::prev_wait(const event &event,
|
|
|
|
vm::eval &eval)
|
|
|
|
{
|
|
|
|
const auto &opts(*eval.opts);
|
|
|
|
const event::prev prev(event);
|
2023-02-04 08:12:29 +01:00
|
|
|
const milliseconds &wait_time
|
2020-04-17 23:01:58 +02:00
|
|
|
{
|
2023-02-04 08:12:29 +01:00
|
|
|
opts.fetch_prev_wait_time >= 0ms?
|
|
|
|
opts.fetch_prev_wait_time:
|
|
|
|
milliseconds(prev_wait_time)
|
2020-04-17 23:01:58 +02:00
|
|
|
};
|
|
|
|
|
2023-02-04 08:12:29 +01:00
|
|
|
const auto ids
|
2020-04-17 23:01:58 +02:00
|
|
|
{
|
2023-02-04 08:12:29 +01:00
|
|
|
prev.prev_events_count()
|
2020-04-17 23:01:58 +02:00
|
|
|
};
|
|
|
|
|
2023-02-04 08:12:29 +01:00
|
|
|
assume(ids <= event::prev::MAX);
|
|
|
|
event::id buf[event::prev::MAX];
|
|
|
|
const vector_view<const event::id> prev_id
|
|
|
|
(
|
|
|
|
prev.ids(buf)
|
|
|
|
);
|
|
|
|
|
|
|
|
const auto exists
|
2020-04-17 23:01:58 +02:00
|
|
|
{
|
2023-02-04 08:12:29 +01:00
|
|
|
notify::wait(prev_id, wait_time)
|
2020-04-17 23:01:58 +02:00
|
|
|
};
|
|
|
|
|
2023-02-04 08:12:29 +01:00
|
|
|
const bool obtained
|
2020-04-17 23:01:58 +02:00
|
|
|
{
|
2023-02-04 08:12:29 +01:00
|
|
|
exists == ids
|
|
|
|
};
|
2020-04-17 23:01:58 +02:00
|
|
|
|
2023-02-04 08:12:29 +01:00
|
|
|
return obtained;
|
2020-04-17 23:01:58 +02:00
|
|
|
}
|
|
|
|
|
2019-09-06 01:30:51 +02:00
|
|
|
void
|
|
|
|
ircd::m::vm::fetch::prev_check(const event &event,
|
|
|
|
vm::eval &eval)
|
|
|
|
{
|
|
|
|
const auto &opts
|
|
|
|
{
|
|
|
|
*eval.opts
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::prev prev
|
|
|
|
{
|
|
|
|
event
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t prev_exists
|
|
|
|
{
|
|
|
|
prev.prev_events_exist()
|
|
|
|
};
|
|
|
|
|
2019-08-27 00:12:43 +02:00
|
|
|
// Aborts this event if the options want us to guarantee at least one
|
|
|
|
// prev_event was fetched and evaluated for this event. This is generally
|
|
|
|
// used in conjunction with the fetch_prev_wait option to be effective.
|
2019-09-05 04:26:46 +02:00
|
|
|
if(opts.fetch_prev_any && !prev_exists)
|
2019-08-27 00:12:43 +02:00
|
|
|
throw vm::error
|
|
|
|
{
|
2019-09-05 04:26:46 +02:00
|
|
|
vm::fault::EVENT, "Failed to fetch any of the %zu prev_events for %s in %s",
|
2019-09-06 01:30:51 +02:00
|
|
|
prev.prev_events_count(),
|
2019-08-27 00:12:43 +02:00
|
|
|
string_view{event.event_id},
|
|
|
|
json::get<"room_id"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Aborts this event if the options want us to guarantee ALL of the
|
|
|
|
// prev_events were fetched and evaluated for this event.
|
2019-09-06 01:30:51 +02:00
|
|
|
if(opts.fetch_prev_all && prev_exists < prev.prev_events_count())
|
2019-08-27 00:12:43 +02:00
|
|
|
throw vm::error
|
|
|
|
{
|
2019-09-05 04:26:46 +02:00
|
|
|
vm::fault::EVENT, "Missing %zu of %zu required prev_events for %s in %s",
|
|
|
|
prev_exists,
|
2019-09-06 01:30:51 +02:00
|
|
|
prev.prev_events_count(),
|
2019-08-27 00:12:43 +02:00
|
|
|
string_view{event.event_id},
|
|
|
|
json::get<"room_id"_>(event)
|
|
|
|
};
|
|
|
|
}
|