mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Compare commits
2 Commits
ba2333069a
...
shadowFork
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0d1d4f75e | ||
|
|
9cba1012f2 |
21
beacon-chain/cache/committee.go
vendored
21
beacon-chain/cache/committee.go
vendored
@@ -44,6 +44,7 @@ type CommitteeCache struct {
|
||||
CommitteeCache *lru.Cache
|
||||
lock sync.RWMutex
|
||||
inProgress map[string]bool
|
||||
disabled bool
|
||||
}
|
||||
|
||||
// committeeKeyFn takes the seed as the key to retrieve shuffled indices of a committee in a given epoch.
|
||||
@@ -63,9 +64,20 @@ func NewCommitteesCache() *CommitteeCache {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CommitteeCache) Disable() {
|
||||
c.disabled = true
|
||||
}
|
||||
|
||||
func (c *CommitteeCache) Enable() {
|
||||
c.disabled = false
|
||||
}
|
||||
|
||||
// Committee fetches the shuffled indices by slot and committee index. Every list of indices
|
||||
// represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil.
|
||||
func (c *CommitteeCache) Committee(ctx context.Context, slot types.Slot, seed [32]byte, index types.CommitteeIndex) ([]types.ValidatorIndex, error) {
|
||||
if c.disabled {
|
||||
return nil, nil
|
||||
}
|
||||
if err := c.checkInProgress(ctx, seed); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -116,6 +128,9 @@ func (c *CommitteeCache) AddCommitteeShuffledList(committees *Committees) error
|
||||
|
||||
// ActiveIndices returns the active indices of a given seed stored in cache.
|
||||
func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]types.ValidatorIndex, error) {
|
||||
if c.disabled {
|
||||
return nil, nil
|
||||
}
|
||||
if err := c.checkInProgress(ctx, seed); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -138,6 +153,9 @@ func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]ty
|
||||
|
||||
// ActiveIndicesCount returns the active indices count of a given seed stored in cache.
|
||||
func (c *CommitteeCache) ActiveIndicesCount(ctx context.Context, seed [32]byte) (int, error) {
|
||||
if c.disabled {
|
||||
return 0, nil
|
||||
}
|
||||
if err := c.checkInProgress(ctx, seed); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -160,6 +178,9 @@ func (c *CommitteeCache) ActiveIndicesCount(ctx context.Context, seed [32]byte)
|
||||
|
||||
// HasEntry returns true if the committee cache has a value.
|
||||
func (c *CommitteeCache) HasEntry(seed string) bool {
|
||||
if c.disabled {
|
||||
return false
|
||||
}
|
||||
_, ok := c.CommitteeCache.Get(seed)
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -28,6 +28,14 @@ var (
|
||||
proposerIndicesCache = cache.NewProposerIndicesCache()
|
||||
)
|
||||
|
||||
func EnableComCache() {
|
||||
committeeCache.Enable()
|
||||
}
|
||||
|
||||
func DisableComCache() {
|
||||
committeeCache.Disable()
|
||||
}
|
||||
|
||||
// SlotCommitteeCount returns the number of beacon committees of a slot. The
|
||||
// active validator count is provided as an argument rather than an imported implementation
|
||||
// from the spec definition. Having the active validator count as an argument allows for
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SkipSlotCache exists for the unlikely scenario that is a large gap between the head state and
|
||||
@@ -28,5 +29,6 @@ func cacheKey(_ context.Context, state state.ReadOnlyBeaconState) ([32]byte, err
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
logrus.Infof("checking with cache key of slot %d and root %#x", state.Slot(), r)
|
||||
return hash.Hash(append(bytesutil.Bytes32(uint64(state.Slot())), r[:]...)), nil
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cachedState != nil && !cachedState.IsNil() && cachedState.Slot() < slot {
|
||||
if cachedState != nil && !cachedState.IsNil() && cachedState.Slot() <= slot {
|
||||
highestSlot = cachedState.Slot()
|
||||
state = cachedState
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cachedState != nil && !cachedState.IsNil() && cachedState.Slot() < slot {
|
||||
if cachedState != nil && !cachedState.IsNil() && cachedState.Slot() <= slot {
|
||||
highestSlot = cachedState.Slot()
|
||||
state = cachedState
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func (s *Service) broadcastSyncCommittee(ctx context.Context, subnet uint64, sMs
|
||||
if err := func() error {
|
||||
s.subnetLocker(wrappedSubIdx).Lock()
|
||||
defer s.subnetLocker(wrappedSubIdx).Unlock()
|
||||
ok, err := s.FindPeersWithSubnet(ctx, syncCommitteeToTopic(subnet, forkDigest), subnet, 1)
|
||||
ok, err := s.FindPeersWithSubnet(ctx, syncCommitteeToTopic(subnet, forkDigest), subnet, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func (s *Service) filterPeerForSyncSubnet(index uint64) func(node *enode.Node) b
|
||||
func (s *Service) hasPeerWithSubnet(topic string) bool {
|
||||
// In the event peer threshold is lower, we will choose the lower
|
||||
// threshold.
|
||||
minPeers := mathutil.Min(1, uint64(flags.Get().MinimumPeersPerSubnet))
|
||||
minPeers := mathutil.Min(0, uint64(flags.Get().MinimumPeersPerSubnet))
|
||||
return len(s.pubsub.ListPeers(topic+s.Encoding().ProtocolSuffix())) >= int(minPeers) // lint:ignore uintcast -- Min peers can be safely cast to int.
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ go_library(
|
||||
"//crypto/hash:go_default_library",
|
||||
"//crypto/rand:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//encoding/ssz/equality:go_default_library",
|
||||
"//monitoring/tracing:go_default_library",
|
||||
"//network/forks:go_default_library",
|
||||
"//proto/engine/v1:go_default_library",
|
||||
|
||||
@@ -3,6 +3,10 @@ package validator
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
@@ -16,10 +20,12 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/rand"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/encoding/ssz/equality"
|
||||
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -137,6 +143,49 @@ func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb.
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not compute committee assignments: %v", err)
|
||||
}
|
||||
helpers.DisableComCache()
|
||||
committeeAssignments2, _, err := helpers.CommitteeAssignments(ctx, s, req.Epoch)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not compute committee assignments: %v", err)
|
||||
}
|
||||
helpers.EnableComCache()
|
||||
comMap := make(map[string][]types.ValidatorIndex)
|
||||
comMap2 := make(map[string][]types.ValidatorIndex)
|
||||
for _, v := range committeeAssignments {
|
||||
comMap[fmt.Sprintf("%d,%d", v.CommitteeIndex, v.AttesterSlot)] = v.Committee
|
||||
}
|
||||
for _, v := range committeeAssignments2 {
|
||||
comMap2[fmt.Sprintf("%d,%d", v.CommitteeIndex, v.AttesterSlot)] = v.Committee
|
||||
}
|
||||
for k, v := range comMap {
|
||||
sep := strings.Split(k, ",")
|
||||
comIdx, err := strconv.Atoi(sep[0])
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not compute committee assignments: %v", err)
|
||||
}
|
||||
atSlot, err := strconv.Atoi(sep[1])
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not compute committee assignments: %v", err)
|
||||
}
|
||||
val2, ok := comMap2[k]
|
||||
if !ok {
|
||||
logrus.Infof("Committee Index of %d at slot %d has committee of %v, but no cache shuffle doesnt have it", comIdx, atSlot, v)
|
||||
continue
|
||||
}
|
||||
copiedV := make([]types.ValidatorIndex, len(v))
|
||||
copy(copiedV, v)
|
||||
copiedVal2 := make([]types.ValidatorIndex, len(val2))
|
||||
copy(copiedVal2, v)
|
||||
sort.Slice(copiedV, func(i, j int) bool {
|
||||
return uint64(copiedV[i]) < uint64(copiedV[j])
|
||||
})
|
||||
sort.Slice(copiedVal2, func(i, j int) bool {
|
||||
return uint64(copiedVal2[i]) < uint64(copiedVal2[j])
|
||||
})
|
||||
if !equality.DeepEqual(copiedV, copiedVal2) {
|
||||
logrus.Infof("Committee Index of %d at slot %d has committee of %v, but no cache shuffle has %v", comIdx, atSlot, copiedV, copiedVal2)
|
||||
}
|
||||
}
|
||||
// Query the next epoch assignments for committee subnet subscriptions.
|
||||
nextCommitteeAssignments, _, err := helpers.CommitteeAssignments(ctx, s, req.Epoch+1)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,9 @@ package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -23,6 +26,29 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/testing/util"
|
||||
)
|
||||
|
||||
func TestRandom(t *testing.T) {
|
||||
junk := "134 555 98 1319 237 827 319 1101 1808 821 1788 1490 995 1289 227 1868 996 636 877 38 714 1863 653 1489 1988 1307 437 1910 1660 1030 523 1968 1717 1381 257 357 1466 1521 155 2 1950 1555 510 67 1959 924 1128 70 591 1053 1431 753 212 1476 436 1310 1837 683 99 393 1265 5 1292 487 159 464 1961 852 404 243 368 1124 1075 671 1093 1690 785 1585 1485 1084 1800 51 629 1631 1919 366 313 1028 1331 124 1953 999 1253 559 1887 1415 3 738 1237 132 181 680 1010 1397 1208 150 1257 17 1996 402 1185 757 898 1417 375 1487 232 1658 1274 967 1180 1915 834 1562 542 1554 312 1040 1716 1911 846 93 192 1338 1355 919 361 715 1134 1032 1967 531 1181 634 1546 439 396 1549 211 1760 24 1141 520 978 267 1118 587 1591 876 684 891 187 597 1801 585 841 1793"
|
||||
junk2 := "419 703 1123 1773 1081 1776 1488 780 589 1903 1341 1454 1626 448 671 1896 110 1976 1855 275 1001 283 1471 1617 493 1235 444 1906 1772 1924 1298 1040 773 888 584 520 1286 1482 1531 1619 774 1135 1340 13 1096 1291 1935 535 1716 1148 1121 631 1758 1240 32 391 550 758 1425 1004 1179 1484 1178 1024 735 1145 986 1417 143 1490 108 875 575 471 1948 1257 1878 1862 1106 700 720 992 1677 1239 842 867 1651 1146 706 1073 1622 843 783 816 1670 1988 1249 1373 461 1410 1978 1221 802 1068 1054 1371 155 456 1202 31 1051 898 1067 100 498 326 1621 1588 1887 1521 1996 1248 985 844 130 271 434 39 1163 1043 1569 1149 183 677 824 1962 1501 113 1154 1246 1863 374 874 625 179 1021 887 376 141 18 704 1066 1109 199 716 508 1649 1640 595 1652 886 1475 981 1979 624 1194 270"
|
||||
junk3 := "106 1570 1819 131 268 557 754 1597 29 1777 1064 325 1046 244 388 266 354 1897 1585 1147 49 1909 1690 1008 160 642 1055 1356 251 885 1524 1322 617 312 1207 1337 891 1358 24 1039 680 1119 1781 1561 1628 76 1045 1834 787 224 1473 1949 1762 502 662 1496 1444 712 650 567 1016 1616 1946 1139 495 134 1056 1381 1017 1228 302 1845 1983 2 1975 927 470 7 541 998 836 293 410 1180 1553 1107 450 1659 1186 644 1714 314 337 1967 859 1014 15 180 361 1090 1231 1105 196 10 1805 848 840 213 478 1084 1479 1951 682 1953 223 1769 1789 347 1159 922 1223 479 428 1261 139 768 932 1648 1700 152 1369 365 1166 1324 1366 987 1803 1441 661 1078 1082 1704 1981 1440 1111 239 19 873 881 300 1203 136 8 756 1669 1136 1408 771 920 1268 475 1880 855 396 747 1130"
|
||||
assert.DeepEqual(t, numSorter(junk, t), numSorter(junk2, t))
|
||||
assert.DeepEqual(t, numSorter(junk, t), numSorter(junk3, t))
|
||||
}
|
||||
|
||||
func numSorter(obj string, t *testing.T) []int {
|
||||
nums := strings.Split(obj, " ")
|
||||
|
||||
intNums := []int{}
|
||||
|
||||
for _, n := range nums {
|
||||
nmbr, err := strconv.Atoi(n)
|
||||
assert.NoError(t, err)
|
||||
intNums = append(intNums, nmbr)
|
||||
}
|
||||
sort.Slice(intNums, func(i, j int) bool {
|
||||
return intNums[i] < intNums[j]
|
||||
})
|
||||
return intNums
|
||||
}
|
||||
func TestProposeExit_Notification(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -180,6 +180,9 @@ func (vs *Server) getPowBlockHashAtTerminalTotalDifficulty(ctx context.Context)
|
||||
if overflows {
|
||||
return nil, false, errors.New("could not convert terminal total difficulty to uint256")
|
||||
}
|
||||
if len(params.BeaconConfig().TerminalTotalDifficulty) >= 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
blk, err := vs.ExecutionEngineCaller.LatestExecutionBlock(ctx)
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrap(err, "could not get latest execution block")
|
||||
|
||||
@@ -68,6 +68,7 @@ go_test(
|
||||
"setters_test.go",
|
||||
"state_trie_test.go",
|
||||
],
|
||||
data = glob(["testdata/**"]),
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/state:go_default_library",
|
||||
|
||||
@@ -169,7 +169,7 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed *ethpb.Signe
|
||||
|
||||
// Verify validator index is within the beacon committee.
|
||||
if err := validateIndexInCommittee(ctx, bs, signed.Message.Aggregate, signed.Message.AggregatorIndex); err != nil {
|
||||
wrappedErr := errors.Wrapf(err, "Could not validate index in committee")
|
||||
wrappedErr := errors.Wrapf(err, "Could not validate index in committee for agg index %d, com idx %d and slot %d", signed.Message.AggregatorIndex, signed.Message.Aggregate.Data.CommitteeIndex, signed.Message.Aggregate.Data.Slot)
|
||||
tracing.AnnotateError(span, wrappedErr)
|
||||
return pubsub.ValidationReject, wrappedErr
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ const (
|
||||
// Genesis Fork Epoch for the mainnet config.
|
||||
genesisForkEpoch = 0
|
||||
// Altair Fork Epoch for mainnet config.
|
||||
mainnetAltairForkEpoch = 74240 // Oct 27, 2021, 10:56:23am UTC
|
||||
mainnetAltairForkEpoch = 8 // Oct 27, 2021, 10:56:23am UTC
|
||||
// Placeholder for the merge epoch until it is decided
|
||||
mainnetBellatrixForkEpoch = math.MaxUint64
|
||||
mainnetBellatrixForkEpoch = 10
|
||||
)
|
||||
|
||||
var mainnetNetworkConfig = &NetworkConfig{
|
||||
@@ -103,8 +103,8 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
|
||||
// Time parameter constants.
|
||||
MinAttestationInclusionDelay: 1,
|
||||
SecondsPerSlot: 12,
|
||||
SlotsPerEpoch: 32,
|
||||
SecondsPerSlot: 6,
|
||||
SlotsPerEpoch: 6,
|
||||
SqrRootSlotsPerEpoch: 5,
|
||||
MinSeedLookahead: 1,
|
||||
MaxSeedLookahead: 4,
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
|
||||
@@ -76,12 +75,6 @@ func (v *validator) SubmitSyncCommitteeMessage(ctx context.Context, slot types.S
|
||||
log.WithError(err).Error("Could not submit sync committee message")
|
||||
return
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
"slot": msg.Slot,
|
||||
"blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(msg.BlockRoot)),
|
||||
"validatorIndex": msg.ValidatorIndex,
|
||||
}).Info("Submitted new sync message")
|
||||
}
|
||||
|
||||
// SubmitSignedContributionAndProof submits the signed sync committee contribution and proof to the beacon chain.
|
||||
@@ -164,14 +157,6 @@ func (v *validator) SubmitSignedContributionAndProof(ctx context.Context, slot t
|
||||
log.Errorf("Could not submit signed contribution and proof: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
"slot": contributionAndProof.Contribution.Slot,
|
||||
"blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(contributionAndProof.Contribution.BlockRoot)),
|
||||
"subcommitteeIndex": contributionAndProof.Contribution.SubcommitteeIndex,
|
||||
"aggregatorIndex": contributionAndProof.AggregatorIndex,
|
||||
"bitsCount": contributionAndProof.Contribution.AggregationBits.Count(),
|
||||
}).Info("Submitted new sync contribution and proof")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user