-
Notifications
You must be signed in to change notification settings - Fork 0
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
Introduce TypeScript monitors #135
Conversation
Immutable.fromJS deeply converts all JS objects to Maps. For deserializing storage, we want the target object to instead be Map -> JS object {instance:, persistent:, temporary:} -> Map. Thus, we provide a custom loader instead.
@konnov This is a rather large change-set, so I recommend reviewing by commit. |
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 like this idea a lot. Obviously, we need more examples and iterations to figure out, what would be needed to specify monitors right in JS. However, it is a very good approach to avoiding the complexity of Rust and TLA+.
/* the monitor */ | ||
|
||
class TimelockMonitor extends SolarkraftJsMonitor { | ||
deposit( |
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 like this. One idea: When you write deposit
, this may be confusing, as you do not describe the behavior of deposit
. Would it make sense to have a name like on_deposit
, before_deposit
, or deposit_ensures
?
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.
Good point! I think on_deposit
would work well.
I've put it in #141 to follow up on.
solarkraft/src/types.ts
Outdated
*/ | ||
import { Either } from '@sweet-monads/either' | ||
|
||
export type Result<T> = Either<string, T> |
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 like that a lot!
In order to evaluate how we write monitors, we need to iterate quickly based on several case studies.
The current TLA+ instrumentation is a bit too brittle to iterate quickly, and we have not fully understood how to translate Soroban's heterogeneous/duck-typed storage into TLA+ types.
Thus, we introduce a monitor driver for writing monitors in TypeScript.
Using the TS monitor driver introduced in this PR, writing a monitor in TypeScript is very simple: Create a TS class that extends
SolarkraftJsMonitor
and provide methods corresponding to the contract functions. In the body of those functions, usereverts_if
andsucceeds_with
methods to specify the conditions under which the contract should revert or succeed. The monitor is then (programmatically) verified by instantiating the monitor class and calling theverify
method with the hashes of the transactions to be verified.For an example, see f6e994e.
Closes #134