• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision73c5c97414d2a6eba7ab2ea00fc58484d63314a1 (tree)
Time2019-07-02 20:17:12
Authormars <mars@byto...>
Commitermars

Log Message

tx validate for minging

Change Summary

Incremental Difference

--- a/proposal/proposal.go
+++ b/proposal/proposal.go
@@ -1,7 +1,6 @@
11 package proposal
22
33 import (
4- "fmt"
54 "sort"
65 "strconv"
76 "time"
@@ -100,7 +99,16 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
10099
101100 txs := txPool.GetTransactions()
102101 sort.Sort(byTime(txs))
102+
103+ entriesTxs := []*bc.Tx{}
103104 for _, txDesc := range txs {
105+ entriesTxs = append(entriesTxs, txDesc.Tx.Tx)
106+ }
107+
108+ validateResults := validation.ValidateTxs(entriesTxs, bcBlock)
109+ for _, validateResult := range validateResults {
110+ index := validateResult.GetIndex()
111+ txDesc := txs[index]
104112 tx := txDesc.Tx.Tx
105113 gasOnlyTx := false
106114
@@ -109,8 +117,8 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
109117 continue
110118 }
111119
112- gasStatus, err := validation.ValidateTx(tx, bcBlock)
113- if err != nil {
120+ gasStatus := validateResult.GetGasState()
121+ if validateResult.GetError() != nil {
114122 if !gasStatus.GasValid {
115123 blkGenSkipTxForErr(txPool, &tx.ID, err)
116124 continue
@@ -139,6 +147,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
139147 if gasUsed == consensus.MaxBlockGas {
140148 break
141149 }
150+
142151 }
143152
144153 // creater coinbase transaction
@@ -163,17 +172,3 @@ func blkGenSkipTxForErr(txPool *protocol.TxPool, txHash *bc.Hash, err error) {
163172 log.WithFields(log.Fields{"module": logModule, "error": err}).Error("mining block generation: skip tx due to")
164173 txPool.RemoveTransaction(txHash)
165174 }
166-
167-func validateTxs(txDescs []*protocol.TxDesc, block *bc.Block) []*bc.Tx {
168- txs := []*bc.Tx{}
169- for _, txDesc := range txDescs {
170- txs = append(txs, txDesc.Tx.Tx)
171- }
172-
173- validateResults := validation.ValidateTxs(txs, block)
174- for i, validateResult := range validateResults {
175- fmt.Println(i, validateResult)
176- }
177-
178- return txs
179-}
--- a/protocol/validation/tx.go
+++ b/protocol/validation/tx.go
@@ -587,6 +587,16 @@ type validateTxResult struct {
587587 err error
588588 }
589589
590+func (r *validateTxResult) GetIndex() int {
591+ return r.i
592+}
593+func (r *validateTxResult) GetGasState() *GasState {
594+ return r.gasStatus
595+}
596+func (r *validateTxResult) GetError() error {
597+ return r.err
598+}
599+
590600 func validateTxWorker(workCh chan *validateTxWork, resultCh chan *validateTxResult, closeCh chan struct{}, wg *sync.WaitGroup) {
591601 for {
592602 select {
Show on old repository browser