Mask common types.
This commit is contained in:
parent
ecb5490b01
commit
dceb81866f
@ -13,6 +13,11 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Slot common.Slot
|
||||
type Root common.Root
|
||||
|
||||
type Eth1Data common.Eth1Data
|
||||
|
||||
type SignedBeaconBlock struct {
|
||||
bellatrix *bellatrix.SignedBeaconBlock
|
||||
altair *altair.SignedBeaconBlock
|
||||
@ -181,36 +186,36 @@ func (s *BeaconBlock) GetPhase0() *phase0.BeaconBlock {
|
||||
return s.phase0
|
||||
}
|
||||
|
||||
func (b *BeaconBlock) ParentRoot() *common.Root {
|
||||
func (b *BeaconBlock) ParentRoot() Root {
|
||||
if b.IsBellatrix() {
|
||||
return &b.bellatrix.ParentRoot
|
||||
return Root(b.bellatrix.ParentRoot)
|
||||
}
|
||||
|
||||
if b.IsAltair() {
|
||||
return &b.altair.ParentRoot
|
||||
return Root(b.altair.ParentRoot)
|
||||
}
|
||||
|
||||
if b.IsPhase0() {
|
||||
return &b.phase0.ParentRoot
|
||||
return Root(b.phase0.ParentRoot)
|
||||
}
|
||||
|
||||
return nil
|
||||
return Root{}
|
||||
}
|
||||
|
||||
func (b *BeaconBlock) StateRoot() *common.Root {
|
||||
func (b *BeaconBlock) StateRoot() Root {
|
||||
if b.IsBellatrix() {
|
||||
return &b.bellatrix.StateRoot
|
||||
return Root(b.bellatrix.StateRoot)
|
||||
}
|
||||
|
||||
if b.IsAltair() {
|
||||
return &b.altair.StateRoot
|
||||
return Root(b.altair.StateRoot)
|
||||
}
|
||||
|
||||
if b.IsPhase0() {
|
||||
return &b.phase0.StateRoot
|
||||
return Root(b.phase0.StateRoot)
|
||||
}
|
||||
|
||||
return nil
|
||||
return Root{}
|
||||
}
|
||||
|
||||
func (b *BeaconBlock) Body() *BeaconBlockBody {
|
||||
@ -241,36 +246,36 @@ func (b *BeaconBlockBody) IsPhase0() bool {
|
||||
return b.phase0 != nil
|
||||
}
|
||||
|
||||
func (b *BeaconBlockBody) Eth1Data() *common.Eth1Data {
|
||||
func (b *BeaconBlockBody) Eth1Data() Eth1Data {
|
||||
if b.IsBellatrix() {
|
||||
return &b.bellatrix.Eth1Data
|
||||
return Eth1Data(b.bellatrix.Eth1Data)
|
||||
}
|
||||
|
||||
if b.IsAltair() {
|
||||
return &b.altair.Eth1Data
|
||||
return Eth1Data(b.altair.Eth1Data)
|
||||
}
|
||||
|
||||
if b.IsPhase0() {
|
||||
return &b.phase0.Eth1Data
|
||||
return Eth1Data(b.phase0.Eth1Data)
|
||||
}
|
||||
|
||||
return nil
|
||||
return Eth1Data{}
|
||||
}
|
||||
|
||||
func (b *BeaconBlock) HashTreeRoot() common.Root {
|
||||
func (b *BeaconBlock) HashTreeRoot() Root {
|
||||
if b.IsBellatrix() {
|
||||
return b.bellatrix.HashTreeRoot(configs.Mainnet, tree.Hash)
|
||||
return Root(b.bellatrix.HashTreeRoot(configs.Mainnet, tree.Hash))
|
||||
}
|
||||
|
||||
if b.IsAltair() {
|
||||
return b.altair.HashTreeRoot(configs.Mainnet, tree.Hash)
|
||||
return Root(b.altair.HashTreeRoot(configs.Mainnet, tree.Hash))
|
||||
}
|
||||
|
||||
if b.IsPhase0() {
|
||||
return b.phase0.HashTreeRoot(configs.Mainnet, tree.Hash)
|
||||
return Root(b.phase0.HashTreeRoot(configs.Mainnet, tree.Hash))
|
||||
}
|
||||
|
||||
return common.Root{}
|
||||
return Root{}
|
||||
}
|
||||
|
||||
func (s *BeaconState) UnmarshalSSZ(ssz []byte) error {
|
||||
@ -349,37 +354,37 @@ func (s *BeaconState) IsPhase0() bool {
|
||||
return s.phase0 != nil
|
||||
}
|
||||
|
||||
func (s *BeaconState) Slot() common.Slot {
|
||||
func (s *BeaconState) Slot() Slot {
|
||||
if s.IsBellatrix() {
|
||||
return s.bellatrix.Slot
|
||||
return Slot(s.bellatrix.Slot)
|
||||
}
|
||||
|
||||
if s.IsAltair() {
|
||||
return s.altair.Slot
|
||||
return Slot(s.altair.Slot)
|
||||
}
|
||||
|
||||
if s.IsPhase0() {
|
||||
return s.phase0.Slot
|
||||
return Slot(s.phase0.Slot)
|
||||
}
|
||||
|
||||
// TODO(telackey): Something better than 0?
|
||||
return 0
|
||||
}
|
||||
|
||||
func (b *BeaconState) HashTreeRoot() common.Root {
|
||||
func (b *BeaconState) HashTreeRoot() Root {
|
||||
if b.IsBellatrix() {
|
||||
return b.bellatrix.HashTreeRoot(configs.Mainnet, tree.Hash)
|
||||
return Root(b.bellatrix.HashTreeRoot(configs.Mainnet, tree.Hash))
|
||||
}
|
||||
|
||||
if b.IsAltair() {
|
||||
return b.altair.HashTreeRoot(configs.Mainnet, tree.Hash)
|
||||
return Root(b.altair.HashTreeRoot(configs.Mainnet, tree.Hash))
|
||||
}
|
||||
|
||||
if b.IsPhase0() {
|
||||
return b.phase0.HashTreeRoot(configs.Mainnet, tree.Hash)
|
||||
return Root(b.phase0.HashTreeRoot(configs.Mainnet, tree.Hash))
|
||||
}
|
||||
|
||||
return common.Root{}
|
||||
return Root{}
|
||||
}
|
||||
|
||||
func (s *BeaconState) GetBellatrix() *bellatrix.BeaconState {
|
||||
|
1
pkg/beaconclient/eth2.0-spec-tests
Symbolic link
1
pkg/beaconclient/eth2.0-spec-tests
Symbolic link
@ -0,0 +1 @@
|
||||
../../../external/eth2.0-spec-tests
|
@ -23,7 +23,6 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/protolambda/zrnt/eth2/beacon/common"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -272,7 +271,7 @@ func (ps *ProcessSlot) getSignedBeaconBlock(serverAddress string) error {
|
||||
ps.FullSignedBeaconBlock = signedBeaconBlock
|
||||
ps.SszSignedBeaconBlock = sszSignedBeaconBlock
|
||||
|
||||
ps.ParentBlockRoot = rootToHex(ps.FullSignedBeaconBlock.Block().ParentRoot())
|
||||
ps.ParentBlockRoot = toHex(ps.FullSignedBeaconBlock.Block().ParentRoot())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -306,7 +305,7 @@ func (ps *ProcessSlot) getBeaconState(serverEndpoint string) error {
|
||||
|
||||
// Check to make sure that the previous block we processed is the parent of the current block.
|
||||
func (ps *ProcessSlot) checkPreviousSlot(tx sql.Tx, ctx context.Context, previousSlot int, previousBlockRoot string, knownGapsTableIncrement int) {
|
||||
parentRoot := rootToHex(ps.FullSignedBeaconBlock.Block().ParentRoot())
|
||||
parentRoot := toHex(ps.FullSignedBeaconBlock.Block().ParentRoot())
|
||||
slot := int(ps.FullBeaconState.Slot())
|
||||
if previousSlot == slot {
|
||||
log.WithFields(log.Fields{
|
||||
@ -369,7 +368,7 @@ func (ps *ProcessSlot) provideFinalHash() (string, string, string, error) {
|
||||
if ps.StateRoot != "" {
|
||||
stateRoot = ps.StateRoot
|
||||
} else {
|
||||
stateRoot = rootToHex(ps.FullSignedBeaconBlock.Block().StateRoot())
|
||||
stateRoot = toHex(ps.FullSignedBeaconBlock.Block().StateRoot())
|
||||
log.Debug("StateRoot: ", stateRoot)
|
||||
}
|
||||
|
||||
@ -377,14 +376,14 @@ func (ps *ProcessSlot) provideFinalHash() (string, string, string, error) {
|
||||
blockRoot = ps.BlockRoot
|
||||
} else {
|
||||
rawBlockRoot := ps.FullSignedBeaconBlock.Block().HashTreeRoot()
|
||||
blockRoot = rootToHex(&rawBlockRoot)
|
||||
blockRoot = toHex(rawBlockRoot)
|
||||
log.WithFields(log.Fields{"blockRoot": blockRoot}).Debug("Block Root from ssz")
|
||||
}
|
||||
eth1BlockHash = rootToHex(&ps.FullSignedBeaconBlock.Block().Body().Eth1Data().BlockHash)
|
||||
eth1BlockHash = toHex(ps.FullSignedBeaconBlock.Block().Body().Eth1Data().BlockHash)
|
||||
}
|
||||
return blockRoot, stateRoot, eth1BlockHash, nil
|
||||
}
|
||||
|
||||
func rootToHex(r *common.Root) string {
|
||||
func toHex(r [32]byte) string {
|
||||
return "0x" + hex.EncodeToString(r[:])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user