github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/state/v1/doc.go (about)

     1  // Package v1 defines how the beacon chain state for Ethereum
     2  // functions in the running beacon node, using an advanced,
     3  // immutable implementation of the state data structure.
     4  //
     5  // BeaconState getters may be accessed from inside or outside the package. To
     6  // avoid duplicating locks, we have internal and external versions of the
     7  // getter The external function carries out the short-circuit conditions,
     8  // obtains a read lock, then calls the internal function.  The internal function
     9  // carries out the short-circuit conditions and returns the required data
    10  // without further locking, allowing it to be used by other package-level
    11  // functions that already hold a lock. Hence the functions look something
    12  // like this:
    13  //
    14  //  func (b *BeaconState) Foo() uint64 {
    15  //    // Short-circuit conditions.
    16  //    if !b.hasInnerState() {
    17  //      return 0
    18  //    }
    19  //
    20  //    // Read lock.
    21  //    b.lock.RLock()
    22  //    defer b.lock.RUnlock()
    23  //
    24  //    // Internal getter.
    25  //    return b.foo()
    26  //  }
    27  //
    28  //  func (b *BeaconState) foo() uint64 {
    29  //    // Short-circuit conditions.
    30  //    if !b.hasInnerState() {
    31  //      return 0
    32  //    }
    33  //
    34  //    return b.state.foo
    35  //  }
    36  //
    37  // Although it is technically possible to remove the short-circuit conditions
    38  // from the external function, that would require every read to obtain a lock
    39  // even if the data was not present, leading to potential slowdowns.
    40  package v1