Golang implemented sidechain for Bytom
リビジョン | 73c5c97414d2a6eba7ab2ea00fc58484d63314a1 (tree) |
---|---|
日時 | 2019-07-02 20:17:12 |
作者 | mars <mars@byto...> |
コミッター | mars |
tx validate for minging
@@ -1,7 +1,6 @@ | ||
1 | 1 | package proposal |
2 | 2 | |
3 | 3 | import ( |
4 | - "fmt" | |
5 | 4 | "sort" |
6 | 5 | "strconv" |
7 | 6 | "time" |
@@ -100,7 +99,16 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager | ||
100 | 99 | |
101 | 100 | txs := txPool.GetTransactions() |
102 | 101 | sort.Sort(byTime(txs)) |
102 | + | |
103 | + entriesTxs := []*bc.Tx{} | |
103 | 104 | 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] | |
104 | 112 | tx := txDesc.Tx.Tx |
105 | 113 | gasOnlyTx := false |
106 | 114 |
@@ -109,8 +117,8 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager | ||
109 | 117 | continue |
110 | 118 | } |
111 | 119 | |
112 | - gasStatus, err := validation.ValidateTx(tx, bcBlock) | |
113 | - if err != nil { | |
120 | + gasStatus := validateResult.GetGasState() | |
121 | + if validateResult.GetError() != nil { | |
114 | 122 | if !gasStatus.GasValid { |
115 | 123 | blkGenSkipTxForErr(txPool, &tx.ID, err) |
116 | 124 | continue |
@@ -139,6 +147,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager | ||
139 | 147 | if gasUsed == consensus.MaxBlockGas { |
140 | 148 | break |
141 | 149 | } |
150 | + | |
142 | 151 | } |
143 | 152 | |
144 | 153 | // creater coinbase transaction |
@@ -163,17 +172,3 @@ func blkGenSkipTxForErr(txPool *protocol.TxPool, txHash *bc.Hash, err error) { | ||
163 | 172 | log.WithFields(log.Fields{"module": logModule, "error": err}).Error("mining block generation: skip tx due to") |
164 | 173 | txPool.RemoveTransaction(txHash) |
165 | 174 | } |
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 | -} |
@@ -587,6 +587,16 @@ type validateTxResult struct { | ||
587 | 587 | err error |
588 | 588 | } |
589 | 589 | |
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 | + | |
590 | 600 | func validateTxWorker(workCh chan *validateTxWork, resultCh chan *validateTxResult, closeCh chan struct{}, wg *sync.WaitGroup) { |
591 | 601 | for { |
592 | 602 | select { |