From 264551cbc1da40ee034ba7cf2fa67bb67a64c8c6 Mon Sep 17 00:00:00 2001
From: Jaynti Kanani <jdkanani@gmail.com>
Date: Thu, 28 Jan 2021 22:22:06 +0530
Subject: [PATCH] fix: use hash instead of block number incase of reorg

---
 consensus/bor/bor.go | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go
index 0c3a840a8..556fbbec3 100644
--- a/consensus/bor/bor.go
+++ b/consensus/bor/bor.go
@@ -846,9 +846,9 @@ func (c *Bor) Close() error {
 }
 
 // GetCurrentSpan get current span from contract
-func (c *Bor) GetCurrentSpan(snapshotNumber uint64) (*Span, error) {
+func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
 	// block
-	blockNr := rpc.BlockNumber(snapshotNumber)
+	blockNr := rpc.BlockNumberOrHashWithHash(headerHash, false)
 
 	// method
 	method := "getCurrentSpan"
@@ -866,7 +866,7 @@ func (c *Bor) GetCurrentSpan(snapshotNumber uint64) (*Span, error) {
 		Gas:  &gas,
 		To:   &toAddress,
 		Data: &msgData,
-	}, rpc.BlockNumberOrHash{BlockNumber: &blockNr}, nil)
+	}, blockNr, nil)
 	if err != nil {
 		return nil, err
 	}
@@ -949,7 +949,7 @@ func (c *Bor) checkAndCommitSpan(
 	chain core.ChainContext,
 ) error {
 	headerNumber := header.Number.Uint64()
-	span, err := c.GetCurrentSpan(headerNumber - 1)
+	span, err := c.GetCurrentSpan(header.ParentHash)
 	if err != nil {
 		return err
 	}
@@ -1167,7 +1167,7 @@ func (c *Bor) getNextHeimdallSpanForTest(
 	chain core.ChainContext,
 ) (*HeimdallSpan, error) {
 	headerNumber := header.Number.Uint64()
-	span, err := c.GetCurrentSpan(headerNumber - 1)
+	span, err := c.GetCurrentSpan(header.ParentHash)
 	if err != nil {
 		return nil, err
 	}
-- 
GitLab