Skip to content

Commit

Permalink
additional logging around reorganizations
Browse files Browse the repository at this point in the history
  • Loading branch information
bitspill committed Jan 22, 2019
1 parent 1f20a7e commit be36515
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func init() {
log.Info("Subscribing to events")
events.Bus.SubscribeAsync("flo:notify:onFilteredBlockConnected", onFilteredBlockConnected, true)
events.Bus.SubscribeAsync("flo:notify:onFilteredBlockDisconnected", onFilteredBlockDisconnected, true)
events.Bus.SubscribeAsync("flo:notify:onTxAcceptedVerbose", onTxAcceptedVerbose, false)
}

Expand All @@ -27,7 +28,7 @@ func onFilteredBlockConnected(height int32, header *wire.BlockHeader, txns []*fl
_, err := IndexBlockAtHeight(int64(height), *ilb)
if err != nil {
attr["err"] = err
log.Error("onFilteredBlockConnected unable to index block", attr)
log.Error("onFilteredBlockConnected unable to index block, follow", attr)
}

return
Expand All @@ -51,7 +52,7 @@ func onFilteredBlockConnected(height int32, header *wire.BlockHeader, txns []*fl
nlb, err := IndexBlockAtHeight(int64(i), *ilb)
if err != nil {
attr["err"] = err
log.Error("onFilteredBlockConnected unable to index block", attr)
log.Error("onFilteredBlockConnected unable to index block, gap", attr)
return
}
ilb = &nlb
Expand All @@ -69,12 +70,14 @@ func onFilteredBlockConnected(height int32, header *wire.BlockHeader, txns []*fl
attr["rewind"] = -i
log.Info("re-org detected", attr)
for ; i < 0; i++ {
attr["pop"] = i
log.Info("popping block", attr)
recentBlocks.PopFront()
}
_, err := IndexBlockAtHeight(int64(height), *ilb)
if err != nil {
attr["err"] = err
log.Error("onFilteredBlockConnected unable to index block", attr)
log.Error("onFilteredBlockConnected unable to index block, re-org", attr)
}

return
Expand All @@ -98,3 +101,11 @@ func onTxAcceptedVerbose(txDetails *flojson.TxRawResult) {
events.Bus.Publish("flo:floData", tx.Transaction.FloData, tx)
}
}

func onFilteredBlockDisconnected(height int32, header *wire.BlockHeader) {
attr := logger.Attrs{"oldHeight": height, "oldHash": header.BlockHash().String()}

log.Info("BlockDisconnected", attr)

// ToDo mark as disconnected in database along with all associated records
}

0 comments on commit be36515

Please sign in to comment.