Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Filesystem watching (#558)
Browse files Browse the repository at this point in the history
* Fix source code formatting

* Init fs watch.
Move bats test to dedicated dir

* Refactor file watching

* Add notification channel to config watcher

* Fix  path to bats tests in  CircleCI config

* observer implementation (#5)

* config file watching, "requiedHash" support

* vendor fsnotify (and update some dependencies)

* Upgrade vendored `color` package.
Add StdErr outup

* Revert changes in a vendor dir

* Fix bats test directory paths

* problem: duplicate config flags (#6)
  • Loading branch information
r8d8 authored Apr 25, 2018
1 parent 4621800 commit d71431f
Show file tree
Hide file tree
Showing 82 changed files with 4,723 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bats_tests_steps: &bats_tests_steps
go build -tags="sputnikvm netgo" -ldflags "$EXT_LD_FLAGS -X main.Version=`janus version -format TAG_OR_NIGHTLY`" ./cmd/geth
mkdir -p $GOPATH/bin
mv ./geth $GOPATH/bin/
bats cmd/geth
bats tests/cmd_bats
- persist_to_workspace:
root: ~/
paths:
Expand Down
8 changes: 7 additions & 1 deletion Gopkg.lock

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

5 changes: 3 additions & 2 deletions cmd/geth/build_atxi_cmd.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"os"
"time"

"github.com/ethereumproject/go-ethereum/core"
"github.com/ethereumproject/go-ethereum/core/types"
"github.com/ethereumproject/go-ethereum/ethdb"
"github.com/ethereumproject/go-ethereum/logger"
"github.com/ethereumproject/go-ethereum/logger/glog"
"gopkg.in/urfave/cli.v1"
"os"
"time"
)

var buildAddrTxIndexCommand = cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ func startNode(ctx *cli.Context, stack *node.Node) *eth.Ethereum {
// Unlock any account specifically requested
var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil {
glog.Fatal("ethereum service not running: ", err)
glog.Fatal("Ethereum service not running: ", err)
}

// Start auxiliary services if enabled
Expand Down
118 changes: 60 additions & 58 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,86 +140,86 @@ func makeCLIApp() (app *cli.App) {
}

app.Flags = []cli.Flag{
PprofFlag,
PprofIntervalFlag,
SputnikVMFlag,
NodeNameFlag,
UnlockedAccountFlag,
PasswordFileFlag,
AccountsIndexFlag,
AddrTxIndexFlag,
AutoDAGFlag,
BacktraceAtFlag,
BlockchainVersionFlag,
BootnodesFlag,
CacheFlag,
ChainIdentityFlag,
DataDirFlag,
DevModeFlag,
DisplayFlag,
DisplayFormatFlag,
DocRootFlag,
KeyStoreDirFlag,
ChainIdentityFlag,
BlockchainVersionFlag,
EtherbaseFlag,
ExecFlag,
ExtraDataFlag,
FakePoWFlag,
FastSyncFlag,
AddrTxIndexFlag,
CacheFlag,
LightKDFFlag,
GasPriceFlag,
GpoFullBlockRatioFlag,
GpoMaxGasPriceFlag,
GpoMinGasPriceFlag,
GpobaseCorrectionFactorFlag,
GpobaseStepDownFlag,
GpobaseStepUpFlag,
IPCApiFlag,
IPCDisabledFlag,
IPCPathFlag,
JSpathFlag,
KeyStoreDirFlag,
LightKDFFlag,
ListenPortFlag,
LogCompressFlag,
LogDirFlag,
LogIntervalFlag,
LogMaxAgeFlag,
LogMaxSizeFlag,
LogMaxTotalSizeFlag,
LogMinSizeFlag,
LogStatusFlag,
MLogComponentsFlag,
MLogDirFlag,
MLogFlag,
MaxPeersFlag,
MaxPendingPeersFlag,
EtherbaseFlag,
GasPriceFlag,
MetricsFlag,
MinerThreadsFlag,
MiningEnabledFlag,
MiningGPUFlag,
AutoDAGFlag,
TargetGasLimitFlag,
NATFlag,
NatspecEnabledFlag,
NeckbeardFlag,
NetworkIdFlag,
NoDiscoverFlag,
NodeKeyFileFlag,
NodeKeyHexFlag,
NodeNameFlag,
PasswordFileFlag,
PprofFlag,
PprofIntervalFlag,
PreloadJSFlag,
RPCApiFlag,
RPCCORSDomainFlag,
RPCEnabledFlag,
RPCListenAddrFlag,
RPCPortFlag,
RPCApiFlag,
SolcPathFlag,
SputnikVMFlag,
TargetGasLimitFlag,
TestNetFlag,
UnlockedAccountFlag,
Unused1,
VModuleFlag,
VerbosityFlag,
WSAllowedOriginsFlag,
WSApiFlag,
WSEnabledFlag,
WSListenAddrFlag,
WSPortFlag,
WSApiFlag,
WSAllowedOriginsFlag,
IPCDisabledFlag,
IPCApiFlag,
IPCPathFlag,
ExecFlag,
PreloadJSFlag,
WhisperEnabledFlag,
DevModeFlag,
TestNetFlag,
NetworkIdFlag,
RPCCORSDomainFlag,
NeckbeardFlag,
VerbosityFlag,
DisplayFlag,
DisplayFormatFlag,
VModuleFlag,
LogDirFlag,
LogMaxSizeFlag,
LogMinSizeFlag,
LogMaxTotalSizeFlag,
LogIntervalFlag,
LogMaxAgeFlag,
LogCompressFlag,
LogStatusFlag,
MLogFlag,
MLogDirFlag,
MLogComponentsFlag,
BacktraceAtFlag,
MetricsFlag,
FakePoWFlag,
SolcPathFlag,
GpoMinGasPriceFlag,
GpoMaxGasPriceFlag,
GpoFullBlockRatioFlag,
GpobaseStepDownFlag,
GpobaseStepUpFlag,
GpobaseCorrectionFactorFlag,
ExtraDataFlag,
Unused1,
}

app.Before = func(ctx *cli.Context) error {
Expand Down Expand Up @@ -343,15 +343,17 @@ func main() {
// It creates a default node based on the command line arguments and runs it in
// blocking mode, waiting for it to be shut down.
func geth(ctx *cli.Context) error {
//_, err := core.NewConfigWatchdog("")
//if err != nil {
// return err
//}

n := MakeSystemNode(Version, ctx)
ethe := startNode(ctx, n)

if ctx.GlobalString(LogStatusFlag.Name) != "off" {
dispatchStatusLogs(ctx, ethe)
}
logLoggingConfiguration(ctx)

n.Wait()

return nil
Expand Down
16 changes: 8 additions & 8 deletions core/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var DEFAULTS *FileSystem
func init() {
DEFAULTS = &FileSystem{
files: map[string]File{
"/core/config/mainnet.json": File{
"/core/config/mainnet.json": {
data: []byte{
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x64, 0x65, 0x6e, 0x74,
0x69, 0x74, 0x79, 0x22, 0x3a, 0x20, 0x22, 0x6d, 0x61, 0x69, 0x6e, 0x6e,
Expand Down Expand Up @@ -438,7 +438,7 @@ func init() {
modTime: time.Unix(0, 1523447624616297268),
isDir: false,
},
}, "/core/config/mainnet_bootnodes.json": File{
}, "/core/config/mainnet_bootnodes.json": {
data: []byte{
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x74, 0x73,
0x74, 0x72, 0x61, 0x70, 0x22, 0x3a, 0x20, 0x5b, 0x0a, 0x20, 0x20, 0x20,
Expand Down Expand Up @@ -590,7 +590,7 @@ func init() {
modTime: time.Unix(0, 1523447624616297268),
isDir: false,
},
}, "/core/config/mainnet_genesis.json": File{
}, "/core/config/mainnet_genesis.json": {
data: []byte{
0x7b, 0x0a, 0x09, 0x22, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x22,
0x3a, 0x20, 0x7b, 0x0a, 0x09, 0x09, 0x22, 0x6e, 0x6f, 0x6e, 0x63, 0x65,
Expand Down Expand Up @@ -626,7 +626,7 @@ func init() {
modTime: time.Unix(0, 1523453563701706189),
isDir: false,
},
}, "/core/config/mainnet_genesis_alloc.csv": File{
}, "/core/config/mainnet_genesis_alloc.csv": {
data: []byte{
0x22, 0x30, 0x30, 0x30, 0x64, 0x38, 0x33, 0x36, 0x32, 0x30, 0x31, 0x33,
0x31, 0x38, 0x65, 0x63, 0x36, 0x38, 0x39, 0x39, 0x61, 0x36, 0x37, 0x35,
Expand Down Expand Up @@ -50744,7 +50744,7 @@ func init() {
modTime: time.Unix(0, 1523452670812442609),
isDir: false,
},
}, "/core/config/morden.json": File{
}, "/core/config/morden.json": {
data: []byte{
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x69, 0x64, 0x65, 0x6e, 0x74,
0x69, 0x74, 0x79, 0x22, 0x3a, 0x20, 0x22, 0x6d, 0x6f, 0x72, 0x64, 0x65,
Expand Down Expand Up @@ -51060,7 +51060,7 @@ func init() {
modTime: time.Unix(0, 1523447624619297289),
isDir: false,
},
}, "/core/config/morden_bootnodes.json": File{
}, "/core/config/morden_bootnodes.json": {
data: []byte{
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x74, 0x73,
0x74, 0x72, 0x61, 0x70, 0x22, 0x3a, 0x20, 0x5b, 0x0a, 0x20, 0x20, 0x20,
Expand Down Expand Up @@ -51170,7 +51170,7 @@ func init() {
modTime: time.Unix(0, 1523447624620297295),
isDir: false,
},
}, "/core/config/morden_genesis.json": File{
}, "/core/config/morden_genesis.json": {
data: []byte{
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x22, 0x67, 0x65, 0x6e, 0x65, 0x73,
0x69, 0x73, 0x22, 0x3a, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
Expand Down Expand Up @@ -51210,7 +51210,7 @@ func init() {
modTime: time.Unix(0, 1523452878606583618),
isDir: false,
},
}, "/core/config/morden_genesis_alloc.csv": File{
}, "/core/config/morden_genesis_alloc.csv": {
data: []byte{
0x22, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
Expand Down
1 change: 1 addition & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"strconv"

"encoding/binary"

"github.com/ethereumproject/go-ethereum/common"
"github.com/ethereumproject/go-ethereum/core/state"
"github.com/ethereumproject/go-ethereum/core/types"
Expand Down
5 changes: 3 additions & 2 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"testing"
"time"

"io/ioutil"
"strings"

"github.com/ethereumproject/ethash"
"github.com/ethereumproject/go-ethereum/common"
"github.com/ethereumproject/go-ethereum/core/state"
Expand All @@ -37,8 +40,6 @@ import (
"github.com/ethereumproject/go-ethereum/logger/glog"
"github.com/ethereumproject/go-ethereum/rlp"
"github.com/hashicorp/golang-lru"
"io/ioutil"
"strings"
)

func init() {
Expand Down
62 changes: 62 additions & 0 deletions core/cfgwatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package core

import (
"log"
"path/filepath"

"github.com/fsnotify/fsnotify"
)

type configWatchdog struct {
path string
watcher *fsnotify.Watcher
observers []func(*SufficientChainConfig)
}

// NewConfigWatchdog creates new file watcher for config
// directory
func NewConfigWatchdog() (*configWatchdog, error) {
path := flaggedExternalChainConfigPath // pull the package-level variable
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
// monitor entire directory - we assume, that files can be included only from this directory
err = watcher.Add(filepath.Dir(path))

return &configWatchdog{path, watcher, nil}, err
}

// Start config directory watching
func (cw *configWatchdog) Start() {
go func() {
for {
select {
case event := <-cw.watcher.Events:
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
newConfig, err := ReadExternalChainConfigFromFile(cw.path)
if err != nil {
log.Println("configuration error:", err)
continue
}
for _, observer := range cw.observers {
observer(newConfig)
}
}
case err := <-cw.watcher.Errors:
log.Println("error:", err)
}
}
}()
}

// Stop config directory watching
func (cw *configWatchdog) Stop() error {
return cw.watcher.Close()
}

func (cw *configWatchdog) Subscribe(observer func(*SufficientChainConfig)) {
cw.observers = append(cw.observers, observer)
}
5 changes: 4 additions & 1 deletion core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,15 @@ func parseExternalChainConfig(mainConfigFile string, open func(string) (io.ReadC
return config, nil
}

// This nasty little variable memoize the last (= the only one) configuration file path.
var flaggedExternalChainConfigPath string

// ReadExternalChainConfigFromFile reads a flagged external json file for blockchain configuration.
// It returns a valid and full ("hard") configuration or an error.
func ReadExternalChainConfigFromFile(incomingPath string) (*SufficientChainConfig, error) {

// ensure flag arg cleanliness
flaggedExternalChainConfigPath := filepath.Clean(incomingPath)
flaggedExternalChainConfigPath = filepath.Clean(incomingPath)

// ensure file exists and that it is NOT a directory
if info, err := os.Stat(flaggedExternalChainConfigPath); os.IsNotExist(err) {
Expand Down
Loading

0 comments on commit d71431f

Please sign in to comment.