Skip to content

Commit

Permalink
Remove references to GoldenAgeForkV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed Nov 22, 2024
1 parent 1993226 commit 81ec6b4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 117 deletions.
4 changes: 2 additions & 2 deletions consensus/misc/statefee.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CalcStateLimit(parent *types.WorkObject, stateCeil uint64) uint64 {

// If parent gas is zero and we have passed the 5 day threshold, we can set the first block gas limit to min gas limit
if parent.StateLimit() == 0 {
return params.MinGasLimit(parent.NumberU64(common.ZONE_CTX))
return params.MinGasLimit(parent.NumberU64(common.PRIME_CTX))
}

parentStateLimit := parent.StateLimit()
Expand All @@ -33,7 +33,7 @@ func CalcStateLimit(parent *types.WorkObject, stateCeil uint64) uint64 {
return limit + delta
}
} else {
desiredLimit = params.MinGasLimit(parent.NumberU64(common.ZONE_CTX))
desiredLimit = params.MinGasLimit(parent.NumberU64(common.PRIME_CTX))
if limit-delta/2 < desiredLimit {
return desiredLimit
} else {
Expand Down
15 changes: 5 additions & 10 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ 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)) {
if wo.GasLimit() < params.MinGasLimit(wo.NumberU64(common.PRIME_CTX)) {
return fmt.Errorf("zone gas limit is less than the new fork gas limit")
}
if len(wo.Manifest()) != 0 {
Expand Down Expand Up @@ -271,10 +271,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.PRIME_CTX)) {
return fmt.Errorf("zone gas limit is less than the new fork gas limit")
}
// Transactions, SubManifestHash, InterlinkHashes should be nil in the workshare in Zone context
if len(wo.Transactions()) != 0 {
Expand Down Expand Up @@ -405,16 +403,13 @@ func CalcGasLimit(parent *types.WorkObject, gasCeil uint64) uint64 {

// If parent gas is zero and we have passed the 5 day threshold, we can set the first block gas limit to min gas limit
if parent.GasLimit() == 0 {
return params.MinGasLimit(parent.NumberU64(common.ZONE_CTX))
return params.MinGasLimit(parent.NumberU64(common.PRIME_CTX))
}

parentGasLimit := parent.GasLimit()

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()
Expand All @@ -426,7 +421,7 @@ func CalcGasLimit(parent *types.WorkObject, gasCeil uint64) uint64 {
return limit + delta
}
} else {
desiredLimit = params.MinGasLimit(parent.NumberU64(common.ZONE_CTX))
desiredLimit = params.MinGasLimit(parent.NumberU64(common.PRIME_CTX))
if limit-delta/2 < desiredLimit {
return desiredLimit
} else {
Expand Down
73 changes: 23 additions & 50 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)]++
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -1161,28 +1161,23 @@ 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 {
return nil, fmt.Errorf("tx [%v] emits too many cross-prime ETXs for block. emitted: %d, limit: %d", tx.Hash().Hex(), ETXPCount, etxPLimit)
}
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() {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions core/types/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 15 additions & 42 deletions core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, db ethdb.Databas
uncles, _ := lru.New[common.Hash, types.WorkObjectHeader](c_uncleCacheSize)
worker.uncles = uncles
// Set the GasFloor of the worker to the minGasLimit
worker.config.GasFloor = params.MinGasLimit(headerchain.CurrentHeader().NumberU64(common.ZONE_CTX))
worker.config.GasFloor = params.MinGasLimit(headerchain.CurrentHeader().NumberU64(common.PRIME_CTX))

phBodyCache, _ := lru.New[common.Hash, types.WorkObject](pendingBlockBodyLimit)
worker.pendingBlockBody = phBodyCache
Expand Down Expand Up @@ -2077,7 +2077,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
Expand All @@ -2094,9 +2094,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())
Expand Down Expand Up @@ -2173,51 +2170,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
}
}
env.wo.Header().SetGasUsed(gasUsed)
env.etxRLimit -= ETXRCount
Expand Down
Loading

0 comments on commit 81ec6b4

Please sign in to comment.