mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd:Ⓜ️:vm: Add eval options for hashing signing and pre-commit debuglog.
This commit is contained in:
parent
1e6d3d3294
commit
b5ad6b55a6
2 changed files with 34 additions and 23 deletions
|
@ -79,6 +79,12 @@ enum ircd::m::vm::fault
|
|||
/// Evaluation Options
|
||||
struct ircd::m::vm::opts
|
||||
{
|
||||
// Hash and include hashes object.
|
||||
bool hash {true};
|
||||
|
||||
// Sign and include signatures object
|
||||
bool sign {true};
|
||||
|
||||
/// Make writes to database
|
||||
bool write {true};
|
||||
|
||||
|
@ -119,6 +125,9 @@ struct ircd::m::vm::opts
|
|||
EXISTS
|
||||
};
|
||||
|
||||
/// Whether to log a debug message before commit
|
||||
bool debuglog_precommit {false};
|
||||
|
||||
/// Whether to log a debug message on successful eval.
|
||||
bool debuglog_accept {false};
|
||||
|
||||
|
|
48
ircd/m/vm.cc
48
ircd/m/vm.cc
|
@ -71,12 +71,14 @@ ircd::m::vm::commit(json::iov &event,
|
|||
char hashes_buf[128];
|
||||
const string_view hashes
|
||||
{
|
||||
m::event::hashes(hashes_buf, event, content)
|
||||
opts.hash?
|
||||
m::event::hashes(hashes_buf, event, content):
|
||||
string_view{}
|
||||
};
|
||||
|
||||
const json::iov::push _hashes
|
||||
const json::iov::add_if _hashes
|
||||
{
|
||||
event, { "hashes", hashes }
|
||||
event, opts.hash, { "hashes", hashes }
|
||||
};
|
||||
|
||||
// sigs
|
||||
|
@ -84,13 +86,19 @@ ircd::m::vm::commit(json::iov &event,
|
|||
char sigs_buf[384];
|
||||
const string_view sigs
|
||||
{
|
||||
m::event::signatures(sigs_buf, event, contents)
|
||||
opts.sign?
|
||||
m::event::signatures(sigs_buf, event, contents):
|
||||
string_view{}
|
||||
};
|
||||
|
||||
const json::iov::push _final[]
|
||||
const json::iov::add_if _sigs
|
||||
{
|
||||
{ event, { "signatures", sigs }},
|
||||
{ event, { "content", content }},
|
||||
event, opts.sign, { "signatures", sigs }
|
||||
};
|
||||
|
||||
const json::iov::push _content
|
||||
{
|
||||
event, { "content", content },
|
||||
};
|
||||
|
||||
return commit(event, opts);
|
||||
|
@ -126,29 +134,23 @@ ircd::m::vm::commit_hook
|
|||
/// out
|
||||
///
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::vm::commit(const event &event)
|
||||
ircd::m::vm::commit(const event &event,
|
||||
const opts &opts)
|
||||
{
|
||||
check_size(event);
|
||||
|
||||
log.debug("injecting event(mark: %ld) %s",
|
||||
vm::current_sequence,
|
||||
pretty_oneline(event));
|
||||
if(opts.debuglog_precommit)
|
||||
log.debug("injecting event(mark: %ld) %s",
|
||||
vm::current_sequence,
|
||||
pretty_oneline(event));
|
||||
|
||||
//TODO: X
|
||||
vm::opts opts;
|
||||
opts.non_conform |= event::conforms::MISSING_PREV_STATE;
|
||||
|
||||
vm::eval eval{opts};
|
||||
ircd::timer timer;
|
||||
vm::opts opts_{opts};
|
||||
opts_.non_conform |= event::conforms::MISSING_PREV_STATE;
|
||||
vm::eval eval{opts_};
|
||||
|
||||
check_size(event);
|
||||
commit_hook(event);
|
||||
eval(event);
|
||||
|
||||
log.debug("committed event %s (mark: %ld time: %ld$ms)",
|
||||
at<"event_id"_>(event),
|
||||
vm::current_sequence,
|
||||
timer.at<milliseconds>().count());
|
||||
|
||||
return unquote(at<"event_id"_>(event));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue