From 93b3fd8574efeb213f886539944ede153809d357 Mon Sep 17 00:00:00 2001 From: Hussam Date: Fri, 22 Nov 2024 13:30:09 -0600 Subject: [PATCH 1/5] Remove forking logic for GoldenAgeForkNumberV1 --- core/block_validator.go | 10 ------ core/chain_indexer.go | 12 ++----- core/evm.go | 6 +--- core/state_processor.go | 66 ++++++--------------------------------- core/worker.go | 19 +++-------- p2p/node/p2p_services.go | 4 --- params/protocol_params.go | 5 +-- 7 files changed, 18 insertions(+), 104 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index e4b96bd2b4..fe1b871450 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -159,11 +159,6 @@ 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") @@ -292,11 +287,6 @@ 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") diff --git a/core/chain_indexer.go b/core/chain_indexer.go index d9e2b2fe17..7f50370a29 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.NewConversionLockPeriod) } 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.NewConversionLockPeriod) 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 38e8907283..c4a6689299 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/state_processor.go b/core/state_processor.go index 9c42f219f3..fbb57117f1 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -458,11 +458,7 @@ func (p *StateProcessor) Process(block *types.WorkObject, batch ethdb.Batch) (ty 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) - } + lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) } else { lockup = new(big.Int).SetUint64(params.LockupByteToBlockDepth[lockupByte]) if lockup.Uint64() < params.OldConversionLockPeriod { @@ -511,11 +507,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.NewConversionLockPeriod) lock := new(big.Int).Add(block.Number(nodeCtx), lockup) value := etx.Value() txGas := etx.Gas() @@ -833,44 +825,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 +865,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 +891,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.NewConversionLockPeriod if types.IsConversionTx(etx) && etx.To().IsInQuaiLedgerScope() && conversionPeriodValid { internal, err := etx.To().InternalAddress() if err != nil { diff --git a/core/worker.go b/core/worker.go index 1b28b566e1..a6ab2ea7a4 100644 --- a/core/worker.go +++ b/core/worker.go @@ -1096,16 +1096,9 @@ func (w *worker) commitTransaction(env *environment, parent *types.WorkObject, t 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) - } + 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]) @@ -1147,11 +1140,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.NewConversionLockPeriod) 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") diff --git a/p2p/node/p2p_services.go b/p2p/node/p2p_services.go index fee2c6b140..84f6053e2e 100644 --- a/p2p/node/p2p_services.go +++ b/p2p/node/p2p_services.go @@ -130,10 +130,6 @@ func (p *P2PNode) requestFromPeer(peerID peer.ID, topic *pubsubManager.Topic, re // 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) { 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 12e870d3e1..a52bffaf0a 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -195,7 +195,6 @@ var ( ) const ( - GoldenAgeForkNumberV1 = 180000 GoldenAgeForkNumberV2 = 588000 GoldenAgeForkGraceNumber = 100 GoldenAgeGracePaymentPeriod = 6000 @@ -229,9 +228,7 @@ func RegionEntropyTarget(expansionNum uint8) *big.Int { } func MinGasLimit(number uint64) uint64 { - if number < GoldenAgeForkNumberV1 { - return 5000000 - } else if number < GoldenAgeForkNumberV2 { + if number < GoldenAgeForkNumberV2 { return 10000000 } else { return 12000000 From ba5b3eba03b7fcecbc9d2df7c4c363d06f11334f Mon Sep 17 00:00:00 2001 From: Hussam Date: Fri, 22 Nov 2024 16:26:52 -0600 Subject: [PATCH 2/5] Consolidate WorkShareThresholdDiffs from forks --- cmd/utils/flags.go | 2 +- consensus/blake3pow/poem.go | 7 +------ consensus/blake3pow/sealer.go | 7 +------ consensus/progpow/poem.go | 7 +------ consensus/progpow/sealer.go | 6 +----- core/headerchain.go | 7 +------ params/protocol_params.go | 3 +-- 7 files changed, 7 insertions(+), 32 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 19eee21aef..80eb5376df 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/poem.go b/consensus/blake3pow/poem.go index 56e5ed9a9f..e0a3367716 100644 --- a/consensus/blake3pow/poem.go +++ b/consensus/blake3pow/poem.go @@ -296,12 +296,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 dcb088ccda..313e90ffcd 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/progpow/poem.go b/consensus/progpow/poem.go index 030a1f64ce..3517711267 100644 --- a/consensus/progpow/poem.go +++ b/consensus/progpow/poem.go @@ -295,12 +295,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 bbbcb87a89..f6421c4601 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/headerchain.go b/core/headerchain.go index 6918576bc9..da1408817e 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/params/protocol_params.go b/params/protocol_params.go index a52bffaf0a..c3855ec5a5 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -175,8 +175,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) From 90a705f58d8f17bacad456b179bb65e47960bc72 Mon Sep 17 00:00:00 2001 From: Hussam Date: Fri, 22 Nov 2024 16:43:31 -0600 Subject: [PATCH 3/5] Remove MinGasLimit fork --- consensus/blake3pow/consensus.go | 54 +++++++++++++++----------------- consensus/blake3pow/poem.go | 20 +++--------- consensus/misc/rewards.go | 11 ------- consensus/misc/statefee.go | 3 -- consensus/progpow/consensus.go | 54 +++++++++++++++----------------- consensus/progpow/poem.go | 20 +++--------- core/block_validator.go | 6 ++-- params/protocol_params.go | 6 +--- 8 files changed, 63 insertions(+), 111 deletions(-) diff --git a/consensus/blake3pow/consensus.go b/consensus/blake3pow/consensus.go index d99ea8c6e7..b8c6aa4928 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 e0a3367716..149ea94b24 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 { diff --git a/consensus/misc/rewards.go b/consensus/misc/rewards.go index e6c1e3ae88..b8d1de1ead 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 d020efc4fa..fb44fc7bda 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 74fcc9aee8..7564469931 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 3517711267..6d535a2da7 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 { diff --git a/core/block_validator.go b/core/block_validator.go index fe1b871450..e344bedeca 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -159,10 +159,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.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 new fork gas limit") } if len(wo.Manifest()) != 0 { return fmt.Errorf("zone body has non zero manifests") diff --git a/params/protocol_params.go b/params/protocol_params.go index c3855ec5a5..b923c0bb94 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -227,11 +227,7 @@ func RegionEntropyTarget(expansionNum uint8) *big.Int { } func MinGasLimit(number uint64) uint64 { - if number < GoldenAgeForkNumberV2 { - return 10000000 - } else { - return 12000000 - } + return 12000000 } // Gas calculation functions From 62f41217a5d1d62f3a4b14dda142bc017138b645 Mon Sep 17 00:00:00 2001 From: Hussam Date: Fri, 22 Nov 2024 17:09:58 -0600 Subject: [PATCH 4/5] Remove references to GoldenAgeForkV2 --- core/block_validator.go | 15 ++------ core/state_processor.go | 73 ++++++++++++--------------------------- core/types/utxo.go | 12 +++---- core/worker.go | 55 ++++++++--------------------- p2p/node/p2p_services.go | 5 +-- params/protocol_params.go | 6 ---- 6 files changed, 47 insertions(+), 119 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index e344bedeca..053d2cd15f 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -157,10 +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.GasLimit() < params.MinGasLimit(wo.NumberU64(common.ZONE_CTX)) { - return fmt.Errorf("zone gas limit is less than the new fork gas limit") + 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") @@ -283,12 +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.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 { @@ -426,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/state_processor.go b/core/state_processor.go index fbb57117f1..fb036d529a 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -1030,7 +1030,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)]++ @@ -1074,7 +1074,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 { @@ -1096,7 +1096,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 @@ -1161,18 +1161,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 { @@ -1180,9 +1178,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() { @@ -1330,9 +1325,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()) @@ -1412,46 +1404,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 2ead36f234..3ecd0bca7b 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 a6ab2ea7a4..02ef0f5db9 100644 --- a/core/worker.go +++ b/core/worker.go @@ -2074,7 +2074,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 @@ -2091,9 +2091,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()) @@ -2170,51 +2167,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 84f6053e2e..b91b72c03f 100644 --- a/p2p/node/p2p_services.go +++ b/p2p/node/p2p_services.go @@ -127,10 +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.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 b923c0bb94..eb86c9c617 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -193,12 +193,6 @@ var ( BaseFeeMultiplier = big.NewInt(50) ) -const ( - GoldenAgeForkNumberV2 = 588000 - GoldenAgeForkGraceNumber = 100 - GoldenAgeGracePaymentPeriod = 6000 -) - func init() { LockupByteToBlockDepth[0] = OldConversionLockPeriod LockupByteToBlockDepth[1] = 30240 // 1.75 days From d0e2b6f09ff18e9dfd9383f93c9e1560b1d654f7 Mon Sep 17 00:00:00 2001 From: Hussam Date: Wed, 4 Dec 2024 12:49:58 -0600 Subject: [PATCH 5/5] Remove New vs Old ConversionLockPeriod --- core/chain_indexer.go | 4 ++-- core/state_processor.go | 15 +++++---------- core/worker.go | 13 ++++--------- params/protocol_params.go | 5 ++--- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/core/chain_indexer.go b/core/chain_indexer.go index 7f50370a29..87a2e90b11 100644 --- a/core/chain_indexer.go +++ b/core/chain_indexer.go @@ -775,7 +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 { - lockup = new(big.Int).SetUint64(params.NewConversionLockPeriod) + lockup = new(big.Int).SetUint64(params.ConversionLockPeriod) } else { lockup = new(big.Int).SetUint64(params.LockupByteToBlockDepth[lockupByte]) } @@ -820,7 +820,7 @@ func (c *ChainIndexer) addOutpointsToIndexer(addressOutpointsWithBlockHeight map } } else if tx.EtxType() == types.ConversionType && tx.To().IsInQiLedgerScope() { var lockup *big.Int - 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/state_processor.go b/core/state_processor.go index fb036d529a..673baab942 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -456,14 +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 { - 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) @@ -507,7 +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 - 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() @@ -891,7 +886,7 @@ func RedeemLockedQuai(hc *HeaderChain, header *types.WorkObject, parent *types.W } var conversionPeriodValid bool - conversionPeriodValid = blockDepth == params.NewConversionLockPeriod + conversionPeriodValid = blockDepth == params.ConversionLockPeriod if types.IsConversionTx(etx) && etx.To().IsInQuaiLedgerScope() && conversionPeriodValid { internal, err := etx.To().InternalAddress() if err != nil { diff --git a/core/worker.go b/core/worker.go index 02ef0f5db9..fd24118cc3 100644 --- a/core/worker.go +++ b/core/worker.go @@ -1094,14 +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 { - 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) @@ -1140,7 +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 - 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") diff --git a/params/protocol_params.go b/params/protocol_params.go index eb86c9c617..4caebc50d9 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 @@ -194,7 +193,7 @@ var ( ) 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