Skip to content
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

ULC: encapsulate consensus logic #70

Open
wants to merge 63 commits into
base: ulc/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d15b3ef
cmd, eth: ulc options added
JekaMas Dec 12, 2017
04e23da
eth: fmt
JekaMas Dec 14, 2017
9a0354e
mobile, eth: ulc options for mobile
JekaMas Dec 20, 2017
57999f6
les: ulc requesting signed headers for trusted nodes
JekaMas Dec 20, 2017
200bd54
core, les: ulc switching off header PoW validation
JekaMas Dec 20, 2017
590137b
les: ulc the server pool always tries to connect to trusted nodes
JekaMas Dec 20, 2017
84708f6
les: ulc config in protocol manager
JekaMas Dec 22, 2017
98c012a
les: add ulc next request select strategy
b00ris Dec 25, 2017
14d25ea
les: fix test
b00ris Feb 27, 2018
76ab62d
les: add announce signed header test
b00ris Mar 3, 2018
c477c51
les: disable pow validation test
b00ris Mar 3, 2018
c165e6c
les: ulc config unit tests
b00ris Mar 3, 2018
f762d9b
les: fix lint
b00ris Mar 5, 2018
1fb5520
added serverpool load trusted nodes test
b00ris Mar 22, 2018
a26c3a0
disable sending requests to ulc
b00ris Mar 25, 2018
c1f6710
clean
b00ris Mar 26, 2018
bf691f9
fix ulc sunc
b00ris Apr 8, 2018
d1a79df
remove verification from downloader for trusted
b00ris Apr 16, 2018
3db20a8
fix lint
b00ris Apr 17, 2018
c535734
change announce only direction
b00ris May 3, 2018
c8e44cd
add onlyannounce flag
b00ris May 3, 2018
e67d70a
disconnect useless peer
b00ris May 3, 2018
e3bb872
peer tests
b00ris May 21, 2018
0b48d4f
Merge remote-tracking branch 'origin/master' into ulc/master
b00ris May 28, 2018
316a391
les: fix
b00ris May 28, 2018
d7f30d5
les: fix les lint
b00ris May 28, 2018
6c4b901
First steps making ULC changes more clear
themue May 23, 2018
7e96d84
Merge branch 'master' into ulc/master-1.8.9
themue May 29, 2018
1f050c2
les: fix announce
b00ris May 30, 2018
62544c4
les: add signature to announce test
b00ris May 30, 2018
914c43c
les: minor fixes
b00ris May 30, 2018
ab009b1
Merge pull request #57 from status-im/ulc/issue-55/fix-announce
b00ris May 31, 2018
d7e5396
config refactoring
JekaMas Jun 3, 2018
a709f6c
les: minor fixes
b00ris Jun 4, 2018
f9380e2
remove ULC prefixes
JekaMas Jun 4, 2018
a311a2b
Merge pull request #58 from status-im/feature/ulc-config-refactoring-#52
b00ris Jun 4, 2018
758a40b
les: n/m downloader validation
b00ris Jun 4, 2018
86c40cb
les: fmt
b00ris Jun 4, 2018
2a05781
les: added isULCEnabled
b00ris Jun 4, 2018
3f1a009
les: comment fixes
b00ris Jun 4, 2018
3d96ec5
Merge pull request #59 from status-im/ulc/issue-51/downloader-n-m-val…
b00ris Jun 4, 2018
94cfe78
les: fix linter
b00ris Jun 5, 2018
c229733
les: fix dataraces
b00ris Jun 6, 2018
ecbf126
les, eth/downloader: remove downloader changes
b00ris Jun 14, 2018
c3edc41
les: add isTrusted check to isTrustedHash
b00ris Jun 14, 2018
adb4411
les: allow unrusted peers register to downloader in ULC mode
b00ris Jun 14, 2018
bb88f32
les: rename requestAnnounceType to announceType
b00ris Jun 14, 2018
8ef606c
Merge pull request #66 from status-im/ulc/issue-63/untrusted-usage
b00ris Jun 14, 2018
abd9861
Merge branch 'master' of https://github.com/ethereum/go-ethereum into…
b00ris Jun 14, 2018
298a8b5
les: change sync verification
b00ris Jun 15, 2018
6a6f30b
les: add comments
b00ris Jun 15, 2018
5393fd9
les: move set valid header
b00ris Jun 18, 2018
9f68c26
Merge pull request #67 from status-im/ulc/issue-63/untrusted-peer-dow…
b00ris Jun 18, 2018
ac49680
les: return to one fetcher mutex
b00ris Jun 25, 2018
e003d4c
Merge pull request #68 from status-im/ulc/fetcher-mutex
b00ris Jun 25, 2018
dd49f9c
les: lastTrustedTreeNode started to use ancestor
b00ris Jul 4, 2018
ba3ebce
les: lastTrustedTreeNode refactor
b00ris Jul 4, 2018
89daab4
les: fix
b00ris Jul 10, 2018
a7b531a
les: fix lint
b00ris Jul 12, 2018
3fabf24
Merge pull request #69 from status-im/ulc/rewiew_update
b00ris Jul 25, 2018
628cd1f
Merge branch 'master' of https://github.com/ethereum/go-ethereum into…
b00ris Jul 25, 2018
f03d6cf
сmd/geth, cmd/utils, eth, les: added minimum num of trusted nodes
JekaMas Jul 27, 2018
040db4e
les: fix in a constant value
JekaMas Aug 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
}

// Apply flags.
utils.SetULC(ctx, &cfg.Eth)
utils.SetNodeConfig(ctx, &cfg.Node)
stack, err := node.New(&cfg.Node)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ var (
utils.TxPoolLifetimeFlag,
utils.FastSyncFlag,
utils.LightModeFlag,
utils.ULCModeConfigFlag,
utils.OnlyAnnounceModeFlag,
utils.ULCTrustedNodesFlag,
utils.ULCMinTrustedFractionFlag,
utils.ULCMinTrustedNodesNumFlag,
utils.SyncModeFlag,
utils.GCModeFlag,
utils.LightServFlag,
Expand Down
69 changes: 68 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package utils

import (
"crypto/ecdsa"
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
Expand Down Expand Up @@ -164,8 +165,31 @@ var (
}
LightModeFlag = cli.BoolFlag{
Name: "light",
Usage: "Enable light client mode (replaced by --syncmode)",
Usage: "Enable light client mode(LES) (replaced by --syncmode)",
}
ULCModeConfigFlag = cli.StringFlag{
Name: "les.ulcconfig",
Usage: "Config file to use for ULC mode",
}
OnlyAnnounceModeFlag = cli.BoolFlag{
Name: "les.onlyannounce",
Usage: "LES server sends only announce",
}
ULCMinTrustedFractionFlag = cli.IntFlag{
Name: "les.mintrustedfraction",
Usage: "LES server minimum percent of trusted node which trust the block",
Value: eth.DefaultUTCMinTrustedFraction,
}
ULCMinTrustedNodesNumFlag = cli.UintFlag{
Name: "les.mintrustednum",
Usage: "LES server minimum number of trusted node which trust the block",
Value: 1,
}
ULCTrustedNodesFlag = cli.StringFlag{
Name: "les.trustednodes",
Usage: "Config file to use for ULC mode",
}

defaultSyncMode = eth.DefaultConfig.SyncMode
SyncModeFlag = TextMarshalerFlag{
Name: "syncmode",
Expand Down Expand Up @@ -765,6 +789,46 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
}
}

// SetULC setup ULC config from file if given.
func SetULC(ctx *cli.Context, cfg *eth.Config) {
// ULC config isn't loaded from global config and ULC config and ULC trusted nodes are not defined.
if cfg.ULC == nil && !(ctx.GlobalIsSet(ULCModeConfigFlag.Name) || ctx.GlobalIsSet(ULCTrustedNodesFlag.Name)) {
return
}
cfg.ULC = &eth.ULCConfig{}

path := ctx.GlobalString(ULCModeConfigFlag.Name)
if path != "" {
cfgData, err := ioutil.ReadFile(path)
if err != nil {
Fatalf("Failed to unmarshal ULC configuration: %v", err)
}

err = json.Unmarshal(cfgData, &cfg.ULC)
if err != nil {
Fatalf("Failed to unmarshal ULC configuration: %s", err.Error())
}
}

if trustedNodes := ctx.GlobalString(ULCTrustedNodesFlag.Name); trustedNodes != "" {
cfg.ULC.TrustedServers = strings.Split(trustedNodes, ",")
}

if trustedFraction := ctx.GlobalInt(ULCMinTrustedFractionFlag.Name); trustedFraction > 0 {
cfg.ULC.MinTrustedFraction = trustedFraction
}
if trustedNum := ctx.GlobalUint(ULCMinTrustedNodesNumFlag.Name); trustedNum > 0 {
cfg.ULC.MinTrustedNodesNum = trustedNum
}
if cfg.ULC.MinTrustedNodesNum == 0 {
cfg.ULC.MinTrustedNodesNum = 1
}
if cfg.ULC.MinTrustedFraction <= 0 && cfg.ULC.MinTrustedFraction > 100 {
log.Error("MinTrustedFraction is invalid", "MinTrustedFraction", cfg.ULC.MinTrustedFraction, "Changed to default", eth.DefaultUTCMinTrustedFraction)
cfg.ULC.MinTrustedFraction = eth.DefaultUTCMinTrustedFraction
}
}

// makeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database.
func makeDatabaseHandles() int {
Expand Down Expand Up @@ -1074,6 +1138,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(LightPeersFlag.Name) {
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
}
if ctx.GlobalIsSet(OnlyAnnounceModeFlag.Name) {
cfg.OnlyAnnounce = ctx.GlobalBool(OnlyAnnounceModeFlag.Name)
}
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
}
Expand Down
16 changes: 10 additions & 6 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,18 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int)

// Generate the list of seal verification requests, and start the parallel verifier
seals := make([]bool, len(chain))
for i := 0; i < len(seals)/checkFreq; i++ {
index := i*checkFreq + hc.rand.Intn(checkFreq)
if index >= len(seals) {
index = len(seals) - 1
if checkFreq != 0 {
// In case of checkFreq == 0 all seals are left false.
for i := 0; i < len(seals)/checkFreq; i++ {
index := i*checkFreq + hc.rand.Intn(checkFreq)
if index >= len(seals) {
index = len(seals) - 1
}
seals[index] = true
}
seals[index] = true
// Last should always be verified to avoid junk.
seals[len(seals)-1] = true
}
seals[len(seals)-1] = true // Last should always be verified to avoid junk

abort, results := hc.engine.VerifyHeaders(hc, chain, seals)
defer close(abort)
Expand Down
8 changes: 6 additions & 2 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ type Config struct {
NoPruning bool

// Light client options
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
OnlyAnnounce bool // Maximum number of LES client peers

// Ultra Light client options
ULC *ULCConfig `toml:",omitempty"`

// Database options
SkipBcVersionCheck bool `toml:"-"`
Expand Down
2 changes: 1 addition & 1 deletion eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sync/atomic"
"time"

ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
Expand Down
22 changes: 14 additions & 8 deletions eth/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions eth/ulc_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package eth

const DefaultUTCMinTrustedFraction = 75

// ULCConfig is a Ultra Light client options.
type ULCConfig struct {
TrustedServers []string `toml:",omitempty"` // A list of trusted servers
MinTrustedFraction int `toml:",omitempty"` // Minimum percentage of connected trusted servers to validate trusted (1-100)
MinTrustedNodesNum uint `toml:",omitempty"` // Minimum num of connected trusted servers to validate trusted (1-...)
}
30 changes: 28 additions & 2 deletions les/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
bloomTrieIndexer: light.NewBloomTrieIndexer(chainDb, true),
}

var trustedNodes []string
if leth.config.ULC != nil {
trustedNodes = leth.config.ULC.TrustedServers
}
leth.relay = NewLesTxRelay(peers, leth.reqDist)
leth.serverPool = newServerPool(chainDb, quitSync, &leth.wg)
leth.serverPool = newServerPool(chainDb, quitSync, &leth.wg, trustedNodes)
leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool)
leth.odr = NewLesOdr(chainDb, leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer, leth.retriever)
if leth.blockchain, err = light.NewLightChain(leth.odr, leth.chainConfig, leth.engine); err != nil {
Expand All @@ -127,10 +131,32 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
}

leth.txPool = light.NewTxPool(leth.chainConfig, leth.blockchain, leth.relay)
if leth.protocolManager, err = NewProtocolManager(leth.chainConfig, true, ClientProtocolVersions, config.NetworkId, leth.eventMux, leth.engine, leth.peers, leth.blockchain, nil, chainDb, leth.odr, leth.relay, leth.serverPool, quitSync, &leth.wg); err != nil {

if leth.protocolManager, err = NewProtocolManager(
leth.chainConfig,
true,
ClientProtocolVersions,
config.NetworkId,
leth.eventMux,
leth.engine,
leth.peers,
leth.blockchain,
nil,
chainDb,
leth.odr,
leth.relay,
leth.serverPool,
quitSync,
&leth.wg,
config.ULC); err != nil {
return nil, err
}

if leth.protocolManager.isULCEnabled() {
leth.blockchain.DisableCheckFreq()
}
leth.ApiBackend = &LesApiBackend{leth, nil}

gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.GasPrice
Expand Down
Loading