2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-15 05:46:47 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
2022-01-13 11:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Eth1Data corresponding to the proof-of-work chain information stored in the beacon state.
|
|
|
|
func (b *BeaconState) Eth1Data() *ethpb.Eth1Data {
|
2022-01-24 10:24:38 +00:00
|
|
|
if b.eth1Data == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
return b.eth1DataVal()
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
// eth1DataVal corresponding to the proof-of-work chain information stored in the beacon state.
|
2022-01-13 11:23:53 +00:00
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2022-01-24 10:24:38 +00:00
|
|
|
func (b *BeaconState) eth1DataVal() *ethpb.Eth1Data {
|
|
|
|
if b.eth1Data == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
return ethpb.CopyETH1Data(b.eth1Data)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain
|
|
|
|
// data retrieved from eth1.
|
|
|
|
func (b *BeaconState) Eth1DataVotes() []*ethpb.Eth1Data {
|
2022-01-24 10:24:38 +00:00
|
|
|
if b.eth1DataVotes == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
return b.eth1DataVotesVal()
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
// eth1DataVotesVal corresponds to votes from Ethereum on the canonical proof-of-work chain
|
2022-01-13 11:23:53 +00:00
|
|
|
// data retrieved from eth1.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2022-01-24 10:24:38 +00:00
|
|
|
func (b *BeaconState) eth1DataVotesVal() []*ethpb.Eth1Data {
|
|
|
|
if b.eth1DataVotes == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
res := make([]*ethpb.Eth1Data, len(b.eth1DataVotes))
|
2022-01-13 11:23:53 +00:00
|
|
|
for i := 0; i < len(res); i++ {
|
2022-01-24 10:24:38 +00:00
|
|
|
res[i] = ethpb.CopyETH1Data(b.eth1DataVotes[i])
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eth1DepositIndex corresponds to the index of the deposit made to the
|
|
|
|
// validator deposit contract at the time of this state's eth1 data.
|
|
|
|
func (b *BeaconState) Eth1DepositIndex() uint64 {
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
return b.eth1DepositIndex
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|