pond: New miner spawning
This commit is contained in:
parent
b4e25701af
commit
e01ab507ca
@ -67,6 +67,7 @@ type FullNode interface {
|
||||
|
||||
MinerRegister(context.Context, address.Address) error
|
||||
MinerUnregister(context.Context, address.Address) error
|
||||
MinerAddresses(context.Context) ([]address.Address, error)
|
||||
MinerCreateBlock(context.Context, address.Address, *types.TipSet, []*types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error)
|
||||
|
||||
// // UX ?
|
||||
|
@ -56,6 +56,7 @@ type FullNodeStruct struct {
|
||||
|
||||
MinerRegister func(context.Context, address.Address) error `perm:"admin"`
|
||||
MinerUnregister func(context.Context, address.Address) error `perm:"admin"`
|
||||
MinerAddresses func(context.Context) ([]address.Address, error) `perm:"write"`
|
||||
MinerCreateBlock func(context.Context, address.Address, *types.TipSet, []*types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error) `perm:"write"`
|
||||
|
||||
WalletNew func(context.Context, string) (address.Address, error) `perm:"write"`
|
||||
@ -168,6 +169,10 @@ func (c *FullNodeStruct) MinerUnregister(ctx context.Context, addr address.Addre
|
||||
return c.Internal.MinerUnregister(ctx, addr)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) MinerAddresses(ctx context.Context) ([]address.Address, error) {
|
||||
return c.Internal.MinerAddresses(ctx)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) MinerCreateBlock(ctx context.Context, addr address.Address, base *types.TipSet, tickets []*types.Ticket, eproof types.ElectionProof, msgs []*types.SignedMessage) (*chain.BlockMsg, error) {
|
||||
return c.Internal.MinerCreateBlock(ctx, addr, base, tickets, eproof, msgs)
|
||||
}
|
||||
|
@ -149,8 +149,13 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) {
|
||||
return nodeInfo{}, err
|
||||
}
|
||||
|
||||
initArgs := []string{"init"}
|
||||
if fullNodeRepo == api.running[1].meta.Repo {
|
||||
initArgs = []string{"init", "--actor=t0101", "--genesis-miner"}
|
||||
}
|
||||
|
||||
id := atomic.AddInt32(&api.cmds, 1)
|
||||
cmd := exec.Command("./lotus-storage-miner", "init")
|
||||
cmd := exec.Command("./lotus-storage-miner", initArgs...)
|
||||
cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile)
|
||||
cmd.Stdout = io.MultiWriter(os.Stdout, logfile)
|
||||
cmd.Env = []string{"LOTUS_STORAGE_PATH=" + dir, "LOTUS_PATH=" + fullNodeRepo}
|
||||
|
@ -10,12 +10,9 @@ class FullNode extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
mining: false,
|
||||
}
|
||||
this.state = {}
|
||||
|
||||
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.add1k = this.add1k.bind(this)
|
||||
@ -46,6 +43,8 @@ class FullNode extends React.Component {
|
||||
return this.props.client.call('Filecoin.PaychVoucherList', [paych])
|
||||
}))
|
||||
|
||||
let minerList = await this.props.client.call('Filecoin.MinerAddresses', [])
|
||||
|
||||
this.setState(() => ({
|
||||
id: id,
|
||||
version: version,
|
||||
@ -56,20 +55,10 @@ class FullNode extends React.Component {
|
||||
paychs: paychs,
|
||||
vouchers: vouchers,
|
||||
|
||||
defaultAddr: defaultAddr}))
|
||||
}
|
||||
defaultAddr: defaultAddr,
|
||||
|
||||
async startMining() {
|
||||
// TODO: Use actual miner address
|
||||
// see cli/miner.go
|
||||
this.setState({mining: true})
|
||||
let addr = "t0101" // in case we have no wallets
|
||||
/*if (this.state.defaultAddr) {
|
||||
addr = this.state.defaultAddr
|
||||
}*/
|
||||
|
||||
this.setState({mining: true})
|
||||
await this.props.client.call("Filecoin.MinerStart", [addr])
|
||||
minerList: minerList,
|
||||
}))
|
||||
}
|
||||
|
||||
async newScepAddr() {
|
||||
@ -105,9 +94,10 @@ class FullNode extends React.Component {
|
||||
)
|
||||
}
|
||||
|
||||
let mine = <a href="#" disabled={this.state.mining} onClick={this.startMining}>[Mine]</a>
|
||||
if (this.state.mining) {
|
||||
mine = "[Mining]"
|
||||
let mining = <span/>
|
||||
if(this.state.minerList.length > 0) {
|
||||
mining = this.state.minerList.map((a, k) => <span key={k}> <Address short={true} client={this.props.client} addr={a} mountWindow={this.props.mountWindow}/></span>)
|
||||
mining = <span>[Mine{mining}]</span>
|
||||
}
|
||||
|
||||
let storageMine = <a href="#" onClick={this.startStorageMiner}>[Spawn Storage Miner]</a>
|
||||
@ -143,7 +133,7 @@ class FullNode extends React.Component {
|
||||
<div>Repo: LOTUS_PATH={this.props.node.Repo}</div>
|
||||
{chainInfo}
|
||||
<div>
|
||||
{mine} {storageMine}
|
||||
{mining} {storageMine}
|
||||
</div>
|
||||
<div>
|
||||
<div>Balances: [New <a href="#" onClick={this.newScepAddr}>[Secp256k1]</a>]</div>
|
||||
|
@ -53,6 +53,16 @@ type Miner struct {
|
||||
lastWork *MiningBase
|
||||
}
|
||||
|
||||
func (m *Miner) Addresses() ([]address.Address, error) {
|
||||
m.lk.Lock()
|
||||
defer m.lk.Unlock()
|
||||
|
||||
out := make([]address.Address, len(m.addresses))
|
||||
copy(out, m.addresses)
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *Miner) Register(addr address.Address) error {
|
||||
m.lk.Lock()
|
||||
defer m.lk.Unlock()
|
||||
|
@ -24,6 +24,10 @@ type FullNodeAPI struct {
|
||||
Miner *miner.Miner
|
||||
}
|
||||
|
||||
func (a *FullNodeAPI) MinerAddresses(context.Context) ([]address.Address, error) {
|
||||
return a.Miner.Addresses()
|
||||
}
|
||||
|
||||
func (a *FullNodeAPI) MinerRegister(ctx context.Context, addr address.Address) error {
|
||||
return a.Miner.Register(addr)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user