cmd, eth, les: fix up ultra light config integration

This commit is contained in:
Péter Szilágyi
2019-07-09 20:30:24 +03:00
parent 8c249cb82f
commit 213690cdfd
21 changed files with 187 additions and 272 deletions

View File

@@ -17,38 +17,38 @@
package les
import (
"github.com/ethereum/go-ethereum/eth"
"errors"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode"
)
type ulc struct {
trustedKeys map[string]struct{}
minTrustedFraction int
keys map[string]bool
fraction int
}
// newULC creates and returns a ultra light client instance.
func newULC(ulcConfig *eth.ULCConfig) *ulc {
if ulcConfig == nil {
return nil
}
m := make(map[string]struct{}, len(ulcConfig.TrustedServers))
for _, id := range ulcConfig.TrustedServers {
// newULC creates and returns an ultra light client instance.
func newULC(servers []string, fraction int) (*ulc, error) {
keys := make(map[string]bool)
for _, id := range servers {
node, err := enode.Parse(enode.ValidSchemes, id)
if err != nil {
log.Debug("Failed to parse trusted server", "id", id, "err", err)
log.Warn("Failed to parse trusted server", "id", id, "err", err)
continue
}
m[node.ID().String()] = struct{}{}
keys[node.ID().String()] = true
}
return &ulc{m, ulcConfig.MinTrustedFraction}
if len(keys) == 0 {
return nil, errors.New("no trusted servers")
}
return &ulc{
keys: keys,
fraction: fraction,
}, nil
}
// isTrusted return an indicator that whether the specified peer is trusted.
func (u *ulc) isTrusted(p enode.ID) bool {
if u.trustedKeys == nil {
return false
}
_, ok := u.trustedKeys[p.String()]
return ok
// trusted return an indicator that whether the specified peer is trusted.
func (u *ulc) trusted(p enode.ID) bool {
return u.keys[p.String()]
}