pond: Display miner power
This commit is contained in:
parent
e01ab507ca
commit
fd2f0ed4f2
@ -98,6 +98,7 @@ type FullNode interface {
|
|||||||
|
|
||||||
StateMinerSectors(context.Context, address.Address) ([]*SectorInfo, error)
|
StateMinerSectors(context.Context, address.Address) ([]*SectorInfo, error)
|
||||||
StateMinerProvingSet(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)
|
PaychCreate(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, error)
|
||||||
PaychList(context.Context) ([]address.Address, error)
|
PaychList(context.Context) ([]address.Address, error)
|
||||||
@ -172,3 +173,8 @@ type ActorState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PaychStatus struct{}
|
type PaychStatus struct{}
|
||||||
|
|
||||||
|
type MinerPower struct {
|
||||||
|
MinerPower types.BigInt
|
||||||
|
TotalPower types.BigInt
|
||||||
|
}
|
||||||
|
@ -72,8 +72,9 @@ type FullNodeStruct struct {
|
|||||||
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
|
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
|
||||||
ClientStartDeal func(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"`
|
ClientStartDeal func(ctx context.Context, data cid.Cid, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"`
|
||||||
|
|
||||||
StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
|
StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
|
||||||
StateMinerProvingSet 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"`
|
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"`
|
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)
|
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) {
|
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)
|
return c.Internal.PaychCreate(ctx, from, to, amt)
|
||||||
}
|
}
|
||||||
|
@ -31,17 +31,21 @@ class Address extends React.Component {
|
|||||||
let balance = 0
|
let balance = 0
|
||||||
let actor = {}
|
let actor = {}
|
||||||
let actorInfo
|
let actorInfo
|
||||||
|
let minerInfo
|
||||||
|
|
||||||
try {
|
try {
|
||||||
balance = await this.props.client.call('Filecoin.WalletBalance', [this.props.addr])
|
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])
|
actor = await this.props.client.call('Filecoin.ChainGetActor', [this.props.addr, this.props.ts || null])
|
||||||
|
|
||||||
actorInfo = await this.actorInfo(actor)
|
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) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
balance = -1
|
balance = -1
|
||||||
}
|
}
|
||||||
this.setState({balance, actor, actorInfo})
|
this.setState({balance, actor, actorInfo, minerInfo})
|
||||||
}
|
}
|
||||||
|
|
||||||
openState() {
|
openState() {
|
||||||
@ -94,7 +98,12 @@ class Address extends React.Component {
|
|||||||
transfer = <span> {this.props.transfer}FIL</span>
|
transfer = <span> {this.props.transfer}FIL</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
return <span>{addr}{balance}{actInfo}{add1k}{transfer}</span>
|
let minerInfo = <span/>
|
||||||
|
if(this.state.minerInfo) {
|
||||||
|
minerInfo = <span> Power: {this.state.minerInfo.MinerPower} ({this.state.minerInfo.MinerPower/this.state.minerInfo.TotalPower*100}%)</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <span>{addr}{balance}{actInfo}{add1k}{transfer}{minerInfo}</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,10 +94,9 @@ class FullNode extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mining = <span/>
|
let miners = <span/>
|
||||||
if(this.state.minerList.length > 0) {
|
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>)
|
miners = this.state.minerList.map((a, k) => <div key={k}><Address miner={true} client={this.props.client} addr={a} mountWindow={this.props.mountWindow}/></div>)
|
||||||
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>
|
||||||
@ -133,11 +132,12 @@ 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>
|
||||||
{mining} {storageMine}
|
{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>
|
||||||
<div>{addresses}</div>
|
<div>{addresses}</div>
|
||||||
|
<div>{miners}</div>
|
||||||
<div>{paychannels}</div>
|
<div>{paychannels}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ type api struct {
|
|||||||
full.ChainAPI
|
full.ChainAPI
|
||||||
full.MpoolAPI
|
full.MpoolAPI
|
||||||
full.WalletAPI
|
full.WalletAPI
|
||||||
|
full.StateAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMiner(api api) *Miner {
|
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)
|
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 {
|
if err != nil {
|
||||||
return false, nil, xerrors.Errorf("failed to check power: %w", err)
|
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 {
|
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
|
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) {
|
func (m *Miner) runVDF(ctx context.Context, input []byte) ([]byte, []byte, error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -3,6 +3,9 @@ package full
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/vm"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
@ -137,3 +140,45 @@ func (a *StateAPI) StateMinerProvingSet(ctx context.Context, addr address.Addres
|
|||||||
})
|
})
|
||||||
return sinfos, nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user