Skip to content

Commit

Permalink
Remove New vs Old ConversionLockPeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed Dec 4, 2024
1 parent 38f54c3 commit 10bb41f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions core/chain_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 5 additions & 10 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 4 additions & 9 deletions core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 10bb41f

Please sign in to comment.