Skip to content

Commit

Permalink
Updating the new workshares threshold diff to 4 after the second gold…
Browse files Browse the repository at this point in the history
…enage fork
  • Loading branch information
gameofpointers committed Nov 8, 2024
1 parent 150efef commit 5e92337
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ func SetQuaiConfig(stack *node.Node, cfg *quaiconfig.Config, slicesRunning []com
cfg.GenesisNonce = viper.GetUint64(GenesisNonce.Name)

cfg.Miner.WorkShareMining = viper.GetBool(WorkShareMiningFlag.Name)
cfg.Miner.WorkShareThreshold = params.WorkSharesThresholdDiff + viper.GetInt(WorkShareThresholdFlag.Name)
cfg.Miner.WorkShareThreshold = params.NewWorkSharesThresholdDiff + viper.GetInt(WorkShareThresholdFlag.Name)
if viper.GetString(WorkShareMinerEndpoints.Name) != "" {
cfg.Miner.Endpoints = []string{viper.GetString(WorkShareMinerEndpoints.Name)}
}
Expand Down
8 changes: 7 additions & 1 deletion consensus/blake3pow/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,13 @@ func (blake3pow *Blake3pow) CalcRank(chain consensus.ChainHeaderReader, header *
}

func (blake3pow *Blake3pow) CheckIfValidWorkShare(workShare *types.WorkObjectHeader) types.WorkShareValidity {
if blake3pow.CheckWorkThreshold(workShare, params.WorkSharesThresholdDiff) {
var thresholdDiff int
if workShare.NumberU64() < params.GoldenAgeForkNumberV2 {
thresholdDiff = params.OldWorkSharesThresholdDiff
} else {
thresholdDiff = params.NewWorkSharesThresholdDiff
}
if blake3pow.CheckWorkThreshold(workShare, thresholdDiff) {
return types.Valid
} else if blake3pow.CheckWorkThreshold(workShare, blake3pow.config.WorkShareThreshold) {
return types.Sub
Expand Down
7 changes: 6 additions & 1 deletion consensus/blake3pow/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime/debug"
"sync"

"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/consensus"
"github.com/dominant-strategies/go-quai/core/types"
"github.com/dominant-strategies/go-quai/log"
Expand Down Expand Up @@ -120,7 +121,11 @@ func (blake3pow *Blake3pow) Seal(header *types.WorkObject, results chan<- *types
}

func (blake3pow *Blake3pow) Mine(header *types.WorkObject, abort <-chan struct{}, found chan *types.WorkObject) {
blake3pow.MineToThreshold(header, params.WorkSharesThresholdDiff, abort, found)
if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 {
blake3pow.MineToThreshold(header, params.OldWorkSharesThresholdDiff, abort, found)
} else {
blake3pow.MineToThreshold(header, params.NewWorkSharesThresholdDiff, abort, found)
}
}

func (blake3pow *Blake3pow) MineToThreshold(workObject *types.WorkObject, workShareThreshold int, abort <-chan struct{}, found chan *types.WorkObject) {
Expand Down
8 changes: 7 additions & 1 deletion consensus/progpow/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,13 @@ func (progpow *Progpow) CalcRank(chain consensus.ChainHeaderReader, header *type
}

func (progpow *Progpow) CheckIfValidWorkShare(workShare *types.WorkObjectHeader) types.WorkShareValidity {
if progpow.CheckWorkThreshold(workShare, params.WorkSharesThresholdDiff) {
var thresholdDiff int
if workShare.NumberU64() < params.GoldenAgeForkNumberV2 {
thresholdDiff = params.OldWorkSharesThresholdDiff
} else {
thresholdDiff = params.NewWorkSharesThresholdDiff
}
if progpow.CheckWorkThreshold(workShare, thresholdDiff) {
return types.Valid
} else if progpow.CheckWorkThreshold(workShare, progpow.config.WorkShareThreshold) {
return types.Sub
Expand Down
6 changes: 5 additions & 1 deletion consensus/progpow/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ func (progpow *Progpow) Seal(header *types.WorkObject, results chan<- *types.Wor
}

func (progpow *Progpow) Mine(workObject *types.WorkObject, abort <-chan struct{}, found chan *types.WorkObject) {
progpow.MineToThreshold(workObject, params.WorkSharesThresholdDiff, abort, found)
if workObject.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 {
progpow.MineToThreshold(workObject, params.OldWorkSharesThresholdDiff, abort, found)
} else {
progpow.MineToThreshold(workObject, params.NewWorkSharesThresholdDiff, abort, found)
}
}

func (progpow *Progpow) MineToThreshold(workObject *types.WorkObject, workShareThreshold int, abort <-chan struct{}, found chan *types.WorkObject) {
Expand Down
7 changes: 6 additions & 1 deletion core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,12 @@ func (hc *HeaderChain) GetMaxTxInWorkShare() uint64 {
currentGasLimit := hc.CurrentHeader().GasLimit()
maxEoaInBlock := currentGasLimit / params.TxGas
// (maxEoaInBlock*2)/(2^bits)
return (maxEoaInBlock * 2) / uint64(math.Pow(2, float64(params.WorkSharesThresholdDiff)))
currentHeader := hc.CurrentHeader()
if currentHeader != nil && currentHeader.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 {
return (maxEoaInBlock * 2) / uint64(math.Pow(2, float64(params.OldWorkSharesThresholdDiff)))
} else {
return (maxEoaInBlock * 2) / uint64(math.Pow(2, float64(params.NewWorkSharesThresholdDiff)))
}
}

func (hc *HeaderChain) Database() ethdb.Database {
Expand Down
3 changes: 2 additions & 1 deletion params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ var (
DifficultyAdjustmentFactor int64 = 40 // This is the factor that divides the log of the change in the difficulty
MinQuaiConversionAmount = new(big.Int).Mul(big.NewInt(10000000000), big.NewInt(GWei)) // 0.000000001 Quai
MaxWorkShareCount = 16
WorkSharesThresholdDiff = 3 // Number of bits lower than the target that the default consensus engine uses
OldWorkSharesThresholdDiff = 3 // Number of bits lower than the target that the default consensus engine uses
NewWorkSharesThresholdDiff = 4 // Number of bits lower than the target that the default consensus engine uses
WorkSharesInclusionDepth = 3 // Number of blocks upto which the work shares can be referenced and this is protocol enforced
LockupByteToBlockDepth = make(map[uint8]uint64)
LockupByteToRewardsRatio = make(map[uint8]*big.Int)
Expand Down

0 comments on commit 5e92337

Please sign in to comment.