[NOD-211] Add concurrent-safe version of BlockConfirmationsByHash (#326)

This commit is contained in:
Svarog 2019-06-10 13:30:16 +03:00 committed by stasatdaglabs
parent 35703e7956
commit 76f5619de7
2 changed files with 17 additions and 3 deletions

View File

@ -1194,7 +1194,19 @@ func (dag *BlockDAG) GetUTXOEntry(outpoint wire.Outpoint) (*UTXOEntry, bool) {
// BlockConfirmationsByHash returns the confirmations number for a block with the
// given hash. See blockConfirmations for further details.
//
// This function is safe for concurrent access
func (dag *BlockDAG) BlockConfirmationsByHash(hash *daghash.Hash) (uint64, error) {
dag.dagLock.RLock()
defer dag.dagLock.RUnlock()
return dag.BlockConfirmationsByHashNoLock(hash)
}
// BlockConfirmationsByHashNoLock is lock free version of BlockConfirmationsByHash
//
// This function is unsafe for concurrent access.
func (dag *BlockDAG) BlockConfirmationsByHashNoLock(hash *daghash.Hash) (uint64, error) {
if hash.IsEqual(&daghash.ZeroHash) {
return 0, nil
}
@ -1286,6 +1298,8 @@ func (dag *BlockDAG) oldestChainBlockWithBlueScoreGreaterThan(blueScore uint64)
}
// IsInSelectedPathChain returns whether or not a block hash is found in the selected path
//
// This method MUST be called with the DAG lock held
func (dag *BlockDAG) IsInSelectedPathChain(blockHash *daghash.Hash) bool {
return dag.virtual.selectedPathChainSet.containsHash(blockHash)
}

View File

@ -12,7 +12,7 @@ services:
"--addrindex",
# "--generate",
"--nodnsseed",
"--miningaddr=dagtest:qrm4zaetvny2yuh4wudf8y43fd20lunkxs8quragg8",
"--miningaddr=dagtest:qrgufg4qzfqacfzrf6xvx46aqedr5nke3qv6a74fex",
"--rpcuser=user",
"--rpcpass=pass",
"--rpclisten=0.0.0.0:18334",
@ -35,7 +35,7 @@ services:
"--connect=first",
"--rpcuser=user",
"--rpcpass=pass",
"--miningaddr=dagtest:qrm4zaetvny2yuh4wudf8y43fd20lunkxs8quragg8",
"--miningaddr=dagtest:qrgufg4qzfqacfzrf6xvx46aqedr5nke3qv6a74fex",
"--rpclisten=0.0.0.0:18334",
"--rpccert=/go/src/github.com/daglabs/btcd/docker/rpc.cert",
"--rpckey=/go/src/github.com/daglabs/btcd/docker/rpc.key"
@ -63,7 +63,7 @@ services:
"--connect=first",
"--rpcuser=user",
"--rpcpass=pass",
"--miningaddr=dagtest:qrm4zaetvny2yuh4wudf8y43fd20lunkxs8quragg8",
"--miningaddr=dagtest:qrgufg4qzfqacfzrf6xvx46aqedr5nke3qv6a74fex",
"--rpclisten=0.0.0.0:18334",
"--rpccert=/go/src/github.com/daglabs/btcd/docker/rpc.cert",
"--rpckey=/go/src/github.com/daglabs/btcd/docker/rpc.key"