Skip to content

Commit

Permalink
Disable on xdcx receiver part (#521)
Browse files Browse the repository at this point in the history
* update all IsTIPXDCXReceiver condition

* add TIPXDCXReceiverDisable on testnet and devnet
  • Loading branch information
liam-lai committed Apr 19, 2024
1 parent bf4f915 commit ef4b8ef
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
3 changes: 2 additions & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var TIPXDCX = big.NewInt(38383838)
var TIPXDCXLending = big.NewInt(38383838)
var TIPXDCXCancellationFee = big.NewInt(38383838)
var TIPXDCXCancellationFeeTestnet = big.NewInt(38383838)
var TIPXDCXDISABLE = big.NewInt(99999999900)
var TIPXDCXMinerDisable = big.NewInt(88999999900)
var TIPXDCXReceiverDisable = big.NewInt(99999999999)
var BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
Expand Down
3 changes: 2 additions & 1 deletion common/constants/constants.go.devnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var TIPXDCX = big.NewInt(225000)
var TIPXDCXLending = big.NewInt(225000)
var TIPXDCXCancellationFee = big.NewInt(225000)
var TIPXDCXCancellationFeeTestnet = big.NewInt(225000)
var TIPXDCXDISABLE = big.NewInt(15894900)
var TIPXDCXMinerDisable = big.NewInt(15894900)
var TIPXDCXReceiverDisable = big.NewInt(9999999999)
var BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
Expand Down
3 changes: 2 additions & 1 deletion common/constants/constants.go.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var TIPXDCX = big.NewInt(23779191)
var TIPXDCXLending = big.NewInt(23779191)
var TIPXDCXCancellationFee = big.NewInt(23779191)
var TIPXDCXCancellationFeeTestnet = big.NewInt(23779191)
var TIPXDCXDISABLE = big.NewInt(61290000) // Target 31st March 2024
var TIPXDCXMinerDisable = big.NewInt(61290000) // Target 31st March 2024
var TIPXDCXReceiverDisable = big.NewInt(9999999999)
var BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
Expand Down
15 changes: 7 additions & 8 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ func (bc *BlockChain) repair(head **types.Block) error {
if ok {
tradingService := engine.GetXDCXService()
lendingService := engine.GetLendingService()
if bc.Config().IsTIPXDCX((*head).Number()) && bc.chainConfig.XDPoS != nil && (*head).NumberU64() > bc.chainConfig.XDPoS.Epoch && tradingService != nil && lendingService != nil {
if bc.Config().IsTIPXDCXReceiver((*head).Number()) && bc.chainConfig.XDPoS != nil && (*head).NumberU64() > bc.chainConfig.XDPoS.Epoch && tradingService != nil && lendingService != nil {
author, _ := bc.Engine().Author((*head).Header())
tradingRoot, err := tradingService.GetTradingStateRoot(*head, author)
if err == nil {
Expand Down Expand Up @@ -913,7 +913,7 @@ func (bc *BlockChain) SaveData() {
if err := triedb.Commit(recent.Root(), true); err != nil {
log.Error("Failed to commit recent state trie", "err", err)
}
if bc.Config().IsTIPXDCX(recent.Number()) && bc.chainConfig.XDPoS != nil && recent.NumberU64() > bc.chainConfig.XDPoS.Epoch && engine != nil {
if bc.Config().IsTIPXDCXReceiver(recent.Number()) && bc.chainConfig.XDPoS != nil && recent.NumberU64() > bc.chainConfig.XDPoS.Epoch && engine != nil {
author, _ := bc.Engine().Author(recent.Header())
if tradingService != nil {
tradingRoot, _ := tradingService.GetTradingStateRoot(recent, author)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
var tradingService utils.TradingService
var lendingTrieDb *trie.Database
var lendingService utils.LendingService
if bc.Config().IsTIPXDCX(block.Number()) && bc.chainConfig.XDPoS != nil && block.NumberU64() > bc.chainConfig.XDPoS.Epoch && engine != nil {
if bc.Config().IsTIPXDCXReceiver(block.Number()) && bc.chainConfig.XDPoS != nil && block.NumberU64() > bc.chainConfig.XDPoS.Epoch && engine != nil {
tradingService = engine.GetXDCXService()
if tradingService != nil {
tradingTrieDb = tradingService.GetStateCache().TrieDB()
Expand Down Expand Up @@ -1592,7 +1592,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
var tradingService utils.TradingService
var lendingService utils.LendingService
isSDKNode := false
if bc.Config().IsTIPXDCX(block.Number()) && bc.chainConfig.XDPoS != nil && engine != nil && block.NumberU64() > bc.chainConfig.XDPoS.Epoch {
if bc.Config().IsTIPXDCXReceiver(block.Number()) && bc.chainConfig.XDPoS != nil && engine != nil && block.NumberU64() > bc.chainConfig.XDPoS.Epoch {
author, err := bc.Engine().Author(block.Header()) // Ignore error, we're past header validation
if err != nil {
bc.reportBlock(block, nil, err)
Expand Down Expand Up @@ -1933,8 +1933,7 @@ func (bc *BlockChain) getResultBlock(block *types.Block, verifiedM2 bool) (*Resu
}
// liquidate / finalize open lendingTrades
if block.Number().Uint64()%bc.chainConfig.XDPoS.Epoch == common.LiquidateLendingTradeBlock {
finalizedTrades := map[common.Hash]*lendingstate.LendingTrade{}
finalizedTrades, _, _, _, _, err = lendingService.ProcessLiquidationData(block.Header(), bc, statedb, tradingState, lendingState)
finalizedTrades, _, _, _, _, err := lendingService.ProcessLiquidationData(block.Header(), bc, statedb, tradingState, lendingState)
if err != nil {
return nil, fmt.Errorf("failed to ProcessLiquidationData. Err: %v ", err)
}
Expand Down Expand Up @@ -2055,7 +2054,7 @@ func (bc *BlockChain) insertBlock(block *types.Block) ([]interface{}, []*types.L
// Only count canonical blocks for GC processing time
bc.gcproc += result.proctime
bc.UpdateBlocksHashCache(block)
if bc.chainConfig.IsTIPXDCX(block.Number()) && bc.chainConfig.XDPoS != nil && block.NumberU64() > bc.chainConfig.XDPoS.Epoch {
if bc.chainConfig.IsTIPXDCXReceiver(block.Number()) && bc.chainConfig.XDPoS != nil && block.NumberU64() > bc.chainConfig.XDPoS.Epoch {
bc.logExchangeData(block)
bc.logLendingData(block)
}
Expand Down Expand Up @@ -2279,7 +2278,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
}
}()
}
if bc.chainConfig.IsTIPXDCX(commonBlock.Number()) && bc.chainConfig.XDPoS != nil && commonBlock.NumberU64() > bc.chainConfig.XDPoS.Epoch {
if bc.chainConfig.IsTIPXDCXReceiver(commonBlock.Number()) && bc.chainConfig.XDPoS != nil && commonBlock.NumberU64() > bc.chainConfig.XDPoS.Epoch {
bc.reorgTxMatches(deletedTxs, newChain)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions core/lending_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (pool *LendingPool) loop() {
// reset retrieves the current state of the blockchain and ensures the content
// of the transaction pool is valid with regard to the chain state.
func (pool *LendingPool) reset(oldHead, newblock *types.Block) {
if !pool.chainconfig.IsTIPXDCX(pool.chain.CurrentBlock().Number()) || pool.chain.Config().XDPoS == nil || pool.chain.CurrentBlock().NumberU64() <= pool.chain.Config().XDPoS.Epoch {
if !pool.chainconfig.IsTIPXDCXReceiver(pool.chain.CurrentBlock().Number()) || pool.chain.Config().XDPoS == nil || pool.chain.CurrentBlock().NumberU64() <= pool.chain.Config().XDPoS.Epoch {
return
}
// If we're reorging an old state, reinject all dropped transactions
Expand Down Expand Up @@ -814,7 +814,7 @@ func (pool *LendingPool) AddRemotes(txs []*types.LendingTransaction) []error {

// addTx enqueues a single transaction into the pool if it is valid.
func (pool *LendingPool) addTx(tx *types.LendingTransaction, local bool) error {
if !pool.chainconfig.IsTIPXDCX(pool.chain.CurrentBlock().Number()) {
if !pool.chainconfig.IsTIPXDCXReceiver(pool.chain.CurrentBlock().Number()) {
return nil
}
tx.CacheHash()
Expand Down
4 changes: 2 additions & 2 deletions core/order_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (pool *OrderPool) loop() {
// reset retrieves the current state of the blockchain and ensures the content
// of the transaction pool is valid with regard to the chain state.
func (pool *OrderPool) reset(oldHead, newblock *types.Block) {
if !pool.chainconfig.IsTIPXDCX(pool.chain.CurrentBlock().Number()) || pool.chain.Config().XDPoS == nil || pool.chain.CurrentBlock().NumberU64() <= pool.chain.Config().XDPoS.Epoch {
if !pool.chainconfig.IsTIPXDCXReceiver(pool.chain.CurrentBlock().Number()) || pool.chain.Config().XDPoS == nil || pool.chain.CurrentBlock().NumberU64() <= pool.chain.Config().XDPoS.Epoch {
return
}
// If we're reorging an old state, reinject all dropped transactions
Expand Down Expand Up @@ -729,7 +729,7 @@ func (pool *OrderPool) AddRemotes(txs []*types.OrderTransaction) []error {

// addTx enqueues a single transaction into the pool if it is valid.
func (pool *OrderPool) addTx(tx *types.OrderTransaction, local bool) error {
if !pool.chainconfig.IsTIPXDCX(pool.chain.CurrentBlock().Number()) {
if !pool.chainconfig.IsTIPXDCXReceiver(pool.chain.CurrentBlock().Number()) {
return nil
}
tx.CacheHash()
Expand Down
8 changes: 4 additions & 4 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ func ApplyTransaction(config *params.ChainConfig, tokensFee map[common.Address]*
if tx.To() != nil && tx.To().String() == common.BlockSigners && config.IsTIPSigning(header.Number) {
return ApplySignTransaction(config, statedb, header, tx, usedGas)
}
if tx.To() != nil && tx.To().String() == common.TradingStateAddr && config.IsTIPXDCX(header.Number) {
if tx.To() != nil && tx.To().String() == common.TradingStateAddr && config.IsTIPXDCXReceiver(header.Number) {
return ApplyEmptyTransaction(config, statedb, header, tx, usedGas)
}
if tx.To() != nil && tx.To().String() == common.XDCXLendingAddress && config.IsTIPXDCX(header.Number) {
if tx.To() != nil && tx.To().String() == common.XDCXLendingAddress && config.IsTIPXDCXReceiver(header.Number) {
return ApplyEmptyTransaction(config, statedb, header, tx, usedGas)
}
if tx.IsTradingTransaction() && config.IsTIPXDCX(header.Number) {
if tx.IsTradingTransaction() && config.IsTIPXDCXReceiver(header.Number) {
return ApplyEmptyTransaction(config, statedb, header, tx, usedGas)
}

if tx.IsLendingFinalizedTradeTransaction() && config.IsTIPXDCX(header.Number) {
if tx.IsLendingFinalizedTradeTransaction() && config.IsTIPXDCXReceiver(header.Number) {
return ApplyEmptyTransaction(config, statedb, header, tx, usedGas)
}

Expand Down
6 changes: 3 additions & 3 deletions core/token_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func RunContract(chain consensus.ChainContext, statedb *state.StateDB, contractA
return unpackResult, nil
}

//FIXME: please use copyState for this function
// FIXME: please use copyState for this function
// CallContractWithState executes a contract call at the given state.
func CallContractWithState(call ethereum.CallMsg, chain consensus.ChainContext, statedb *state.StateDB) ([]byte, error) {
// Ensure message is initialized properly.
Expand Down Expand Up @@ -124,7 +124,7 @@ func ValidateXDCXApplyTransaction(chain consensus.ChainContext, blockNumber *big
if blockNumber == nil || blockNumber.Sign() <= 0 {
blockNumber = chain.CurrentHeader().Number
}
if !chain.Config().IsTIPXDCX(blockNumber) {
if !chain.Config().IsTIPXDCXReceiver(blockNumber) {
return nil
}
contractABI, err := GetTokenAbi(contract.TRC21ABI)
Expand All @@ -146,7 +146,7 @@ func ValidateXDCZApplyTransaction(chain consensus.ChainContext, blockNumber *big
if blockNumber == nil || blockNumber.Sign() <= 0 {
blockNumber = chain.CurrentHeader().Number
}
if !chain.Config().IsTIPXDCX(blockNumber) {
if !chain.Config().IsTIPXDCXReceiver(blockNumber) {
return nil
}
contractABI, err := GetTokenAbi(contract.TRC21ABI)
Expand Down
6 changes: 5 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,11 @@ func (c *ChainConfig) IsTIPXDCX(num *big.Int) bool {
return isForked(common.TIPXDCX, num)
}
func (c *ChainConfig) IsTIPXDCXMiner(num *big.Int) bool {
return isForked(common.TIPXDCX, num) && !isForked(common.TIPXDCXDISABLE, num)
return isForked(common.TIPXDCX, num) && !isForked(common.TIPXDCXMinerDisable, num)
}

func (c *ChainConfig) IsTIPXDCXReceiver(num *big.Int) bool {
return isForked(common.TIPXDCX, num) && !isForked(common.TIPXDCXReceiverDisable, num)
}

func (c *ChainConfig) IsTIPXDCXLending(num *big.Int) bool {
Expand Down

0 comments on commit ef4b8ef

Please sign in to comment.