OSDN Git Service

fix the lock bug (#316)
authorPaladz <yzhu101@uottawa.ca>
Thu, 18 Jul 2019 08:16:44 +0000 (16:16 +0800)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2019 08:16:44 +0000 (16:16 +0800)
protocol/block.go
protocol/tx.go

index 9552a01..6300951 100644 (file)
@@ -238,7 +238,7 @@ func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
                // 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")
                }
        }
index 3562706..bdd3516 100644 (file)
@@ -28,11 +28,12 @@ func (c *Chain) ValidateTx(tx *types.Tx) (bool, error) {
        }
 
        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)
        }
@@ -42,7 +43,6 @@ func (c *Chain) validateTx(tx *types.Tx) (bool, error) {
                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)