17
17
package com .hedera .node .app .statedumpers .scheduledtransactions ;
18
18
19
19
import static com .hedera .node .app .service .mono .statedumpers .associations .BBMTokenAssociation .entityIdFrom ;
20
+ import static com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .ScheduledTransactionsDumpUtils .reportOnScheduledTransactionsByEquality ;
21
+ import static com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .ScheduledTransactionsDumpUtils .reportOnScheduledTransactionsByExpiry ;
20
22
import static com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .ScheduledTransactionsDumpUtils .reportOnScheduledTransactionsById ;
21
23
import static com .swirlds .common .threading .manager .AdHocThreadManager .getStaticThreadManager ;
22
24
23
25
import com .hedera .hapi .node .base .ScheduleID ;
26
+ import com .hedera .hapi .node .state .primitives .ProtoBytes ;
27
+ import com .hedera .hapi .node .state .primitives .ProtoLong ;
24
28
import com .hedera .hapi .node .state .schedule .Schedule ;
29
+ import com .hedera .hapi .node .state .schedule .ScheduleList ;
25
30
import com .hedera .node .app .service .mono .legacy .core .jproto .JKey ;
26
31
import com .hedera .node .app .service .mono .pbj .PbjConverter ;
27
32
import com .hedera .node .app .service .mono .state .adapters .VirtualMapLike ;
28
33
import com .hedera .node .app .service .mono .state .submerkle .RichInstant ;
29
34
import com .hedera .node .app .service .mono .statedumpers .DumpCheckpoint ;
35
+ import com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .BBMScheduledEqualityValue ;
36
+ import com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .BBMScheduledId ;
37
+ import com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .BBMScheduledSecondValue ;
30
38
import com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .BBMScheduledTransaction ;
31
- import com .hedera .node .app .service .mono .statedumpers .scheduledtransactions .BBMScheduledTransactionId ;
32
39
import com .hedera .node .app .service .mono .statedumpers .utils .Writer ;
33
40
import com .hedera .node .app .state .merkle .disk .OnDiskKey ;
34
41
import com .hedera .node .app .state .merkle .disk .OnDiskValue ;
38
45
import java .nio .file .Path ;
39
46
import java .security .InvalidKeyException ;
40
47
import java .time .Instant ;
48
+ import java .util .ArrayList ;
41
49
import java .util .HashMap ;
50
+ import java .util .List ;
42
51
import java .util .Map ;
43
52
import java .util .Optional ;
53
+ import java .util .TreeMap ;
44
54
import java .util .concurrent .ConcurrentLinkedQueue ;
55
+ import java .util .concurrent .CopyOnWriteArrayList ;
45
56
46
57
public class ScheduledTransactionsDumpUtils {
47
58
48
59
public static void dumpModScheduledTransactions (
49
60
@ NonNull final Path path ,
50
61
@ NonNull final VirtualMap <OnDiskKey <ScheduleID >, OnDiskValue <Schedule >> scheduledTransactions ,
62
+ @ NonNull final VirtualMap <OnDiskKey <ProtoBytes >, OnDiskValue <ScheduleList >> byEquality ,
63
+ @ NonNull final VirtualMap <OnDiskKey <ProtoLong >, OnDiskValue <ScheduleList >> byExpiry ,
51
64
@ NonNull final DumpCheckpoint checkpoint ) {
52
65
try (@ NonNull final var writer = new Writer (path )) {
53
- final var dumpableScheduledTransactions = gatherModScheduledTransactions (scheduledTransactions );
54
- reportOnScheduledTransactionsById (writer , dumpableScheduledTransactions );
66
+ final var dumpableScheduledTransactionsById = gatherModScheduledTransactionsById (scheduledTransactions );
67
+ reportOnScheduledTransactionsById (writer , dumpableScheduledTransactionsById );
55
68
System .out .printf (
56
69
"=== mod scheduled transactions report is %d bytes at checkpoint %s%n" ,
57
70
writer .getSize (), checkpoint .name ());
71
+ final var byEqualityDump = gatherModScheduledTransactionsByEquality (byEquality );
72
+ reportOnScheduledTransactionsByEquality (writer , byEqualityDump );
73
+ // Not sure how to compare Equality Virtual map in mono and mod
74
+ final var byExpiryDump = gatherModScheduledTransactionsByExpiry (byExpiry );
75
+ reportOnScheduledTransactionsByExpiry (writer , byExpiryDump );
76
+ System .out .printf (
77
+ "=== mod scheduled transactions by expiry report is %d bytes at checkpoint %s%n" ,
78
+ writer .getSize (), checkpoint .name ());
79
+ }
80
+ }
81
+
82
+ private static List <BBMScheduledEqualityValue > gatherModScheduledTransactionsByEquality (
83
+ final VirtualMap <OnDiskKey <ProtoBytes >, OnDiskValue <ScheduleList >> source ) {
84
+ final List <BBMScheduledEqualityValue > r = new ArrayList <>();
85
+ final var scheduledTransactions = new CopyOnWriteArrayList <BBMScheduledEqualityValue >();
86
+
87
+ try {
88
+ VirtualMapLike .from (source )
89
+ .extractVirtualMapDataC (
90
+ getStaticThreadManager (),
91
+ p -> scheduledTransactions .add (
92
+ fromMod (p .key ().getKey (), p .value ().getValue ())),
93
+ 8 );
94
+ } catch (final InterruptedException ex ) {
95
+ System .err .println ("*** Traversal of scheduledTransactions by equality virtual map interrupted!" );
96
+ Thread .currentThread ().interrupt ();
97
+ }
98
+ return r ;
99
+ }
100
+
101
+ private static Map <BBMScheduledId , BBMScheduledSecondValue > gatherModScheduledTransactionsByExpiry (
102
+ final VirtualMap <OnDiskKey <ProtoLong >, OnDiskValue <ScheduleList >> source ) {
103
+ final var r = new HashMap <BBMScheduledId , BBMScheduledSecondValue >();
104
+ final var scheduledTransactions = new ConcurrentLinkedQueue <Pair <BBMScheduledId , BBMScheduledSecondValue >>();
105
+
106
+ try {
107
+ VirtualMapLike .from (source )
108
+ .extractVirtualMapDataC (
109
+ getStaticThreadManager (),
110
+ p -> scheduledTransactions .add (Pair .of (
111
+ new BBMScheduledId (p .key ().getKey ().value ()),
112
+ fromMod (p .key ().getKey (), p .value ().getValue ()))),
113
+ 8 );
114
+ } catch (final InterruptedException ex ) {
115
+ System .err .println ("*** Traversal of scheduledTransactions virtual map interrupted!" );
116
+ Thread .currentThread ().interrupt ();
58
117
}
118
+ while (!scheduledTransactions .isEmpty ()) {
119
+ final var mapping = scheduledTransactions .poll ();
120
+ r .put (mapping .key (), mapping .value ());
121
+ }
122
+ return r ;
59
123
}
60
124
61
125
@ NonNull
62
- private static Map <BBMScheduledTransactionId , BBMScheduledTransaction > gatherModScheduledTransactions (
126
+ private static Map <BBMScheduledId , BBMScheduledTransaction > gatherModScheduledTransactionsById (
63
127
VirtualMap <OnDiskKey <ScheduleID >, OnDiskValue <Schedule >> source ) {
64
- final var r = new HashMap <BBMScheduledTransactionId , BBMScheduledTransaction >();
65
- final var scheduledTransactions =
66
- new ConcurrentLinkedQueue <Pair <BBMScheduledTransactionId , BBMScheduledTransaction >>();
128
+ final var r = new HashMap <BBMScheduledId , BBMScheduledTransaction >();
129
+ final var scheduledTransactions = new ConcurrentLinkedQueue <Pair <BBMScheduledId , BBMScheduledTransaction >>();
67
130
68
131
try {
69
132
VirtualMapLike .from (source )
70
133
.extractVirtualMapDataC (
71
134
getStaticThreadManager (),
72
135
p -> {
73
- try {
74
- scheduledTransactions .add (Pair .of (
75
- fromMod (p .key ().getKey ()),
76
- fromMod (p .value ().getValue ())));
77
- } catch (InvalidKeyException e ) {
78
- throw new RuntimeException (e );
79
- }
136
+ scheduledTransactions .add (Pair .of (
137
+ fromMod (p .key ().getKey ()),
138
+ fromMod (p .value ().getValue ())));
80
139
},
81
140
8 );
82
141
} catch (final InterruptedException ex ) {
@@ -90,10 +149,35 @@ private static Map<BBMScheduledTransactionId, BBMScheduledTransaction> gatherMod
90
149
return r ;
91
150
}
92
151
93
- static BBMScheduledTransaction fromMod (@ NonNull final Schedule value ) throws InvalidKeyException {
152
+ static BBMScheduledSecondValue fromMod (final ProtoLong expiry , @ NonNull final ScheduleList value ) {
153
+ final var newMap = new TreeMap <Instant , List <Long >>();
154
+ final var longsList = value .schedules ().stream ()
155
+ .map (a -> a .scheduleId ().scheduleNum ())
156
+ .toList ();
157
+ newMap .put (Instant .ofEpochSecond (expiry .value ()), longsList );
158
+ return new BBMScheduledSecondValue (newMap );
159
+ }
160
+
161
+ static BBMScheduledEqualityValue fromMod (final ProtoBytes hash , @ NonNull final ScheduleList value ) {
162
+ final var newMap = new TreeMap <String , Long >();
163
+ final var longsList = value .schedules ().stream ()
164
+ .map (a -> a .scheduleId ().scheduleNum ())
165
+ .toList ();
166
+ newMap .put (hash .value ().asUtf8String (), longsList .get (0 ));
167
+ return new BBMScheduledEqualityValue (newMap );
168
+ }
169
+
170
+ static BBMScheduledTransaction fromMod (@ NonNull final Schedule value ) {
171
+ Optional <JKey > adminKey ;
172
+ try {
173
+ adminKey = value .adminKey () != null ? Optional .of (JKey .mapKey (value .adminKey ())) : Optional .empty ();
174
+ } catch (InvalidKeyException e ) {
175
+ adminKey = Optional .empty ();
176
+ }
177
+
94
178
return new BBMScheduledTransaction (
95
179
value .scheduleId ().scheduleNum (),
96
- value . adminKey () != null ? Optional . of ( JKey . mapKey ( value . adminKey ())) : Optional . empty () ,
180
+ adminKey ,
97
181
value .memo (),
98
182
value .deleted (),
99
183
value .executed (),
@@ -116,8 +200,8 @@ static BBMScheduledTransaction fromMod(@NonNull final Schedule value) throws Inv
116
200
value .signatories ().stream ().map (k -> toPrimitiveKey (k )).toList ());
117
201
}
118
202
119
- static BBMScheduledTransactionId fromMod (@ NonNull final ScheduleID scheduleID ) {
120
- return new BBMScheduledTransactionId (scheduleID .scheduleNum ());
203
+ static BBMScheduledId fromMod (@ NonNull final ScheduleID scheduleID ) {
204
+ return new BBMScheduledId (scheduleID .scheduleNum ());
121
205
}
122
206
123
207
static byte [] toPrimitiveKey (com .hedera .hapi .node .base .Key key ) {
0 commit comments