2022-05-09 13:02:34 +00:00
|
|
|
// Package state_native defines how the beacon chain state for Ethereum
|
2022-01-13 11:23:53 +00:00
|
|
|
// 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
|
2022-05-09 13:02:34 +00:00
|
|
|
// getter. The external function obtains a read lock, then calls the internal function.
|
|
|
|
// The internal function 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:
|
2022-01-13 11:23:53 +00:00
|
|
|
//
|
2022-11-18 19:12:19 +00:00
|
|
|
// func (b *BeaconState) Foo() uint64 {
|
|
|
|
// // Read lock.
|
|
|
|
// b.lock.RLock()
|
|
|
|
// defer b.lock.RUnlock()
|
2022-01-13 11:23:53 +00:00
|
|
|
//
|
2022-11-18 19:12:19 +00:00
|
|
|
// // Internal getter.
|
|
|
|
// return b.foo()
|
|
|
|
// }
|
2022-01-13 11:23:53 +00:00
|
|
|
//
|
2022-11-18 19:12:19 +00:00
|
|
|
// func (b *BeaconState) foo() uint64 {
|
|
|
|
// (...) // Some processing logic.
|
2022-01-13 11:23:53 +00:00
|
|
|
//
|
2022-11-18 19:12:19 +00:00
|
|
|
// return b.foo
|
|
|
|
// }
|
2022-01-13 11:23:53 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|