Initial reorg fix
This commit is contained in:
parent
1002580cd9
commit
fec37dff9a
|
@ -128,9 +128,17 @@ func main() {
|
|||
}
|
||||
|
||||
timeout_count := 0
|
||||
reorg_count := -1
|
||||
hash := ""
|
||||
phash := ""
|
||||
// Start listening for new blocks
|
||||
for {
|
||||
if reorg_count > 0 {
|
||||
reorg_count = -1
|
||||
height -= 10
|
||||
}
|
||||
block, err := getBlock(rpcClient, height)
|
||||
|
||||
if err != nil {
|
||||
log.WithFields(logrus.Fields{
|
||||
"height": height,
|
||||
|
@ -146,11 +154,27 @@ func main() {
|
|||
}
|
||||
if block != nil {
|
||||
handleBlock(db, block)
|
||||
height++
|
||||
if timeout_count > 0 {
|
||||
timeout_count--
|
||||
}
|
||||
//TODO store block current/prev hash for formal reorg
|
||||
phash = hex.EncodeToString(block.GetPrevHash())
|
||||
//check for reorgs once we have inital block hash from startup
|
||||
if hash != phash && reorg_count != -1 {
|
||||
reorg_count++
|
||||
log.WithFields(logrus.Fields{
|
||||
"height": height,
|
||||
"hash": hash,
|
||||
"phash": phash,
|
||||
"reorg": reorg_count,
|
||||
}).Warn("REORG")
|
||||
} else {
|
||||
hash = hex.EncodeToString(block.GetDisplayHash())
|
||||
}
|
||||
if reorg_count == -1 {
|
||||
hash = hex.EncodeToString(block.GetDisplayHash())
|
||||
reorg_count =0
|
||||
}
|
||||
height++
|
||||
} else {
|
||||
//TODO implement blocknotify to minimize polling on corner cases
|
||||
time.Sleep(60 * time.Second)
|
||||
|
@ -204,7 +228,6 @@ func getBlock(rpcClient *rpcclient.Client, height int) (*parser.Block, error) {
|
|||
func handleBlock(db *sql.DB, block *parser.Block) {
|
||||
prevBlockHash := hex.EncodeToString(block.GetPrevHash())
|
||||
blockHash := hex.EncodeToString(block.GetEncodableHash())
|
||||
//blockHash := hex.EncodeToString(block.GetDisplayHash())
|
||||
marshaledBlock, _ := proto.Marshal(block.ToCompact())
|
||||
|
||||
err := storage.StoreBlock(
|
||||
|
|
Loading…
Reference in New Issue