mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: fix nitpick to only retrieve head once
This commit is contained in:
parent
9a4b0ea8f8
commit
b93a22c8b2
1 changed files with 3 additions and 2 deletions
|
|
@ -149,7 +149,8 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er
|
||||||
if ptd == nil {
|
if ptd == nil {
|
||||||
return NonStatTy, consensus.ErrUnknownAncestor
|
return NonStatTy, consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
localTd := hc.GetTd(hc.currentHeaderHash, hc.CurrentHeader().Number.Uint64())
|
head := hc.CurrentHeader().Number.Uint64()
|
||||||
|
localTd := hc.GetTd(hc.currentHeaderHash, head)
|
||||||
externTd := new(big.Int).Add(header.Difficulty, ptd)
|
externTd := new(big.Int).Add(header.Difficulty, ptd)
|
||||||
|
|
||||||
// Irrelevant of the canonical status, write the td and header to the database
|
// Irrelevant of the canonical status, write the td and header to the database
|
||||||
|
|
@ -166,7 +167,7 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er
|
||||||
// Second clause in the if statement reduces the vulnerability to selfish mining.
|
// Second clause in the if statement reduces the vulnerability to selfish mining.
|
||||||
// Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf
|
// Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf
|
||||||
if externTd.Cmp(localTd) > 0 ||
|
if externTd.Cmp(localTd) > 0 ||
|
||||||
(externTd.Cmp(localTd) == 0 && header.Number.Uint64() < hc.CurrentHeader().Number.Uint64()) ||
|
(externTd.Cmp(localTd) == 0 && header.Number.Uint64() < head) ||
|
||||||
(externTd.Cmp(localTd) == 0 && mrand.Float64() < 0.5) {
|
(externTd.Cmp(localTd) == 0 && mrand.Float64() < 0.5) {
|
||||||
// If the header can be added into canonical chain, adjust the
|
// If the header can be added into canonical chain, adjust the
|
||||||
// header chain markers(canonical indexes and head header flag).
|
// header chain markers(canonical indexes and head header flag).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue