@@ -426,17 +426,36 @@ pub async fn write_item(
426
426
None => {
427
427
let tx_data = deps. gateway . raw ( & assign) . await ?;
428
428
let dh = DataItem :: deep_hash_fields (
429
+ gateway_tx. recipient . clone ( ) ,
430
+ gateway_tx. anchor . clone ( ) ,
431
+ gateway_tx. tags . clone ( ) ,
432
+ tx_data. clone ( ) ,
433
+ true
434
+ )
435
+ . map_err ( |_| "Unable to calculate deep hash" . to_string ( ) ) ?;
436
+
437
+ let dh_unordered = DataItem :: deep_hash_fields (
429
438
gateway_tx. recipient ,
430
439
gateway_tx. anchor ,
431
440
gateway_tx. tags ,
432
441
tx_data,
442
+ false
433
443
)
434
- . map_err ( |_| "Unable to calculate deep hash" . to_string ( ) ) ?;
444
+ . map_err ( |_| "Unable to calculate deep hash unordered " . to_string ( ) ) ?;
435
445
436
446
if deps. config . enable_deep_hash_checks ( ) {
437
447
deps. data_store
438
448
. check_existing_deep_hash ( & process_id, & dh)
439
449
. await ?;
450
+
451
+ /*
452
+ A safety check for messages that may have been deep hashed
453
+ with unordered tags, and have not yet been recalculated with
454
+ ordered tags.
455
+ */
456
+ deps. data_store
457
+ . check_existing_deep_hash ( & process_id, & dh_unordered)
458
+ . await ?;
440
459
}
441
460
442
461
Some ( dh)
@@ -621,7 +640,11 @@ pub async fn write_item(
621
640
*/
622
641
Some ( _) => {
623
642
let mut mutable_item = data_item. clone ( ) ;
624
- let deep_hash = match mutable_item. deep_hash ( ) {
643
+ let deep_hash = match mutable_item. deep_hash ( true ) {
644
+ Ok ( d) => d,
645
+ Err ( _) => return Err ( "Unable to calculate deep hash" . to_string ( ) ) ,
646
+ } ;
647
+ let deep_hash_unordered = match mutable_item. deep_hash ( false ) {
625
648
Ok ( d) => d,
626
649
Err ( _) => return Err ( "Unable to calculate deep hash" . to_string ( ) ) ,
627
650
} ;
@@ -634,6 +657,14 @@ pub async fn write_item(
634
657
deps. data_store
635
658
. check_existing_deep_hash ( & dtarget, & deep_hash)
636
659
. await ?;
660
+ /*
661
+ A safety check for messages that may have been deep hashed
662
+ with unordered tags, and have not yet been recalculated with
663
+ ordered tags.
664
+ */
665
+ deps. data_store
666
+ . check_existing_deep_hash ( & dtarget, & deep_hash_unordered)
667
+ . await ?;
637
668
}
638
669
639
670
Some ( deep_hash)
@@ -808,7 +839,7 @@ pub async fn msg_deephash(
808
839
809
840
let mut message_item = bundle. items [ 1 ] . clone ( ) ;
810
841
let deep_hash = match m. tags . iter ( ) . find ( |tag| tag. name == "From-Process" ) {
811
- Some ( _) => match message_item. deep_hash ( ) {
842
+ Some ( _) => match message_item. deep_hash ( true ) {
812
843
Ok ( d) => Some ( d) ,
813
844
Err ( _) => return Err ( "Unable to calculate deep hash" . to_string ( ) ) ,
814
845
} ,
@@ -836,6 +867,7 @@ pub async fn msg_deephash(
836
867
gateway_tx. anchor ,
837
868
gateway_tx. tags ,
838
869
tx_data,
870
+ true
839
871
)
840
872
. map_err ( |_| "Unable to calculate deep hash" . to_string ( ) ) ?;
841
873
0 commit comments