pond: Display miner power

This commit is contained in:
Łukasz Magiera 2019-08-21 18:31:14 +02:00
parent e01ab507ca
commit fd2f0ed4f2
6 changed files with 76 additions and 49 deletions

View File

@ -98,6 +98,7 @@ type FullNode interface {
StateMinerSectors(context.Context, address.Address) ([]*SectorInfo, error)
StateMinerProvingSet(context.Context, address.Address) ([]*SectorInfo, error)
StateMinerPower(context.Context, address.Address, *types.TipSet) (MinerPower, error)
PaychCreate(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, error)
PaychList(context.Context) ([]address.Address, error)
@ -172,3 +173,8 @@ type ActorState struct {
}
type PaychStatus struct{}
type MinerPower struct {
MinerPower types.BigInt
TotalPower types.BigInt
}

View File

@ -74,6 +74,7 @@ type FullNodeStruct struct {
StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
StateMinerPower func(context.Context, address.Address, *types.TipSet) (MinerPower, error) `perm:"read"`
PaychCreate func(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
@ -261,6 +262,10 @@ func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address.
return c.Internal.StateMinerProvingSet(ctx, addr)
}
func (c *FullNodeStruct) StateMinerPower(ctx context.Context, a address.Address, ts *types.TipSet) (MinerPower, error) {
return c.Internal.StateMinerPower(ctx, a, ts)
}
func (c *FullNodeStruct) PaychCreate(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, error) {
return c.Internal.PaychCreate(ctx, from, to, amt)
}

View File

@ -31,17 +31,21 @@ class Address extends React.Component {
let balance = 0
let actor = {}
let actorInfo
let minerInfo
try {
balance = await this.props.client.call('Filecoin.WalletBalance', [this.props.addr])
actor = await this.props.client.call('Filecoin.ChainGetActor', [this.props.addr, this.props.ts || null])
actorInfo = await this.actorInfo(actor)
if(this.props.miner) {
minerInfo = await this.props.client.call('Filecoin.StateMinerPower', [this.props.addr, this.props.ts || null])
}
} catch (err) {
console.log(err)
balance = -1
}
this.setState({balance, actor, actorInfo})
this.setState({balance, actor, actorInfo, minerInfo})
}
openState() {
@ -94,7 +98,12 @@ class Address extends React.Component {
transfer = <span>&nbsp;{this.props.transfer}FIL</span>
}
return <span>{addr}{balance}{actInfo}{add1k}{transfer}</span>
let minerInfo = <span/>
if(this.state.minerInfo) {
minerInfo = <span>&nbsp;Power: {this.state.minerInfo.MinerPower} ({this.state.minerInfo.MinerPower/this.state.minerInfo.TotalPower*100}%)</span>
}
return <span>{addr}{balance}{actInfo}{add1k}{transfer}{minerInfo}</span>
}
}

View File

@ -94,10 +94,9 @@ class FullNode extends React.Component {
)
}
let mining = <span/>
let miners = <span/>
if(this.state.minerList.length > 0) {
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>
miners = this.state.minerList.map((a, k) => <div key={k}><Address miner={true} client={this.props.client} addr={a} mountWindow={this.props.mountWindow}/></div>)
}
let storageMine = <a href="#" onClick={this.startStorageMiner}>[Spawn Storage Miner]</a>
@ -133,11 +132,12 @@ class FullNode extends React.Component {
<div>Repo: LOTUS_PATH={this.props.node.Repo}</div>
{chainInfo}
<div>
{mining} {storageMine}
{storageMine}
</div>
<div>
<div>Balances: [New <a href="#" onClick={this.newScepAddr}>[Secp256k1]</a>]</div>
<div>{addresses}</div>
<div>{miners}</div>
<div>{paychannels}</div>
</div>

View File

@ -30,6 +30,7 @@ type api struct {
full.ChainAPI
full.MpoolAPI
full.WalletAPI
full.StateAPI
}
func NewMiner(api api) *Miner {
@ -264,12 +265,12 @@ func (m *Miner) isWinnerNextRound(ctx context.Context, base *MiningBase) (bool,
return false, nil, xerrors.Errorf("failed to compute VRF: %w", err)
}
mpow, totpow, err := m.getPowerForTipset(ctx, m.addresses[0], base.ts)
pow, err := m.api.StateMinerPower(ctx, m.addresses[0], base.ts)
if err != nil {
return false, nil, xerrors.Errorf("failed to check power: %w", err)
}
return powerCmp(vrfout, mpow, totpow), vrfout, nil
return powerCmp(vrfout, pow.MinerPower, pow.TotalPower), vrfout, nil
}
func powerCmp(vrfout []byte, mpow, totpow types.BigInt) bool {
@ -290,45 +291,6 @@ func powerCmp(vrfout []byte, mpow, totpow types.BigInt) bool {
return types.BigCmp(types.BigFromBytes(h[:]), out) < 0
}
func (m *Miner) getPowerForTipset(ctx context.Context, maddr address.Address, ts *types.TipSet) (types.BigInt, types.BigInt, error) {
var err error
enc, err := actors.SerializeParams(&actors.PowerLookupParams{maddr})
if err != nil {
return types.EmptyInt, types.EmptyInt, err
}
ret, err := m.api.ChainCall(ctx, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup,
Params: enc,
}, ts)
if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get miner power from chain: %w", err)
}
if ret.ExitCode != 0 {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get miner power from chain (exit code %d)", ret.ExitCode)
}
mpow := types.BigFromBytes(ret.Return)
ret, err = m.api.ChainCall(ctx, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage,
}, ts)
if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain: %w", err)
}
if ret.ExitCode != 0 {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain (exit code %d)", ret.ExitCode)
}
tpow := types.BigFromBytes(ret.Return)
return mpow, tpow, nil
}
func (m *Miner) runVDF(ctx context.Context, input []byte) ([]byte, []byte, error) {
select {
case <-ctx.Done():

View File

@ -3,6 +3,9 @@ package full
import (
"context"
"fmt"
"github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/chain/vm"
"golang.org/x/xerrors"
"strconv"
"github.com/filecoin-project/go-lotus/api"
@ -137,3 +140,45 @@ func (a *StateAPI) StateMinerProvingSet(ctx context.Context, addr address.Addres
})
return sinfos, nil
}
func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, ts *types.TipSet) (api.MinerPower, error) {
var err error
enc, err := actors.SerializeParams(&actors.PowerLookupParams{maddr})
if err != nil {
return api.MinerPower{}, err
}
ret, err := vm.Call(ctx, a.Chain, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup,
Params: enc,
}, ts)
if err != nil {
return api.MinerPower{}, xerrors.Errorf("failed to get miner power from chain: %w", err)
}
if ret.ExitCode != 0 {
return api.MinerPower{}, xerrors.Errorf("failed to get miner power from chain (exit code %d)", ret.ExitCode)
}
mpow := types.BigFromBytes(ret.Return)
ret, err = vm.Call(ctx, a.Chain, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage,
}, ts)
if err != nil {
return api.MinerPower{}, xerrors.Errorf("failed to get total power from chain: %w", err)
}
if ret.ExitCode != 0 {
return api.MinerPower{}, xerrors.Errorf("failed to get total power from chain (exit code %d)", ret.ExitCode)
}
tpow := types.BigFromBytes(ret.Return)
return api.MinerPower{
MinerPower: mpow,
TotalPower: tpow,
}, nil
}