mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
7bb0ee78af
* Rationalise state locking * Rationalise state locking * Merge branch 'state-locks' of github.com:mcdee/prysm into state-locks * Merge branch 'master' into state-locks * Add feature flag * Merge * Merge branch 'master' into state-locks * Merge branch 'master' into state-locks * Update locks * Merge branch 'master' into state-locks * Gazelle * Tidy-ups * Merge branch 'master' into state-locks * Remove commentary to a docs.go file for better presentation on godocs * Add newBeaconStateLocks as a --dev flag * gofmt * Merge branch 'master' into state-locks
41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
// Package state defines how the beacon chain state for eth2
|
|
// functions in the running beacon node, using an advanced,
|
|
// immutable implementation of the state data structure.
|
|
//
|
|
// BeaconState getters may be accessed from inside or outside the package. To
|
|
// avoid duplicating locks, we have internal and external versions of the
|
|
// getter The external function carries out the short-circuit conditions,
|
|
// obtains a read lock, then calls the internal function. The internal function
|
|
// carries out the short-circuit conditions and returns the required data
|
|
// without further locking, allowing it to be used by other package-level
|
|
// functions that already hold a lock. Hence the functions look something
|
|
// like this:
|
|
//
|
|
// func (b *BeaconState) Foo() uint64 {
|
|
// // Short-circuit conditions.
|
|
// if !b.HasInnerState() {
|
|
// return 0
|
|
// }
|
|
//
|
|
// // Read lock.
|
|
// b.lock.RLock()
|
|
// defer b.lock.RUnlock()
|
|
//
|
|
// // Internal getter.
|
|
// return b.foo()
|
|
// }
|
|
//
|
|
// func (b *BeaconState) foo() uint64 {
|
|
// // Short-circuit conditions.
|
|
// if !b.HasInnerState() {
|
|
// return 0
|
|
// }
|
|
//
|
|
// return b.state.foo
|
|
// }
|
|
//
|
|
// Although it is technically possible to remove the short-circuit conditions
|
|
// from the external function, that would require every read to obtain a lock
|
|
// even if the data was not present, leading to potential slowdowns.
|
|
package state
|