11//! Copyright (c) 2022 MASSA LABS <[email protected] > 22
33use massa_models:: {
4- operation:: { OperationId , OperationIdDeserializer , OperationIdSerializer } ,
4+ operation:: {
5+ BoolDeserializer , BoolSerializer , OperationId , OperationIdDeserializer ,
6+ OperationIdSerializer ,
7+ } ,
58 prehash:: PreHashMap ,
69 slot:: { Slot , SlotDeserializer , SlotSerializer } ,
710} ;
811use massa_serialization:: {
9- Deserializer , SerializeError , Serializer , U64VarIntDeserializer , U64VarIntSerializer ,
12+ Deserializer , OptionDeserializer , OptionSerializer , SerializeError , Serializer ,
13+ U64VarIntDeserializer , U64VarIntSerializer ,
1014} ;
1115use nom:: {
1216 error:: { context, ContextError , ParseError } ,
@@ -16,13 +20,14 @@ use nom::{
1620} ;
1721use std:: ops:: Bound :: { Excluded , Included } ;
1822
19- /// Speculatives changes for ExecutedOps
20- pub type ExecutedOpsChanges = PreHashMap < OperationId , Slot > ;
23+ /// Speculative changes for ExecutedOps
24+ pub type ExecutedOpsChanges = PreHashMap < OperationId , ( Option < bool > , Slot ) > ;
2125
2226/// `ExecutedOps` Serializer
2327pub struct ExecutedOpsChangesSerializer {
2428 u64_serializer : U64VarIntSerializer ,
2529 operation_id_serializer : OperationIdSerializer ,
30+ op_execution : OptionSerializer < bool , BoolSerializer > ,
2631 slot_serializer : SlotSerializer ,
2732}
2833
@@ -38,6 +43,7 @@ impl ExecutedOpsChangesSerializer {
3843 ExecutedOpsChangesSerializer {
3944 u64_serializer : U64VarIntSerializer :: new ( ) ,
4045 operation_id_serializer : OperationIdSerializer :: new ( ) ,
46+ op_execution : OptionSerializer :: new ( BoolSerializer :: new ( ) ) ,
4147 slot_serializer : SlotSerializer :: new ( ) ,
4248 }
4349 }
@@ -51,8 +57,10 @@ impl Serializer<ExecutedOpsChanges> for ExecutedOpsChangesSerializer {
5157 ) -> Result < ( ) , SerializeError > {
5258 self . u64_serializer
5359 . serialize ( & ( value. len ( ) as u64 ) , buffer) ?;
54- for ( op_id, slot) in value {
60+ for ( op_id, ( op_execution_succeeded , slot) ) in value {
5561 self . operation_id_serializer . serialize ( op_id, buffer) ?;
62+ self . op_execution
63+ . serialize ( op_execution_succeeded, buffer) ?;
5664 self . slot_serializer . serialize ( slot, buffer) ?;
5765 }
5866 Ok ( ( ) )
@@ -63,6 +71,7 @@ impl Serializer<ExecutedOpsChanges> for ExecutedOpsChangesSerializer {
6371pub struct ExecutedOpsChangesDeserializer {
6472 u64_deserializer : U64VarIntDeserializer ,
6573 operation_id_deserializer : OperationIdDeserializer ,
74+ op_execution_deserializer : OptionDeserializer < bool , BoolDeserializer > ,
6675 slot_deserializer : SlotDeserializer ,
6776}
6877
@@ -75,6 +84,7 @@ impl ExecutedOpsChangesDeserializer {
7584 Included ( max_ops_changes_length) ,
7685 ) ,
7786 operation_id_deserializer : OperationIdDeserializer :: new ( ) ,
87+ op_execution_deserializer : OptionDeserializer :: new ( BoolDeserializer :: new ( ) ) ,
7888 slot_deserializer : SlotDeserializer :: new (
7989 ( Included ( u64:: MIN ) , Included ( u64:: MAX ) ) ,
8090 ( Included ( 0 ) , Excluded ( thread_count) ) ,
@@ -98,13 +108,20 @@ impl Deserializer<ExecutedOpsChanges> for ExecutedOpsChangesDeserializer {
98108 context ( "operation id" , |input| {
99109 self . operation_id_deserializer . deserialize ( input)
100110 } ) ,
111+ context ( "operation execution succeeded" , |input| {
112+ self . op_execution_deserializer . deserialize ( input)
113+ } ) ,
101114 context ( "expiration slot" , |input| {
102115 self . slot_deserializer . deserialize ( input)
103116 } ) ,
104117 ) ) ,
105118 ) ,
106119 )
107- . map ( |ids| ids. into_iter ( ) . collect ( ) )
120+ . map ( |ids| {
121+ ids. into_iter ( )
122+ . map ( |( id, op_exec_status, slot) | ( id, ( op_exec_status, slot) ) )
123+ . collect ( )
124+ } )
108125 . parse ( buffer)
109126 }
110127}
0 commit comments