genlayer.std.advanced package#
This module provides some “advanced” features that can be used for optimizations
Warning
If you are using something “advanced” you must know what you do
- class genlayer.std.advanced.AlreadySerializedResult[source]#
Bases:
bytes
If contract method returns instance of this class, calldata encoding won’t be performed. Instead stored bytes will be passed as is
- exception genlayer.std.advanced.ContractError[source]#
Bases:
Exception
Represents “Contract error” result of a contract that is passed to validator function of
genlayer.std.run_nondet()
Validating leader output and sandbox invocation are only places where contract can “handle” contract error
- class genlayer.std.advanced.ContractReturn[source]#
Bases:
object
Represents a normal “Return” result of a contract that is passed to validator function of
genlayer.std.run_nondet()
- genlayer.std.advanced.run_nondet(leader_fn: Callable[[], T], validator_fn: Callable[[ContractReturn | Rollback | ContractError], bool]) Lazy [source]#
Most generic user-friendly api to execute a non-deterministic block
- Parameters:
leader_fn (Callable[[], T]) – function that is executed in the leader
validator_fn (Callable[[ContractReturn | Rollback | ContractError], bool]) – function that is executed in the validator that also checks leader result
- Return type:
Uses cloudpickle to pass a “function” to sub VM
Note
If validator_fn produces an error and leader_fn produces an error, executor itself will set result of this block to “agree” and fail entire contract with leader’s error. This is done because not all errors can be caught in code itself (i.e.
exit
). If this behavior is not desired, just fast returnFalse
for leader error result.Warning
All sub-vm returns go through
genlayer.py.calldata
encoding
- genlayer.std.advanced.sandbox(fn: Callable[[], Any]) Lazy[Any] [source]#
Runs function in the sandbox
- genlayer.std.advanced.validator_handle_rollbacks_and_errors_default(fn: Callable[[], Any], leaders_result: ContractReturn | Rollback | ContractError) tuple[Any, Any] [source]#
Default function to handle rollbacks and contract errors
Errors and rollbacks are always checked for strict equality, which means that it’s user responsibility to dump least possible text in there
- Returns:
ContractReturn
data fields as(validator, leader)`
iff both results are not errors/rollbacks- Return type: