-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd, eth: implement full-sync tester #26035
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2022 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package catalyst | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/core/beacon" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/eth" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/node" | ||
) | ||
|
||
// FullSyncTester is an auxiliary service that allows Geth to perform full sync | ||
// alone without consensus-layer attached. Users must specify a valid block as | ||
// the sync target. This tester can be applied to different networks, no matter | ||
// it's pre-merge or post-merge, but only for full-sync. | ||
type FullSyncTester struct { | ||
api *ConsensusAPI | ||
block *types.Block | ||
closed chan struct{} | ||
wg sync.WaitGroup | ||
} | ||
|
||
// RegisterFullSyncTester registers the full-sync tester service into the node | ||
// stack for launching and stopping the service controlled by node. | ||
func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, block *types.Block) (*FullSyncTester, error) { | ||
cl := &FullSyncTester{ | ||
api: NewConsensusAPI(backend), | ||
block: block, | ||
closed: make(chan struct{}), | ||
} | ||
stack.RegisterLifecycle(cl) | ||
return cl, nil | ||
} | ||
|
||
// Start launches the full-sync tester by spinning up a background thread | ||
// for keeping firing NewPayload-UpdateForkChoice combos with the provided | ||
// target block, it may or may not trigger the beacon sync depends on if | ||
// there are protocol peers connected. | ||
func (tester *FullSyncTester) Start() error { | ||
tester.wg.Add(1) | ||
go func() { | ||
defer tester.wg.Done() | ||
|
||
ticker := time.NewTicker(time.Second * 5) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ticker.C: | ||
// Don't bother downloader in case it's already syncing. | ||
if tester.api.eth.Downloader().Synchronising() { | ||
continue | ||
} | ||
// Short circuit in case the target block is already stored | ||
// locally. | ||
if tester.api.eth.BlockChain().HasBlock(tester.block.Hash(), tester.block.NumberU64()) { | ||
log.Info("Full-sync target reached", "number", tester.block.NumberU64(), "hash", tester.block.Hash()) | ||
return | ||
} | ||
// Shoot out consensus events in order to trigger syncing. | ||
data := beacon.BlockToExecutableData(tester.block) | ||
tester.api.NewPayloadV1(*data) | ||
tester.api.ForkchoiceUpdatedV1(beacon.ForkchoiceStateV1{ | ||
HeadBlockHash: tester.block.Hash(), | ||
SafeBlockHash: tester.block.Hash(), | ||
FinalizedBlockHash: tester.block.Hash(), | ||
}, nil) | ||
case <-tester.closed: | ||
return | ||
} | ||
} | ||
}() | ||
return nil | ||
} | ||
|
||
// Stop stops the full-sync tester to stop all background activities. | ||
// This function can only be called for one time. | ||
func (tester *FullSyncTester) Stop() error { | ||
close(tester.closed) | ||
tester.wg.Wait() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, despite this check here, I see this in the logs :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, it's snap sync? This thing shouldn't work in snap sync mode at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No ... well, I told it to do
syncmode=full
. As far as I know, it has not switched over to snap (but it started from an already initiated genesis)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so there is an issue that "reverse-header-sync" is not considered as SYNCING. We should fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, syncmode=full. While it has peers, and actively downloading headers from them, it still spits out this message:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's because the status of downloader is still NON-SYNCING but actually it is. So tester keeps firing events non-stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup