// the number of restored Tx should be very small or most of time ZERO
// Error returned from validation is ignored, tx could still be lost if validation fails.
// TODO: adjust tx timestamp so that it won't starve in pool.
- if _, err := c.validateTx(tx); err != nil {
+ if _, err := c.validateTx(tx, blockHeader); err != nil {
log.WithFields(log.Fields{"module": logModule, "tx_id": tx.Tx.ID.String(), "error": err}).Info("restore tx fail")
}
}
}
c.markTransactions(tx)
- return c.validateTx(tx)
+ bh := c.BestBlockHeader()
+ return c.validateTx(tx, bh)
}
// validateTx validates the given transaction without checking duplication.
-func (c *Chain) validateTx(tx *types.Tx) (bool, error) {
+func (c *Chain) validateTx(tx *types.Tx, bh *types.BlockHeader) (bool, error) {
if ok := c.txPool.HaveTransaction(&tx.ID); ok {
return false, c.txPool.GetErrCache(&tx.ID)
}
return false, ErrDustTx
}
- bh := c.BestBlockHeader()
gasStatus, err := validation.ValidateTx(tx.Tx, types.MapBlock(&types.Block{BlockHeader: *bh}))
if !gasStatus.GasValid {
c.txPool.AddErrCache(&tx.ID, err)