Skip to content

Commit

Permalink
blockchain: Comment concurrency semantics.
Browse files Browse the repository at this point in the history
This calls out the concurrency semantics for some exported query
functions to ensure callers are aware they are safe for concurrent
access to be more consistent with other exported methods in the package.
  • Loading branch information
davecgh committed May 11, 2022
1 parent bf16271 commit 38dadd5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions blockchain/chainquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type ChainTipInfo struct {

// ChainTips returns information, in JSON-RPC format, about all of the currently
// known chain tips in the block index.
//
// This function is safe for concurrent access.
func (b *BlockChain) ChainTips() []ChainTipInfo {
b.index.RLock()
chainTips := make([]*blockNode, 0, b.index.totalTips)
Expand Down Expand Up @@ -136,6 +138,8 @@ func (b *BlockChain) ChainTips() []ChainTipInfo {

// BestHeader returns the header with the most cumulative work that is NOT
// known to be invalid.
//
// This function is safe for concurrent access.
func (b *BlockChain) BestHeader() (chainhash.Hash, int64) {
b.index.RLock()
header := b.index.bestHeader
Expand All @@ -146,6 +150,8 @@ func (b *BlockChain) BestHeader() (chainhash.Hash, int64) {
// BestInvalidHeader returns the header with the most cumulative work that is
// known to be invalid. It will be a hash of all zeroes if there is no such
// header.
//
// This function is safe for concurrent access.
func (b *BlockChain) BestInvalidHeader() chainhash.Hash {
var hash chainhash.Hash
b.index.RLock()
Expand Down

0 comments on commit 38dadd5

Please sign in to comment.