@@ -288,7 +288,10 @@ func (txi *TXIndex) Update() error {
288
288
if ! exists || err != nil {
289
289
return fmt .Errorf ("Update: Problem getting block at height %d: %v" , txindexTipNode .Height + 1 , err )
290
290
}
291
- for ! blockToAttach .Hash .IsEqual (blockTipNode .Hash ) {
291
+ for blockToAttach != nil &&
292
+ blockToAttach .Header != nil &&
293
+ blockToAttach .Header .PrevBlockHash != nil &&
294
+ ! blockToAttach .Header .PrevBlockHash .IsEqual (blockTipNode .Hash ) {
292
295
if txi .killed {
293
296
glog .Infof (CLog (Yellow , "TxIndex: Update: Killed while attaching blocks" ))
294
297
break
@@ -300,7 +303,8 @@ func (txi *TXIndex) Update() error {
300
303
glog .V (2 ).Infof ("Update: Attaching block (height: %d, hash: %v)" ,
301
304
blockToAttach .Height , blockToAttach .Hash )
302
305
303
- blockMsg , err := GetBlock (blockToAttach .Hash , txi .CoreChain .DB (), nil )
306
+ var blockMsg * MsgDeSoBlock
307
+ blockMsg , err = GetBlock (blockToAttach .Hash , txi .CoreChain .DB (), nil )
304
308
if err != nil {
305
309
return fmt .Errorf ("Update: Problem fetching attach block " +
306
310
"with hash %v: %v" , blockToAttach .Hash , err )
@@ -330,19 +334,19 @@ func (txi *TXIndex) Update() error {
330
334
// - Compute its mapping values, which may include custom metadata fields
331
335
// - add all its mappings to the db.
332
336
for txnIndexInBlock , txn := range blockMsg .Txns {
333
- txnMeta , err := ConnectTxnAndComputeTransactionMetadata (
337
+ txnMeta , innerErr := ConnectTxnAndComputeTransactionMetadata (
334
338
txn , utxoView , blockToAttach .Hash , blockToAttach .Height ,
335
339
blockToAttach .Header .TstampNanoSecs , uint64 (txnIndexInBlock ))
336
- if err != nil {
340
+ if innerErr != nil {
337
341
return fmt .Errorf ("Update: Problem connecting txn %v to txindex: %v" ,
338
- txn , err )
342
+ txn , innerErr )
339
343
}
340
344
341
- err = DbPutTxindexTransactionMappingsWithTxn (dbTxn , nil , blockMsg .Header .Height ,
345
+ innerErr = DbPutTxindexTransactionMappingsWithTxn (dbTxn , nil , blockMsg .Header .Height ,
342
346
txn , txi .Params , txnMeta , txi .CoreChain .eventManager )
343
- if err != nil {
347
+ if innerErr != nil {
344
348
return fmt .Errorf ("Update: Problem adding txn %v to txindex: %v" ,
345
- txn , err )
349
+ txn , innerErr )
346
350
}
347
351
}
348
352
return nil
@@ -358,10 +362,14 @@ func (txi *TXIndex) Update() error {
358
362
return fmt .Errorf ("Update: Problem attaching block %v: %v" ,
359
363
blockToAttach , err )
360
364
}
361
- var exists bool
365
+ prevBlockToAttachHeight := blockToAttach . Height
362
366
blockToAttach , exists , err = txi .CoreChain .GetBlockFromBestChainByHeight (uint64 (blockToAttach .Height + 1 ), false )
363
- if ! exists || err != nil {
364
- return fmt .Errorf ("Update: Problem getting block at height %d: %v" , blockToAttach .Height + 1 , err )
367
+ if err != nil {
368
+ return fmt .Errorf ("Update: Problem getting block at height %d: %v" , prevBlockToAttachHeight + 1 , err )
369
+ }
370
+ if ! exists {
371
+ glog .Infof ("Update: No more blocks to attach to txindex, exiting loop" )
372
+ break
365
373
}
366
374
}
367
375
0 commit comments