Compare commits

...

2 Commits

Author SHA1 Message Date
terence tsao
63a8b0804e passing 2022-02-08 15:18:09 -08:00
terence tsao
f572ba9d56 Add forkchoice spec tests 2022-02-07 16:45:20 -08:00
27 changed files with 297 additions and 55 deletions

View File

@@ -12,7 +12,7 @@ import (
// is_parent_total_difficulty_valid = parent.total_difficulty < TERMINAL_TOTAL_DIFFICULTY
// return is_total_difficulty_reached and is_parent_total_difficulty_valid
func validTerminalPowBlock(currentDifficulty *uint256.Int, parentDifficulty *uint256.Int) bool {
ttd := uint256.NewInt(params.BeaconConfig().TerminalTotalDifficulty)
ttd := params.BeaconConfig().TerminalTotalDifficulty
totalDifficultyReached := currentDifficulty.Cmp(ttd) >= 0
parentTotalDifficultyValid := ttd.Cmp(parentDifficulty) > 0
return totalDifficultyReached && parentTotalDifficultyValid

View File

@@ -61,7 +61,7 @@ func Test_validTerminalPowBlock(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := params.BeaconConfig()
cfg.TerminalTotalDifficulty = tt.ttd
cfg.TerminalTotalDifficulty = uint256.NewInt(tt.ttd)
params.OverrideBeaconConfig(cfg)
if got := validTerminalPowBlock(tt.currentDifficulty, tt.parentDifficulty); got != tt.want {
t.Errorf("validTerminalPowBlock() = %v, want %v", got, tt.want)

View File

@@ -697,10 +697,16 @@ func (s *Service) validateTerminalBlock(b block.SignedBeaconBlock) error {
if err != nil {
return errors.Wrap(err, "could not get transition block")
}
if transitionBlk == nil {
return errors.New("transition block is nil")
}
parentTransitionBlk, err := s.cfg.ExecutionEngineCaller.ExecutionBlockByHash(common.HexToHash(transitionBlk.ParentHash))
if err != nil {
return errors.Wrap(err, "could not get transition parent block")
}
if parentTransitionBlk == nil {
return errors.New("transition parent block is nil")
}
transitionBlkTTD, err := uint256.FromHex(transitionBlk.TotalDifficulty)
if err != nil {
return err
@@ -709,6 +715,7 @@ func (s *Service) validateTerminalBlock(b block.SignedBeaconBlock) error {
if err != nil {
return err
}
if !validTerminalPowBlock(transitionBlkTTD, transitionParentBlkTTD) {
return errors.New("invalid difficulty for terminal block")
}
@@ -717,9 +724,9 @@ func (s *Service) validateTerminalBlock(b block.SignedBeaconBlock) error {
"slot": b.Block().Slot(),
"transitionBlockHash": common.BytesToHash(payload.ParentHash).String(),
"transitionBlockParentHash": common.HexToHash(transitionBlk.ParentHash).String(),
"terminalTotalDifficulty": uint256.NewInt(params.BeaconConfig().TerminalTotalDifficulty).Uint64(),
"transitionBlockTotalDifficulty": transitionBlkTTD.Uint64(),
"transitionBlockParentTotalDifficulty": transitionParentBlkTTD.Uint64(),
"terminalTotalDifficulty": params.BeaconConfig().TerminalTotalDifficulty,
"transitionBlockTotalDifficulty": transitionBlkTTD,
"transitionBlockParentTotalDifficulty": transitionParentBlkTTD,
}).Info("Verified terminal block")
return nil

View File

@@ -19,6 +19,7 @@ go_library(
"//beacon-chain:__subpackages__",
"//cmd/beacon-chain:__subpackages__",
"//contracts:__subpackages__",
"//testing/spectest:__subpackages__",
],
deps = [
"//beacon-chain/cache/depositcache:go_default_library",

View File

@@ -106,6 +106,7 @@ go_test(
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_grpc_ecosystem_grpc_gateway_v2//runtime:go_default_library",
"@com_github_holiman_uint256//:go_default_library",
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_wealdtech_go_bytesutil//:go_default_library",

View File

@@ -6,6 +6,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
@@ -99,7 +100,7 @@ func TestGetSpec(t *testing.T) {
config.MinSyncCommitteeParticipants = 71
config.TerminalBlockHash = common.HexToHash("TerminalBlockHash")
config.TerminalBlockHashActivationEpoch = 72
config.TerminalTotalDifficulty = 73
config.TerminalTotalDifficulty = uint256.NewInt(73)
config.FeeRecipient = common.HexToAddress("FeeRecipient")
var dbp [4]byte

View File

@@ -3,7 +3,6 @@ package validator
import (
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth/catalyst"
@@ -218,9 +217,7 @@ func (vs *Server) getPowBlockHashAtTerminalTotalDifficulty(ctx context.Context)
return nil, false, nil
}
terminalTotalDifficulty := new(big.Int)
terminalTotalDifficulty.SetUint64(params.BeaconConfig().TerminalTotalDifficulty)
terminalTotalDifficulty := params.BeaconConfig().TerminalTotalDifficulty.ToBig()
currentTotalDifficulty := common.HexToHash(blk.TotalDifficulty).Big()
parentTotalDifficulty := common.HexToHash(parentBlk.TotalDifficulty).Big()
blkNumber := blk.Number

View File

@@ -1,5 +1,5 @@
// Code generated by fastssz. DO NOT EDIT.
// Hash: 6de36f732d72b5c4c0c967bc0edcc752b7afdd337e829486954eb6affda84da8
// Hash: 2e923b42b8e4fcc278301da6506b212334a78169cb32c70e0d66a636435b8925
package v1
import (

2
beacon-chain/state/state-native/v2/generated.ssz.go Executable file → Normal file
View File

@@ -1,5 +1,5 @@
// Code generated by fastssz. DO NOT EDIT.
// Hash: 6a7886393e8874ccf57ea6c160647da09f5e541234a235ee71f3bf786d56a100
// Hash: ec98b14e43fd11e74e0d9e705a7afe74a77706c3e215d7940b11411859873f4b
package v2
import (

View File

@@ -1,5 +1,5 @@
// Code generated by fastssz. DO NOT EDIT.
// Hash: a71c6e70ae416774612961057f4c96b97b5c3323270a80167d30ea672ea2f5cd
// Hash: aa2156293aac4326afe2b8c0ba985a0291c83f20c8d8b92d148bc810a7f442e9
package v3
import (

View File

@@ -25,6 +25,7 @@ go_library(
"//math:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//params:go_default_library",
"@com_github_holiman_uint256//:go_default_library",
"@com_github_mohae_deepcopy//:go_default_library",
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

View File

@@ -5,6 +5,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
)
@@ -188,7 +189,7 @@ type BeaconChainConfig struct {
// Bellatrix
TerminalBlockHash common.Hash `yaml:"TERMINAL_BLOCK_HASH" spec:"true"` // TerminalBlockHash of beacon chain.
TerminalBlockHashActivationEpoch types.Epoch `yaml:"TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH" spec:"true"` // TerminalBlockHashActivationEpoch of beacon chain.
TerminalTotalDifficulty uint64 `yaml:"TERMINAL_TOTAL_DIFFICULTY" spec:"true"` // TerminalTotalDifficulty is part of the experimental Bellatrix spec. This value is type is currently TBD: https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#transition-settings
TerminalTotalDifficulty *uint256.Int `yaml:"TERMINAL_TOTAL_DIFFICULTY" spec:"true"` // TerminalTotalDifficulty is part of the experimental Bellatrix spec. This value is type is currently TBD: https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#transition-settings
FeeRecipient common.Address // FeeRecipient where the transaction fee goes to.
}

View File

@@ -4,6 +4,7 @@ import (
"math"
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
)
// UseMergeTestNetworkConfig uses the Merge specific
@@ -38,7 +39,7 @@ func KintsugiTestnetConfig() *BeaconChainConfig {
cfg.AltairForkEpoch = 10
cfg.BellatrixForkVersion = []byte{0x62, 0x00, 0x00, 0x71}
cfg.BellatrixForkEpoch = 20
cfg.TerminalTotalDifficulty = 5000000000
cfg.TerminalTotalDifficulty = uint256.NewInt(5000000000)
cfg.TerminalBlockHash = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
cfg.TerminalBlockHashActivationEpoch = 18446744073709551615
cfg.ShardingForkVersion = []byte{0x03, 0x00, 0x00, 0x00}

View File

@@ -2,6 +2,7 @@ package params
import (
eth1Params "github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)
// UsePraterNetworkConfig uses the Prater specific
@@ -43,7 +44,7 @@ func PraterConfig() *BeaconChainConfig {
cfg.AltairForkVersion = []byte{0x1, 0x0, 0x10, 0x20}
cfg.ShardingForkVersion = []byte{0x3, 0x0, 0x10, 0x20}
cfg.BellatrixForkVersion = []byte{0x2, 0x0, 0x10, 0x20}
cfg.TerminalTotalDifficulty = 4294967296
cfg.TerminalTotalDifficulty = uint256.NewInt(4294967296)
cfg.DepositContractAddress = "0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b"
return cfg
}

View File

@@ -1,5 +1,5 @@
// Code generated by fastssz. DO NOT EDIT.
// Hash: dc04c886a976aeec2f44be5d57a2afbc88a4811ff4c318c6786b60e8749e5fd7
// Hash: a9ca79248a2934a60aa64037e6c99f4407b0f1859d60dfc3a01389529682d36b
package v1
import (

View File

@@ -103,6 +103,7 @@ ssz_gen_marshal(
"SigningData",
"SyncCommittee",
"SyncAggregatorSelectionData",
"PowBlock",
],
)

View File

@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc-gen-go v1.27.1
// protoc v3.15.8
// source: proto/prysm/v1alpha1/beacon_state.proto
@@ -10,7 +10,6 @@ import (
reflect "reflect"
sync "sync"
proto "github.com/golang/protobuf/proto"
github_com_prysmaticlabs_eth2_types "github.com/prysmaticlabs/eth2-types"
github_com_prysmaticlabs_go_bitfield "github.com/prysmaticlabs/go-bitfield"
_ "github.com/prysmaticlabs/prysm/proto/eth/ext"
@@ -25,10 +24,6 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type BeaconState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -1463,6 +1458,69 @@ func (x *ExecutionPayloadHeader) GetTransactionsRoot() []byte {
return nil
}
type PowBlock struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
BlockHash []byte `protobuf:"bytes,1,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty" ssz-size:"32"`
ParentHash []byte `protobuf:"bytes,2,opt,name=parent_hash,json=parentHash,proto3" json:"parent_hash,omitempty" ssz-size:"32"`
TotalDifficulty []byte `protobuf:"bytes,3,opt,name=total_difficulty,json=totalDifficulty,proto3" json:"total_difficulty,omitempty" ssz-size:"32"`
}
func (x *PowBlock) Reset() {
*x = PowBlock{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PowBlock) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PowBlock) ProtoMessage() {}
func (x *PowBlock) ProtoReflect() protoreflect.Message {
mi := &file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes[14]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PowBlock.ProtoReflect.Descriptor instead.
func (*PowBlock) Descriptor() ([]byte, []int) {
return file_proto_prysm_v1alpha1_beacon_state_proto_rawDescGZIP(), []int{14}
}
func (x *PowBlock) GetBlockHash() []byte {
if x != nil {
return x.BlockHash
}
return nil
}
func (x *PowBlock) GetParentHash() []byte {
if x != nil {
return x.ParentHash
}
return nil
}
func (x *PowBlock) GetTotalDifficulty() []byte {
if x != nil {
return x.TotalDifficulty
}
return nil
}
var File_proto_prysm_v1alpha1_beacon_state_proto protoreflect.FileDescriptor
var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{
@@ -1931,7 +1989,16 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{
0x68, 0x12, 0x33, 0x0a, 0x11, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5,
0x18, 0x02, 0x33, 0x32, 0x52, 0x10, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x73, 0x52, 0x6f, 0x6f, 0x74, 0x42, 0x98, 0x01, 0x0a, 0x19, 0x6f, 0x72, 0x67, 0x2e, 0x65,
0x6e, 0x73, 0x52, 0x6f, 0x6f, 0x74, 0x22, 0x8d, 0x01, 0x0a, 0x08, 0x50, 0x6f, 0x77, 0x42, 0x6c,
0x6f, 0x63, 0x6b, 0x12, 0x25, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, 0x73,
0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52,
0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, 0x27, 0x0a, 0x0b, 0x70, 0x61,
0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42,
0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x48,
0x61, 0x73, 0x68, 0x12, 0x31, 0x0a, 0x10, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x64, 0x69, 0x66,
0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a,
0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x44, 0x69, 0x66, 0x66,
0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x42, 0x98, 0x01, 0x0a, 0x19, 0x6f, 0x72, 0x67, 0x2e, 0x65,
0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c,
0x70, 0x68, 0x61, 0x31, 0x42, 0x10, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74,
0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
@@ -1956,7 +2023,7 @@ func file_proto_prysm_v1alpha1_beacon_state_proto_rawDescGZIP() []byte {
return file_proto_prysm_v1alpha1_beacon_state_proto_rawDescData
}
var file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
var file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes = make([]protoimpl.MessageInfo, 15)
var file_proto_prysm_v1alpha1_beacon_state_proto_goTypes = []interface{}{
(*BeaconState)(nil), // 0: ethereum.eth.v1alpha1.BeaconState
(*BeaconStateAltair)(nil), // 1: ethereum.eth.v1alpha1.BeaconStateAltair
@@ -1972,43 +2039,44 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_goTypes = []interface{}{
(*SyncAggregatorSelectionData)(nil), // 11: ethereum.eth.v1alpha1.SyncAggregatorSelectionData
(*BeaconStateBellatrix)(nil), // 12: ethereum.eth.v1alpha1.BeaconStateBellatrix
(*ExecutionPayloadHeader)(nil), // 13: ethereum.eth.v1alpha1.ExecutionPayloadHeader
(*BeaconBlockHeader)(nil), // 14: ethereum.eth.v1alpha1.BeaconBlockHeader
(*Eth1Data)(nil), // 15: ethereum.eth.v1alpha1.Eth1Data
(*Validator)(nil), // 16: ethereum.eth.v1alpha1.Validator
(*Checkpoint)(nil), // 17: ethereum.eth.v1alpha1.Checkpoint
(*AttestationData)(nil), // 18: ethereum.eth.v1alpha1.AttestationData
(*PowBlock)(nil), // 14: ethereum.eth.v1alpha1.PowBlock
(*BeaconBlockHeader)(nil), // 15: ethereum.eth.v1alpha1.BeaconBlockHeader
(*Eth1Data)(nil), // 16: ethereum.eth.v1alpha1.Eth1Data
(*Validator)(nil), // 17: ethereum.eth.v1alpha1.Validator
(*Checkpoint)(nil), // 18: ethereum.eth.v1alpha1.Checkpoint
(*AttestationData)(nil), // 19: ethereum.eth.v1alpha1.AttestationData
}
var file_proto_prysm_v1alpha1_beacon_state_proto_depIdxs = []int32{
2, // 0: ethereum.eth.v1alpha1.BeaconState.fork:type_name -> ethereum.eth.v1alpha1.Fork
14, // 1: ethereum.eth.v1alpha1.BeaconState.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader
15, // 2: ethereum.eth.v1alpha1.BeaconState.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data
15, // 3: ethereum.eth.v1alpha1.BeaconState.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data
16, // 4: ethereum.eth.v1alpha1.BeaconState.validators:type_name -> ethereum.eth.v1alpha1.Validator
15, // 1: ethereum.eth.v1alpha1.BeaconState.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader
16, // 2: ethereum.eth.v1alpha1.BeaconState.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data
16, // 3: ethereum.eth.v1alpha1.BeaconState.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data
17, // 4: ethereum.eth.v1alpha1.BeaconState.validators:type_name -> ethereum.eth.v1alpha1.Validator
3, // 5: ethereum.eth.v1alpha1.BeaconState.previous_epoch_attestations:type_name -> ethereum.eth.v1alpha1.PendingAttestation
3, // 6: ethereum.eth.v1alpha1.BeaconState.current_epoch_attestations:type_name -> ethereum.eth.v1alpha1.PendingAttestation
17, // 7: ethereum.eth.v1alpha1.BeaconState.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
17, // 8: ethereum.eth.v1alpha1.BeaconState.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
17, // 9: ethereum.eth.v1alpha1.BeaconState.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 7: ethereum.eth.v1alpha1.BeaconState.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 8: ethereum.eth.v1alpha1.BeaconState.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 9: ethereum.eth.v1alpha1.BeaconState.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
2, // 10: ethereum.eth.v1alpha1.BeaconStateAltair.fork:type_name -> ethereum.eth.v1alpha1.Fork
14, // 11: ethereum.eth.v1alpha1.BeaconStateAltair.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader
15, // 12: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data
15, // 13: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data
16, // 14: ethereum.eth.v1alpha1.BeaconStateAltair.validators:type_name -> ethereum.eth.v1alpha1.Validator
17, // 15: ethereum.eth.v1alpha1.BeaconStateAltair.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
17, // 16: ethereum.eth.v1alpha1.BeaconStateAltair.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
17, // 17: ethereum.eth.v1alpha1.BeaconStateAltair.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
15, // 11: ethereum.eth.v1alpha1.BeaconStateAltair.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader
16, // 12: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data
16, // 13: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data
17, // 14: ethereum.eth.v1alpha1.BeaconStateAltair.validators:type_name -> ethereum.eth.v1alpha1.Validator
18, // 15: ethereum.eth.v1alpha1.BeaconStateAltair.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 16: ethereum.eth.v1alpha1.BeaconStateAltair.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 17: ethereum.eth.v1alpha1.BeaconStateAltair.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
10, // 18: ethereum.eth.v1alpha1.BeaconStateAltair.current_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee
10, // 19: ethereum.eth.v1alpha1.BeaconStateAltair.next_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee
18, // 20: ethereum.eth.v1alpha1.PendingAttestation.data:type_name -> ethereum.eth.v1alpha1.AttestationData
19, // 20: ethereum.eth.v1alpha1.PendingAttestation.data:type_name -> ethereum.eth.v1alpha1.AttestationData
2, // 21: ethereum.eth.v1alpha1.CheckPtInfo.fork:type_name -> ethereum.eth.v1alpha1.Fork
2, // 22: ethereum.eth.v1alpha1.BeaconStateBellatrix.fork:type_name -> ethereum.eth.v1alpha1.Fork
14, // 23: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader
15, // 24: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data
15, // 25: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data
16, // 26: ethereum.eth.v1alpha1.BeaconStateBellatrix.validators:type_name -> ethereum.eth.v1alpha1.Validator
17, // 27: ethereum.eth.v1alpha1.BeaconStateBellatrix.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
17, // 28: ethereum.eth.v1alpha1.BeaconStateBellatrix.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
17, // 29: ethereum.eth.v1alpha1.BeaconStateBellatrix.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
15, // 23: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader
16, // 24: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data
16, // 25: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data
17, // 26: ethereum.eth.v1alpha1.BeaconStateBellatrix.validators:type_name -> ethereum.eth.v1alpha1.Validator
18, // 27: ethereum.eth.v1alpha1.BeaconStateBellatrix.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 28: ethereum.eth.v1alpha1.BeaconStateBellatrix.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
18, // 29: ethereum.eth.v1alpha1.BeaconStateBellatrix.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint
10, // 30: ethereum.eth.v1alpha1.BeaconStateBellatrix.current_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee
10, // 31: ethereum.eth.v1alpha1.BeaconStateBellatrix.next_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee
13, // 32: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_execution_payload_header:type_name -> ethereum.eth.v1alpha1.ExecutionPayloadHeader
@@ -2196,6 +2264,18 @@ func file_proto_prysm_v1alpha1_beacon_state_proto_init() {
return nil
}
}
file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PowBlock); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -2203,7 +2283,7 @@ func file_proto_prysm_v1alpha1_beacon_state_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc,
NumEnums: 0,
NumMessages: 14,
NumMessages: 15,
NumExtensions: 0,
NumServices: 0,
},

View File

@@ -251,3 +251,9 @@ message ExecutionPayloadHeader {
bytes block_hash = 13 [(ethereum.eth.ext.ssz_size) = "32"];
bytes transactions_root = 14 [(ethereum.eth.ext.ssz_size) = "32"];
}
message PowBlock {
bytes block_hash = 1 [(ethereum.eth.ext.ssz_size) = "32"];
bytes parent_hash = 2 [(ethereum.eth.ext.ssz_size) = "32"];
bytes total_difficulty = 3 [(ethereum.eth.ext.ssz_size) = "32"];
}

View File

@@ -0,0 +1,14 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["forkchoice_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
tags = ["spectest"],
deps = [
"//runtime/version:go_default_library",
"//testing/spectest/shared/common/forkchoice:go_default_library",
],
)

View File

@@ -0,0 +1,12 @@
package forkchoice
import (
"testing"
"github.com/prysmaticlabs/prysm/runtime/version"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/common/forkchoice"
)
func TestMainnet_Bellatrix_Forkchoice(t *testing.T) {
forkchoice.Run(t, "mainnet", version.Bellatrix)
}

View File

@@ -0,0 +1,18 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["forkchoice_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_minimal//:test_data",
],
eth_network = "minimal",
tags = [
"minimal",
"spectest",
],
deps = [
"//runtime/version:go_default_library",
"//testing/spectest/shared/common/forkchoice:go_default_library",
],
)

View File

@@ -0,0 +1,12 @@
package forkchoice
import (
"testing"
"github.com/prysmaticlabs/prysm/runtime/version"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/common/forkchoice"
)
func TestMinimal_Bellatrix_Forkchoice(t *testing.T) {
forkchoice.Run(t, "minimal", version.Bellatrix)
}

View File

@@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
testonly = True,
srcs = [
"execution_engine_mock.go",
"runner.go",
"service.go",
"type.go",
@@ -18,6 +19,7 @@ go_library(
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/v1:go_default_library",
@@ -34,7 +36,10 @@ go_library(
"//testing/spectest/utils:go_default_library",
"//testing/util:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//eth/catalyst:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@com_github_holiman_uint256//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
],
)

View File

@@ -0,0 +1,55 @@
package forkchoice
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/holiman/uint256"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
type ExecutionEngineMock struct {
powBlocks map[[32]byte]*eth.PowBlock
}
func (m *ExecutionEngineMock) PreparePayload(context.Context, catalyst.ForkchoiceStateV1, catalyst.PayloadAttributesV1) (string, error) {
return "", nil
}
func (m *ExecutionEngineMock) GetPayload(context.Context, string) (*catalyst.ExecutableDataV1, error) {
return nil, nil
}
func (m *ExecutionEngineMock) NotifyForkChoiceValidated(context.Context, catalyst.ForkchoiceStateV1) error {
return nil
}
func (m *ExecutionEngineMock) ExecutePayload(context.Context, *catalyst.ExecutableDataV1) ([]byte, error) {
return nil, nil
}
func (m *ExecutionEngineMock) LatestExecutionBlock() (*powchain.ExecutionBlock, error) {
return nil, nil
}
func (m *ExecutionEngineMock) ExecutionBlockByHash(blockHash common.Hash) (*powchain.ExecutionBlock, error) {
b, ok := m.powBlocks[bytesutil.ToBytes32(blockHash.Bytes())]
if !ok {
return nil, nil
}
tdInBigEndian := bytesutil.ReverseByteOrder(b.TotalDifficulty)
tdBigint := new(big.Int)
tdBigint.SetBytes(tdInBigEndian)
td256, of := uint256.FromBig(tdBigint)
if of {
return nil, errors.New("could not convert big.Int to uint256")
}
return &powchain.ExecutionBlock{
ParentHash: common.Bytes2Hex(b.ParentHash),
TotalDifficulty: td256.String(),
Hash: common.Bytes2Hex(b.BlockHash),
}, nil
}

View File

@@ -3,12 +3,14 @@ package forkchoice
import (
"context"
"fmt"
"math/big"
"path"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/golang/snappy"
"github.com/holiman/uint256"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
@@ -53,6 +55,15 @@ func Run(t *testing.T, config string, fork int) {
blockSSZ, err := snappy.Decode(nil /* dst */, blockFile)
require.NoError(t, err)
cfg := params.BeaconConfig()
b, _ := new(big.Int).SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10)
ttd, of := uint256.FromBig(b)
if of {
t.Fatal("Could not set big int")
}
cfg.TerminalTotalDifficulty = ttd
params.OverrideBeaconConfig(cfg)
var beaconState state.BeaconState
var beaconBlock block.SignedBeaconBlock
switch fork {
@@ -69,7 +80,10 @@ func Run(t *testing.T, config string, fork int) {
t.Fatalf("unknown fork version: %v", fork)
}
service := startChainService(t, beaconState, beaconBlock)
execMock := &ExecutionEngineMock{
powBlocks: make(map[[32]byte]*ethpb.PowBlock),
}
service := startChainService(t, beaconState, beaconBlock, execMock)
var lastTick int64
for _, step := range steps {
if step.Tick != nil {
@@ -114,6 +128,18 @@ func Run(t *testing.T, config string, fork int) {
require.NoError(t, att.UnmarshalSSZ(attSSZ), "Failed to unmarshal")
require.NoError(t, service.OnAttestation(ctx, att))
}
if step.PowBlock != nil {
powBlockFile, err := util.BazelFileBytes(testsFolderPath, folder.Name(), fmt.Sprint(*step.PowBlock, ".ssz_snappy"))
require.NoError(t, err)
p, err := snappy.Decode(nil /* dst */, powBlockFile)
require.NoError(t, err)
pb := &ethpb.PowBlock{}
require.NoError(t, pb.UnmarshalSSZ(p), "Failed to unmarshal")
execMock.powBlocks[bytesutil.ToBytes32(pb.BlockHash)] = pb
tdInBigEndian := bytesutil.ReverseByteOrder(pb.TotalDifficulty)
tdBigint := new(big.Int)
tdBigint.SetBytes(tdInBigEndian)
}
if step.Check != nil {
require.NoError(t, service.UpdateHeadWithBalances(ctx))
c := step.Check

View File

@@ -19,7 +19,7 @@ import (
"github.com/prysmaticlabs/prysm/testing/require"
)
func startChainService(t *testing.T, st state.BeaconState, block block.SignedBeaconBlock) *blockchain.Service {
func startChainService(t *testing.T, st state.BeaconState, block block.SignedBeaconBlock, engineMock *ExecutionEngineMock) *blockchain.Service {
db := testDB.SetupDB(t)
ctx := context.Background()
require.NoError(t, db.SaveBlock(ctx, block))
@@ -42,6 +42,7 @@ func startChainService(t *testing.T, st state.BeaconState, block block.SignedBea
require.NoError(t, err)
opts := append([]blockchain.Option{},
blockchain.WithExecutionEngineCaller(engineMock),
blockchain.WithFinalizedStateAtStartUp(st),
blockchain.WithDatabase(db),
blockchain.WithAttestationService(attPool),

View File

@@ -5,6 +5,7 @@ type Step struct {
Block *string `json:"block"`
Valid *bool `json:"valid"`
Attestation *string `json:"attestation"`
PowBlock *string `json:"pow_block"`
Check *Check `json:"checks"`
}