Skip to content

Commit

Permalink
Cherry-picked external block checks and trace updates (dominant-strat…
Browse files Browse the repository at this point in the history
…egies#267)

* Updated link block checks in blockchain.go and moved extBlockLink

* Reworked TraceBranches to single function

* Remove reorg 50% on equal difficulty

* Added reset extBlockLink after failed reorg

* Update extBlockLink after normal reorg

* Updated genesis hashes

* Additional reportBlock and feed data for invalid writeBlockWithState

* Updated error checking and comments

* Added bracket
  • Loading branch information
alanorwick authored Jun 7, 2022
1 parent a9b7898 commit 645185c
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 504 deletions.
217 changes: 61 additions & 156 deletions consensus/blake3/consensus.go

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ func (c *Clique) GetExternalBlocks(chain consensus.ChainHeaderReader, header *ty
return make([]*types.ExternalBlock, 0), nil
}

// GetExternalBlocks traces all available branches to find external blocks
func (c *Clique) GetLinkExternalBlocks(chain consensus.ChainHeaderReader, header *types.Header, logging bool) ([]*types.ExternalBlock, error) {
return make([]*types.ExternalBlock, 0), nil
}

// GetCoincidentHeader retrieves the furthest coincident header back
func (c *Clique) GetDifficultyOrder(header *types.Header) (int, error) {
return 0, nil
Expand All @@ -614,12 +619,8 @@ func (c *Clique) GetStopHash(chain consensus.ChainHeaderReader, difficultyContex
return common.Hash{}, 0
}

// TraceBranch recursively traces branches to find
func (c *Clique) PrimeTraceBranch(chain consensus.ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) ([]*types.ExternalBlock, error) {
return make([]*types.ExternalBlock, 0), nil
}

func (c *Clique) RegionTraceBranch(chain consensus.ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) ([]*types.ExternalBlock, error) {
// TraceBranches recursively traces branches to find external blocks.
func (c *Clique) TraceBranches(chain consensus.ChainHeaderReader, header *types.Header, context int, originalContext int, originalLocation []byte) ([]*types.ExternalBlock, error) {
return make([]*types.ExternalBlock, 0), nil
}

Expand Down
14 changes: 7 additions & 7 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type ChainHeaderReader interface {
// GetExternalBlocks retrieve all external blocks for a header.
GetExternalBlocks(header *types.Header) ([]*types.ExternalBlock, error)

// GetExternalBlocks retrieve all external link blocks for a header.
GetLinkExternalBlocks(header *types.Header) ([]*types.ExternalBlock, error)

// GetExternalBlock retrieves an external block header by its hash and context.
GetExternalBlock(hash common.Hash, number uint64, context uint64) (*types.ExternalBlock, error)

Expand Down Expand Up @@ -127,14 +130,11 @@ type Engine interface {
// This function determines the difficulty order of a block
GetDifficultyOrder(header *types.Header) (int, error)

// GetStopHash retrieves the stop hash for tracing of blocks in a trace branch.
GetStopHash(chain ChainHeaderReader, difficultyContext int, originalContext int, startingHeader *types.Header) (common.Hash, int)

// PrimeTraceBranch recursively traces branches to find.
PrimeTraceBranch(chain ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) ([]*types.ExternalBlock, error)
// TraceBranches recursively traces region and zone branches to find external blocks.
TraceBranches(chain ChainHeaderReader, header *types.Header, context int, originalContext int, originalLocation []byte) ([]*types.ExternalBlock, error)

// RegionTraceBranch recursively traces region branches to find.
RegionTraceBranch(chain ChainHeaderReader, header *types.Header, context int, stopHash common.Hash, originalContext int, originalLocation []byte) ([]*types.ExternalBlock, error)
// GetLinkExternalBlocks links every block to the correct previous block
GetLinkExternalBlocks(chain ChainHeaderReader, header *types.Header, logging bool) ([]*types.ExternalBlock, error)

// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
Expand Down
Loading

0 comments on commit 645185c

Please sign in to comment.