From 282654bf7b867421b40742ea096ddfdad83b825a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 31 Jul 2019 01:18:21 +0200 Subject: [PATCH] pond: storage miner init --- cmd/lotus-storage-miner/init.go | 2 +- lotuspond/front/src/App.css | 3 +- lotuspond/front/src/FullNode.js | 22 ++++++++- lotuspond/front/src/NodeList.js | 2 +- lotuspond/front/src/StorageNode.js | 18 +++++++ lotuspond/front/src/StorageNodeInit.js | 26 +++++++++++ lotuspond/main.go | 65 +++++++++++++++++++++++++- node/repo/fsrepo.go | 12 +++-- 8 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 lotuspond/front/src/StorageNode.js create mode 100644 lotuspond/front/src/StorageNodeInit.js diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 59e4a7ada..92005df13 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -155,7 +155,7 @@ var initCmd = &cli.Command{ return err } - log.Infof("Waiting for confirmation (TODO: actually wait)") + log.Infof("Waiting for confirmation") mw, err := api.ChainWaitMsg(ctx, signed.Cid()) if err != nil { diff --git a/lotuspond/front/src/App.css b/lotuspond/front/src/App.css index 7bc75558a..0f5e72b26 100644 --- a/lotuspond/front/src/App.css +++ b/lotuspond/front/src/App.css @@ -13,8 +13,9 @@ } .CristalScroll { + display: flex; min-width: 100%; - height: 100%; + min-height: 100%; overflow: auto; } diff --git a/lotuspond/front/src/FullNode.js b/lotuspond/front/src/FullNode.js index 43da62bd2..1e73f3583 100644 --- a/lotuspond/front/src/FullNode.js +++ b/lotuspond/front/src/FullNode.js @@ -2,6 +2,7 @@ import React from 'react'; import { Client } from 'rpc-websockets' import Cristal from 'react-cristal' import { BlockLinks } from "./BlockLink"; +import StorageNodeInit from "./StorageNodeInit"; const stateConnected = 'connected' const stateConnecting = 'connecting' @@ -31,6 +32,8 @@ class FullNode extends React.Component { this.loadInfo = this.loadInfo.bind(this) this.startMining = this.startMining.bind(this) + this.newScepAddr = this.newScepAddr.bind(this) + this.startStorageMiner = this.startStorageMiner.bind(this) this.connect() } @@ -101,6 +104,7 @@ class FullNode extends React.Component { async startMining() { // TODO: Use actual miner address // see cli/miner.go + this.setState({mining: true}) let addr = "t0523423423" // in case we have no wallets if (this.state.defaultAddr) { addr = this.state.defaultAddr @@ -110,6 +114,16 @@ class FullNode extends React.Component { await this.state.client.call("Filecoin.MinerStart", [addr]) } + async newScepAddr() { + const t = "secp256k1" + await this.state.client.call("Filecoin.WalletNew", [t]) + this.loadInfo() + } + + async startStorageMiner() { + this.props.mountWindow((onClose) => ) + } + render() { let runtime =
if (this.state.state === stateConnected) { @@ -129,6 +143,8 @@ class FullNode extends React.Component { mine = "[Mining]" } + let storageMine = [Spawn Storage Miner] + let balances = this.state.balances.map(([addr, balance]) => { let line = {truncAddr(addr)}: {balance} (ActTyp) if (this.state.defaultAddr === addr) { @@ -142,9 +158,11 @@ class FullNode extends React.Component {
v{this.state.version.Version}, {this.state.id.substr(-8)}, {this.state.peers} peers
Repo: LOTUS_PATH={this.props.node.Repo}
{chainInfo} - {mine}
-
Balances:
+ {mine} {storageMine} +
+
+
Balances: [New [Secp256k1]]
{balances}
diff --git a/lotuspond/front/src/NodeList.js b/lotuspond/front/src/NodeList.js index bd775d7cd..d92cfb279 100644 --- a/lotuspond/front/src/NodeList.js +++ b/lotuspond/front/src/NodeList.js @@ -52,7 +52,7 @@ class NodeList extends React.Component { this.setState({nextWindow: id + 1}) const window = cb(() => { - console.log("umount wnd todo") + this.setState(prev => ({windows: {...prev.windows, [id]: undefined}})) }) this.setState(prev => ({windows: {...prev.windows, [id]: window}})) diff --git a/lotuspond/front/src/StorageNode.js b/lotuspond/front/src/StorageNode.js new file mode 100644 index 000000000..bb7a19ff5 --- /dev/null +++ b/lotuspond/front/src/StorageNode.js @@ -0,0 +1,18 @@ +import React from 'react'; +import {Cristal} from "react-cristal"; + +class StorageNode extends React.Component { + render() { + return +
+
+ I'm a node +
+
+
+ } +} + +export default StorageNode \ No newline at end of file diff --git a/lotuspond/front/src/StorageNodeInit.js b/lotuspond/front/src/StorageNodeInit.js new file mode 100644 index 000000000..674e8c601 --- /dev/null +++ b/lotuspond/front/src/StorageNodeInit.js @@ -0,0 +1,26 @@ +import React from 'react'; +import {Cristal} from "react-cristal"; +import StorageNode from "./StorageNode"; + +class StorageNodeInit extends React.Component { + async componentDidMount() { + const info = await this.props.pondClient.call('Pond.SpawnStorage', [this.props.fullRepo]) + + this.props.onClose() + this.props.mountWindow((onClose) => ) + } + + render() { + return +
+
+ Waiting for init, make sure at least one miner is enabled +
+
+
+ } +} + +export default StorageNodeInit \ No newline at end of file diff --git a/lotuspond/main.go b/lotuspond/main.go index 2c48afccb..0f0ca3ee0 100644 --- a/lotuspond/main.go +++ b/lotuspond/main.go @@ -37,6 +37,8 @@ type nodeInfo struct { Repo string ID int32 ApiPort int32 + + Storage bool } func (api *api) Spawn() (nodeInfo, error) { @@ -63,11 +65,11 @@ func (api *api) Spawn() (nodeInfo, error) { } - errlogfile, err := os.OpenFile(dir + ".err.log", os.O_CREATE | os.O_WRONLY, 0644) + errlogfile, err := os.OpenFile(dir+".err.log", os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return nodeInfo{}, err } - logfile, err := os.OpenFile(dir + ".out.log", os.O_CREATE | os.O_WRONLY, 0644) + logfile, err := os.OpenFile(dir+".out.log", os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return nodeInfo{}, err } @@ -137,6 +139,65 @@ func (api *api) TokenFor(id int32) (string, error) { return string(t), nil } +func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) { + dir, err := ioutil.TempDir(os.TempDir(), "lotus-storage-") + if err != nil { + return nodeInfo{}, err + } + + errlogfile, err := os.OpenFile(dir+".err.log", os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return nodeInfo{}, err + } + logfile, err := os.OpenFile(dir+".out.log", os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return nodeInfo{}, err + } + + id := atomic.AddInt32(&api.cmds, 1) + cmd := exec.Command("./lotus-storage-miner", "init") + cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile) + cmd.Stdout = io.MultiWriter(os.Stdout, logfile) + cmd.Env = []string{"LOTUS_STORAGE_PATH=" + dir, "LOTUS_PATH=" + fullNodeRepo} + if err := cmd.Run(); err != nil { + return nodeInfo{}, err + } + + time.Sleep(time.Millisecond * 300) + + cmd = exec.Command("./lotus-storage-miner", "run", "--api", fmt.Sprintf("%d", 2500+id)) + cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile) + cmd.Stdout = io.MultiWriter(os.Stdout, logfile) + cmd.Env = []string{"LOTUS_STORAGE_PATH=" + dir, "LOTUS_PATH=" + fullNodeRepo} + if err := cmd.Start(); err != nil { + return nodeInfo{}, err + } + + info := nodeInfo{ + Repo: dir, + ID: id, + ApiPort: 2500 + id, + + Storage: true, + } + + api.runningLk.Lock() + api.running[id] = runningNode{ + cmd: cmd, + meta: info, + + stop: func() { + defer errlogfile.Close() + defer logfile.Close() + }, + } + api.runningLk.Unlock() + + time.Sleep(time.Millisecond * 750) // TODO: Something less terrible + + return info, nil +} + func main() { rpcServer := jsonrpc.NewServer() rpcServer.Register("Pond", &api{running: map[int32]runningNode{}}) diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index 22057f72c..abe232b60 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -67,15 +67,17 @@ func (fsr *FsRepo) Exists() (bool, error) { } func (fsr *FsRepo) Init() error { - if _, err := os.Stat(fsr.path); err == nil { - return fsr.initKeystore() - } else if !os.IsNotExist(err) { + exist, err := fsr.Exists() + if err != nil { return err } + if exist { + return nil + } log.Infof("Initializing repo at '%s'", fsr.path) - err := os.Mkdir(fsr.path, 0755) //nolint: gosec - if err != nil { + err = os.Mkdir(fsr.path, 0755) //nolint: gosec + if err != nil && !os.IsExist(err) { return err } c, err := os.Create(filepath.Join(fsr.path, fsConfig))