mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +00:00
[NOD-719] Added defers to unlocks (#618)
* [NOD-719] Added defers to unlocks * [NOD-719] Added another defer to another Unlock * [NOD-719] Added yet another defer to yet another Unlock
This commit is contained in:
parent
193add502f
commit
be556ada9b
@ -1713,11 +1713,11 @@ func (dag *BlockDAG) antiPastBetween(lowHash, highHash *daghash.Hash, maxEntries
|
|||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (dag *BlockDAG) AntiPastHashesBetween(lowHash, highHash *daghash.Hash, maxHashes uint64) ([]*daghash.Hash, error) {
|
func (dag *BlockDAG) AntiPastHashesBetween(lowHash, highHash *daghash.Hash, maxHashes uint64) ([]*daghash.Hash, error) {
|
||||||
dag.dagLock.RLock()
|
dag.dagLock.RLock()
|
||||||
|
defer dag.dagLock.RUnlock()
|
||||||
hashes, err := dag.antiPastHashesBetween(lowHash, highHash, maxHashes)
|
hashes, err := dag.antiPastHashesBetween(lowHash, highHash, maxHashes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dag.dagLock.RUnlock()
|
|
||||||
return hashes, nil
|
return hashes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1791,11 +1791,11 @@ func (dag *BlockDAG) RUnlock() {
|
|||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (dag *BlockDAG) AntiPastHeadersBetween(lowHash, highHash *daghash.Hash) ([]*wire.BlockHeader, error) {
|
func (dag *BlockDAG) AntiPastHeadersBetween(lowHash, highHash *daghash.Hash) ([]*wire.BlockHeader, error) {
|
||||||
dag.dagLock.RLock()
|
dag.dagLock.RLock()
|
||||||
|
defer dag.dagLock.RUnlock()
|
||||||
headers, err := dag.antiPastHeadersBetween(lowHash, highHash, wire.MaxBlockHeadersPerMsg)
|
headers, err := dag.antiPastHeadersBetween(lowHash, highHash, wire.MaxBlockHeadersPerMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dag.dagLock.RUnlock()
|
|
||||||
return headers, nil
|
return headers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -267,8 +267,8 @@ func (dag *BlockDAG) thresholdState(prevNode *blockNode, checker thresholdCondit
|
|||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (dag *BlockDAG) ThresholdState(deploymentID uint32) (ThresholdState, error) {
|
func (dag *BlockDAG) ThresholdState(deploymentID uint32) (ThresholdState, error) {
|
||||||
dag.dagLock.Lock()
|
dag.dagLock.Lock()
|
||||||
|
defer dag.dagLock.Unlock()
|
||||||
state, err := dag.deploymentState(dag.selectedTip(), deploymentID)
|
state, err := dag.deploymentState(dag.selectedTip(), deploymentID)
|
||||||
dag.dagLock.Unlock()
|
|
||||||
|
|
||||||
return state, err
|
return state, err
|
||||||
}
|
}
|
||||||
@ -279,8 +279,8 @@ func (dag *BlockDAG) ThresholdState(deploymentID uint32) (ThresholdState, error)
|
|||||||
// This function is safe for concurrent access.
|
// This function is safe for concurrent access.
|
||||||
func (dag *BlockDAG) IsDeploymentActive(deploymentID uint32) (bool, error) {
|
func (dag *BlockDAG) IsDeploymentActive(deploymentID uint32) (bool, error) {
|
||||||
dag.dagLock.Lock()
|
dag.dagLock.Lock()
|
||||||
|
defer dag.dagLock.Unlock()
|
||||||
state, err := dag.deploymentState(dag.selectedTip(), deploymentID)
|
state, err := dag.deploymentState(dag.selectedTip(), deploymentID)
|
||||||
dag.dagLock.Unlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,11 @@ package netsync
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/blockdag"
|
"github.com/kaspanet/kaspad/blockdag"
|
||||||
"github.com/kaspanet/kaspad/dagconfig"
|
"github.com/kaspanet/kaspad/dagconfig"
|
||||||
"github.com/kaspanet/kaspad/database"
|
"github.com/kaspanet/kaspad/database"
|
||||||
@ -15,10 +20,6 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/util/daghash"
|
"github.com/kaspanet/kaspad/util/daghash"
|
||||||
"github.com/kaspanet/kaspad/wire"
|
"github.com/kaspanet/kaspad/wire"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"net"
|
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user