-
Notifications
You must be signed in to change notification settings - Fork 274
sync: coreth-archived PR #1178: enable state sync by default #1813
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
Closed
JonathanOppenheimer
wants to merge
1
commit into
master
from
JonathanOppenheimer/sync-enable-state-sync-by-default
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -338,14 +338,21 @@ func (vm *VM) Initialize( | |
| return err | ||
| } | ||
|
|
||
| // vm.ChainConfig() should be available for wrapping VMs before vm.initializeChain() | ||
| vm.chainConfig = g.Config | ||
|
|
||
| vm.ethConfig = ethconfig.NewDefaultConfig() | ||
| vm.ethConfig.Genesis = g | ||
| // NetworkID here is different than Avalanche's NetworkID. | ||
| // Avalanche's NetworkID represents the Avalanche network is running on | ||
| // like Fuji, Mainnet, Local, etc. | ||
| // The NetworkId here is kept same as ChainID to be compatible with | ||
| // Ethereum tooling. | ||
| vm.ethConfig.NetworkId = g.Config.ChainID.Uint64() | ||
| vm.genesisHash = vm.ethConfig.Genesis.ToBlock().Hash() // must create genesis hash before [vm.ReadLastAccepted] | ||
| lastAcceptedHash, lastAcceptedHeight, err := vm.readLastAccepted() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| log.Info("read last accepted", | ||
| "hash", lastAcceptedHash, | ||
| "height", lastAcceptedHeight, | ||
| ) | ||
|
|
||
| // Set minimum price for mining and default gas price oracle value to the min | ||
| // gas price to prevent so transactions and blocks all use the correct fees | ||
|
|
@@ -380,7 +387,7 @@ func (vm *VM) Initialize( | |
| vm.ethConfig.PopulateMissingTries = vm.config.PopulateMissingTries | ||
| vm.ethConfig.PopulateMissingTriesParallelism = vm.config.PopulateMissingTriesParallelism | ||
| vm.ethConfig.AllowMissingTries = vm.config.AllowMissingTries | ||
| vm.ethConfig.SnapshotDelayInit = vm.config.StateSyncEnabled | ||
| vm.ethConfig.SnapshotDelayInit = vm.stateSyncEnabled(lastAcceptedHeight) | ||
| vm.ethConfig.SnapshotWait = vm.config.SnapshotWait | ||
| vm.ethConfig.SnapshotVerify = vm.config.SnapshotVerify | ||
| vm.ethConfig.HistoricalProofQueryWindow = vm.config.HistoricalProofQueryWindow | ||
|
|
@@ -409,7 +416,7 @@ func (vm *VM) Initialize( | |
| if vm.config.OfflinePruning { | ||
| return errFirewoodOfflinePruningUnsupported | ||
| } | ||
| if vm.config.StateSyncEnabled { | ||
| if vm.config.StateSyncEnabled == nil || *vm.config.StateSyncEnabled { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the difference is rectified! annoyed me a couple months ago. |
||
| return errFirewoodStateSyncUnsupported | ||
| } | ||
| } | ||
|
|
@@ -436,20 +443,6 @@ func (vm *VM) Initialize( | |
| vm.ethConfig.Miner.Etherbase = constants.BlackholeAddr | ||
| } | ||
|
|
||
| vm.chainConfig = g.Config | ||
|
|
||
| // create genesisHash after applying upgradeBytes in case | ||
| // upgradeBytes modifies genesis. | ||
| vm.genesisHash = vm.ethConfig.Genesis.ToBlock().Hash() // must create genesis hash before [vm.readLastAccepted] | ||
| lastAcceptedHash, lastAcceptedHeight, err := vm.readLastAccepted() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| log.Info("read last accepted", | ||
| "hash", lastAcceptedHash, | ||
| "height", lastAcceptedHeight, | ||
| ) | ||
|
|
||
| vm.networkCodec = message.Codec | ||
| vm.Network, err = network.NewNetwork(vm.ctx, appSender, vm.networkCodec, vm.config.MaxOutboundActiveRequests, vm.sdkMetrics) | ||
| if err != nil { | ||
|
|
@@ -652,9 +645,10 @@ func (vm *VM) initializeChain(lastAcceptedHash common.Hash, ethConfig ethconfig. | |
| // If state sync is disabled, this function will wipe any ongoing summary from | ||
| // disk to ensure that we do not continue syncing from an invalid snapshot. | ||
| func (vm *VM) initializeStateSyncClient(lastAcceptedHeight uint64) error { | ||
| stateSyncEnabled := vm.stateSyncEnabled(lastAcceptedHeight) | ||
| // parse nodeIDs from state sync IDs in vm config | ||
| var stateSyncIDs []ids.NodeID | ||
| if vm.config.StateSyncEnabled && len(vm.config.StateSyncIDs) > 0 { | ||
| if stateSyncEnabled && len(vm.config.StateSyncIDs) > 0 { | ||
| nodeIDs := strings.Split(vm.config.StateSyncIDs, ",") | ||
| stateSyncIDs = make([]ids.NodeID, len(nodeIDs)) | ||
| for i, nodeIDString := range nodeIDs { | ||
|
|
@@ -679,7 +673,7 @@ func (vm *VM) initializeStateSyncClient(lastAcceptedHeight uint64) error { | |
| BlockParser: vm, | ||
| }, | ||
| ), | ||
| Enabled: vm.config.StateSyncEnabled, | ||
| Enabled: stateSyncEnabled, | ||
| SkipResume: vm.config.StateSyncSkipResume, | ||
| MinBlocks: vm.config.StateSyncMinBlocks, | ||
| RequestSize: vm.config.StateSyncRequestSize, | ||
|
|
@@ -693,7 +687,7 @@ func (vm *VM) initializeStateSyncClient(lastAcceptedHeight uint64) error { | |
|
|
||
| // If StateSync is disabled, clear any ongoing summary so that we will not attempt to resume | ||
| // sync using a snapshot that has been modified by the node running normal operations. | ||
| if !vm.config.StateSyncEnabled { | ||
| if !stateSyncEnabled { | ||
| return vm.Client.ClearOngoingSummary() | ||
| } | ||
|
|
||
|
|
@@ -1360,6 +1354,16 @@ func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error { | |
| return vm.Network.Disconnected(ctx, nodeID) | ||
| } | ||
|
|
||
| func (vm *VM) stateSyncEnabled(lastAcceptedHeight uint64) bool { | ||
| if vm.config.StateSyncEnabled != nil { | ||
| // if the config is set, use that | ||
| return *vm.config.StateSyncEnabled | ||
| } | ||
|
|
||
| // enable state sync by default if the chain is empty. | ||
| return lastAcceptedHeight == 0 | ||
| } | ||
|
|
||
| func (vm *VM) PutLastAcceptedID(id ids.ID) error { | ||
| return vm.acceptedBlockDB.Put(lastAcceptedKey, id[:]) | ||
| } | ||
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.
this comment is not present in coreth, but not part of the original PR. I removed it to align the two repositories.