diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d0a0b4580..57600e677 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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)} } diff --git a/consensus/blake3pow/poem.go b/consensus/blake3pow/poem.go index 6e06b1ad5..56e5ed9a9 100644 --- a/consensus/blake3pow/poem.go +++ b/consensus/blake3pow/poem.go @@ -296,7 +296,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 diff --git a/consensus/blake3pow/sealer.go b/consensus/blake3pow/sealer.go index 313e90ffc..dcb088ccd 100644 --- a/consensus/blake3pow/sealer.go +++ b/consensus/blake3pow/sealer.go @@ -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" @@ -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) { diff --git a/consensus/misc/rewards.go b/consensus/misc/rewards.go index bceaf6c10..34c0a3df6 100644 --- a/consensus/misc/rewards.go +++ b/consensus/misc/rewards.go @@ -23,6 +23,12 @@ func CalculateReward(parent *types.WorkObject, header *types.WorkObjectHeader) * reward = new(big.Int).Add(reward, new(big.Int).Div(reward, big.NewInt(70))) } + // Since after the second fork, the number of the workshares allowed is increased by 2x, + // the reward value is cut by half to keep the rate of inflation the same + if header.NumberU64() >= params.GoldenAgeForkNumberV2 { + reward = new(big.Int).Div(reward, common.Big2) + } + return reward } diff --git a/consensus/progpow/poem.go b/consensus/progpow/poem.go index 0677860d4..030a1f64c 100644 --- a/consensus/progpow/poem.go +++ b/consensus/progpow/poem.go @@ -295,7 +295,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 diff --git a/consensus/progpow/sealer.go b/consensus/progpow/sealer.go index f6421c460..bbbcb87a8 100644 --- a/consensus/progpow/sealer.go +++ b/consensus/progpow/sealer.go @@ -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) { diff --git a/core/headerchain.go b/core/headerchain.go index aff75c4aa..a47312fc0 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -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 { diff --git a/params/protocol_params.go b/params/protocol_params.go index 04d7152a8..f37acb6c5 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -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)