-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CheckTx API #1675
Add CheckTx API #1675
Conversation
789b6f1
to
b95bf35
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not handle checks as separate API methods. The reasoning is that execution also must run the exact same check before proceeding with execution which would lead to some duplication and could be easily forgotten by the runtime implementors.
So instead we should just add a flag (e.g., check_only
) to the transaction Context
and then format the methods as follows:
pub fn insert(/* ... */) -> Fallible<Option<FooBar>> {
// ... perform checks here ...
if ctx.check_only {
return Ok(None);
}
// ... actual execution here ...
Ok(Some(result))
}
The only downside is that this adds Option
s to all results as otherwise you need to generate a valid return value in that check only branch, so for the example insert
call it would look like this (since the API call also uses an Option
in its result type):
pub fn insert(args: &KeyValue, ctx: &mut TxnContext) -> Fallible<Option<Option<String>>> {
// ...
}
An alternative could be defining a special error that would signify that the check was successful and this error would be transparently handled by the dispatcher and convert it into a successful result with no output value, for example:
use ekiden_runtime::transaction::dispatcher::CheckOnlySuccess;
pub fn insert(/* ... */) -> Fallible<FooBar> {
// ... perform checks here ...
if ctx.check_only {
return Err(CheckOnlySuccess.into());
}
// ... actual execution here ...
Ok(result)
}
I think I would prefer this last approach.
1f077d4
to
b68b700
Compare
use ekiden_runtime::transaction::dispatcher::CheckOnlySuccess;
pub fn insert(/* ... */) -> Fallible<FooBar> {
// ... perform checks here ...
if ctx.check_only {
return Err(CheckOnlySuccess.into());
}
// ... actual execution here ...
Ok(result)
}
I've refactored my PR to follow this approach. @kostko, please take another look. |
b68b700
to
efc26fc
Compare
Codecov Report
@@ Coverage Diff @@
## master #1675 +/- ##
=======================================
Coverage 55.22% 55.22%
=======================================
Files 200 200
Lines 19082 19082
=======================================
Hits 10538 10538
Misses 7461 7461
Partials 1083 1083
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1675 +/- ##
==========================================
- Coverage 56.46% 56.45% -0.02%
==========================================
Files 206 206
Lines 19548 19548
==========================================
- Hits 11038 11036 -2
- Misses 7360 7361 +1
- Partials 1150 1151 +1
Continue to review full report at Codecov.
|
1bc7dd4
to
e6420ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, this looks pretty good! Only some minor nits and after you fix those and mark the PR as ready for review it is good to merge!
e6420ab
to
1cf2633
Compare
This is in preparation to adding the CheckTx API to the worker-host protocol and ensuring we use a consistent naming scheme.
This will allow worker host to request runtime-specific light-weight transaction checks.
Add a simple check to the insert() method.
1cf2633
to
5f3c681
Compare
Closes: #1555.