0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

modules/vm: Move some fetch related to vm_fetch; reorg write commitment.

This commit is contained in:
Jason Volk 2018-09-06 01:23:48 -07:00
parent d97a5ac571
commit 88c2a22a30
2 changed files with 40 additions and 35 deletions

View file

@ -649,21 +649,6 @@ ircd::m::vm::_eval_pdu(eval &eval,
// Fetch dependencies
fetch_hook(event, eval);
int64_t top;
id::event::buf head;
std::tie(head, top, std::ignore) = m::top(std::nothrow, room_id);
if(top < 0 && (opts.head_must_exist || opts.history))
if(type != "m.room.create")
throw error
{
fault::STATE, "Found nothing for room %s", string_view{room_id}
};
static m::import<m::vm::phase> fetch
{
"vm_fetch", "phase"
};
// Evaluation by module hooks
eval_hook(event);
@ -688,27 +673,35 @@ ircd::m::vm::_eval_pdu(eval &eval,
// Preliminary write_opts
m::dbs::write_opts wopts;
m::state::id_buffer new_root_buf;
wopts.root_out = new_root_buf;
wopts.present = opts.present;
wopts.history = opts.history;
wopts.head = opts.head;
wopts.refs = opts.refs;
wopts.event_idx = eval.sequence;
m::state::id_buffer new_root_buf;
wopts.root_out = new_root_buf;
string_view new_root;
if(type != "m.room.create")
if(type == "m.room.create")
{
m::room room{room_id, head};
m::room::state state{room};
wopts.root_in = state.root_id;
new_root = dbs::write(txn, event, wopts);
}
else
{
new_root = dbs::write(txn, event, wopts);
dbs::write(txn, event, wopts);
write_commit(eval);
return fault::ACCEPT;
}
int64_t top;
id::event::buf head;
std::tie(head, top, std::ignore) = m::top(std::nothrow, room_id);
if(top < 0 && (opts.head_must_exist || opts.history))
throw error
{
fault::STATE, "Found nothing for room %s",
string_view{room_id}
};
m::room room{room_id, head};
m::room::state state{room};
wopts.root_in = state.root_id;
dbs::write(txn, event, wopts);
write_commit(eval);
return fault::ACCEPT;
}

View file

@ -68,6 +68,26 @@ m::vm::fetch::enter(const event &event,
eval &eval)
{
assert(eval.opts);
const auto &opts{*eval.opts};
const m::room::id &room_id{at<"room_id"_>(event)};
int64_t top;
id::event::buf head;
std::tie(head, top, std::ignore) = m::top(std::nothrow, room_id);
if(top < 0 && (opts.head_must_exist || opts.history))
{
const auto &type{at<"type"_>(event)};
if(type == "m.room.member" && membership(event) == "invite")
{
const auto &user_id{at<"state_key"_>(event)};
//m::join(m::room{room_id}, user_id);
}
else if(type != "m.room.create")
throw error
{
fault::STATE, "Found nothing for room %s", string_view{room_id}
};
}
const event::prev prev
{
@ -96,14 +116,6 @@ m::vm::fetch::enter(const event &event,
json::get<"event_id"_>(*eval.event_),
json::get<"room_id"_>(*eval.event_)
};
/*
auto future
{
vm::evaluated(prev_id)
};
*/
//future.wait();
// std::cout << "got " << prev_id << " for " << json::get<"event_id"_>(*eval.event_) << std::endl;
}
if(eval.opts->prev_check_exists && !exists(prev_id))