@@ -10,6 +10,7 @@ use sqlx::{
10
10
use strata_bridge_tx_graph:: transactions:: prelude:: CovenantTx ;
11
11
use strata_primitives:: params:: RollupParams ;
12
12
use thiserror:: Error ;
13
+ use tracing:: { debug, error} ;
13
14
14
15
use crate :: contract_state_machine:: { ContractCfg , ContractSM , MachineState } ;
15
16
@@ -57,7 +58,11 @@ impl ContractPersister {
57
58
)
58
59
. execute ( & pool)
59
60
. await
60
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
61
+ . map_err ( |e| {
62
+ error ! ( ?e, "failed to create contracts table" ) ;
63
+
64
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
65
+ } ) ?;
61
66
Ok ( ContractPersister { pool } )
62
67
}
63
68
@@ -85,7 +90,10 @@ impl ContractPersister {
85
90
. bind ( bincode:: serialize ( & state) ?)
86
91
. execute ( & self . pool )
87
92
. await
88
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
93
+ . map_err ( |e| {
94
+ error ! ( ?e, "failed to insert contract into database" ) ;
95
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
96
+ } ) ?;
89
97
Ok ( ( ) )
90
98
}
91
99
@@ -104,7 +112,10 @@ impl ContractPersister {
104
112
. bind ( deposit_txid. to_string ( ) )
105
113
. execute ( & self . pool )
106
114
. await
107
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
115
+ . map_err ( |e| {
116
+ error ! ( ?e, "failed to commit machine state to disk" ) ;
117
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
118
+ } ) ?;
108
119
Ok ( ( ) )
109
120
}
110
121
@@ -113,6 +124,8 @@ impl ContractPersister {
113
124
& self ,
114
125
active_contracts : impl Iterator < Item = ( & Txid , & ContractSM ) > ,
115
126
) -> Result < ( ) , ContractPersistErr > {
127
+ debug ! ( "committing all active contracts" ) ;
128
+
116
129
for ( txid, contract_sm) in active_contracts {
117
130
let machine_state = contract_sm. state ( ) ;
118
131
// FIXME: (@Rajil1213) wrap all commits into a single db transaction.
@@ -145,22 +158,37 @@ impl ContractPersister {
145
158
. bind ( deposit_txid. to_string ( ) )
146
159
. fetch_one ( & self . pool )
147
160
. await
148
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
149
- let deposit_idx = row
150
- . try_get ( "deposit_idx" )
151
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
152
- let deposit_tx = bincode:: deserialize (
153
- row. try_get ( "deposit_tx" )
154
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?,
155
- ) ?;
156
- let operator_table = bincode:: deserialize (
157
- row. try_get ( "operator_table" )
158
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?,
159
- ) ?;
160
- let state = bincode:: deserialize (
161
- row. try_get ( "state" )
162
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?,
163
- ) ?;
161
+ . map_err ( |e| {
162
+ error ! ( ?e, %deposit_txid, "could not load contract from disk" ) ;
163
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
164
+ } ) ?;
165
+
166
+ let deposit_idx = row. try_get ( "deposit_idx" ) . map_err ( |e| {
167
+ error ! ( ?e, %deposit_txid, "could not parse deposit_idx from contract entry in disk" ) ;
168
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
169
+ } ) ?;
170
+
171
+ let deposit_tx = bincode:: deserialize ( row. try_get ( "deposit_tx" ) . map_err ( |e| {
172
+ error ! ( ?e, %deposit_txid, "could not parse deposit_tx from contract entry in disk" ) ;
173
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
174
+ } ) ?) . inspect_err ( |e| {
175
+ error ! ( ?e, %deposit_txid, "could not deserialize deposit_tx from contract entry in disk" ) ;
176
+ } ) ?;
177
+
178
+ let operator_table = bincode:: deserialize ( row. try_get ( "operator_table" ) . map_err ( |e| {
179
+ error ! ( ?e, %deposit_txid, "could not parse operator_table from contract entry in disk" ) ;
180
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
181
+ } ) ?) . inspect_err ( |e| {
182
+ error ! ( ?e, %deposit_txid, "could not deserialize operator_table from contract entry in disk" ) ;
183
+ } ) ?;
184
+
185
+ let state = bincode:: deserialize ( row. try_get ( "state" ) . map_err ( |e| {
186
+ error ! ( ?e, %deposit_txid, "could not parse state from contract entry in disk" ) ;
187
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
188
+ } ) ?)
189
+ . inspect_err ( |e| {
190
+ error ! ( ?e, %deposit_txid, "could not deserialize state from contract entry in disk" ) ;
191
+ } ) ?;
164
192
165
193
Ok ( (
166
194
ContractCfg {
@@ -199,24 +227,59 @@ impl ContractPersister {
199
227
)
200
228
. fetch_all ( & self . pool )
201
229
. await
202
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
230
+ . map_err ( |e| {
231
+ error ! ( ?e, "could not load all contracts from disk" ) ;
232
+
233
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
234
+ } ) ?;
235
+
203
236
rows. into_iter ( )
204
237
. map ( |row| {
205
- let deposit_idx = row
206
- . try_get ( "deposit_idx" )
207
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?;
208
- let deposit_tx = bincode:: deserialize (
209
- row. try_get ( "deposit_tx" )
210
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?,
211
- ) ?;
212
- let operator_table = bincode:: deserialize (
213
- row. try_get ( "operator_table" )
214
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?,
215
- ) ?;
216
- let state = bincode:: deserialize (
217
- row. try_get ( "state" )
218
- . map_err ( |e| ContractPersistErr :: Unexpected ( e. to_string ( ) ) ) ?,
219
- ) ?;
238
+ let deposit_idx = row. try_get ( "deposit_idx" ) . map_err ( |e| {
239
+ error ! (
240
+ ?e,
241
+ "could not parse deposit_idx from contract entry in disk"
242
+ ) ;
243
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
244
+ } ) ?;
245
+
246
+ let deposit_tx = bincode:: deserialize ( row. try_get ( "deposit_tx" ) . map_err ( |e| {
247
+ error ! ( ?e, "could not parse deposit_tx from contract entry in disk" ) ;
248
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
249
+ } ) ?)
250
+ . inspect_err ( |e| {
251
+ error ! (
252
+ ?e,
253
+ "could not deserialize deposit_tx from contract entry in disk"
254
+ ) ;
255
+ } ) ?;
256
+
257
+ let operator_table =
258
+ bincode:: deserialize ( row. try_get ( "operator_table" ) . map_err ( |e| {
259
+ error ! (
260
+ ?e,
261
+ "could not parse operator_table from contract entry in disk"
262
+ ) ;
263
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
264
+ } ) ?)
265
+ . inspect_err ( |e| {
266
+ error ! (
267
+ ?e,
268
+ "could not deserialize operator_table from contract entry in disk"
269
+ ) ;
270
+ } ) ?;
271
+
272
+ let state = bincode:: deserialize ( row. try_get ( "state" ) . map_err ( |e| {
273
+ error ! ( ?e, "could not parse state from contract entry in disk" ) ;
274
+ ContractPersistErr :: Unexpected ( e. to_string ( ) )
275
+ } ) ?)
276
+ . inspect_err ( |e| {
277
+ error ! (
278
+ ?e,
279
+ "could not deserialize state from contract entry in disk"
280
+ ) ;
281
+ } ) ?;
282
+
220
283
Ok ( (
221
284
ContractCfg {
222
285
network,
0 commit comments