Skip to content
This repository was archived by the owner on May 25, 2020. It is now read-only.

Commit d3995a0

Browse files
authored
Merge branch 'tomoX' into fix_restart_nonde_empty_tomox_state
2 parents b926559 + 934dab5 commit d3995a0

1 file changed

Lines changed: 47 additions & 45 deletions

File tree

miner/worker.go

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -615,47 +615,6 @@ func (self *worker) commitNewWork() {
615615
txMatches []tomox.TxDataMatch
616616
)
617617
feeCapacity := state.GetTRC21FeeCapacityFromStateWithCache(parent.Root(), work.state)
618-
if self.config.Posv != nil && header.Number.Uint64()%self.config.Posv.Epoch != 0 && self.chain.Config().IsTIPTomoX(header.Number) {
619-
tomoX := self.eth.GetTomoX()
620-
if tomoX != nil && header.Number.Uint64() > self.config.Posv.Epoch {
621-
log.Debug("Start processing order pending")
622-
orderPending, _ := self.eth.OrderPool().Pending()
623-
log.Debug("Start processing order pending", "len", len(orderPending))
624-
txMatches = tomoX.ProcessOrderPending(self.coinbase, self.chain.IPCEndpoint, orderPending, work.state, work.tomoxState)
625-
log.Debug("transaction matches found", "txMatches", len(txMatches))
626-
}
627-
}
628-
TomoxStateRoot := work.tomoxState.IntermediateRoot()
629-
txMatchBatch := &tomox.TxMatchBatch{
630-
Data: txMatches,
631-
Timestamp: time.Now().UnixNano(),
632-
TxHash: common.Hash{},
633-
}
634-
wallet, err := self.eth.AccountManager().Find(accounts.Account{Address: self.coinbase})
635-
if err != nil {
636-
log.Warn("Can't find coinbase account wallet", "coinbase", self.coinbase, "err", err)
637-
return
638-
}
639-
txMatchBytes, err := tomox.EncodeTxMatchesBatch(*txMatchBatch)
640-
if err != nil {
641-
log.Error("Fail to marshal txMatch", "error", err)
642-
return
643-
}
644-
nonce := work.state.GetNonce(self.coinbase)
645-
tx := types.NewTransaction(nonce, common.HexToAddress(common.TomoXAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), txMatchBytes)
646-
txM, err := wallet.SignTx(accounts.Account{Address: self.coinbase}, tx, self.config.ChainId)
647-
if err != nil {
648-
log.Error("Fail to create tx matches", "error", err)
649-
return
650-
} else {
651-
matchingTransaction = txM
652-
}
653-
tx = types.NewTransaction(nonce, common.HexToAddress(common.TomoXStateAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), TomoxStateRoot.Bytes())
654-
txStateRoot, err := wallet.SignTx(accounts.Account{Address: self.coinbase}, tx, self.config.ChainId)
655-
if err != nil {
656-
log.Error("Fail to create tx state root", "error", err)
657-
return
658-
}
659618
if self.config.Posv != nil && header.Number.Uint64()%self.config.Posv.Epoch != 0 {
660619
pending, err := self.eth.TxPool().Pending()
661620
if err != nil {
@@ -664,9 +623,52 @@ func (self *worker) commitNewWork() {
664623
}
665624
txs, specialTxs = types.NewTransactionsByPriceAndNonce(self.current.signer, pending, signers, feeCapacity)
666625
}
667-
// force adding matching transaction to this block
668-
specialTxs = append(specialTxs, matchingTransaction)
669-
specialTxs = append(specialTxs, txStateRoot)
626+
if atomic.LoadInt32(&self.mining) == 1 {
627+
if self.config.Posv != nil && header.Number.Uint64()%self.config.Posv.Epoch != 0 && self.chain.Config().IsTIPTomoX(header.Number) {
628+
tomoX := self.eth.GetTomoX()
629+
if tomoX != nil && header.Number.Uint64() > self.config.Posv.Epoch {
630+
log.Debug("Start processing order pending")
631+
orderPending, _ := self.eth.OrderPool().Pending()
632+
log.Debug("Start processing order pending", "len", len(orderPending))
633+
txMatches = tomoX.ProcessOrderPending(self.coinbase, self.chain.IPCEndpoint, orderPending, work.state, work.tomoxState)
634+
log.Debug("transaction matches found", "txMatches", len(txMatches))
635+
}
636+
}
637+
TomoxStateRoot := work.tomoxState.IntermediateRoot()
638+
txMatchBatch := &tomox.TxMatchBatch{
639+
Data: txMatches,
640+
Timestamp: time.Now().UnixNano(),
641+
TxHash: common.Hash{},
642+
}
643+
wallet, err := self.eth.AccountManager().Find(accounts.Account{Address: self.coinbase})
644+
if err != nil {
645+
log.Warn("Can't find coinbase account wallet", "coinbase", self.coinbase, "err", err)
646+
return
647+
}
648+
txMatchBytes, err := tomox.EncodeTxMatchesBatch(*txMatchBatch)
649+
if err != nil {
650+
log.Error("Fail to marshal txMatch", "error", err)
651+
return
652+
}
653+
nonce := work.state.GetNonce(self.coinbase)
654+
tx := types.NewTransaction(nonce, common.HexToAddress(common.TomoXAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), txMatchBytes)
655+
txM, err := wallet.SignTx(accounts.Account{Address: self.coinbase}, tx, self.config.ChainId)
656+
if err != nil {
657+
log.Error("Fail to create tx matches", "error", err)
658+
return
659+
} else {
660+
matchingTransaction = txM
661+
}
662+
tx = types.NewTransaction(nonce, common.HexToAddress(common.TomoXStateAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), TomoxStateRoot.Bytes())
663+
txStateRoot, err := wallet.SignTx(accounts.Account{Address: self.coinbase}, tx, self.config.ChainId)
664+
if err != nil {
665+
log.Error("Fail to create tx state root", "error", err)
666+
return
667+
}
668+
// force adding matching transaction to this block
669+
specialTxs = append(specialTxs, matchingTransaction)
670+
specialTxs = append(specialTxs, txStateRoot)
671+
}
670672
work.commitTransactions(self.mux, feeCapacity, txs, specialTxs, self.chain, self.coinbase)
671673
// compute uncles for the new block.
672674
var (
@@ -698,7 +700,7 @@ func (self *worker) commitNewWork() {
698700
return
699701
}
700702
if atomic.LoadInt32(&self.mining) == 1 {
701-
log.Info("Committing new block", "number", work.Block.Number(), "tomox state root", common.BytesToHash(txStateRoot.Data()), "state root", work.state.IntermediateRoot(false).Hex(), "txs", work.tcount, "special-txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
703+
log.Info("Committing new block", "number", work.Block.Number(), "txs", work.tcount, "special-txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
702704
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
703705
self.lastParentBlockCommit = parent.Hash().Hex()
704706
}

0 commit comments

Comments
 (0)