From c32547af796ee15201f739e304a977eeb47447e9 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 03:04:56 +0200 Subject: [PATCH 01/16] save --- cl/cltypes/solid/uint64slice_byte.go | 2 +- cl/phase1/core/state/raw/hashing.go | 2 +- cl/phase1/stages/stage_history_download.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cl/cltypes/solid/uint64slice_byte.go b/cl/cltypes/solid/uint64slice_byte.go index e660c178527..f3c2b09c5e4 100644 --- a/cl/cltypes/solid/uint64slice_byte.go +++ b/cl/cltypes/solid/uint64slice_byte.go @@ -29,7 +29,7 @@ import ( "github.com/ledgerwatch/erigon/cl/utils" ) -const treeCacheDepthUint64Slice = 0 +const treeCacheDepthUint64Slice = 3 func convertDepthToChunkSize(d int) int { return (1 << d) // just power of 2 diff --git a/cl/phase1/core/state/raw/hashing.go b/cl/phase1/core/state/raw/hashing.go index fb8ddb5732a..bdd7d40abd6 100644 --- a/cl/phase1/core/state/raw/hashing.go +++ b/cl/phase1/core/state/raw/hashing.go @@ -199,7 +199,7 @@ func (b *BeaconState) computeDirtyLeaves() error { } b.updateLeaf(BalancesLeafIndex, root) } - log.Trace("Balances hashing", "elapsed", time.Since(begin)) + log.Debug("Balances hashing", "elapsed", time.Since(begin)) begin = time.Now() // Field(13): RandaoMixes diff --git a/cl/phase1/stages/stage_history_download.go b/cl/phase1/stages/stage_history_download.go index ad737973ec6..b2b4039d84f 100644 --- a/cl/phase1/stages/stage_history_download.go +++ b/cl/phase1/stages/stage_history_download.go @@ -144,8 +144,8 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co } } isInElSnapshots := true - frozenBlocksInEL := cfg.engine.FrozenBlocks(ctx) if blk.Version() >= clparams.BellatrixVersion && cfg.engine != nil && cfg.engine.SupportInsertion() { + frozenBlocksInEL := cfg.engine.FrozenBlocks(ctx) isInElSnapshots = blk.Block.Body.ExecutionPayload.BlockNumber < frozenBlocksInEL if cfg.engine.HasGapInSnapshots(ctx) && frozenBlocksInEL > 0 { destinationSlotForEL = frozenBlocksInEL - 1 From ec8daf0a5ea38478635c630190c9482863924ca1 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 03:06:01 +0200 Subject: [PATCH 02/16] save --- cl/phase1/core/state/raw/hashing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cl/phase1/core/state/raw/hashing.go b/cl/phase1/core/state/raw/hashing.go index bdd7d40abd6..fb8ddb5732a 100644 --- a/cl/phase1/core/state/raw/hashing.go +++ b/cl/phase1/core/state/raw/hashing.go @@ -199,7 +199,7 @@ func (b *BeaconState) computeDirtyLeaves() error { } b.updateLeaf(BalancesLeafIndex, root) } - log.Debug("Balances hashing", "elapsed", time.Since(begin)) + log.Trace("Balances hashing", "elapsed", time.Since(begin)) begin = time.Now() // Field(13): RandaoMixes From 3039142c5e67d3986211e5db1425ee51f94ff24e Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 17:03:39 +0200 Subject: [PATCH 03/16] save --- cl/cltypes/solid/uint64slice_byte.go | 2 +- cl/cltypes/solid/validator_set.go | 2 +- cl/phase1/core/state/raw/hashing.go | 124 +++++++++++++-------------- cl/sentinel/gossip.go | 2 +- 4 files changed, 62 insertions(+), 68 deletions(-) diff --git a/cl/cltypes/solid/uint64slice_byte.go b/cl/cltypes/solid/uint64slice_byte.go index f3c2b09c5e4..372d15caba1 100644 --- a/cl/cltypes/solid/uint64slice_byte.go +++ b/cl/cltypes/solid/uint64slice_byte.go @@ -29,7 +29,7 @@ import ( "github.com/ledgerwatch/erigon/cl/utils" ) -const treeCacheDepthUint64Slice = 3 +const treeCacheDepthUint64Slice = 4 func convertDepthToChunkSize(d int) int { return (1 << d) // just power of 2 diff --git a/cl/cltypes/solid/validator_set.go b/cl/cltypes/solid/validator_set.go index 262eb604494..089c3aadaed 100644 --- a/cl/cltypes/solid/validator_set.go +++ b/cl/cltypes/solid/validator_set.go @@ -39,7 +39,7 @@ const ( const ( validatorSetCapacityMultiplier = 1.01 // allocate 20% to the validator set when re-allocation is needed. - validatorTreeCacheGroupLayer = 3 // It will cache group validatorTreeCacheGroupLayer^2 accordingly + validatorTreeCacheGroupLayer = 4 // It will cache group validatorTreeCacheGroupLayer^2 accordingly ) // This is all stuff used by phase0 state transition. It makes many operations faster. diff --git a/cl/phase1/core/state/raw/hashing.go b/cl/phase1/core/state/raw/hashing.go index fb8ddb5732a..2e7efd95614 100644 --- a/cl/phase1/core/state/raw/hashing.go +++ b/cl/phase1/core/state/raw/hashing.go @@ -17,21 +17,64 @@ package raw import ( + "fmt" + "sync" "time" "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" - "github.com/ledgerwatch/erigon-lib/log/v3" + "github.com/ledgerwatch/erigon-lib/types/ssz" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) +type parallelBeaconStateHasher struct { + jobs map[StateLeafIndex]ssz.HashableSSZ + results sync.Map +} + +func (p *parallelBeaconStateHasher) run(b *BeaconState) { + wg := sync.WaitGroup{} + if p.jobs == nil { + p.jobs = make(map[StateLeafIndex]ssz.HashableSSZ) + } + + for idx, job := range p.jobs { + wg.Add(1) + go func(idx StateLeafIndex, job ssz.HashableSSZ) { + defer wg.Done() + root, err := job.HashSSZ() + if err != nil { + panic(err) + } + p.results.Store(idx, root) + }(idx, job) + } + wg.Wait() + p.results.Range(func(key, value any) bool { + idx := key.(StateLeafIndex) + root := value.([32]byte) + b.updateLeaf(idx, root) + return true + }) +} + +func (b *parallelBeaconStateHasher) add(idx StateLeafIndex, job ssz.HashableSSZ) { + if b.jobs == nil { + b.jobs = make(map[StateLeafIndex]ssz.HashableSSZ) + } + b.jobs[idx] = job +} + func (b *BeaconState) HashSSZ() (out [32]byte, err error) { b.mu.Lock() defer b.mu.Unlock() + + start := time.Now() if err = b.computeDirtyLeaves(); err != nil { return [32]byte{}, err } + fmt.Println(time.Since(start)) // for i := 0; i < len(b.leaves); i += 32 { // fmt.Println(i/32, libcommon.BytesToHash(b.leaves[i:i+32])) @@ -89,6 +132,8 @@ func preparateRootsForHashing(roots []common.Hash) [][32]byte { } func (b *BeaconState) computeDirtyLeaves() error { + + parallelHasher := parallelBeaconStateHasher{} // Update all dirty leafs // ---- // Field(0): GenesisTime @@ -142,8 +187,6 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(StateRootsLeafIndex, root) } - begin := time.Now() - // Field(7): HistoricalRoots if b.isLeafDirty(HistoricalRootsLeafIndex) { root, err := b.historicalRoots.HashSSZ() @@ -152,7 +195,6 @@ func (b *BeaconState) computeDirtyLeaves() error { } b.updateLeaf(HistoricalRootsLeafIndex, root) } - log.Trace("HistoricalRoots hashing", "elapsed", time.Since(begin)) // Field(8): Eth1Data if b.isLeafDirty(Eth1DataLeafIndex) { @@ -177,88 +219,45 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(Eth1DepositIndexLeafIndex, merkle_tree.Uint64Root(b.eth1DepositIndex)) } - begin = time.Now() - // Field(11): Validators if b.isLeafDirty(ValidatorsLeafIndex) { - root, err := b.validators.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(ValidatorsLeafIndex, root) - + parallelHasher.add(ValidatorsLeafIndex, b.validators) } - log.Trace("ValidatorSet hashing", "elapsed", time.Since(begin)) - begin = time.Now() // Field(12): Balances if b.isLeafDirty(BalancesLeafIndex) { - root, err := b.balances.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(BalancesLeafIndex, root) + parallelHasher.add(BalancesLeafIndex, b.balances) } - log.Trace("Balances hashing", "elapsed", time.Since(begin)) - begin = time.Now() // Field(13): RandaoMixes + if b.isLeafDirty(RandaoMixesLeafIndex) { - root, err := b.randaoMixes.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(RandaoMixesLeafIndex, root) + parallelHasher.add(RandaoMixesLeafIndex, b.randaoMixes) } - log.Trace("RandaoMixes hashing", "elapsed", time.Since(begin)) - begin = time.Now() // Field(14): Slashings if b.isLeafDirty(SlashingsLeafIndex) { - root, err := b.slashings.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(SlashingsLeafIndex, root) + parallelHasher.add(SlashingsLeafIndex, b.slashings) } - log.Trace("Slashings hashing", "elapsed", time.Since(begin)) // Field(15) and Field(16) are special due to the fact that they have different format in Phase0. - begin = time.Now() // Field(15): PreviousEpochParticipation if b.isLeafDirty(PreviousEpochParticipationLeafIndex) { - var root libcommon.Hash - var err error if b.version == clparams.Phase0Version { - root, err = b.previousEpochAttestations.HashSSZ() + parallelHasher.add(PreviousEpochParticipationLeafIndex, b.previousEpochAttestations) } else { - root, err = b.previousEpochParticipation.HashSSZ() - } - if err != nil { - return err + parallelHasher.add(PreviousEpochParticipationLeafIndex, b.previousEpochParticipation) } - - b.updateLeaf(PreviousEpochParticipationLeafIndex, root) } - log.Trace("PreviousEpochParticipation hashing", "elapsed", time.Since(begin)) - - begin = time.Now() // Field(16): CurrentEpochParticipation if b.isLeafDirty(CurrentEpochParticipationLeafIndex) { - var root libcommon.Hash - var err error if b.version == clparams.Phase0Version { - root, err = b.currentEpochAttestations.HashSSZ() + parallelHasher.add(CurrentEpochParticipationLeafIndex, b.currentEpochAttestations) } else { - root, err = b.currentEpochParticipation.HashSSZ() - } - if err != nil { - return err + parallelHasher.add(CurrentEpochParticipationLeafIndex, b.currentEpochParticipation) } - b.updateLeaf(CurrentEpochParticipationLeafIndex, root) } - log.Trace("CurrentEpochParticipation hashing", "elapsed", time.Since(begin)) // Field(17): JustificationBits if b.isLeafDirty(JustificationBitsLeafIndex) { @@ -293,18 +292,14 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(FinalizedCheckpointLeafIndex, checkpointRoot) } if b.version == clparams.Phase0Version { + parallelHasher.run(b) return nil } - begin = time.Now() + // Field(21): Inactivity Scores if b.isLeafDirty(InactivityScoresLeafIndex) { - root, err := b.inactivityScores.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(InactivityScoresLeafIndex, root) + parallelHasher.add(InactivityScoresLeafIndex, b.inactivityScores) } - log.Trace("InactivityScores hashing", "elapsed", time.Since(begin)) // Field(22): CurrentSyncCommitte if b.isLeafDirty(CurrentSyncCommitteeLeafIndex) { @@ -324,6 +319,7 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(NextSyncCommitteeLeafIndex, committeeRoot) } + parallelHasher.run(b) if b.version < clparams.BellatrixVersion { return nil } @@ -350,7 +346,6 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(NextWithdrawalValidatorIndexLeafIndex, merkle_tree.Uint64Root(b.nextWithdrawalValidatorIndex)) } - begin = time.Now() // Field(27): HistoricalSummaries if b.isLeafDirty(HistoricalSummariesLeafIndex) { root, err := b.historicalSummaries.HashSSZ() @@ -359,7 +354,6 @@ func (b *BeaconState) computeDirtyLeaves() error { } b.updateLeaf(HistoricalSummariesLeafIndex, root) } - log.Trace("HistoricalSummaries hashing", "elapsed", time.Since(begin)) return nil } diff --git a/cl/sentinel/gossip.go b/cl/sentinel/gossip.go index e27ad0d35cb..e7f97ca7595 100644 --- a/cl/sentinel/gossip.go +++ b/cl/sentinel/gossip.go @@ -519,7 +519,7 @@ type GossipSubscription struct { func (sub *GossipSubscription) Listen() { go func() { var err error - checkingInterval := time.NewTicker(100 * time.Millisecond) + checkingInterval := time.NewTicker(5 * time.Millisecond) for { select { case <-sub.ctx.Done(): From cf45d63e6f77edc893ce723e6cb2ba6bc06eb100 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 17:07:28 +0200 Subject: [PATCH 04/16] save --- cl/sentinel/discovery.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cl/sentinel/discovery.go b/cl/sentinel/discovery.go index 2fd0e43197e..38658764bfb 100644 --- a/cl/sentinel/discovery.go +++ b/cl/sentinel/discovery.go @@ -118,11 +118,10 @@ func (s *Sentinel) listenForPeers() { continue } - go func(peerInfo *peer.AddrInfo) { - if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil { - log.Trace("[Sentinel] Could not connect with peer", "err", err) - } - }(peerInfo) + if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil { + log.Trace("[Sentinel] Could not connect with peer", "err", err) + } + } } From df66326144c8dfeee46e66202eea8064fa6aa7f2 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 18:21:58 +0200 Subject: [PATCH 05/16] save --- cl/phase1/core/state/raw/hashing.go | 33 ++----- .../forkchoice/fork_graph/fork_graph_disk.go | 33 ++++--- .../fork_graph/fork_graph_disk_fs.go | 5 +- cl/phase1/forkchoice/fork_graph/interface.go | 1 + cl/phase1/forkchoice/forkchoice.go | 8 ++ .../services/aggregate_and_proof_service.go | 2 +- cl/phase1/network/services/constants.go | 4 +- cl/phase1/stages/clstages.go | 5 ++ cl/sentinel/gossip.go | 88 +++++++++++-------- cl/sentinel/service/start.go | 6 +- cl/transition/impl/eth2/operations.go | 3 - 11 files changed, 98 insertions(+), 90 deletions(-) diff --git a/cl/phase1/core/state/raw/hashing.go b/cl/phase1/core/state/raw/hashing.go index 2e7efd95614..c71b44707c7 100644 --- a/cl/phase1/core/state/raw/hashing.go +++ b/cl/phase1/core/state/raw/hashing.go @@ -17,9 +17,7 @@ package raw import ( - "fmt" "sync" - "time" "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" @@ -70,11 +68,9 @@ func (b *BeaconState) HashSSZ() (out [32]byte, err error) { b.mu.Lock() defer b.mu.Unlock() - start := time.Now() if err = b.computeDirtyLeaves(); err != nil { return [32]byte{}, err } - fmt.Println(time.Since(start)) // for i := 0; i < len(b.leaves); i += 32 { // fmt.Println(i/32, libcommon.BytesToHash(b.leaves[i:i+32])) @@ -171,29 +167,17 @@ func (b *BeaconState) computeDirtyLeaves() error { // Field(5): BlockRoots if b.isLeafDirty(BlockRootsLeafIndex) { - root, err := b.blockRoots.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(BlockRootsLeafIndex, root) + parallelHasher.add(BlockRootsLeafIndex, b.blockRoots) } // Field(6): StateRoots if b.isLeafDirty(StateRootsLeafIndex) { - root, err := b.stateRoots.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(StateRootsLeafIndex, root) + parallelHasher.add(StateRootsLeafIndex, b.stateRoots) } // Field(7): HistoricalRoots if b.isLeafDirty(HistoricalRootsLeafIndex) { - root, err := b.historicalRoots.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(HistoricalRootsLeafIndex, root) + parallelHasher.add(HistoricalRootsLeafIndex, b.historicalRoots) } // Field(8): Eth1Data @@ -230,7 +214,6 @@ func (b *BeaconState) computeDirtyLeaves() error { } // Field(13): RandaoMixes - if b.isLeafDirty(RandaoMixesLeafIndex) { parallelHasher.add(RandaoMixesLeafIndex, b.randaoMixes) } @@ -319,8 +302,8 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(NextSyncCommitteeLeafIndex, committeeRoot) } - parallelHasher.run(b) if b.version < clparams.BellatrixVersion { + parallelHasher.run(b) return nil } // Field(24): LatestExecutionPayloadHeader @@ -333,6 +316,7 @@ func (b *BeaconState) computeDirtyLeaves() error { } if b.version < clparams.CapellaVersion { + parallelHasher.run(b) return nil } @@ -348,12 +332,9 @@ func (b *BeaconState) computeDirtyLeaves() error { // Field(27): HistoricalSummaries if b.isLeafDirty(HistoricalSummariesLeafIndex) { - root, err := b.historicalSummaries.HashSSZ() - if err != nil { - return err - } - b.updateLeaf(HistoricalSummariesLeafIndex, root) + parallelHasher.add(HistoricalSummariesLeafIndex, b.historicalSummaries) } + parallelHasher.run(b) return nil } diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go index 0378e8ab6ab..ee38cc40bd6 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go @@ -190,7 +190,7 @@ func NewForkGraphDisk(anchorState *state.CachingBeaconState, aferoFs afero.Fs, r f.lowestAvaiableBlock.Store(anchorState.Slot()) f.headers.Store(libcommon.Hash(anchorRoot), &anchorHeader) - f.dumpBeaconStateOnDisk(anchorState, anchorRoot) + f.DumpBeaconStateOnDisk(anchorRoot, anchorState, true) return f } @@ -313,12 +313,6 @@ func (f *forkGraphDisk) AddChainSegment(signedBlock *cltypes.SignedBeaconBlock, BodyRoot: bodyRoot, }) - if newState.Slot()%dumpSlotFrequency == 0 { - if err := f.dumpBeaconStateOnDisk(newState, blockRoot); err != nil { - return nil, LogisticError, err - } - } - // Lastly add checkpoints to caches as well. f.currentJustifiedCheckpoints.Store(libcommon.Hash(blockRoot), newState.CurrentJustifiedCheckpoint().Copy()) f.finalizedCheckpoints.Store(libcommon.Hash(blockRoot), newState.FinalizedCheckpoint().Copy()) @@ -361,31 +355,36 @@ func (f *forkGraphDisk) GetState(blockRoot libcommon.Hash, alwaysCopy bool) (*st blocksInTheWay := []*cltypes.SignedBeaconBlock{} // Use the parent root as a reverse iterator. currentIteratorRoot := blockRoot + var copyReferencedState *state.CachingBeaconState + var err error // try and find the point of recconection - for { + for copyReferencedState == nil { block, isSegmentPresent := f.getBlock(currentIteratorRoot) if !isSegmentPresent { // check if it is in the header bHeader, ok := f.GetHeader(currentIteratorRoot) if ok && bHeader.Slot%dumpSlotFrequency == 0 { - break + copyReferencedState, err = f.readBeaconStateFromDisk(currentIteratorRoot) + if err != nil { + log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot, "err", err) + } + continue } log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot) return nil, nil } if block.Block.Slot%dumpSlotFrequency == 0 { - break + copyReferencedState, err = f.readBeaconStateFromDisk(currentIteratorRoot) + if err != nil { + log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot, "err", err) + } + if copyReferencedState != nil { + continue + } } blocksInTheWay = append(blocksInTheWay, block) currentIteratorRoot = block.Block.ParentRoot } - copyReferencedState, err := f.readBeaconStateFromDisk(currentIteratorRoot) - if err != nil { - return nil, err - } - if copyReferencedState == nil { - return nil, ErrStateNotFound - } // Traverse the blocks from top to bottom. for i := len(blocksInTheWay) - 1; i >= 0; i-- { diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go index b11052a9c9f..0a5d58ac0a5 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk_fs.go @@ -104,7 +104,10 @@ func (f *forkGraphDisk) readBeaconStateFromDisk(blockRoot libcommon.Hash) (bs *s } // dumpBeaconStateOnDisk dumps a beacon state on disk in ssz snappy format -func (f *forkGraphDisk) dumpBeaconStateOnDisk(bs *state.CachingBeaconState, blockRoot libcommon.Hash) (err error) { +func (f *forkGraphDisk) DumpBeaconStateOnDisk(blockRoot libcommon.Hash, bs *state.CachingBeaconState, forced bool) (err error) { + if !forced && bs.Slot()%dumpSlotFrequency != 0 { + return + } // Truncate and then grow the buffer to the size of the state. encodingSizeSSZ := bs.EncodingSizeSSZ() f.sszBuffer.Grow(encodingSizeSSZ) diff --git a/cl/phase1/forkchoice/fork_graph/interface.go b/cl/phase1/forkchoice/fork_graph/interface.go index 060e1de500b..33345bc52e5 100644 --- a/cl/phase1/forkchoice/fork_graph/interface.go +++ b/cl/phase1/forkchoice/fork_graph/interface.go @@ -54,4 +54,5 @@ type ForkGraph interface { GetPreviousPartecipationIndicies(blockRoot libcommon.Hash) (*solid.BitList, error) GetValidatorSet(blockRoot libcommon.Hash) (*solid.ValidatorSet, error) GetCurrentPartecipationIndicies(blockRoot libcommon.Hash) (*solid.BitList, error) + DumpBeaconStateOnDisk(blockRoot libcommon.Hash, state *state.CachingBeaconState, forced bool) error } diff --git a/cl/phase1/forkchoice/forkchoice.go b/cl/phase1/forkchoice/forkchoice.go index 47382f3d0c9..5adf97027e2 100644 --- a/cl/phase1/forkchoice/forkchoice.go +++ b/cl/phase1/forkchoice/forkchoice.go @@ -540,3 +540,11 @@ func (f *ForkChoiceStore) IsHeadOptimistic() bool { latestRoot := headState.LatestBlockHeader().Root return f.optimisticStore.IsOptimistic(latestRoot) } + +func (f *ForkChoiceStore) DumpBeaconStateOnDisk(bs *state.CachingBeaconState) error { + anchorRoot, err := bs.BlockRoot() + if err != nil { + return err + } + return f.forkGraph.DumpBeaconStateOnDisk(anchorRoot, bs, false) +} diff --git a/cl/phase1/network/services/aggregate_and_proof_service.go b/cl/phase1/network/services/aggregate_and_proof_service.go index 7fb91a0eaa1..c56c6d2147c 100644 --- a/cl/phase1/network/services/aggregate_and_proof_service.go +++ b/cl/phase1/network/services/aggregate_and_proof_service.go @@ -69,7 +69,7 @@ func NewAggregateAndProofService( opPool: opPool, test: test, } - go a.loop(ctx) + //go a.loop(ctx) return a } diff --git a/cl/phase1/network/services/constants.go b/cl/phase1/network/services/constants.go index cb545e9387e..8de33883449 100644 --- a/cl/phase1/network/services/constants.go +++ b/cl/phase1/network/services/constants.go @@ -29,8 +29,8 @@ const ( blobJobsIntervalTick = 5 * time.Millisecond singleAttestationIntervalTick = 10 * time.Millisecond attestationJobsIntervalTick = 100 * time.Millisecond - blockJobExpiry = 7 * time.Minute - blobJobExpiry = 7 * time.Minute + blockJobExpiry = 24 * time.Second + blobJobExpiry = 24 * time.Second attestationJobExpiry = 30 * time.Minute singleAttestationJobExpiry = 6 * time.Second ) diff --git a/cl/phase1/stages/clstages.go b/cl/phase1/stages/clstages.go index 09c0e3cbc4c..5ac55503bf7 100644 --- a/cl/phase1/stages/clstages.go +++ b/cl/phase1/stages/clstages.go @@ -663,6 +663,7 @@ func ConsensusClStages(ctx context.Context, if _, err = cfg.attestationDataProducer.ProduceAndCacheAttestationData(copiedHeadState, copiedHeadState.Slot(), 0); err != nil { logger.Warn("failed to produce and cache attestation data", "err", err) } + // Incement some stuff here preverifiedValidators := cfg.forkChoice.PreverifiedValidator(headState.FinalizedCheckpoint().BlockRoot()) preverifiedHistoricalSummary := cfg.forkChoice.PreverifiedHistoricalSummaries(headState.FinalizedCheckpoint().BlockRoot()) @@ -683,6 +684,10 @@ func ConsensusClStages(ctx context.Context, return fmt.Errorf("failed to hash ssz: %w", err) } + if err := cfg.forkChoice.DumpBeaconStateOnDisk(headState); err != nil { + return fmt.Errorf("failed to dump beacon state on disk: %w", err) + } + headEpoch := headSlot / cfg.beaconCfg.SlotsPerEpoch previous_duty_dependent_root, err := headState.GetBlockRootAtSlot((headEpoch-1)*cfg.beaconCfg.SlotsPerEpoch - 1) if err != nil { diff --git a/cl/sentinel/gossip.go b/cl/sentinel/gossip.go index e7f97ca7595..04aae07a054 100644 --- a/cl/sentinel/gossip.go +++ b/cl/sentinel/gossip.go @@ -208,11 +208,10 @@ func (s *Sentinel) forkWatcher() { s.subManager.subscriptions.Range(func(key, value interface{}) bool { sub := value.(*GossipSubscription) s.subManager.unsubscribe(key.(string)) - newSub, err := s.SubscribeGossip(sub.gossip_topic, sub.expiration.Load().(time.Time)) + _, err := s.SubscribeGossip(sub.gossip_topic, sub.expiration.Load().(time.Time)) if err != nil { log.Warn("[Gossip] Failed to resubscribe to topic", "err", err) } - newSub.Listen() return true }) prevDigest = digest @@ -250,6 +249,10 @@ func (s *Sentinel) SubscribeGossip(topic GossipTopic, expiration time.Time, opts return sub, nil } +func (s *Sentinel) Context() context.Context { + return s.ctx +} + func (s *Sentinel) Unsubscribe(topic GossipTopic, opts ...pubsub.TopicOpt) (err error) { digest, err := s.ethClock.CurrentForkDigest() if err != nil { @@ -495,6 +498,27 @@ func (g *GossipManager) Close() { }) } +func (g *GossipManager) Start(ctx context.Context) { + go func() { + checkingInterval := time.NewTicker(time.Second) + for { + select { + case <-ctx.Done(): + return + case <-checkingInterval.C: + g.subscriptions.Range(func(key, value any) bool { + sub := value.(*GossipSubscription) + if sub.sub == nil { + return true + } + sub.checkIfTopicNeedsToEnabledOrDisabled() + return true + }) + } + } + }() +} + // GossipSubscription abstracts a gossip subscription to write decoded structs. type GossipSubscription struct { gossip_topic GossipTopic @@ -516,42 +540,32 @@ type GossipSubscription struct { closeOnce sync.Once } -func (sub *GossipSubscription) Listen() { - go func() { - var err error - checkingInterval := time.NewTicker(5 * time.Millisecond) - for { - select { - case <-sub.ctx.Done(): - return - case <-checkingInterval.C: - expirationTime := sub.expiration.Load().(time.Time) - if sub.subscribed.Load() && time.Now().After(expirationTime) { - sub.stopCh <- struct{}{} - sub.topic.Close() - sub.subscribed.Store(false) - log.Info("[Gossip] Unsubscribed from topic", "topic", sub.sub.Topic()) - sub.s.updateENROnSubscription(sub.sub.Topic(), false) - continue - } - if !sub.subscribed.Load() && time.Now().Before(expirationTime) { - sub.stopCh = make(chan struct{}, 3) - sub.sub, err = sub.topic.Subscribe() - if err != nil { - log.Warn("[Gossip] failed to begin topic subscription", "err", err) - time.Sleep(30 * time.Second) - continue - } - var sctx context.Context - sctx, sub.cf = context.WithCancel(sub.ctx) - go sub.run(sctx, sub.sub, sub.sub.Topic()) - sub.subscribed.Store(true) - sub.s.updateENROnSubscription(sub.sub.Topic(), true) - log.Info("[Gossip] Subscribed to topic", "topic", sub.sub.Topic()) - } - } +func (sub *GossipSubscription) checkIfTopicNeedsToEnabledOrDisabled() { + var err error + expirationTime := sub.expiration.Load().(time.Time) + if sub.subscribed.Load() && time.Now().After(expirationTime) { + sub.stopCh <- struct{}{} + sub.topic.Close() + sub.subscribed.Store(false) + log.Info("[Gossip] Unsubscribed from topic", "topic", sub.sub.Topic()) + sub.s.updateENROnSubscription(sub.sub.Topic(), false) + return + } + if !sub.subscribed.Load() && time.Now().Before(expirationTime) { + sub.stopCh = make(chan struct{}, 3) + sub.sub, err = sub.topic.Subscribe() + if err != nil { + log.Warn("[Gossip] failed to begin topic subscription", "err", err) + return } - }() + var sctx context.Context + sctx, sub.cf = context.WithCancel(sub.ctx) + go sub.run(sctx, sub.sub, sub.sub.Topic()) + sub.subscribed.Store(true) + sub.s.updateENROnSubscription(sub.sub.Topic(), true) + log.Info("[Gossip] Subscribed to topic", "topic", sub.sub.Topic()) + } + } func (sub *GossipSubscription) OverwriteSubscriptionExpiry(expiry time.Time) { diff --git a/cl/sentinel/service/start.go b/cl/sentinel/service/start.go index e2fc2a7a5f9..1ccfbf07923 100644 --- a/cl/sentinel/service/start.go +++ b/cl/sentinel/service/start.go @@ -131,13 +131,13 @@ func createSentinel( } // now lets separately connect to the gossip topics. this joins the room - subscriber, err := sent.SubscribeGossip(v, getExpirationForTopic(v.Name)) // Listen forever. + _, err := sent.SubscribeGossip(v, getExpirationForTopic(v.Name)) // Listen forever. if err != nil { logger.Error("[Sentinel] failed to start sentinel", "err", err) } - // actually start the subscription, aka listening and sending packets to the sentinel recv channel - subscriber.Listen() } + // Start the gossip manager + sent.GossipManager().Start(sent.Context()) return sent, nil } diff --git a/cl/transition/impl/eth2/operations.go b/cl/transition/impl/eth2/operations.go index beebf702b21..0f0bf3c992d 100644 --- a/cl/transition/impl/eth2/operations.go +++ b/cl/transition/impl/eth2/operations.go @@ -816,11 +816,8 @@ func verifyAttestations( attestingIndicies [][]uint64, ) (bool, error) { indexedAttestations := make([]*cltypes.IndexedAttestation, 0, attestations.Len()) - commonBuffer := make([]byte, 8*2048) attestations.Range(func(idx int, a *solid.Attestation, _ int) bool { idxAttestations := state.GetIndexedAttestation(a, attestingIndicies[idx]) - idxAttestations.AttestingIndices.SetReusableHashBuffer(commonBuffer) - idxAttestations.HashSSZ() indexedAttestations = append(indexedAttestations, idxAttestations) return true }) From 1c9cb8f1151a59483df44c7d0642de22414301e6 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 18:30:01 +0200 Subject: [PATCH 06/16] save --- cl/cltypes/solid/validator_set.go | 2 +- cl/phase1/network/services/aggregate_and_proof_service.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cl/cltypes/solid/validator_set.go b/cl/cltypes/solid/validator_set.go index 089c3aadaed..262eb604494 100644 --- a/cl/cltypes/solid/validator_set.go +++ b/cl/cltypes/solid/validator_set.go @@ -39,7 +39,7 @@ const ( const ( validatorSetCapacityMultiplier = 1.01 // allocate 20% to the validator set when re-allocation is needed. - validatorTreeCacheGroupLayer = 4 // It will cache group validatorTreeCacheGroupLayer^2 accordingly + validatorTreeCacheGroupLayer = 3 // It will cache group validatorTreeCacheGroupLayer^2 accordingly ) // This is all stuff used by phase0 state transition. It makes many operations faster. diff --git a/cl/phase1/network/services/aggregate_and_proof_service.go b/cl/phase1/network/services/aggregate_and_proof_service.go index c56c6d2147c..7fb91a0eaa1 100644 --- a/cl/phase1/network/services/aggregate_and_proof_service.go +++ b/cl/phase1/network/services/aggregate_and_proof_service.go @@ -69,7 +69,7 @@ func NewAggregateAndProofService( opPool: opPool, test: test, } - //go a.loop(ctx) + go a.loop(ctx) return a } From 83edc38a12a981ff1fe505010202749ef6b45f50 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sat, 6 Jul 2024 22:00:30 +0200 Subject: [PATCH 07/16] save --- cl/sentinel/gossip.go | 4 ---- cl/sentinel/sentinel.go | 1 + cl/sentinel/sentinel_gossip_test.go | 3 --- cl/sentinel/service/start.go | 2 -- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/cl/sentinel/gossip.go b/cl/sentinel/gossip.go index 04aae07a054..36c82d26704 100644 --- a/cl/sentinel/gossip.go +++ b/cl/sentinel/gossip.go @@ -249,10 +249,6 @@ func (s *Sentinel) SubscribeGossip(topic GossipTopic, expiration time.Time, opts return sub, nil } -func (s *Sentinel) Context() context.Context { - return s.ctx -} - func (s *Sentinel) Unsubscribe(topic GossipTopic, opts ...pubsub.TopicOpt) (err error) { digest, err := s.ethClock.CurrentForkDigest() if err != nil { diff --git a/cl/sentinel/sentinel.go b/cl/sentinel/sentinel.go index 5b77c60b322..e2bfe582f9e 100644 --- a/cl/sentinel/sentinel.go +++ b/cl/sentinel/sentinel.go @@ -303,6 +303,7 @@ func (s *Sentinel) Start() error { }, }) s.subManager = NewGossipManager(s.ctx) + s.subManager.Start(s.ctx) go s.listenForPeers() go s.forkWatcher() diff --git a/cl/sentinel/sentinel_gossip_test.go b/cl/sentinel/sentinel_gossip_test.go index 4b98cb8cf00..529ac23e12c 100644 --- a/cl/sentinel/sentinel_gossip_test.go +++ b/cl/sentinel/sentinel_gossip_test.go @@ -88,12 +88,9 @@ func TestSentinelGossipOnHardFork(t *testing.T) { require.NoError(t, err) defer sub1.Close() - sub1.Listen() - sub2, err := sentinel2.SubscribeGossip(BeaconBlockSsz, time.Unix(0, math.MaxInt64)) require.NoError(t, err) defer sub2.Close() - sub2.Listen() time.Sleep(200 * time.Millisecond) err = h.Connect(ctx, peer.AddrInfo{ diff --git a/cl/sentinel/service/start.go b/cl/sentinel/service/start.go index 1ccfbf07923..a6e7e5e9334 100644 --- a/cl/sentinel/service/start.go +++ b/cl/sentinel/service/start.go @@ -136,8 +136,6 @@ func createSentinel( logger.Error("[Sentinel] failed to start sentinel", "err", err) } } - // Start the gossip manager - sent.GossipManager().Start(sent.Context()) return sent, nil } From 1fcc8f6bb64f4c8b78490e6e775249a75b5386a2 Mon Sep 17 00:00:00 2001 From: Giulio Date: Sun, 7 Jul 2024 00:27:16 +0200 Subject: [PATCH 08/16] save --- cl/sentinel/gossip.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cl/sentinel/gossip.go b/cl/sentinel/gossip.go index 36c82d26704..6526c8201d6 100644 --- a/cl/sentinel/gossip.go +++ b/cl/sentinel/gossip.go @@ -504,9 +504,6 @@ func (g *GossipManager) Start(ctx context.Context) { case <-checkingInterval.C: g.subscriptions.Range(func(key, value any) bool { sub := value.(*GossipSubscription) - if sub.sub == nil { - return true - } sub.checkIfTopicNeedsToEnabledOrDisabled() return true }) From cbd253cbce0c867a58a6808407d972793b57ebfb Mon Sep 17 00:00:00 2001 From: Giulio Date: Sun, 7 Jul 2024 00:47:07 +0200 Subject: [PATCH 09/16] save --- cl/sentinel/discovery.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cl/sentinel/discovery.go b/cl/sentinel/discovery.go index 38658764bfb..7e5b7e10e91 100644 --- a/cl/sentinel/discovery.go +++ b/cl/sentinel/discovery.go @@ -118,9 +118,11 @@ func (s *Sentinel) listenForPeers() { continue } - if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil { - log.Trace("[Sentinel] Could not connect with peer", "err", err) - } + go func(peerInfo *peer.AddrInfo) { + if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil { + log.Trace("[Sentinel] Could not connect with peer", "err", err) + } + }(peerInfo) } } From 506ee6f6db202b11b4e5485d35612b91a9e66056 Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 12 Jul 2024 00:05:46 +0200 Subject: [PATCH 10/16] save --- cl/phase1/core/state/raw/hashing.go | 147 ++++++++++++++++------------ 1 file changed, 86 insertions(+), 61 deletions(-) diff --git a/cl/phase1/core/state/raw/hashing.go b/cl/phase1/core/state/raw/hashing.go index c71b44707c7..fb8ddb5732a 100644 --- a/cl/phase1/core/state/raw/hashing.go +++ b/cl/phase1/core/state/raw/hashing.go @@ -17,57 +17,18 @@ package raw import ( - "sync" + "time" "github.com/ledgerwatch/erigon-lib/common" libcommon "github.com/ledgerwatch/erigon-lib/common" - "github.com/ledgerwatch/erigon-lib/types/ssz" + "github.com/ledgerwatch/erigon-lib/log/v3" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/merkle_tree" ) -type parallelBeaconStateHasher struct { - jobs map[StateLeafIndex]ssz.HashableSSZ - results sync.Map -} - -func (p *parallelBeaconStateHasher) run(b *BeaconState) { - wg := sync.WaitGroup{} - if p.jobs == nil { - p.jobs = make(map[StateLeafIndex]ssz.HashableSSZ) - } - - for idx, job := range p.jobs { - wg.Add(1) - go func(idx StateLeafIndex, job ssz.HashableSSZ) { - defer wg.Done() - root, err := job.HashSSZ() - if err != nil { - panic(err) - } - p.results.Store(idx, root) - }(idx, job) - } - wg.Wait() - p.results.Range(func(key, value any) bool { - idx := key.(StateLeafIndex) - root := value.([32]byte) - b.updateLeaf(idx, root) - return true - }) -} - -func (b *parallelBeaconStateHasher) add(idx StateLeafIndex, job ssz.HashableSSZ) { - if b.jobs == nil { - b.jobs = make(map[StateLeafIndex]ssz.HashableSSZ) - } - b.jobs[idx] = job -} - func (b *BeaconState) HashSSZ() (out [32]byte, err error) { b.mu.Lock() defer b.mu.Unlock() - if err = b.computeDirtyLeaves(); err != nil { return [32]byte{}, err } @@ -128,8 +89,6 @@ func preparateRootsForHashing(roots []common.Hash) [][32]byte { } func (b *BeaconState) computeDirtyLeaves() error { - - parallelHasher := parallelBeaconStateHasher{} // Update all dirty leafs // ---- // Field(0): GenesisTime @@ -167,18 +126,33 @@ func (b *BeaconState) computeDirtyLeaves() error { // Field(5): BlockRoots if b.isLeafDirty(BlockRootsLeafIndex) { - parallelHasher.add(BlockRootsLeafIndex, b.blockRoots) + root, err := b.blockRoots.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(BlockRootsLeafIndex, root) } // Field(6): StateRoots if b.isLeafDirty(StateRootsLeafIndex) { - parallelHasher.add(StateRootsLeafIndex, b.stateRoots) + root, err := b.stateRoots.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(StateRootsLeafIndex, root) } + begin := time.Now() + // Field(7): HistoricalRoots if b.isLeafDirty(HistoricalRootsLeafIndex) { - parallelHasher.add(HistoricalRootsLeafIndex, b.historicalRoots) + root, err := b.historicalRoots.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(HistoricalRootsLeafIndex, root) } + log.Trace("HistoricalRoots hashing", "elapsed", time.Since(begin)) // Field(8): Eth1Data if b.isLeafDirty(Eth1DataLeafIndex) { @@ -203,44 +177,88 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(Eth1DepositIndexLeafIndex, merkle_tree.Uint64Root(b.eth1DepositIndex)) } + begin = time.Now() + // Field(11): Validators if b.isLeafDirty(ValidatorsLeafIndex) { - parallelHasher.add(ValidatorsLeafIndex, b.validators) + root, err := b.validators.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(ValidatorsLeafIndex, root) + } + log.Trace("ValidatorSet hashing", "elapsed", time.Since(begin)) + begin = time.Now() // Field(12): Balances if b.isLeafDirty(BalancesLeafIndex) { - parallelHasher.add(BalancesLeafIndex, b.balances) + root, err := b.balances.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(BalancesLeafIndex, root) } + log.Trace("Balances hashing", "elapsed", time.Since(begin)) + begin = time.Now() // Field(13): RandaoMixes if b.isLeafDirty(RandaoMixesLeafIndex) { - parallelHasher.add(RandaoMixesLeafIndex, b.randaoMixes) + root, err := b.randaoMixes.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(RandaoMixesLeafIndex, root) } + log.Trace("RandaoMixes hashing", "elapsed", time.Since(begin)) + begin = time.Now() // Field(14): Slashings if b.isLeafDirty(SlashingsLeafIndex) { - parallelHasher.add(SlashingsLeafIndex, b.slashings) + root, err := b.slashings.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(SlashingsLeafIndex, root) } + log.Trace("Slashings hashing", "elapsed", time.Since(begin)) // Field(15) and Field(16) are special due to the fact that they have different format in Phase0. + begin = time.Now() // Field(15): PreviousEpochParticipation if b.isLeafDirty(PreviousEpochParticipationLeafIndex) { + var root libcommon.Hash + var err error if b.version == clparams.Phase0Version { - parallelHasher.add(PreviousEpochParticipationLeafIndex, b.previousEpochAttestations) + root, err = b.previousEpochAttestations.HashSSZ() } else { - parallelHasher.add(PreviousEpochParticipationLeafIndex, b.previousEpochParticipation) + root, err = b.previousEpochParticipation.HashSSZ() + } + if err != nil { + return err } + + b.updateLeaf(PreviousEpochParticipationLeafIndex, root) } + log.Trace("PreviousEpochParticipation hashing", "elapsed", time.Since(begin)) + + begin = time.Now() // Field(16): CurrentEpochParticipation if b.isLeafDirty(CurrentEpochParticipationLeafIndex) { + var root libcommon.Hash + var err error if b.version == clparams.Phase0Version { - parallelHasher.add(CurrentEpochParticipationLeafIndex, b.currentEpochAttestations) + root, err = b.currentEpochAttestations.HashSSZ() } else { - parallelHasher.add(CurrentEpochParticipationLeafIndex, b.currentEpochParticipation) + root, err = b.currentEpochParticipation.HashSSZ() + } + if err != nil { + return err } + b.updateLeaf(CurrentEpochParticipationLeafIndex, root) } + log.Trace("CurrentEpochParticipation hashing", "elapsed", time.Since(begin)) // Field(17): JustificationBits if b.isLeafDirty(JustificationBitsLeafIndex) { @@ -275,14 +293,18 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(FinalizedCheckpointLeafIndex, checkpointRoot) } if b.version == clparams.Phase0Version { - parallelHasher.run(b) return nil } - + begin = time.Now() // Field(21): Inactivity Scores if b.isLeafDirty(InactivityScoresLeafIndex) { - parallelHasher.add(InactivityScoresLeafIndex, b.inactivityScores) + root, err := b.inactivityScores.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(InactivityScoresLeafIndex, root) } + log.Trace("InactivityScores hashing", "elapsed", time.Since(begin)) // Field(22): CurrentSyncCommitte if b.isLeafDirty(CurrentSyncCommitteeLeafIndex) { @@ -303,7 +325,6 @@ func (b *BeaconState) computeDirtyLeaves() error { } if b.version < clparams.BellatrixVersion { - parallelHasher.run(b) return nil } // Field(24): LatestExecutionPayloadHeader @@ -316,7 +337,6 @@ func (b *BeaconState) computeDirtyLeaves() error { } if b.version < clparams.CapellaVersion { - parallelHasher.run(b) return nil } @@ -330,11 +350,16 @@ func (b *BeaconState) computeDirtyLeaves() error { b.updateLeaf(NextWithdrawalValidatorIndexLeafIndex, merkle_tree.Uint64Root(b.nextWithdrawalValidatorIndex)) } + begin = time.Now() // Field(27): HistoricalSummaries if b.isLeafDirty(HistoricalSummariesLeafIndex) { - parallelHasher.add(HistoricalSummariesLeafIndex, b.historicalSummaries) + root, err := b.historicalSummaries.HashSSZ() + if err != nil { + return err + } + b.updateLeaf(HistoricalSummariesLeafIndex, root) } - parallelHasher.run(b) + log.Trace("HistoricalSummaries hashing", "elapsed", time.Since(begin)) return nil } From 52ad26a01ebcda5643c5cf243b42b91f87eff07b Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 12 Jul 2024 00:29:18 +0200 Subject: [PATCH 11/16] save --- cl/cltypes/solid/uint64slice_byte.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cl/cltypes/solid/uint64slice_byte.go b/cl/cltypes/solid/uint64slice_byte.go index 372d15caba1..e660c178527 100644 --- a/cl/cltypes/solid/uint64slice_byte.go +++ b/cl/cltypes/solid/uint64slice_byte.go @@ -29,7 +29,7 @@ import ( "github.com/ledgerwatch/erigon/cl/utils" ) -const treeCacheDepthUint64Slice = 4 +const treeCacheDepthUint64Slice = 0 func convertDepthToChunkSize(d int) int { return (1 << d) // just power of 2 From 3d6d7481f2ee983d0669fa60c85ee7bf0317df21 Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 12 Jul 2024 00:29:50 +0200 Subject: [PATCH 12/16] save --- cl/sentinel/discovery.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cl/sentinel/discovery.go b/cl/sentinel/discovery.go index 7e5b7e10e91..2fd0e43197e 100644 --- a/cl/sentinel/discovery.go +++ b/cl/sentinel/discovery.go @@ -123,7 +123,6 @@ func (s *Sentinel) listenForPeers() { log.Trace("[Sentinel] Could not connect with peer", "err", err) } }(peerInfo) - } } From 9e16f4463b78293b254113fcbe52b4c3c579478e Mon Sep 17 00:00:00 2001 From: Giulio Date: Fri, 12 Jul 2024 00:30:05 +0200 Subject: [PATCH 13/16] save --- cl/sentinel/discovery.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cl/sentinel/discovery.go b/cl/sentinel/discovery.go index 2fd0e43197e..4bf27821202 100644 --- a/cl/sentinel/discovery.go +++ b/cl/sentinel/discovery.go @@ -118,11 +118,9 @@ func (s *Sentinel) listenForPeers() { continue } - go func(peerInfo *peer.AddrInfo) { - if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil { - log.Trace("[Sentinel] Could not connect with peer", "err", err) - } - }(peerInfo) + if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil { + log.Trace("[Sentinel] Could not connect with peer", "err", err) + } } } From 3a3968bae0e7c62230b739b12e6111bc3e9205e5 Mon Sep 17 00:00:00 2001 From: Giulio Date: Tue, 16 Jul 2024 11:43:50 +0200 Subject: [PATCH 14/16] save --- cl/phase1/forkchoice/fork_graph/fork_graph_disk.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go index ee38cc40bd6..0aeadcebe87 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go @@ -367,6 +367,7 @@ func (f *forkGraphDisk) GetState(blockRoot libcommon.Hash, alwaysCopy bool) (*st copyReferencedState, err = f.readBeaconStateFromDisk(currentIteratorRoot) if err != nil { log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot, "err", err) + copyReferencedState = nil } continue } From be00488ae455fe2427ba580095ef06873f02086f Mon Sep 17 00:00:00 2001 From: Giulio Date: Tue, 16 Jul 2024 11:44:37 +0200 Subject: [PATCH 15/16] save --- cl/phase1/forkchoice/fork_graph/fork_graph_disk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go index 0aeadcebe87..6226413350d 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go @@ -369,7 +369,7 @@ func (f *forkGraphDisk) GetState(blockRoot libcommon.Hash, alwaysCopy bool) (*st log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot, "err", err) copyReferencedState = nil } - continue + break } log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot) return nil, nil From de238a81ec165fc6d4dcdcc47c32cfc96007eb7d Mon Sep 17 00:00:00 2001 From: Giulio Date: Tue, 16 Jul 2024 11:45:19 +0200 Subject: [PATCH 16/16] save --- cl/phase1/forkchoice/fork_graph/fork_graph_disk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go index 6226413350d..73e06e2a0c4 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go @@ -369,7 +369,7 @@ func (f *forkGraphDisk) GetState(blockRoot libcommon.Hash, alwaysCopy bool) (*st log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot, "err", err) copyReferencedState = nil } - break + continue } log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot) return nil, nil @@ -380,7 +380,7 @@ func (f *forkGraphDisk) GetState(blockRoot libcommon.Hash, alwaysCopy bool) (*st log.Trace("Could not retrieve state: Missing header", "missing", currentIteratorRoot, "err", err) } if copyReferencedState != nil { - continue + break } } blocksInTheWay = append(blocksInTheWay, block)