Prevalidation.Make
How-to obtain an instance of this module's main module type: T
module Proto : Mavryk_validation.Protocol_plugin.T
type protocol_operation = Proto.operation
Similar to the same type in the protocol, see Mavryk_protocol_environment.PROTOCOL.operation
Mempool configuration that groups both the plugin config (e.g. minimal fee to pass the pre_filter
) and the bounding config (e.g. max number of valid operations in the mempool).
val default_config : config
Default mempool configuration.
val config_encoding : config Mavryk_base.TzPervasives.Data_encoding.t
Encoding for config
.
Internally an object without any variable fields.
type chain_store = Mavryk_store.Store.chain_store
The type implemented by Mavryk_store.Store.chain_store
in production, and mocked in tests
The state used internally by this module. Created by create
and then passed back and possibly updated by add_operation
and remove_operation
.
This state notably contains a representation of the protocol mempool, as well as the bounding state.
val create :
chain_store ->
head:Mavryk_store.Store.Block.t ->
timestamp:Mavryk_base.Time.Protocol.t ->
t Mavryk_base.TzPervasives.tzresult Lwt.t
Create an empty state based on the head
block.
Called only once when a prevalidator starts.
val flush :
chain_store ->
head:Mavryk_store.Store.Block.t ->
timestamp:Mavryk_base.Time.Protocol.t ->
t ->
t Mavryk_base.TzPervasives.tzresult Lwt.t
Create a new empty state based on the head
block.
The previous state must be provided (even when it was based on a different block). Indeed, parts of it are recycled to make this function more efficient than create
.
val pre_filter :
t ->
config ->
protocol_operation Shell_operation.operation ->
[ `Passed_prefilter of Prevalidator_pending_operations.priority
| Prevalidator_classification.error_classification ]
Lwt.t
Light preliminary checks that should be performed on arrival of an operation and after a flush of the prevalidator.
See Protocol_plugin.T.Plugin.pre_filter
.
type replacements =
(Mavryk_base.TzPervasives.Operation_hash.t
* Prevalidator_classification.error_classification)
list
Contain the hash and new classification of any operations that had to be removed to make room for a newly added operation.
type add_result =
t
* protocol_operation Shell_operation.operation
* Prevalidator_classification.classification
* replacements
Result of add_operation
.
Contain the updated (or unchanged) state t
, the operation (in which the signature_checked
field has been updated if appropriate), its classification, and the potential replacements
.
Invariant: replacements
can only be non-empty when the classification is `Prechecked
.
val add_operation :
t ->
config ->
protocol_operation Shell_operation.operation ->
add_result Lwt.t
Try and add an operation to the protocol's mempool; also ensure that this mempool remains bounded (in terms of both operation count and total byte size; the bounds are specified in the config
).
See add_result
for a description of the output.
val remove_operation : t -> Mavryk_base.TzPervasives.Operation_hash.t -> t
Remove an operation from the state.
The state remains unchanged when the operation was not present (though not physically equal to the input state).
module Internal_for_tests : sig ... end