Skip to content

Commit

Permalink
Add version to operation id
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Jul 6, 2023
1 parent 97bbf08 commit d91b37e
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions massa-executed-ops/src/executed_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl ExecutedOps {
return false;
}

let Ok((rest, _id)) = self.operation_id_deserializer.deserialize::<DeserializeError>(&serialized_key[EXECUTED_OPS_PREFIX.len()..]) else {
let Ok((rest, _id)): Result<(&[u8], OperationId), nom::Err<DeserializeError>> = self.operation_id_deserializer.deserialize::<DeserializeError>(&serialized_key[EXECUTED_OPS_PREFIX.len()..]) else {
return false;
};
if !rest.is_empty() {
Expand Down Expand Up @@ -377,6 +377,7 @@ fn test_executed_ops_hash_computing() {
pub struct ExecutedOpsSerializer {
slot_serializer: SlotSerializer,
u64_serializer: U64VarIntSerializer,
op_id_serializer: OperationIdSerializer,
}

impl Default for ExecutedOpsSerializer {
Expand All @@ -391,6 +392,7 @@ impl ExecutedOpsSerializer {
ExecutedOpsSerializer {
slot_serializer: SlotSerializer::new(),
u64_serializer: U64VarIntSerializer::new(),
op_id_serializer: OperationIdSerializer::new(),
}
}
}
Expand All @@ -412,7 +414,7 @@ impl Serializer<BTreeMap<Slot, PreHashSet<OperationId>>> for ExecutedOpsSerializ
self.u64_serializer.serialize(&(ids.len() as u64), buffer)?;
// slots ids
for op_id in ids {
buffer.extend(op_id.to_bytes());
self.op_id_serializer.serialize(op_id, buffer)?;
}
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions massa-factory-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tracing = "0.1"
massa_channel = { path = "../massa-channel" }
massa_models = { path = "../massa-models" }
massa_factory_exports = { path = "../massa-factory-exports" }
massa_serialization = { path = "../massa-serialization" }
massa_signature = { path = "../massa-signature" }
massa_storage = { path = "../massa-storage" }
massa_time = { path = "../massa-time" }
Expand Down
12 changes: 10 additions & 2 deletions massa-factory-worker/src/block_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use massa_models::{
prehash::PreHashSet,
secure_share::SecureShareContent,
slot::Slot,
timeslots::{get_block_slot_timestamp, get_closest_slot_to_timestamp},
timeslots::{get_block_slot_timestamp, get_closest_slot_to_timestamp}, operation::OperationIdSerializer,
};
use massa_serialization::Serializer;
use massa_time::MassaTime;
use massa_versioning::versioning::MipStore;
use massa_wallet::Wallet;
Expand All @@ -27,6 +28,7 @@ pub(crate) struct BlockFactoryWorker {
channels: FactoryChannels,
factory_receiver: MassaReceiver<()>,
mip_store: MipStore,
op_id_serializer: OperationIdSerializer,
}

impl BlockFactoryWorker {
Expand All @@ -48,6 +50,7 @@ impl BlockFactoryWorker {
channels,
factory_receiver,
mip_store,
op_id_serializer: OperationIdSerializer::new(),
};
this.run();
})
Expand Down Expand Up @@ -223,7 +226,12 @@ impl BlockFactoryWorker {
let global_operations_hash = Hash::compute_from(
&op_ids
.iter()
.flat_map(|op_id| *op_id.to_bytes())
.flat_map(|op_id| {
let mut buffer = Vec::new();
//It was a to_bytes() there before, we know the op is valid because it comes from the pool
self.op_id_serializer.serialize(op_id, &mut buffer).unwrap();
buffer
})
.collect::<Vec<u8>>(),
);

Expand Down
Loading

0 comments on commit d91b37e

Please sign in to comment.