diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 19eee21ae..80eb5376d 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.NewWorkSharesThresholdDiff + viper.GetInt(WorkShareThresholdFlag.Name) + cfg.Miner.WorkShareThreshold = params.WorkSharesThresholdDiff + viper.GetInt(WorkShareThresholdFlag.Name) if viper.GetString(WorkShareMinerEndpoints.Name) != "" { cfg.Miner.Endpoints = []string{viper.GetString(WorkShareMinerEndpoints.Name)} } diff --git a/consensus/blake3pow/consensus.go b/consensus/blake3pow/consensus.go index d99ea8c6e..b8c6aa492 100644 --- a/consensus/blake3pow/consensus.go +++ b/consensus/blake3pow/consensus.go @@ -658,36 +658,34 @@ func (blake3pow *Blake3pow) Finalize(chain consensus.ChainHeaderReader, batch et trimmedUtxos := make([]*types.SpentUtxoEntry, 0) - if header.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 { - start := time.Now() - var wg sync.WaitGroup - var lock sync.Mutex - for denomination, depth := range types.TrimDepths { - if denomination <= types.MaxTrimDenomination && header.NumberU64(nodeCtx) > depth { - wg.Add(1) - go func(denomination uint8, depth uint64) { - defer func() { - if r := recover(); r != nil { - blake3pow.logger.WithFields(log.Fields{ - "error": r, - "stacktrace": string(debug.Stack()), - }).Error("Go-Quai Panicked") - } - }() - nextBlockToTrim := rawdb.ReadCanonicalHash(chain.Database(), header.NumberU64(nodeCtx)-depth) - TrimBlock(chain, batch, denomination, header.NumberU64(nodeCtx)-depth, nextBlockToTrim, &utxosDelete, &trimmedUtxos, &utxoSetSize, !setRoots, &lock, blake3pow.logger) // setRoots is false when we are processing the block - wg.Done() - }(denomination, depth) - } - } - wg.Wait() - if len(trimmedUtxos) > 0 { - blake3pow.logger.Infof("Trimmed %d UTXOs from db in %s", len(trimmedUtxos), common.PrettyDuration(time.Since(start))) - } - if !setRoots { - rawdb.WriteTrimmedUTXOs(batch, header.Hash(), trimmedUtxos) + start := time.Now() + var wg sync.WaitGroup + var lock sync.Mutex + for denomination, depth := range types.TrimDepths { + if denomination <= types.MaxTrimDenomination && header.NumberU64(nodeCtx) > depth { + wg.Add(1) + go func(denomination uint8, depth uint64) { + defer func() { + if r := recover(); r != nil { + blake3pow.logger.WithFields(log.Fields{ + "error": r, + "stacktrace": string(debug.Stack()), + }).Error("Go-Quai Panicked") + } + }() + nextBlockToTrim := rawdb.ReadCanonicalHash(chain.Database(), header.NumberU64(nodeCtx)-depth) + TrimBlock(chain, batch, denomination, header.NumberU64(nodeCtx)-depth, nextBlockToTrim, &utxosDelete, &trimmedUtxos, &utxoSetSize, !setRoots, &lock, blake3pow.logger) // setRoots is false when we are processing the block + wg.Done() + }(denomination, depth) } } + wg.Wait() + if len(trimmedUtxos) > 0 { + blake3pow.logger.Infof("Trimmed %d UTXOs from db in %s", len(trimmedUtxos), common.PrettyDuration(time.Since(start))) + } + if !setRoots { + rawdb.WriteTrimmedUTXOs(batch, header.Hash(), trimmedUtxos) + } for _, hash := range utxosCreate { multiSet.Add(hash.Bytes()) } diff --git a/consensus/blake3pow/poem.go b/consensus/blake3pow/poem.go index 56e5ed9a9..149ea94b2 100644 --- a/consensus/blake3pow/poem.go +++ b/consensus/blake3pow/poem.go @@ -45,14 +45,8 @@ func (blake3pow *Blake3pow) CalcOrder(chain consensus.BlockReader, header *types totalDeltaEntropyPrime := new(big.Int).Add(header.ParentDeltaEntropy(common.REGION_CTX), header.ParentDeltaEntropy(common.ZONE_CTX)) totalDeltaEntropyPrime = new(big.Int).Add(totalDeltaEntropyPrime, intrinsicEntropy) - var primeDeltaEntropyTarget *big.Int - if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - primeDeltaEntropyTarget = new(big.Int).Div(params.PrimeEntropyTarget(expansionNum), big2) - primeDeltaEntropyTarget = new(big.Int).Mul(zoneThresholdEntropy, primeDeltaEntropyTarget) - } else { - primeDeltaEntropyTarget = new(big.Int).Mul(params.PrimeEntropyTarget(expansionNum), zoneThresholdEntropy) - primeDeltaEntropyTarget = new(big.Int).Div(primeDeltaEntropyTarget, common.Big2) - } + primeDeltaEntropyTarget := new(big.Int).Mul(params.PrimeEntropyTarget(expansionNum), zoneThresholdEntropy) + primeDeltaEntropyTarget = new(big.Int).Div(primeDeltaEntropyTarget, common.Big2) primeBlockEntropyThreshold := new(big.Int).Add(zoneThresholdEntropy, common.BitsToBigBits(params.PrimeEntropyTarget(expansionNum))) if intrinsicEntropy.Cmp(primeBlockEntropyThreshold) > 0 && totalDeltaEntropyPrime.Cmp(primeDeltaEntropyTarget) > 0 { @@ -64,14 +58,8 @@ func (blake3pow *Blake3pow) CalcOrder(chain consensus.BlockReader, header *types // Compute the total accumulated entropy since the last region block totalDeltaEntropyRegion := new(big.Int).Add(header.ParentDeltaEntropy(common.ZONE_CTX), intrinsicEntropy) - var regionDeltaEntropyTarget *big.Int - if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - regionDeltaEntropyTarget = new(big.Int).Div(params.RegionEntropyTarget(expansionNum), big2) - regionDeltaEntropyTarget = new(big.Int).Mul(zoneThresholdEntropy, regionDeltaEntropyTarget) - } else { - regionDeltaEntropyTarget = new(big.Int).Mul(zoneThresholdEntropy, params.RegionEntropyTarget(expansionNum)) - regionDeltaEntropyTarget = new(big.Int).Div(regionDeltaEntropyTarget, big2) - } + regionDeltaEntropyTarget := new(big.Int).Mul(zoneThresholdEntropy, params.RegionEntropyTarget(expansionNum)) + regionDeltaEntropyTarget = new(big.Int).Div(regionDeltaEntropyTarget, big2) regionBlockEntropyThreshold := new(big.Int).Add(zoneThresholdEntropy, common.BitsToBigBits(params.RegionEntropyTarget(expansionNum))) if intrinsicEntropy.Cmp(regionBlockEntropyThreshold) > 0 && totalDeltaEntropyRegion.Cmp(regionDeltaEntropyTarget) > 0 { @@ -296,12 +284,7 @@ func (blake3pow *Blake3pow) CalcRank(chain consensus.ChainHeaderReader, header * } func (blake3pow *Blake3pow) CheckIfValidWorkShare(workShare *types.WorkObjectHeader) types.WorkShareValidity { - var thresholdDiff int - if workShare.NumberU64() < params.GoldenAgeForkNumberV2 { - thresholdDiff = params.OldWorkSharesThresholdDiff - } else { - thresholdDiff = params.NewWorkSharesThresholdDiff - } + thresholdDiff := params.WorkSharesThresholdDiff if blake3pow.CheckWorkThreshold(workShare, thresholdDiff) { return types.Valid } else if blake3pow.CheckWorkThreshold(workShare, blake3pow.config.WorkShareThreshold) { diff --git a/consensus/blake3pow/sealer.go b/consensus/blake3pow/sealer.go index dcb088ccd..313e90ffc 100644 --- a/consensus/blake3pow/sealer.go +++ b/consensus/blake3pow/sealer.go @@ -10,7 +10,6 @@ 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" @@ -121,11 +120,7 @@ func (blake3pow *Blake3pow) Seal(header *types.WorkObject, results chan<- *types } func (blake3pow *Blake3pow) Mine(header *types.WorkObject, abort <-chan struct{}, found chan *types.WorkObject) { - if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - blake3pow.MineToThreshold(header, params.OldWorkSharesThresholdDiff, abort, found) - } else { - blake3pow.MineToThreshold(header, params.NewWorkSharesThresholdDiff, abort, found) - } + blake3pow.MineToThreshold(header, params.WorkSharesThresholdDiff, 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 e6c1e3ae8..b8d1de1ea 100644 --- a/consensus/misc/rewards.go +++ b/consensus/misc/rewards.go @@ -18,17 +18,6 @@ func CalculateReward(parent *types.WorkObject, header *types.WorkObjectHeader) * reward = new(big.Int).Set(CalculateQuaiReward(parent)) } - // ~30% extra reward for grace number of blocks after the fork to encourage nodes to move to the fork - if header.NumberU64() >= params.GoldenAgeForkNumberV2 && header.NumberU64() < params.GoldenAgeForkNumberV2+params.GoldenAgeGracePaymentPeriod { - 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/misc/statefee.go b/consensus/misc/statefee.go index d020efc4f..fb44fc7bd 100644 --- a/consensus/misc/statefee.go +++ b/consensus/misc/statefee.go @@ -22,9 +22,6 @@ func CalcStateLimit(parent *types.WorkObject, stateCeil uint64) uint64 { delta := parentStateLimit/params.StateLimitBoundDivisor - 1 limit := parentStateLimit - if parent.NumberU64(common.ZONE_CTX) == params.GoldenAgeForkNumberV2 { - limit = params.MinGasLimit(parent.NumberU64(common.ZONE_CTX)) - } var desiredLimit uint64 percentStateUsed := parent.StateUsed() * 100 / parent.StateLimit() diff --git a/consensus/progpow/consensus.go b/consensus/progpow/consensus.go index 74fcc9aee..756446993 100644 --- a/consensus/progpow/consensus.go +++ b/consensus/progpow/consensus.go @@ -715,36 +715,34 @@ func (progpow *Progpow) Finalize(chain consensus.ChainHeaderReader, batch ethdb. utxoSetSize -= uint64(len(utxosDelete)) trimmedUtxos := make([]*types.SpentUtxoEntry, 0) - if header.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 { - start := time.Now() - var wg sync.WaitGroup - var lock sync.Mutex - for denomination, depth := range types.TrimDepths { - if denomination <= types.MaxTrimDenomination && header.NumberU64(nodeCtx) > depth { - wg.Add(1) - go func(denomination uint8, depth uint64) { - defer func() { - if r := recover(); r != nil { - progpow.logger.WithFields(log.Fields{ - "error": r, - "stacktrace": string(debug.Stack()), - }).Error("Go-Quai Panicked") - } - }() - nextBlockToTrim := rawdb.ReadCanonicalHash(chain.Database(), header.NumberU64(nodeCtx)-depth) - TrimBlock(chain, batch, denomination, header.NumberU64(nodeCtx)-depth, nextBlockToTrim, &utxosDelete, &trimmedUtxos, &utxoSetSize, !setRoots, &lock, progpow.logger) // setRoots is false when we are processing the block - wg.Done() - }(denomination, depth) - } - } - wg.Wait() - if len(trimmedUtxos) > 0 { - progpow.logger.Infof("Trimmed %d UTXOs from db in %s", len(trimmedUtxos), common.PrettyDuration(time.Since(start))) - } - if !setRoots { - rawdb.WriteTrimmedUTXOs(batch, header.Hash(), trimmedUtxos) + start := time.Now() + var wg sync.WaitGroup + var lock sync.Mutex + for denomination, depth := range types.TrimDepths { + if denomination <= types.MaxTrimDenomination && header.NumberU64(nodeCtx) > depth { + wg.Add(1) + go func(denomination uint8, depth uint64) { + defer func() { + if r := recover(); r != nil { + progpow.logger.WithFields(log.Fields{ + "error": r, + "stacktrace": string(debug.Stack()), + }).Error("Go-Quai Panicked") + } + }() + nextBlockToTrim := rawdb.ReadCanonicalHash(chain.Database(), header.NumberU64(nodeCtx)-depth) + TrimBlock(chain, batch, denomination, header.NumberU64(nodeCtx)-depth, nextBlockToTrim, &utxosDelete, &trimmedUtxos, &utxoSetSize, !setRoots, &lock, progpow.logger) // setRoots is false when we are processing the block + wg.Done() + }(denomination, depth) } } + wg.Wait() + if len(trimmedUtxos) > 0 { + progpow.logger.Infof("Trimmed %d UTXOs from db in %s", len(trimmedUtxos), common.PrettyDuration(time.Since(start))) + } + if !setRoots { + rawdb.WriteTrimmedUTXOs(batch, header.Hash(), trimmedUtxos) + } for _, hash := range utxosCreate { multiSet.Add(hash.Bytes()) } diff --git a/consensus/progpow/poem.go b/consensus/progpow/poem.go index 030a1f64c..6d535a2da 100644 --- a/consensus/progpow/poem.go +++ b/consensus/progpow/poem.go @@ -44,14 +44,8 @@ func (progpow *Progpow) CalcOrder(chain consensus.BlockReader, header *types.Wor totalDeltaEntropyPrime := new(big.Int).Add(header.ParentDeltaEntropy(common.REGION_CTX), header.ParentDeltaEntropy(common.ZONE_CTX)) totalDeltaEntropyPrime = new(big.Int).Add(totalDeltaEntropyPrime, intrinsicEntropy) - var primeDeltaEntropyTarget *big.Int - if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - primeDeltaEntropyTarget = new(big.Int).Div(params.PrimeEntropyTarget(expansionNum), big2) - primeDeltaEntropyTarget = new(big.Int).Mul(zoneThresholdEntropy, primeDeltaEntropyTarget) - } else { - primeDeltaEntropyTarget = new(big.Int).Mul(params.PrimeEntropyTarget(expansionNum), zoneThresholdEntropy) - primeDeltaEntropyTarget = new(big.Int).Div(primeDeltaEntropyTarget, big2) - } + primeDeltaEntropyTarget := new(big.Int).Mul(params.PrimeEntropyTarget(expansionNum), zoneThresholdEntropy) + primeDeltaEntropyTarget = new(big.Int).Div(primeDeltaEntropyTarget, big2) primeBlockEntropyThreshold := new(big.Int).Add(zoneThresholdEntropy, common.BitsToBigBits(params.PrimeEntropyTarget(expansionNum))) if intrinsicEntropy.Cmp(primeBlockEntropyThreshold) > 0 && totalDeltaEntropyPrime.Cmp(primeDeltaEntropyTarget) > 0 { @@ -63,14 +57,8 @@ func (progpow *Progpow) CalcOrder(chain consensus.BlockReader, header *types.Wor // Compute the total accumulated entropy since the last region block totalDeltaSRegion := new(big.Int).Add(header.ParentDeltaEntropy(common.ZONE_CTX), intrinsicEntropy) - var regionDeltaSTarget *big.Int - if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - regionDeltaSTarget = new(big.Int).Div(params.RegionEntropyTarget(expansionNum), big2) - regionDeltaSTarget = new(big.Int).Mul(zoneThresholdEntropy, regionDeltaSTarget) - } else { - regionDeltaSTarget = new(big.Int).Mul(zoneThresholdEntropy, params.RegionEntropyTarget(expansionNum)) - regionDeltaSTarget = new(big.Int).Div(regionDeltaSTarget, big2) - } + regionDeltaSTarget := new(big.Int).Mul(zoneThresholdEntropy, params.RegionEntropyTarget(expansionNum)) + regionDeltaSTarget = new(big.Int).Div(regionDeltaSTarget, big2) regionBlockEntropyThreshold := new(big.Int).Add(zoneThresholdEntropy, common.BitsToBigBits(params.RegionEntropyTarget(expansionNum))) if intrinsicEntropy.Cmp(regionBlockEntropyThreshold) > 0 && totalDeltaSRegion.Cmp(regionDeltaSTarget) > 0 { @@ -295,12 +283,7 @@ func (progpow *Progpow) CalcRank(chain consensus.ChainHeaderReader, header *type } func (progpow *Progpow) CheckIfValidWorkShare(workShare *types.WorkObjectHeader) types.WorkShareValidity { - var thresholdDiff int - if workShare.NumberU64() < params.GoldenAgeForkNumberV2 { - thresholdDiff = params.OldWorkSharesThresholdDiff - } else { - thresholdDiff = params.NewWorkSharesThresholdDiff - } + thresholdDiff := params.WorkSharesThresholdDiff if progpow.CheckWorkThreshold(workShare, thresholdDiff) { return types.Valid } else if progpow.CheckWorkThreshold(workShare, progpow.config.WorkShareThreshold) { diff --git a/consensus/progpow/sealer.go b/consensus/progpow/sealer.go index bbbcb87a8..f6421c460 100644 --- a/consensus/progpow/sealer.go +++ b/consensus/progpow/sealer.go @@ -121,11 +121,7 @@ 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) { - if workObject.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - progpow.MineToThreshold(workObject, params.OldWorkSharesThresholdDiff, abort, found) - } else { - progpow.MineToThreshold(workObject, params.NewWorkSharesThresholdDiff, abort, found) - } + progpow.MineToThreshold(workObject, params.WorkSharesThresholdDiff, abort, found) } func (progpow *Progpow) MineToThreshold(workObject *types.WorkObject, workShareThreshold int, abort <-chan struct{}, found chan *types.WorkObject) { diff --git a/core/block_validator.go b/core/block_validator.go index e4b96bd2b..053d2cd15 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -157,17 +157,8 @@ func (v *BlockValidator) SanityCheckWorkObjectBlockViewBody(wo *types.WorkObject } } } else { - // If the fork has been triggered and within some grace period the nodes - // have not upgraded we reject the block validation - if wo.NumberU64(common.ZONE_CTX) > params.GoldenAgeForkNumberV1+params.GoldenAgeForkGraceNumber { - if wo.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV1) { - return fmt.Errorf("zone gas limit is less than the new fork gas limit") - } - } - if wo.NumberU64(common.ZONE_CTX) > params.GoldenAgeForkNumberV2+params.GoldenAgeForkGraceNumber { - if wo.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV2) { - return fmt.Errorf("zone gas limit is less than the new fork gas limit") - } + if wo.GasLimit() < params.MinGasLimit(wo.NumberU64(common.ZONE_CTX)) { + return fmt.Errorf("zone gas limit is less than the required gas limit") } if len(wo.Manifest()) != 0 { return fmt.Errorf("zone body has non zero manifests") @@ -290,17 +281,8 @@ func (v *BlockValidator) SanityCheckWorkObjectHeaderViewBody(wo *types.WorkObjec } } } else { - // If the fork has been triggered and within some grace period the nodes - // have not upgraded we reject the block validation - if wo.NumberU64(common.ZONE_CTX) > params.GoldenAgeForkNumberV1+params.GoldenAgeForkGraceNumber { - if wo.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV1) { - return fmt.Errorf("zone gas limit is less than the new fork gas limit") - } - } - if wo.NumberU64(common.ZONE_CTX) > params.GoldenAgeForkNumberV2+params.GoldenAgeForkGraceNumber { - if wo.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV2) { - return fmt.Errorf("zone gas limit is less than the new fork gas limit") - } + if wo.GasLimit() < params.MinGasLimit(wo.NumberU64(common.ZONE_CTX)) { + return fmt.Errorf("zone gas limit is less than the required gas limit") } // Transactions, SubManifestHash, InterlinkHashes should be nil in the workshare in Zone context if len(wo.Transactions()) != 0 { @@ -438,9 +420,6 @@ func CalcGasLimit(parent *types.WorkObject, gasCeil uint64) uint64 { delta := parentGasLimit/params.GasLimitBoundDivisor - 1 limit := parentGasLimit - if parent.NumberU64(common.ZONE_CTX) == params.GoldenAgeForkNumberV2 { - limit = params.MinGasLimit(parent.NumberU64(common.ZONE_CTX)) - } var desiredLimit uint64 percentGasUsed := parent.GasUsed() * 100 / parent.GasLimit() diff --git a/core/chain_indexer.go b/core/chain_indexer.go index d9e2b2fe1..87a2e90b1 100644 --- a/core/chain_indexer.go +++ b/core/chain_indexer.go @@ -775,11 +775,7 @@ func (c *ChainIndexer) addOutpointsToIndexer(addressOutpointsWithBlockHeight map // After the BigSporkFork the minimum conversion period changes to 7200 blocks var lockup *big.Int if lockupByte == 0 { - if block.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - lockup = new(big.Int).SetUint64(params.OldConversionLockPeriod) - } else { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) - } + lockup = new(big.Int).SetUint64(params.ConversionLockPeriod) } else { lockup = new(big.Int).SetUint64(params.LockupByteToBlockDepth[lockupByte]) } @@ -824,11 +820,7 @@ func (c *ChainIndexer) addOutpointsToIndexer(addressOutpointsWithBlockHeight map } } else if tx.EtxType() == types.ConversionType && tx.To().IsInQiLedgerScope() { var lockup *big.Int - if block.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - lockup = new(big.Int).SetUint64(params.OldConversionLockPeriod) - } else { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) - } + lockup = new(big.Int).SetUint64(params.ConversionLockPeriod) lock := new(big.Int).Add(block.Number(nodeCtx), lockup) value := tx.Value() addr20 := tx.To().Bytes20() diff --git a/core/evm.go b/core/evm.go index 38e890728..c4a668929 100644 --- a/core/evm.go +++ b/core/evm.go @@ -115,11 +115,7 @@ func NewEVMBlockContext(header *types.WorkObject, parent *types.WorkObject, chai } var averageBaseFee *big.Int - if header.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - averageBaseFee = new(big.Int).Set(baseFee) - } else { - averageBaseFee = new(big.Int).Div(maxBaseFee, params.BaseFeeMultiplier) - } + averageBaseFee = new(big.Int).Div(maxBaseFee, params.BaseFeeMultiplier) return vm.BlockContext{ CanTransfer: CanTransfer, diff --git a/core/headerchain.go b/core/headerchain.go index 6918576bc..da1408817 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -1363,12 +1363,7 @@ func (hc *HeaderChain) GetMaxTxInWorkShare() uint64 { currentGasLimit := hc.CurrentHeader().GasLimit() maxEoaInBlock := currentGasLimit / params.TxGas // (maxEoaInBlock*2)/(2^bits) - 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))) - } + return (maxEoaInBlock * 2) / uint64(math.Pow(2, float64(params.WorkSharesThresholdDiff))) } func (hc *HeaderChain) Database() ethdb.Database { diff --git a/core/state_processor.go b/core/state_processor.go index 9c42f219f..673baab94 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -456,18 +456,9 @@ func (p *StateProcessor) Process(block *types.WorkObject, batch ethdb.Batch) (ty return nil, nil, nil, nil, 0, 0, 0, nil, nil, fmt.Errorf("coinbase lockup byte %d is out of range", lockupByte) } var lockup *big.Int - // The first lock up period changes after the fork - if lockupByte == 0 { - if block.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - lockup = new(big.Int).SetUint64(params.OldConversionLockPeriod) - } else { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) - } - } else { - lockup = new(big.Int).SetUint64(params.LockupByteToBlockDepth[lockupByte]) - if lockup.Uint64() < params.OldConversionLockPeriod { - return nil, nil, nil, nil, 0, 0, 0, nil, nil, fmt.Errorf("coinbase lockup period is less than the minimum lockup period of %d blocks", params.OldConversionLockPeriod) - } + lockup = new(big.Int).SetUint64(params.LockupByteToBlockDepth[lockupByte]) + if lockup.Uint64() < params.ConversionLockPeriod { + return nil, nil, nil, nil, 0, 0, 0, nil, nil, fmt.Errorf("coinbase lockup period is less than the minimum lockup period of %d blocks", params.ConversionLockPeriod) } lockup.Add(lockup, blockNumber) value := params.CalculateCoinbaseValueWithLockup(tx.Value(), lockupByte) @@ -511,11 +502,7 @@ func (p *StateProcessor) Process(block *types.WorkObject, batch ethdb.Batch) (ty if etx.To().IsInQiLedgerScope() { if etx.ETXSender().Location().Equal(*etx.To().Location()) { // Quai->Qi Conversion var lockup *big.Int - if block.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - lockup = new(big.Int).SetUint64(params.OldConversionLockPeriod) - } else { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) - } + lockup = new(big.Int).SetUint64(params.ConversionLockPeriod) lock := new(big.Int).Add(block.Number(nodeCtx), lockup) value := etx.Value() txGas := etx.Gas() @@ -833,44 +820,18 @@ func (p *StateProcessor) Process(block *types.WorkObject, batch ethdb.Batch) (ty func RedeemLockedQuai(hc *HeaderChain, header *types.WorkObject, parent *types.WorkObject, statedb *state.StateDB) (error, []common.Unlock) { currentBlockHeight := header.Number(hc.NodeCtx()).Uint64() - var blockDepths []uint64 - if currentBlockHeight < params.GoldenAgeForkNumberV1 { - blockDepths = []uint64{ - params.OldConversionLockPeriod, - params.LockupByteToBlockDepth[0], - params.LockupByteToBlockDepth[1], - params.LockupByteToBlockDepth[2], - params.LockupByteToBlockDepth[3], - } - } else { - blockDepths = []uint64{ - params.LockupByteToBlockDepth[0], - params.LockupByteToBlockDepth[1], - params.LockupByteToBlockDepth[2], - params.LockupByteToBlockDepth[3], - } + blockDepths := []uint64{ + params.LockupByteToBlockDepth[0], + params.LockupByteToBlockDepth[1], + params.LockupByteToBlockDepth[2], + params.LockupByteToBlockDepth[3], } // Array of specific block depths for which we will redeem the Quai unlocks := []common.Unlock{} // Loop through the predefined block depths - for i, blockDepth := range blockDepths { - - // Minimum lock period is neutered between the fork number + old - // conversion period and fork number + new conversion period - if i == 0 { - if currentBlockHeight >= params.GoldenAgeForkNumberV1+params.OldConversionLockPeriod && - currentBlockHeight < params.GoldenAgeForkNumberV1+params.NewConversionLockPeriod { - continue - } - - if currentBlockHeight >= params.GoldenAgeForkNumberV1+params.NewConversionLockPeriod { - // block depth for the first index gets changed into the new conversion lock period - // after the fork height + new conversion number - blockDepth = params.NewConversionLockPeriod - } - } + for _, blockDepth := range blockDepths { // Ensure we can look back far enough if currentBlockHeight <= blockDepth { @@ -899,14 +860,7 @@ func RedeemLockedQuai(hc *HeaderChain, header *types.WorkObject, parent *types.W lockupByte := etx.Data()[0] // if lock up byte is 0, the fork change updates the lockup time var lockup uint64 - if lockupByte == 0 { - lockup = params.OldConversionLockPeriod - if currentBlockHeight >= params.GoldenAgeForkNumberV1+params.NewConversionLockPeriod { - lockup = params.NewConversionLockPeriod - } - } else { - lockup = params.LockupByteToBlockDepth[lockupByte] - } + lockup = params.LockupByteToBlockDepth[lockupByte] if lockup == blockDepth { balance := params.CalculateCoinbaseValueWithLockup(etx.Value(), lockupByte) @@ -932,12 +886,7 @@ func RedeemLockedQuai(hc *HeaderChain, header *types.WorkObject, parent *types.W } var conversionPeriodValid bool - if currentBlockHeight < params.GoldenAgeForkNumberV1 { - conversionPeriodValid = blockDepth == params.OldConversionLockPeriod - } else { - conversionPeriodValid = blockDepth == params.NewConversionLockPeriod - } - + conversionPeriodValid = blockDepth == params.ConversionLockPeriod if types.IsConversionTx(etx) && etx.To().IsInQuaiLedgerScope() && conversionPeriodValid { internal, err := etx.To().InternalAddress() if err != nil { @@ -1076,7 +1025,7 @@ func ValidateQiTxInputs(tx *types.Transaction, chain ChainContext, db ethdb.Read types.MaxDenomination) return nil, errors.New(str) } - if currentHeader.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && txOut.Lock != nil && txOut.Lock.Sign() != 0 { + if txOut.Lock != nil && txOut.Lock.Sign() != 0 { return nil, errors.New("QiTx output has non-zero lock") } outputs[uint(txOut.Denomination)]++ @@ -1120,7 +1069,7 @@ func ValidateQiTxOutputsAndSignature(tx *types.Transaction, chain ChainContext, if txOutIdx > types.MaxOutputIndex { return nil, fmt.Errorf("tx [%v] exceeds max output index of %d", tx.Hash().Hex(), types.MaxOutputIndex) } - if currentHeader.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && txOut.Lock != nil && txOut.Lock.Sign() != 0 { + if txOut.Lock != nil && txOut.Lock.Sign() != 0 { return nil, errors.New("QiTx output has non-zero lock") } if txOut.Denomination > types.MaxDenomination { @@ -1142,7 +1091,7 @@ func ValidateQiTxOutputsAndSignature(tx *types.Transaction, chain ChainContext, if toAddr.Location().Equal(location) && toAddr.IsInQuaiLedgerScope() { // Qi->Quai conversion conversion = true - if currentHeader.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 && txOut.Denomination < params.MinQiConversionDenomination { + if txOut.Denomination < params.MinQiConversionDenomination { return nil, fmt.Errorf("tx %v emits UTXO with value %d less than minimum denomination %d", tx.Hash().Hex(), txOut.Denomination, params.MinQiConversionDenomination) } totalConvertQitOut.Add(totalConvertQitOut, types.Denominations[txOut.Denomination]) // Add to total conversion output for aggregation @@ -1207,18 +1156,16 @@ func ValidateQiTxOutputsAndSignature(tx *types.Transaction, chain ChainContext, return nil, fmt.Errorf("tx %032x has insufficient fee for base fee, have %d want %d", tx.Hash(), txFeeInQuai.Uint64(), minimumFeeInQuai.Uint64()) } if conversion { - if currentHeader.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && totalConvertQitOut.Cmp(types.Denominations[params.MinQiConversionDenomination]) < 0 { + if totalConvertQitOut.Cmp(types.Denominations[params.MinQiConversionDenomination]) < 0 { return nil, fmt.Errorf("tx %032x emits convert UTXO with value %d less than minimum conversion denomination", tx.Hash(), totalConvertQitOut.Uint64()) } - if currentHeader.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 { - // Since this transaction contains a conversion, check if the required conversion gas is paid - // The user must pay this to the miner now, but it is only added to the block gas limit when the ETX is played in the destination - requiredGas += params.QiToQuaiConversionGas - minimumFeeInQuai = new(big.Int).Mul(new(big.Int).SetUint64(requiredGas), currentHeader.BaseFee()) - if txFeeInQuai.Cmp(minimumFeeInQuai) < 0 { - return nil, fmt.Errorf("tx %032x has insufficient fee for base fee * gas, have %d want %d", tx.Hash(), txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()) - } + // Since this transaction contains a conversion, check if the required conversion gas is paid + // The user must pay this to the miner now, but it is only added to the block gas limit when the ETX is played in the destination + requiredGas += params.QiToQuaiConversionGas + minimumFeeInQuai = new(big.Int).Mul(new(big.Int).SetUint64(requiredGas), currentHeader.BaseFee()) + if txFeeInQuai.Cmp(minimumFeeInQuai) < 0 { + return nil, fmt.Errorf("tx %032x has insufficient fee for base fee * gas, have %d want %d", tx.Hash(), txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()) } ETXPCount++ if ETXPCount > etxPLimit { @@ -1226,9 +1173,6 @@ func ValidateQiTxOutputsAndSignature(tx *types.Transaction, chain ChainContext, } usedGas += params.ETXGas - if currentHeader.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - txFeeInQit.Sub(txFeeInQit, txFeeInQit) // Fee goes entirely to gas to pay for conversion - } } if usedGas > currentHeader.GasLimit() { @@ -1376,9 +1320,6 @@ func ProcessQiTx(tx *types.Transaction, chain ChainContext, checkSig bool, isFir if toAddr.Location().Equal(location) && toAddr.IsInQuaiLedgerScope() { // Qi->Quai conversion conversion = true convertAddress = toAddr - if currentHeader.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 && txOut.Denomination < params.MinQiConversionDenomination { - return nil, nil, nil, fmt.Errorf("tx %v emits UTXO with value %d less than minimum denomination %d", tx.Hash().Hex(), txOut.Denomination, params.MinQiConversionDenomination), nil - } totalConvertQitOut.Add(totalConvertQitOut, types.Denominations[txOut.Denomination]) // Add to total conversion output for aggregation outputs[uint(txOut.Denomination)] -= 1 // This output no longer exists because it has been aggregated delete(addresses, toAddr.Bytes20()) @@ -1458,46 +1399,27 @@ func ProcessQiTx(tx *types.Transaction, chain ChainContext, checkSig bool, isFir return nil, nil, nil, fmt.Errorf("tx %032x has insufficient fee for base fee, have %d want %d", tx.Hash(), txFeeInQuai.Uint64(), minimumFeeInQuai.Uint64()), nil } if conversion { - if currentHeader.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && totalConvertQitOut.Cmp(types.Denominations[params.MinQiConversionDenomination]) < 0 { + if totalConvertQitOut.Cmp(types.Denominations[params.MinQiConversionDenomination]) < 0 { return nil, nil, nil, fmt.Errorf("tx %032x emits convert UTXO with value %d less than minimum conversion denomination", tx.Hash(), totalConvertQitOut.Uint64()), nil } - var etxInner types.ExternalTx - if currentHeader.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - // Since this transaction contains a conversion, the rest of the tx gas is given to conversion - remainingTxFeeInQuai := misc.QiToQuai(parent, txFeeInQit) - // Fee is basefee * gas, so gas remaining is fee remaining / basefee - remainingGas := new(big.Int).Div(remainingTxFeeInQuai, currentHeader.BaseFee()) - if remainingGas.Uint64() > (currentHeader.GasLimit() / params.MinimumEtxGasDivisor) { - // Limit ETX gas to max ETX gas limit (the rest is burned) - remainingGas = new(big.Int).SetUint64(currentHeader.GasLimit() / params.MinimumEtxGasDivisor) - } - ETXPCount++ - if ETXPCount > *etxPLimit { - return nil, nil, nil, fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, etxPLimit), nil - } - etxInner = types.ExternalTx{Value: totalConvertQitOut, To: &convertAddress, Sender: common.ZeroAddress(location), EtxType: types.ConversionType, OriginatingTxHash: tx.Hash(), Gas: remainingGas.Uint64()} // Value is in Qits not Denomination - } else { - // Since this transaction contains a conversion, check if the required conversion gas is paid - // The user must pay this to the miner now, but it is only added to the block gas limit when the ETX is played in the destination - requiredGas += params.QiToQuaiConversionGas - minimumFeeInQuai = new(big.Int).Mul(new(big.Int).SetUint64(requiredGas), currentHeader.BaseFee()) - if txFeeInQuai.Cmp(minimumFeeInQuai) < 0 { - return nil, nil, nil, fmt.Errorf("tx %032x has insufficient fee for base fee * gas: %d, have %d want %d", tx.Hash(), requiredGas, txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()), nil - } - ETXPCount++ - if ETXPCount > *etxPLimit { - return nil, nil, nil, fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, etxPLimit), nil - } - etxInner = types.ExternalTx{Value: totalConvertQitOut, To: &convertAddress, Sender: common.ZeroAddress(location), EtxType: types.ConversionType, OriginatingTxHash: tx.Hash(), Gas: 0} // Value is in Qits not Denomination + + // Since this transaction contains a conversion, check if the required conversion gas is paid + // The user must pay this to the miner now, but it is only added to the block gas limit when the ETX is played in the destination + requiredGas += params.QiToQuaiConversionGas + minimumFeeInQuai = new(big.Int).Mul(new(big.Int).SetUint64(requiredGas), currentHeader.BaseFee()) + if txFeeInQuai.Cmp(minimumFeeInQuai) < 0 { + return nil, nil, nil, fmt.Errorf("tx %032x has insufficient fee for base fee * gas: %d, have %d want %d", tx.Hash(), requiredGas, txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()), nil + } + ETXPCount++ + if ETXPCount > *etxPLimit { + return nil, nil, nil, fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, etxPLimit), nil } + etxInner := types.ExternalTx{Value: totalConvertQitOut, To: &convertAddress, Sender: common.ZeroAddress(location), EtxType: types.ConversionType, OriginatingTxHash: tx.Hash(), Gas: 0} // Value is in Qits not Denomination *usedGas += params.ETXGas if err := gp.SubGas(params.ETXGas); err != nil { return nil, nil, nil, err, nil } etxs = append(etxs, &etxInner) - if currentHeader.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - txFeeInQit.Sub(txFeeInQit, txFeeInQit) // Fee goes entirely to gas to pay for conversion - } } elapsedTime = time.Since(stepStart) stepTimings["Fee Verification"] = elapsedTime diff --git a/core/types/utxo.go b/core/types/utxo.go index 2ead36f23..3ecd0bca7 100644 --- a/core/types/utxo.go +++ b/core/types/utxo.go @@ -47,12 +47,12 @@ func init() { Denominations[14] = big.NewInt(1000000000) // 1000000 Qi TrimDepths = make(map[uint8]uint64) - TrimDepths[0] = params.GoldenAgeForkNumberV2 + 720 // 2 hours after fork starts from block 1 - TrimDepths[1] = params.GoldenAgeForkNumberV2 + 720 // 2 hours - TrimDepths[2] = params.GoldenAgeForkNumberV2 + 1080 // 3 hours - TrimDepths[3] = params.GoldenAgeForkNumberV2 + 1080 // 3 hours - TrimDepths[4] = params.GoldenAgeForkNumberV2 + 2160 // 6 hours - TrimDepths[5] = params.GoldenAgeForkNumberV2 + 4320 // 12 hours + TrimDepths[0] = 720 // 2 hours after fork starts from block 1 + TrimDepths[1] = 720 // 2 hours + TrimDepths[2] = 1080 // 3 hours + TrimDepths[3] = 1080 // 3 hours + TrimDepths[4] = 2160 // 6 hours + TrimDepths[5] = 4320 // 12 hours } type TxIns []TxIn diff --git a/core/worker.go b/core/worker.go index 1b28b566e..fd24118cc 100644 --- a/core/worker.go +++ b/core/worker.go @@ -1094,21 +1094,9 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t } if tx.To().IsInQiLedgerScope() { var lockup *big.Int - // The first lock up period changes after the fork - if lockupByte == 0 { - if env.wo.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - lockup = new(big.Int).SetUint64(params.OldConversionLockPeriod) - if lockup.Uint64() < params.OldConversionLockPeriod { - return nil, false, fmt.Errorf("coinbase lockup period is less than the minimum lockup period of %d blocks", params.OldConversionLockPeriod) - } - } else { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) - if lockup.Uint64() < params.NewConversionLockPeriod { - return nil, false, fmt.Errorf("coinbase lockup period is less than the minimum lockup period of %d blocks", params.NewConversionLockPeriod) - } - } - } else { - lockup = new(big.Int).SetUint64(params.LockupByteToBlockDepth[lockupByte]) + lockup = new(big.Int).SetUint64(params.ConversionLockPeriod) + if lockup.Uint64() < params.ConversionLockPeriod { + return nil, false, fmt.Errorf("coinbase lockup period is less than the minimum lockup period of %d blocks", params.ConversionLockPeriod) } lockup.Add(lockup, env.wo.Number(w.hc.NodeCtx())) value := params.CalculateCoinbaseValueWithLockup(tx.Value(), lockupByte) @@ -1147,11 +1135,7 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t if tx.ETXSender().Location().Equal(*tx.To().Location()) { // Quai->Qi conversion txGas := tx.Gas() var lockup *big.Int - if env.wo.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV1 { - lockup = new(big.Int).SetUint64(params.OldConversionLockPeriod) - } else { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) - } + lockup = new(big.Int).SetUint64(params.ConversionLockPeriod) lock := new(big.Int).Add(env.wo.Number(w.hc.NodeCtx()), lockup) if env.parentOrder == nil { return nil, false, errors.New("parent order not set") @@ -2085,7 +2069,7 @@ func (w *worker) processQiTx(tx *types.Transaction, env *environment, primeTermi types.MaxDenomination) return errors.New(str) } - if env.wo.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && txOut.Lock != nil && txOut.Lock.Sign() != 0 { + if txOut.Lock != nil && txOut.Lock.Sign() != 0 { return errors.New("QiTx output has non-zero lock") } outputs[uint(txOut.Denomination)] += 1 @@ -2102,9 +2086,6 @@ func (w *worker) processQiTx(tx *types.Transaction, env *environment, primeTermi } conversion = true convertAddress = toAddr - if txOut.Denomination < params.MinQiConversionDenomination && env.wo.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - return fmt.Errorf("tx %032x emits convert UTXO with value %d less than minimum conversion denomination", tx.Hash(), txOut.Denomination) - } totalConvertQitOut.Add(totalConvertQitOut, types.Denominations[txOut.Denomination]) // Add to total conversion output for aggregation outputs[uint(txOut.Denomination)] -= 1 // This output no longer exists because it has been aggregated delete(addresses, toAddr.Bytes20()) @@ -2181,51 +2162,27 @@ func (w *worker) processQiTx(tx *types.Transaction, env *environment, primeTermi return fmt.Errorf("tx %032x has insufficient fee for base fee * gas, have %d want %d", tx.Hash(), txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()) } if conversion { - if env.wo.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && totalConvertQitOut.Cmp(types.Denominations[params.MinQiConversionDenomination]) < 0 { + if totalConvertQitOut.Cmp(types.Denominations[params.MinQiConversionDenomination]) < 0 { return fmt.Errorf("tx %032x emits convert UTXO with value %d less than minimum conversion denomination", tx.Hash(), totalConvertQitOut.Uint64()) } - var etxInner types.ExternalTx - if env.wo.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - // Since this transaction contains a conversion, the rest of the tx gas is given to conversion - remainingTxFeeInQuai := misc.QiToQuai(parent, txFeeInQit) - // Fee is basefee * gas, so gas remaining is fee remaining / basefee - remainingGas := new(big.Int).Div(remainingTxFeeInQuai, env.wo.BaseFee()) - if remainingGas.Uint64() > (env.wo.GasLimit() / params.MinimumEtxGasDivisor) { - // Limit ETX gas to max ETX gas limit (the rest is burned) - remainingGas = new(big.Int).SetUint64(env.wo.GasLimit() / params.MinimumEtxGasDivisor) - } - if remainingGas.Uint64() < params.TxGas { - // Minimum gas for ETX is TxGas - return fmt.Errorf("tx %032x has insufficient remaining gas for conversion ETX, have %d want %d", tx.Hash(), remainingGas.Uint64(), params.TxGas) - } - ETXPCount++ // conversion is technically a cross-prime ETX - if ETXPCount > env.etxPLimit { - return fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, env.etxPLimit) - } - etxInner = types.ExternalTx{Value: totalConvertQitOut, To: &convertAddress, Sender: common.ZeroAddress(location), EtxType: types.ConversionType, OriginatingTxHash: tx.Hash(), Gas: remainingGas.Uint64()} // Value is in Qits not Denomination - } else { - // Since this transaction contains a conversion, check if the required conversion gas is paid - // The user must pay this to the miner now, but it is only added to the block gas limit when the ETX is played in the destination - requiredGas += params.QiToQuaiConversionGas - minimumFeeInQuai = new(big.Int).Mul(new(big.Int).SetUint64(requiredGas), env.wo.BaseFee()) - if txFeeInQuai.Cmp(minimumFeeInQuai) < 0 { - return fmt.Errorf("tx %032x has insufficient fee for base fee * gas, have %d want %d", tx.Hash(), txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()) - } - ETXPCount++ // conversion is technically a cross-prime ETX - if ETXPCount > env.etxPLimit { - return fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, env.etxPLimit) - } - // Value is in Qits not Denomination - etxInner = types.ExternalTx{Value: totalConvertQitOut, To: &convertAddress, Sender: common.ZeroAddress(location), EtxType: types.ConversionType, OriginatingTxHash: tx.Hash(), Gas: 0} // Conversion gas is paid from the converted Quai balance (for new account creation, when redeemed) + // Since this transaction contains a conversion, check if the required conversion gas is paid + // The user must pay this to the miner now, but it is only added to the block gas limit when the ETX is played in the destination + requiredGas += params.QiToQuaiConversionGas + minimumFeeInQuai = new(big.Int).Mul(new(big.Int).SetUint64(requiredGas), env.wo.BaseFee()) + if txFeeInQuai.Cmp(minimumFeeInQuai) < 0 { + return fmt.Errorf("tx %032x has insufficient fee for base fee * gas, have %d want %d", tx.Hash(), txFeeInQit.Uint64(), minimumFeeInQuai.Uint64()) } + ETXPCount++ // conversion is technically a cross-prime ETX + if ETXPCount > env.etxPLimit { + return fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, env.etxPLimit) + } + // Value is in Qits not Denomination + etxInner := types.ExternalTx{Value: totalConvertQitOut, To: &convertAddress, Sender: common.ZeroAddress(location), EtxType: types.ConversionType, OriginatingTxHash: tx.Hash(), Gas: 0} // Conversion gas is paid from the converted Quai balance (for new account creation, when redeemed) gasUsed += params.ETXGas if err := env.gasPool.SubGas(params.ETXGas); err != nil { return err } etxs = append(etxs, &etxInner) - if env.wo.NumberU64(common.ZONE_CTX) < params.GoldenAgeForkNumberV2 { - txFeeInQit.Sub(txFeeInQit, txFeeInQit) // Fee goes entirely to gas to pay for conversion - } } if gasUsed > env.wo.GasLimit() { return fmt.Errorf("tx %032x uses too much gas, have used %d out of %d", tx.Hash(), gasUsed, env.wo.GasLimit()) diff --git a/p2p/node/p2p_services.go b/p2p/node/p2p_services.go index fee2c6b14..b91b72c03 100644 --- a/p2p/node/p2p_services.go +++ b/p2p/node/p2p_services.go @@ -127,14 +127,7 @@ func (p *P2PNode) requestFromPeer(peerID peer.ID, topic *pubsubManager.Topic, re } case []*types.WorkObjectBlockView: for _, block := range recvdType.([]*types.WorkObjectBlockView) { - // If a block is received which has a number greater than - // the goldenage fork number and does not have the updated - // gas limit, reject the response - if block != nil && block.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV1 && block.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV1) { - p.AdjustPeerQuality(peerID, topic.String(), p2p.QualityAdjOnBadResponse) - return nil, errors.New("invalid response") - } - if block != nil && block.NumberU64(common.ZONE_CTX) >= params.GoldenAgeForkNumberV2 && block.GasLimit() < params.MinGasLimit(params.GoldenAgeForkNumberV2) { + if block != nil && block.GasLimit() < params.MinGasLimit(block.NumberU64(common.ZONE_CTX)) { p.AdjustPeerQuality(peerID, topic.String(), p2p.QualityAdjOnBadResponse) return nil, errors.New("invalid response") } diff --git a/params/protocol_params.go b/params/protocol_params.go index 12e870d3e..4caebc50d 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -148,8 +148,7 @@ const ( // infrastructure, if needed, to account for the upcoming network change. TREE_EXPANSION_WAIT_COUNT = 1024 - OldConversionLockPeriod uint64 = 10 // The number of zone blocks that a conversion output is locked for - NewConversionLockPeriod uint64 = 7200 + ConversionLockPeriod uint64 = 7200 MinQiConversionDenomination = 10 ConversionConfirmationContext = common.PRIME_CTX // A conversion requires a single coincident Dom confirmation QiToQuaiConversionGas = 100000 // The gas used to convert Qi to Quai @@ -175,8 +174,7 @@ 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 - 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 + WorkSharesThresholdDiff = 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) @@ -194,15 +192,8 @@ var ( BaseFeeMultiplier = big.NewInt(50) ) -const ( - GoldenAgeForkNumberV1 = 180000 - GoldenAgeForkNumberV2 = 588000 - GoldenAgeForkGraceNumber = 100 - GoldenAgeGracePaymentPeriod = 6000 -) - func init() { - LockupByteToBlockDepth[0] = OldConversionLockPeriod + LockupByteToBlockDepth[0] = ConversionLockPeriod LockupByteToBlockDepth[1] = 30240 // 1.75 days LockupByteToBlockDepth[2] = 60480 // 3.5 days LockupByteToBlockDepth[3] = 120960 // 7 days @@ -229,13 +220,7 @@ func RegionEntropyTarget(expansionNum uint8) *big.Int { } func MinGasLimit(number uint64) uint64 { - if number < GoldenAgeForkNumberV1 { - return 5000000 - } else if number < GoldenAgeForkNumberV2 { - return 10000000 - } else { - return 12000000 - } + return 12000000 } // Gas calculation functions