2019-07-30 23:18:21 +00:00
|
|
|
import React from 'react';
|
2019-07-31 18:20:05 +00:00
|
|
|
import { Client } from 'rpc-websockets'
|
2019-08-10 01:54:45 +00:00
|
|
|
import Address from "./Address";
|
2019-09-19 14:27:01 +00:00
|
|
|
import Window from "./Window";
|
2019-07-31 18:20:05 +00:00
|
|
|
|
|
|
|
const stateConnected = 'connected'
|
|
|
|
const stateConnecting = 'connecting'
|
|
|
|
const stateGettingToken = 'getting-token'
|
|
|
|
|
|
|
|
let sealCodes = [
|
2020-02-24 00:05:20 +00:00
|
|
|
"UndefinedSectorState",
|
|
|
|
"Empty",
|
|
|
|
"Packing",
|
|
|
|
"Unsealed",
|
|
|
|
"PreCommitting",
|
|
|
|
"WaitSeed",
|
|
|
|
"Committing",
|
|
|
|
"CommitWait",
|
|
|
|
"FinalizeSector",
|
|
|
|
"Proving",
|
2019-12-04 16:53:32 +00:00
|
|
|
|
2020-02-24 00:05:20 +00:00
|
|
|
"SealFailed",
|
|
|
|
"PreCommitFailed",
|
|
|
|
"SealCommitFailed",
|
|
|
|
"CommitFailed",
|
|
|
|
"PackingFailed",
|
|
|
|
|
|
|
|
"FailedUnrecoverable",
|
|
|
|
"Faulty",
|
|
|
|
"FaultReported",
|
|
|
|
"FaultedFinal",
|
2019-07-31 18:20:05 +00:00
|
|
|
]
|
2019-07-30 23:18:21 +00:00
|
|
|
|
|
|
|
class StorageNode extends React.Component {
|
2019-07-31 18:20:05 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
state: stateGettingToken,
|
|
|
|
id: "~",
|
|
|
|
|
|
|
|
mining: false,
|
|
|
|
|
2019-09-25 13:02:15 +00:00
|
|
|
statusCounts: [0, 0, 0, 0, 0]
|
2019-07-31 18:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.loadInfo = this.loadInfo.bind(this)
|
2019-12-08 21:48:20 +00:00
|
|
|
this.pledgeSector = this.pledgeSector.bind(this)
|
2019-09-17 12:53:43 +00:00
|
|
|
this.stop = this.stop.bind(this)
|
2019-07-31 18:20:05 +00:00
|
|
|
|
|
|
|
this.connect()
|
|
|
|
}
|
|
|
|
|
|
|
|
async connect() {
|
|
|
|
const token = await this.props.pondClient.call('Pond.TokenFor', [this.props.node.ID])
|
|
|
|
|
|
|
|
this.setState(() => ({
|
|
|
|
state: stateConnecting,
|
|
|
|
token: token,
|
|
|
|
}))
|
|
|
|
|
|
|
|
const client = new Client(`ws://127.0.0.1:${this.props.node.ApiPort}/rpc/v0?token=${token}`)
|
|
|
|
client.on('open', async () => {
|
|
|
|
this.setState(() => ({
|
|
|
|
state: stateConnected,
|
|
|
|
client: client,
|
|
|
|
|
|
|
|
version: {Version: "~version~"},
|
|
|
|
id: "~peerid~",
|
|
|
|
peers: -1,
|
|
|
|
balances: []
|
|
|
|
}))
|
|
|
|
|
|
|
|
const id = await this.state.client.call("Filecoin.ID", [])
|
|
|
|
this.setState(() => ({id: id}))
|
|
|
|
|
|
|
|
// this.props.onConnect(client, id) // TODO: dedupe connecting part
|
|
|
|
|
2019-09-17 12:53:43 +00:00
|
|
|
let updates = setInterval(this.loadInfo, 1050)
|
|
|
|
client.on('close', () => clearInterval(updates))
|
2019-07-31 18:20:05 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
console.log(token) // todo: use
|
|
|
|
}
|
|
|
|
|
|
|
|
async loadInfo() {
|
|
|
|
const version = await this.state.client.call("Filecoin.Version", [])
|
|
|
|
const peers = await this.state.client.call("Filecoin.NetPeers", [])
|
2019-10-15 05:07:28 +00:00
|
|
|
const actor = await this.state.client.call("Filecoin.ActorAddress", [])
|
2019-07-31 18:20:05 +00:00
|
|
|
|
2019-09-19 16:17:49 +00:00
|
|
|
const stActor = await this.props.fullConn.call('Filecoin.StateGetActor', [actor, null])
|
|
|
|
const actorState = await this.props.fullConn.call('Filecoin.StateReadState', [stActor, null])
|
|
|
|
|
|
|
|
this.setState({version: version, peers: peers.length, actor: actor, actorState: actorState})
|
2019-07-31 18:20:05 +00:00
|
|
|
await this.stagedList()
|
|
|
|
}
|
|
|
|
|
|
|
|
async stagedList() {
|
2019-10-15 05:07:28 +00:00
|
|
|
let stagedList = await this.state.client.call("Filecoin.SectorsList", [])
|
2019-07-31 18:20:05 +00:00
|
|
|
let staged = await stagedList
|
2019-10-15 05:07:28 +00:00
|
|
|
.map(sector => this.state.client.call("Filecoin.SectorsStatus", [sector]))
|
2019-07-31 18:20:05 +00:00
|
|
|
.reduce(async (p, n) => [...await p, await n], Promise.resolve([]))
|
|
|
|
|
2019-09-25 13:02:15 +00:00
|
|
|
let statusCounts = staged.reduce((p, n) => p.map((e, i) => e + (i === n.State ? 1 : 0) ), [0, 0, 0, 0, 0])
|
2019-07-31 18:20:05 +00:00
|
|
|
|
|
|
|
this.setState({staged, statusCounts})
|
|
|
|
}
|
|
|
|
|
2019-12-08 21:48:20 +00:00
|
|
|
async pledgeSector() {
|
|
|
|
await this.state.client.call("Filecoin.PledgeSector", [])
|
2019-07-31 18:20:05 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 13:02:15 +00:00
|
|
|
sealStaged = async () => {
|
|
|
|
await this.state.client.call("Filecoin.SectorsStagedSeal", [])
|
|
|
|
}
|
|
|
|
|
2019-09-17 12:53:43 +00:00
|
|
|
async stop() {
|
|
|
|
await this.props.stop()
|
|
|
|
}
|
|
|
|
|
2019-07-30 23:18:21 +00:00
|
|
|
render() {
|
2019-07-31 18:20:05 +00:00
|
|
|
let runtime = <div></div>
|
2019-08-10 01:54:45 +00:00
|
|
|
if (this.state.actor) {
|
2019-12-08 21:48:20 +00:00
|
|
|
const pledgeSector = <a href="#" onClick={this.pledgeSector}>[Pledge Sector]</a>
|
2019-09-25 13:02:15 +00:00
|
|
|
const sealStaged = <a href="#" onClick={this.sealStaged}>[Seal Staged]</a>
|
2019-07-31 18:20:05 +00:00
|
|
|
|
|
|
|
runtime = (
|
|
|
|
<div>
|
|
|
|
<div>v{this.state.version.Version}, <abbr title={this.state.id}>{this.state.id.substr(-8)}</abbr>, {this.state.peers} peers</div>
|
2020-07-08 10:38:59 +00:00
|
|
|
<div>Repo: LOTUS_MINER_PATH={this.props.node.Repo}</div>
|
2019-07-31 18:20:05 +00:00
|
|
|
<div>
|
2019-12-08 21:48:20 +00:00
|
|
|
{pledgeSector} {sealStaged}
|
2019-07-31 18:20:05 +00:00
|
|
|
</div>
|
2019-08-10 01:54:45 +00:00
|
|
|
<div>
|
|
|
|
<Address client={this.props.fullConn} addr={this.state.actor} mountWindow={this.props.mountWindow}/>
|
2019-11-29 20:18:34 +00:00
|
|
|
<span> <abbr title="Proving period end">EPS:</abbr> <b>{this.state.actorState.State.ElectionPeriodStart}</b></span>
|
2019-08-10 01:54:45 +00:00
|
|
|
</div>
|
2019-09-16 21:25:23 +00:00
|
|
|
<div>{this.state.statusCounts.map((c, i) => <span key={i}>{sealCodes[i]}: {c} | </span>)}</div>
|
2019-07-31 18:20:05 +00:00
|
|
|
<div>
|
2019-09-16 21:25:23 +00:00
|
|
|
{this.state.staged ? this.state.staged.map((s, i) => (
|
2019-10-27 08:56:53 +00:00
|
|
|
<div key={i}>{s.SectorID} {sealCodes[s.State] || `unk ${s.State}`}</div>
|
2019-09-16 21:25:23 +00:00
|
|
|
)) : <div/>}
|
2019-07-31 18:20:05 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-19 14:27:01 +00:00
|
|
|
return <Window
|
2020-07-11 08:55:13 +00:00
|
|
|
title={"Miner Node " + this.props.node.ID}
|
2019-09-17 12:53:43 +00:00
|
|
|
initialPosition={{x: this.props.node.ID*30, y: this.props.node.ID * 30}}
|
|
|
|
onClose={this.stop} >
|
2019-07-30 23:18:21 +00:00
|
|
|
<div className="CristalScroll">
|
2019-07-31 18:20:05 +00:00
|
|
|
<div className="StorageNode">
|
|
|
|
{runtime}
|
2019-07-30 23:18:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-19 14:27:01 +00:00
|
|
|
</Window>
|
2019-07-30 23:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default StorageNode
|