Skip to content

Commit 39c3ff6

Browse files
Merge pull request #294 from OffchainLabs/nit-1280-switch-to-go-ethereum-pos-apis-to-write-new-blocks-and
Switch to go-ethereum PoS API to write reorgs to blockchain [NIT-1280]
2 parents 22399a7 + 4cf1b34 commit 39c3ff6

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

core/blockchain_arbitrum.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package core
1919

2020
import (
21-
"errors"
21+
"fmt"
2222
"time"
2323

2424
"github.com/ethereum/go-ethereum/core/state"
@@ -40,21 +40,9 @@ func (bc *BlockChain) WriteBlockAndSetHeadWithTime(block *types.Block, receipts
4040
func (bc *BlockChain) ReorgToOldBlock(newHead *types.Block) error {
4141
bc.wg.Add(1)
4242
defer bc.wg.Done()
43-
locked := bc.chainmu.TryLock()
44-
if !locked {
45-
return errors.New("couldn't catch lock to reorg")
43+
if _, err := bc.SetCanonical(newHead); err != nil {
44+
return fmt.Errorf("error reorging to old block: %w", err)
4645
}
47-
defer bc.chainmu.Unlock()
48-
oldHead := bc.CurrentBlock()
49-
if oldHead.Hash() == newHead.Hash() {
50-
return nil
51-
}
52-
bc.writeHeadBlock(newHead)
53-
err := bc.reorg(oldHead, newHead)
54-
if err != nil {
55-
return err
56-
}
57-
bc.chainHeadFeed.Send(ChainHeadEvent{Block: newHead})
5846
return nil
5947
}
6048

0 commit comments

Comments
 (0)