core: fix the condition of reorg

This commit is contained in:
icodezjb 2020-04-16 14:15:59 +08:00 committed by GitHub
parent 359d9c3f0a
commit 9a4b0ea8f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -165,7 +165,9 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er
// If the total difficulty is higher than our known, add it to the canonical chain // If the total difficulty is higher than our known, add it to the canonical chain
// 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 || (externTd.Cmp(localTd) == 0 && mrand.Float64() < 0.5) { if externTd.Cmp(localTd) > 0 ||
(externTd.Cmp(localTd) == 0 && header.Number.Uint64() < hc.CurrentHeader().Number.Uint64()) ||
(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).
// //