diff --git a/consensus/blake3pow/poem.go b/consensus/blake3pow/poem.go index 494b77771f..c01e167bdc 100644 --- a/consensus/blake3pow/poem.go +++ b/consensus/blake3pow/poem.go @@ -29,15 +29,23 @@ func (blake3pow *Blake3pow) CalcOrder(header *types.Header) (*big.Int, int, erro // PRIME // PrimeEntropyThreshold number of zone blocks times the intrinsic logs of // the given header determines the prime block + totalDeltaSPrime := new(big.Int).Add(header.ParentDeltaS(common.REGION_CTX), header.ParentDeltaS(common.ZONE_CTX)) + totalDeltaSPrime = new(big.Int).Add(totalDeltaSPrime, intrinsicS) + primeDeltaSTarget := new(big.Int).Div(params.PrimeEntropyTarget, big2) + primeDeltaSTarget = new(big.Int).Mul(zoneThresholdS, primeDeltaSTarget) + primeBlockEntropyThreshold := new(big.Int).Add(zoneThresholdS, common.BitsToBigBits(params.PrimeEntropyTarget)) - if intrinsicS.Cmp(primeBlockEntropyThreshold) > 0 { + if intrinsicS.Cmp(primeBlockEntropyThreshold) > 0 && totalDeltaSPrime.Cmp(primeDeltaSTarget) > 0 { return intrinsicS, common.PRIME_CTX, nil } // REGION // Compute the total accumulated entropy since the last region block + totalDeltaSRegion := new(big.Int).Add(header.ParentDeltaS(common.ZONE_CTX), intrinsicS) + regionDeltaSTarget := new(big.Int).Div(params.RegionEntropyTarget, big2) + regionDeltaSTarget = new(big.Int).Mul(zoneThresholdS, regionDeltaSTarget) regionBlockEntropyThreshold := new(big.Int).Add(zoneThresholdS, common.BitsToBigBits(params.RegionEntropyTarget)) - if intrinsicS.Cmp(regionBlockEntropyThreshold) > 0 { + if intrinsicS.Cmp(regionBlockEntropyThreshold) > 0 && totalDeltaSRegion.Cmp(regionDeltaSTarget) > 0 { return intrinsicS, common.REGION_CTX, nil } diff --git a/consensus/progpow/poem.go b/consensus/progpow/poem.go index 42d7dad25f..f19d677e06 100644 --- a/consensus/progpow/poem.go +++ b/consensus/progpow/poem.go @@ -26,20 +26,30 @@ func (progpow *Progpow) CalcOrder(header *types.Header) (*big.Int, int, error) { target := new(big.Int).Div(common.Big2e256, header.Difficulty()) zoneThresholdS := progpow.IntrinsicLogS(common.BytesToHash(target.Bytes())) - // Prime case - // PrimeEntropyThreshold number of zone blocks times the intrinsic logs of the given header determines the prime block + // PRIME + // PrimeEntropyThreshold number of zone blocks times the intrinsic logs of + // the given header determines the prime block + totalDeltaSPrime := new(big.Int).Add(header.ParentDeltaS(common.REGION_CTX), header.ParentDeltaS(common.ZONE_CTX)) + totalDeltaSPrime = new(big.Int).Add(totalDeltaSPrime, intrinsicS) + primeDeltaSTarget := new(big.Int).Div(params.PrimeEntropyTarget, big2) + primeDeltaSTarget = new(big.Int).Mul(zoneThresholdS, primeDeltaSTarget) + primeBlockEntropyThreshold := new(big.Int).Add(zoneThresholdS, common.BitsToBigBits(params.PrimeEntropyTarget)) - if intrinsicS.Cmp(primeBlockEntropyThreshold) > 0 { + if intrinsicS.Cmp(primeBlockEntropyThreshold) > 0 && totalDeltaSPrime.Cmp(primeDeltaSTarget) > 0 { return intrinsicS, common.PRIME_CTX, nil } // REGION // Compute the total accumulated entropy since the last region block + totalDeltaSRegion := new(big.Int).Add(header.ParentDeltaS(common.ZONE_CTX), intrinsicS) + regionDeltaSTarget := new(big.Int).Div(params.RegionEntropyTarget, big2) + regionDeltaSTarget = new(big.Int).Mul(zoneThresholdS, regionDeltaSTarget) regionBlockEntropyThreshold := new(big.Int).Add(zoneThresholdS, common.BitsToBigBits(params.RegionEntropyTarget)) - if intrinsicS.Cmp(regionBlockEntropyThreshold) > 0 { + if intrinsicS.Cmp(regionBlockEntropyThreshold) > 0 && totalDeltaSRegion.Cmp(regionDeltaSTarget) > 0 { return intrinsicS, common.REGION_CTX, nil } + // Zone case return intrinsicS, common.ZONE_CTX, nil }