mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
mobile: Make sync mode configurable
Make sync mode configurable. Keep Light as the default sync mode to maintain backward-compatibility. The mode can be configured by calling `NodeConfig.setSyncMode()`
This commit is contained in:
parent
0bcff8f525
commit
821a9f2d13
1 changed files with 28 additions and 0 deletions
|
|
@ -38,6 +38,13 @@ import (
|
|||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
||||
)
|
||||
|
||||
// I am intentionally duplicating these constants different from downloader.SyncMode integer values, to ensure the
|
||||
// backwards compatibility where the mobile node defaults to LightSync.
|
||||
const SyncModeUnset = 0 // will be treated as SyncModeLightSync
|
||||
const SyncModeFullSync = 1
|
||||
const SyncModeFastSync = 2
|
||||
const SyncModeLightSync = 3
|
||||
|
||||
// NodeConfig represents the collection of configuration values to fine tune the Geth
|
||||
// node embedded into a mobile process. The available values are a subset of the
|
||||
// entire API provided by go-ethereum to reduce the maintenance surface and dev
|
||||
|
|
@ -76,6 +83,10 @@ type NodeConfig struct {
|
|||
|
||||
// Listening address of pprof server.
|
||||
PprofAddress string
|
||||
|
||||
// Sync mode for the node (eth/downloader/modes.go)
|
||||
// This has to be integer since Enum exports to Java are not supported by "gomobile"
|
||||
SyncMode int
|
||||
}
|
||||
|
||||
// defaultNodeConfig contains the default node configuration values to use if all
|
||||
|
|
@ -188,6 +199,23 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
|
|||
return &Node{rawStack}, nil
|
||||
}
|
||||
|
||||
func getSyncMode(syncMode int) downloader.SyncMode {
|
||||
switch syncMode {
|
||||
case SyncModeFullSync:
|
||||
return downloader.FullSync
|
||||
case SyncModeFastSync:
|
||||
return downloader.FastSync
|
||||
case SyncModeUnset:
|
||||
fallthrough
|
||||
// If unset, default to light sync.
|
||||
// This maintains backward compatibility.
|
||||
case SyncModeLightSync:
|
||||
return downloader.LightSync
|
||||
default:
|
||||
panic(fmt.Sprintf("Unexpected sync mode value: %d", syncMode))
|
||||
}
|
||||
}
|
||||
|
||||
// Start creates a live P2P node and starts running it.
|
||||
func (n *Node) Start() error {
|
||||
return n.node.Start()
|
||||
|
|
|
|||
Loading…
Reference in a new issue