pond: New miner spawning

This commit is contained in:
Łukasz Magiera 2019-08-21 17:14:38 +02:00
parent b4e25701af
commit e01ab507ca
6 changed files with 37 additions and 22 deletions

View File

@ -67,6 +67,7 @@ type FullNode interface {
MinerRegister(context.Context, address.Address) error MinerRegister(context.Context, address.Address) error
MinerUnregister(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) MinerCreateBlock(context.Context, address.Address, *types.TipSet, []*types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error)
// // UX ? // // UX ?

View File

@ -56,6 +56,7 @@ type FullNodeStruct struct {
MinerRegister func(context.Context, address.Address) error `perm:"admin"` MinerRegister func(context.Context, address.Address) error `perm:"admin"`
MinerUnregister 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"` 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"` 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) 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) { 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) return c.Internal.MinerCreateBlock(ctx, addr, base, tickets, eproof, msgs)
} }

View File

@ -149,8 +149,13 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) {
return nodeInfo{}, err 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) 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.Stderr = io.MultiWriter(os.Stderr, errlogfile)
cmd.Stdout = io.MultiWriter(os.Stdout, logfile) cmd.Stdout = io.MultiWriter(os.Stdout, logfile)
cmd.Env = []string{"LOTUS_STORAGE_PATH=" + dir, "LOTUS_PATH=" + fullNodeRepo} cmd.Env = []string{"LOTUS_STORAGE_PATH=" + dir, "LOTUS_PATH=" + fullNodeRepo}

View File

@ -10,12 +10,9 @@ class FullNode extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {}
mining: false,
}
this.loadInfo = this.loadInfo.bind(this) this.loadInfo = this.loadInfo.bind(this)
this.startMining = this.startMining.bind(this)
this.newScepAddr = this.newScepAddr.bind(this) this.newScepAddr = this.newScepAddr.bind(this)
this.startStorageMiner = this.startStorageMiner.bind(this) this.startStorageMiner = this.startStorageMiner.bind(this)
this.add1k = this.add1k.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]) return this.props.client.call('Filecoin.PaychVoucherList', [paych])
})) }))
let minerList = await this.props.client.call('Filecoin.MinerAddresses', [])
this.setState(() => ({ this.setState(() => ({
id: id, id: id,
version: version, version: version,
@ -56,20 +55,10 @@ class FullNode extends React.Component {
paychs: paychs, paychs: paychs,
vouchers: vouchers, vouchers: vouchers,
defaultAddr: defaultAddr})) defaultAddr: defaultAddr,
}
async startMining() { minerList: minerList,
// 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])
} }
async newScepAddr() { async newScepAddr() {
@ -105,9 +94,10 @@ class FullNode extends React.Component {
) )
} }
let mine = <a href="#" disabled={this.state.mining} onClick={this.startMining}>[Mine]</a> let mining = <span/>
if (this.state.mining) { if(this.state.minerList.length > 0) {
mine = "[Mining]" mining = this.state.minerList.map((a, k) => <span key={k}>&nbsp;<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> 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> <div>Repo: LOTUS_PATH={this.props.node.Repo}</div>
{chainInfo} {chainInfo}
<div> <div>
{mine} {storageMine} {mining} {storageMine}
</div> </div>
<div> <div>
<div>Balances: [New <a href="#" onClick={this.newScepAddr}>[Secp256k1]</a>]</div> <div>Balances: [New <a href="#" onClick={this.newScepAddr}>[Secp256k1]</a>]</div>

View File

@ -53,6 +53,16 @@ type Miner struct {
lastWork *MiningBase 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 { func (m *Miner) Register(addr address.Address) error {
m.lk.Lock() m.lk.Lock()
defer m.lk.Unlock() defer m.lk.Unlock()

View File

@ -24,6 +24,10 @@ type FullNodeAPI struct {
Miner *miner.Miner 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 { func (a *FullNodeAPI) MinerRegister(ctx context.Context, addr address.Address) error {
return a.Miner.Register(addr) return a.Miner.Register(addr)
} }