fix: use hash instead of block number incase of reorg

This commit is contained in:
Jaynti Kanani 2021-01-28 22:22:06 +05:30
parent 34c3457c07
commit 264551cbc1
No known key found for this signature in database
GPG key ID: 4396982C976BAE5E

View file

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