Skip to content

Commit

Permalink
Disable xdcx related tx creation (#430)
Browse files Browse the repository at this point in the history
* stop create xdcx tx
* refactor disable flag
* disable miner only
  • Loading branch information
liam-lai committed Mar 4, 2024
1 parent 07d40a0 commit 753729c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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 BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
Expand Down
1 change: 1 addition & 0 deletions common/constants/constants.go.devnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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 BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
Expand Down
1 change: 1 addition & 0 deletions common/constants/constants.go.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var TIPXDCX = big.NewInt(23779191)
var TIPXDCXLending = big.NewInt(23779191)
var TIPXDCXCancellationFee = big.NewInt(23779191)
var TIPXDCXCancellationFeeTestnet = big.NewInt(23779191)
var TIPXDCXDISABLE = big.NewInt(99999999900)
var BerlinBlock = big.NewInt(9999999999)
var LondonBlock = big.NewInt(9999999999)
var MergeBlock = big.NewInt(9999999999)
Expand Down
45 changes: 22 additions & 23 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (self *worker) commitNewWork() {
log.Warn("Can't find coinbase account wallet", "coinbase", self.coinbase, "err", err)
return
}
if self.config.XDPoS != nil && self.chain.Config().IsTIPXDCX(header.Number) {
if self.config.XDPoS != nil && self.chain.Config().IsTIPXDCXMiner(header.Number) {
XDCX := self.eth.GetXDCX()
XDCXLending := self.eth.GetXDCXLending()
if XDCX != nil && header.Number.Uint64() > self.config.XDPoS.Epoch {
Expand Down Expand Up @@ -710,8 +710,13 @@ func (self *worker) commitNewWork() {
if XDCX.IsSDKNode() {
self.chain.AddMatchingResult(tradingTransaction.Hash(), tradingMatchingResults)
}
// force adding trading, lending transaction to this block
if tradingTransaction != nil {
specialTxs = append(specialTxs, tradingTransaction)
}
}
}

if len(lendingInput) > 0 {
// lending transaction
lendingBatch := &lendingstate.TxLendingBatch{
Expand All @@ -735,6 +740,9 @@ func (self *worker) commitNewWork() {
if XDCX.IsSDKNode() {
self.chain.AddLendingResult(lendingTransaction.Hash(), lendingMatchingResults)
}
if lendingTransaction != nil {
specialTxs = append(specialTxs, lendingTransaction)
}
}
}

Expand All @@ -756,32 +764,23 @@ func (self *worker) commitNewWork() {
if XDCX.IsSDKNode() {
self.chain.AddFinalizedTrades(lendingFinalizedTradeTransaction.Hash(), updatedTrades)
}
if lendingFinalizedTradeTransaction != nil {
specialTxs = append(specialTxs, lendingFinalizedTradeTransaction)
}
}
}
}
XDCxStateRoot := work.tradingState.IntermediateRoot()
LendingStateRoot := work.lendingState.IntermediateRoot()
txData := append(XDCxStateRoot.Bytes(), LendingStateRoot.Bytes()...)
tx := types.NewTransaction(work.state.GetNonce(self.coinbase), common.HexToAddress(common.TradingStateAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), txData)
txStateRoot, err := wallet.SignTx(accounts.Account{Address: self.coinbase}, tx, self.config.ChainId)
if err != nil {
log.Error("Fail to create tx state root", "error", err)
return
}
specialTxs = append(specialTxs, txStateRoot)
}

// force adding trading, lending transaction to this block
if tradingTransaction != nil {
specialTxs = append(specialTxs, tradingTransaction)
}
if lendingTransaction != nil {
specialTxs = append(specialTxs, lendingTransaction)
}
if lendingFinalizedTradeTransaction != nil {
specialTxs = append(specialTxs, lendingFinalizedTradeTransaction)
}

XDCxStateRoot := work.tradingState.IntermediateRoot()
LendingStateRoot := work.lendingState.IntermediateRoot()
txData := append(XDCxStateRoot.Bytes(), LendingStateRoot.Bytes()...)
tx := types.NewTransaction(work.state.GetNonce(self.coinbase), common.HexToAddress(common.TradingStateAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), txData)
txStateRoot, err := wallet.SignTx(accounts.Account{Address: self.coinbase}, tx, self.config.ChainId)
if err != nil {
log.Error("Fail to create tx state root", "error", err)
return
}
specialTxs = append(specialTxs, txStateRoot)
}
work.commitTransactions(self.mux, feeCapacity, txs, specialTxs, self.chain, self.coinbase)
// compute uncles for the new block.
Expand Down
9 changes: 4 additions & 5 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,10 @@ func (c *ChainConfig) IsTIPNoHalvingMNReward(num *big.Int) bool {
return isForked(common.TIPNoHalvingMNReward, num)
}
func (c *ChainConfig) IsTIPXDCX(num *big.Int) bool {
if common.IsTestnet {
return isForked(common.TIPXDCXTestnet, num)
} else {
return isForked(common.TIPXDCX, num)
}
return isForked(common.TIPXDCX, num)
}
func (c *ChainConfig) IsTIPXDCXMiner(num *big.Int) bool {
return isForked(common.TIPXDCX, num) && !isForked(common.TIPXDCXDISABLE, num)
}

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

0 comments on commit 753729c

Please sign in to comment.