Skip to content

Commit

Permalink
Rename HasCoincidentDifficulty() -> IsDomCoincident() for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Jan 25, 2023
1 parent 1c8023c commit 76d0238
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (blake3pow *Blake3pow) CalcDifficulty(chain consensus.ChainHeaderReader, pa
return x
}

func (blake3pow *Blake3pow) HasCoincidentDifficulty(header *types.Header) bool {
func (blake3pow *Blake3pow) IsDomCoincident(header *types.Header) bool {
nodeCtx := common.NodeLocation.Context()

// Since the Prime chain is the highest order, it cannot have coincident blocks
Expand Down
4 changes: 2 additions & 2 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ type Engine interface {
// that a new block should have.
CalcDifficulty(chain ChainHeaderReader, parent *types.Header) *big.Int

// IsCoincident returns true if this block satisfies the difficulty order
// IsDomCoincident returns true if this block satisfies the difficulty order
// of a dominant chain. If this node does not have a dominant chain (i.e.
// if this is a prime node), then the function will always return false.
//
// Importantly, this check does NOT mean the block is canonical in the
// dominant chain, or even that the claimed dominant difficulty is valid.
HasCoincidentDifficulty(header *types.Header) bool
IsDomCoincident(header *types.Header) bool

// APIs returns the RPC APIs this consensus engine provides.
APIs(chain ChainHeaderReader) []rpc.API
Expand Down
3 changes: 2 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func NewCore(db ethdb.Database, config *Config, isLocalBlock func(block *types.H
func (c *Core) InsertChain(blocks types.Blocks) (int, error) {
domWait := false
for i, block := range blocks {
isCoincident := c.sl.engine.HasCoincidentDifficulty(block.Header())
isCoincident := c.sl.engine.IsDomCoincident(block.Header())

// Write the block body to the db.
rawdb.WritePendingBlockBody(c.sl.sliceDb, block.Header().Root(), block.Body())

Expand Down
10 changes: 5 additions & 5 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (sl *Slice) pcrc(batch ethdb.Batch, header *types.Header, domTerminus commo
nodeCtx := common.NodeLocation.Context()
location := header.Location()

isCoincident := sl.engine.HasCoincidentDifficulty(header)
isDomCoincident := sl.engine.IsDomCoincident(header)

log.Debug("PCRC:", "Parent Hash:", header.ParentHash(), "Number", header.Number, "Location:", header.Location())
termini := sl.hc.GetTerminiByHash(header.ParentHash())
Expand All @@ -270,14 +270,14 @@ func (sl *Slice) pcrc(batch ethdb.Batch, header *types.Header, domTerminus commo
}

// Set the terminus
if nodeCtx == common.PRIME_CTX || isCoincident {
if nodeCtx == common.PRIME_CTX || isDomCoincident {
newTermini[terminiIndex] = header.Hash()
} else {
newTermini[terminiIndex] = termini[terminiIndex]
}

// Check for a graph cyclic reference
if isCoincident {
if isDomCoincident {
if termini[terminiIndex] != domTerminus {
log.Warn("Cyclic Block:", "block number", header.NumberArray(), "hash", header.Hash(), "terminus", domTerminus, "termini", termini)
return common.Hash{}, []common.Hash{}, errors.New("termini do not match, block rejected due to cyclic reference")
Expand Down Expand Up @@ -307,8 +307,8 @@ func (sl *Slice) hlcr(externTd *big.Int) bool {
// CalcTd calculates the TD of the given header using PCRC.
func (sl *Slice) calcTd(header *types.Header) (*big.Int, error) {
// Stop from
isCoincident := sl.engine.HasCoincidentDifficulty(header)
if isCoincident {
isDomCoincident := sl.engine.IsDomCoincident(header)
if isDomCoincident {
return nil, errors.New("td on a dom block cannot be calculated by a sub")
}
priorTd := sl.hc.GetTd(header.ParentHash(), header.NumberU64()-1)
Expand Down

0 comments on commit 76d0238

Please sign in to comment.