Skip to content

Commit

Permalink
Added minimum threshold deltaS into CalcOrder
Browse files Browse the repository at this point in the history
From simulations and rigorous testing we have understood that there is
stable operating point on just using Stoichastic or using the threshold
to determine Dom blocks in a Synchronous setting

To be able to handle the adverse network scenarios and testnet
environment and malicious miners the correct solution is mixture of
having threshold to counteract malicious miners getting lucky and
having a increased difficulty threshold to find a dom block
  • Loading branch information
kiltsonfire authored and gameofpointers committed Sep 12, 2023
1 parent 8ac0cda commit 2f2a0f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 10 additions & 2 deletions consensus/blake3pow/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 14 additions & 4 deletions consensus/progpow/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 2f2a0f8

Please sign in to comment.