Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
}
// Both sides of the reorg are at the same number, reduce both until the common
// ancestor is found
log.Info("neo reorg start")
for {
// If the common ancestor was found, bail out
if oldBlock.Hash() == newBlock.Hash() {
Expand All @@ -2228,10 +2229,12 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
}
// Remove an old block as well as stash away a new block
oldChain = append(oldChain, oldBlock)
log.Info("neo reorg oldBlock info ", "hash", oldBlock.Hash(), "number", oldBlock.Number())
for _, tx := range oldBlock.Transactions() {
deletedTxs = append(deletedTxs, tx.Hash())
}
newChain = append(newChain, newBlock)
log.Info("neo reorg newBlock info ", "hash", newBlock.Hash(), "number", newBlock.Number())

// Step back with both chains
oldBlock = bc.GetBlock(oldBlock.ParentHash(), oldBlock.NumberU64()-1)
Expand All @@ -2243,6 +2246,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
return fmt.Errorf("invalid new chain")
}
}
log.Info("neo reorg end")

// Ensure the user sees large reorgs
if len(oldChain) > 0 && len(newChain) > 0 {
Expand Down Expand Up @@ -2378,6 +2382,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
// Run the reorg if necessary and set the given block as new head.
start := time.Now()
if head.ParentHash() != bc.CurrentBlock().Hash() {
log.Info("neo reorg start ", "parentHash", head.ParentHash(), "currentHash", bc.CurrentBlock().Hash())
if err := bc.reorg(bc.CurrentBlock(), head); err != nil {
return common.Hash{}, err
}
Expand Down
2 changes: 2 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"github.com/ethereum/go-ethereum/log"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -182,6 +183,7 @@ func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
// GetBlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found.
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
log.Info("neo get block by number test")
hash := rawdb.ReadCanonicalHash(bc.db, number)
if hash == (common.Hash{}) {
return nil
Expand Down
3 changes: 2 additions & 1 deletion eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ func (api *ConsensusAPI) verifyPayloadAttributes(attr *engine.PayloadAttributes)
}

func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
log.Info("neo reorg verify")
api.forkchoiceLock.Lock()
defer api.forkchoiceLock.Unlock()

log.Trace("Engine API request received", "method", "ForkchoiceUpdated", "head", update.HeadBlockHash, "finalized", update.FinalizedBlockHash, "safe", update.SafeBlockHash)
log.Info("Engine API request received", "method", "ForkchoiceUpdated", "head", update.HeadBlockHash, "finalized", update.FinalizedBlockHash, "safe", update.SafeBlockHash)
if update.HeadBlockHash == (common.Hash{}) {
log.Warn("Forkchoice requested update to zero hash")
return engine.STATUS_INVALID, nil // TODO(karalabe): Why does someone send us this?
Expand Down