From: Paladz Date: Thu, 18 Jul 2019 08:16:44 +0000 (+0800) Subject: fix the lock bug (#316) X-Git-Tag: v1.0.5~109 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=a4d2fccbb6638bee6a8afa2af4df6e3989b91609 fix the lock bug (#316) --- diff --git a/protocol/block.go b/protocol/block.go index 9552a015..63009513 100644 --- a/protocol/block.go +++ b/protocol/block.go @@ -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") } } diff --git a/protocol/tx.go b/protocol/tx.go index 35627061..bdd35162 100644 --- a/protocol/tx.go +++ b/protocol/tx.go @@ -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)