config: add CHT root URL, fixes #170

This commit is contained in:
Victor Farazdagi 2017-05-27 23:26:07 +03:00
parent 0e2839b705
commit bc3ea62eca
9 changed files with 55 additions and 11 deletions

View File

@ -1,7 +1,10 @@
package api_test package api_test
import ( import (
"io/ioutil"
"math/rand" "math/rand"
"os"
"strconv"
"testing" "testing"
"time" "time"
@ -28,6 +31,35 @@ func (s *APITestSuite) SetupTest() {
require.IsType(&api.StatusAPI{}, statusAPI) require.IsType(&api.StatusAPI{}, statusAPI)
s.api = statusAPI s.api = statusAPI
} }
func (s *APITestSuite) TestCHTUpdate() {
require := s.Require()
require.NotNil(s.api)
tmpDir, err := ioutil.TempDir(os.TempDir(), "cht-updates")
require.NoError(err)
defer os.RemoveAll(tmpDir)
url := "https://gist.githubusercontent.com/farazdagi/3d05d1d3bfa36db7b650c955e23fd7ae/raw/?u=" + strconv.Itoa(int(time.Now().Unix()))
configJSON := `{
"NetworkId": ` + strconv.Itoa(params.RopstenNetworkID) + `,
"DataDir": "` + tmpDir + `",
"LogEnabled": true,
"LogLevel": "INFO",
"LightEthConfig": {
"CHTRootConfigURL": "` + url + `"
}
}`
nodeConfig, err := params.LoadNodeConfig(configJSON)
require.NoError(err)
// start node
nodeConfig.DevMode = true
s.api.StartNode(nodeConfig)
time.Sleep(TestConfig.Node.SyncSeconds * time.Second)
s.api.StopNode()
}
func (s *APITestSuite) TestRaceConditions() { func (s *APITestSuite) TestRaceConditions() {
require := s.Require() require := s.Require()
require.NotNil(s.api) require.NotNil(s.api)

View File

@ -149,7 +149,7 @@ func updateCHT(eth *les.LightEthereum, config *params.NodeConfig) {
Dev string `json:"dev"` Dev string `json:"dev"`
} }
loadCHTLists := func() ([]MsgCHTRoot, error) { loadCHTLists := func() ([]MsgCHTRoot, error) {
url := "https://gist.githubusercontent.com/farazdagi/a8d36e2818b3b2b6074d691da63a0c36/raw/?u=" + strconv.Itoa(int(time.Now().Unix())) url := config.LightEthConfig.CHTRootConfigURL + "?u=" + strconv.Itoa(int(time.Now().Unix()))
client := &http.Client{Timeout: 5 * time.Second} client := &http.Client{Timeout: 5 * time.Second}
r, err := client.Get(url) r, err := client.Get(url)
if err != nil { if err != nil {
@ -181,7 +181,7 @@ func updateCHT(eth *les.LightEthereum, config *params.NodeConfig) {
Number: root.Number, Number: root.Number,
Root: gethcommon.HexToHash(chtRoot), Root: gethcommon.HexToHash(chtRoot),
}) })
log.Info("Loaded CHT from net", "CHT", chtRoot, "number", root.Number) log.Info("Loaded CHT from net", "CHT", chtRoot, "number", root.Number, "dev", config.DevMode)
return return
} }
} }

View File

@ -49,6 +49,10 @@ type LightEthConfig struct {
// DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced) // DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced)
DatabaseCache int DatabaseCache int
// CHTRootConfigURL defines URL to file containing hard-coded CHT roots
// TODO remove this hack, once CHT sync is implemented on LES side
CHTRootConfigURL string
} }
// FirebaseConfig holds FCM-related configuration // FirebaseConfig holds FCM-related configuration
@ -233,8 +237,9 @@ func NewNodeConfig(dataDir string, networkID uint64, devMode bool) (*NodeConfig,
LogLevel: LogLevel, LogLevel: LogLevel,
LogToStderr: LogToStderr, LogToStderr: LogToStderr,
LightEthConfig: &LightEthConfig{ LightEthConfig: &LightEthConfig{
Enabled: true, Enabled: true,
DatabaseCache: DatabaseCache, DatabaseCache: DatabaseCache,
CHTRootConfigURL: CHTRootConfigURL,
}, },
BootClusterConfig: &BootClusterConfig{ BootClusterConfig: &BootClusterConfig{
Enabled: true, Enabled: true,

View File

@ -51,6 +51,10 @@ const (
// DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced) // DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced)
DatabaseCache = 16 DatabaseCache = 16
// CHTRootConfigURL defines URL to file containing hard-coded CHT roots
// TODO remove this hack, once CHT sync is implemented on LES side
CHTRootConfigURL = "https://gist.githubusercontent.com/farazdagi/a8d36e2818b3b2b6074d691da63a0c36/raw/"
// LogFile defines where to write logs to // LogFile defines where to write logs to
LogFile = "geth.log" LogFile = "geth.log"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -124,7 +124,7 @@ func scriptsWeb3Js() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "scripts/web3.js", size: 496217, mode: os.FileMode(420), modTime: time.Unix(1495715456, 0)} info := bindataFileInfo{name: "scripts/web3.js", size: 496217, mode: os.FileMode(420), modTime: time.Unix(1495916191, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -269,7 +269,7 @@ func configLinter_exclude_listTxt() (*asset, error) {
return a, nil return a, nil
} }
var _configTestDataJson = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x84\x8d\x31\x6b\xc4\x30\x0c\x46\xf7\xfc\x0a\xa1\xb9\x83\x1d\x57\xb2\x93\xed\xb6\x4e\x25\x90\x83\xce\xb2\xac\x8c\x31\xc4\x57\xda\x52\xee\xbf\x17\xd3\x83\x83\x42\xb9\x41\x20\x1e\x7c\xef\x7d\x0f\x00\xf8\x5a\x8b\xe1\x0c\xfd\x07\xc0\xf5\x6b\xd7\xd5\xb4\xee\xa5\xe1\x0c\xa3\x7b\xfa\xc5\x2f\xe7\xf3\xb2\xd4\xe3\x82\x33\x24\x7e\xa6\x1b\x7d\x5b\xef\x8c\x07\x80\x6b\xe7\x78\x52\xad\xef\xfb\xc5\xdf\xa5\xa7\x52\x0e\x6b\x5d\x88\xee\x53\x8a\x6c\x9e\x5c\x9e\x1c\xe9\x46\xc6\x12\x63\x32\xa2\x60\x9e\xc4\x87\x29\x33\xfb\x94\x73\x8e\x78\x8b\x2c\xd2\xda\x47\x3d\x4a\x5f\x4b\x2b\x5b\x3f\xfc\x1b\x1b\xff\x89\x31\xa9\xf3\x94\x58\xc4\xa9\x79\x1a\x53\x20\x8d\x29\x89\x1a\x33\xd9\xe4\x25\x07\x1a\x63\x4e\x0f\x63\xc3\xf5\x27\x00\x00\xff\xff\x86\xe9\x3c\x6a\x2d\x01\x00\x00") var _configTestDataJson = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x84\x8d\x31\x6b\xc4\x30\x0c\x46\xf7\xfc\x0a\xa1\xb9\x83\x1d\x57\xb2\x93\xed\xb6\x4e\x25\x90\x83\xce\xb2\xac\x8c\x31\xc4\x57\xda\x52\xee\xbf\x17\xd3\x83\x83\x42\xb9\x41\x20\x1e\x7c\xef\x7d\x0f\x00\xf8\x5a\x8b\xe1\x0c\xfd\x07\xc0\xf5\x6b\xd7\xd5\xb4\xee\xa5\xe1\x0c\xf1\xe9\x97\xbe\x9c\xcf\xcb\x52\x8f\x0b\xce\x90\xf8\x99\x6e\xf4\x6d\xbd\x33\x1e\x00\xae\x9d\xe3\x49\xb5\xbe\xef\x17\x7f\x77\x9e\x4a\x39\xac\x75\x1f\xba\x4f\x29\xb2\x79\x72\x79\x72\xa4\x1b\x19\x4b\x8c\xc9\x88\x82\x79\x12\x1f\xa6\xcc\xec\x53\xce\x39\xe2\x2d\xb2\x48\x6b\x1f\xf5\x28\x7d\x2d\xad\x6c\xfd\xf0\x6f\x6c\xfc\x27\xc6\xa4\xce\x53\x62\x11\xa7\xe6\x69\x4c\x81\x34\xa6\x24\x6a\xcc\x64\x93\x97\x1c\x68\x8c\x39\x3d\x8c\x0d\xd7\x9f\x00\x00\x00\xff\xff\xb4\xe1\xf5\x0c\x2c\x01\x00\x00")
func configTestDataJsonBytes() ([]byte, error) { func configTestDataJsonBytes() ([]byte, error) {
return bindataRead( return bindataRead(
@ -284,7 +284,7 @@ func configTestDataJson() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "config/test-data.json", size: 301, mode: os.FileMode(420), modTime: time.Unix(1495715449, 0)} info := bindataFileInfo{name: "config/test-data.json", size: 300, mode: os.FileMode(420), modTime: time.Unix(1495916186, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }

View File

@ -1,6 +1,6 @@
{ {
"Node": { "Node": {
"SyncSeconds": 20, "SyncSeconds": 7,
"HTTPPort": 8645, "HTTPPort": 8645,
"WSPort": 8646 "WSPort": 8646
}, },