• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision94ffe408f68d354070374ef01b5c1578b79d2cd9 (tree)
Time2019-07-02 20:53:58
Authorwz <mars@byto...>
CommiterPaladz

Log Message

Tx validate mining (#237)

* add func

* tx validate for minging

* fix review

Change Summary

Incremental Difference

--- a/proposal/proposal.go
+++ b/proposal/proposal.go
@@ -99,17 +99,20 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
9999
100100 txs := txPool.GetTransactions()
101101 sort.Sort(byTime(txs))
102+
103+ entriesTxs := []*bc.Tx{}
102104 for _, txDesc := range txs {
105+ entriesTxs = append(entriesTxs, txDesc.Tx.Tx)
106+ }
107+
108+ validateResults := validation.ValidateTxs(entriesTxs, bcBlock)
109+ for i, validateResult := range validateResults {
110+ txDesc := txs[i]
103111 tx := txDesc.Tx.Tx
104112 gasOnlyTx := false
105113
106- if err := c.GetTransactionsUtxo(view, []*bc.Tx{tx}); err != nil {
107- blkGenSkipTxForErr(txPool, &tx.ID, err)
108- continue
109- }
110-
111- gasStatus, err := validation.ValidateTx(tx, bcBlock)
112- if err != nil {
114+ gasStatus := validateResult.GetGasState()
115+ if validateResult.GetError() != nil {
113116 if !gasStatus.GasValid {
114117 blkGenSkipTxForErr(txPool, &tx.ID, err)
115118 continue
@@ -117,6 +120,11 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
117120 gasOnlyTx = true
118121 }
119122
123+ if err := c.GetTransactionsUtxo(view, []*bc.Tx{tx}); err != nil {
124+ blkGenSkipTxForErr(txPool, &tx.ID, err)
125+ continue
126+ }
127+
120128 if gasUsed+uint64(gasStatus.GasUsed) > consensus.MaxBlockGas {
121129 break
122130 }
@@ -138,6 +146,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
138146 if gasUsed == consensus.MaxBlockGas {
139147 break
140148 }
149+
141150 }
142151
143152 // creater coinbase transaction
--- a/protocol/validation/tx.go
+++ b/protocol/validation/tx.go
@@ -587,6 +587,14 @@ type validateTxResult struct {
587587 err error
588588 }
589589
590+func (r *validateTxResult) GetGasState() *GasState {
591+ return r.gasStatus
592+}
593+
594+func (r *validateTxResult) GetError() error {
595+ return r.err
596+}
597+
590598 func validateTxWorker(workCh chan *validateTxWork, resultCh chan *validateTxResult, closeCh chan struct{}, wg *sync.WaitGroup) {
591599 for {
592600 select {
Show on old repository browser