cli: Move EpochTime to cliutil
This commit is contained in:
parent
73a515b93f
commit
e66d5a0537
@ -46,6 +46,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StateCmd = &cli.Command{
|
var StateCmd = &cli.Command{
|
||||||
@ -230,7 +231,7 @@ var StateMinerInfo = &cli.Command{
|
|||||||
return xerrors.Errorf("getting miner info: %w", err)
|
return xerrors.Errorf("getting miner info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Proving Period Start:\t%s\n", EpochTime(cd.CurrentEpoch, cd.PeriodStart))
|
fmt.Printf("Proving Period Start:\t%s\n", cliutil.EpochTime(cd.CurrentEpoch, cd.PeriodStart))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -1816,8 +1817,8 @@ var StateSectorCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
fmt.Println("DealIDs: ", si.DealIDs)
|
fmt.Println("DealIDs: ", si.DealIDs)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Activation: ", EpochTimeTs(ts.Height(), si.Activation, ts))
|
fmt.Println("Activation: ", cliutil.EpochTimeTs(ts.Height(), si.Activation, ts))
|
||||||
fmt.Println("Expiration: ", EpochTimeTs(ts.Height(), si.Expiration, ts))
|
fmt.Println("Expiration: ", cliutil.EpochTimeTs(ts.Height(), si.Expiration, ts))
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("DealWeight: ", si.DealWeight)
|
fmt.Println("DealWeight: ", si.DealWeight)
|
||||||
fmt.Println("VerifiedDealWeight: ", si.VerifiedDealWeight)
|
fmt.Println("VerifiedDealWeight: ", si.VerifiedDealWeight)
|
||||||
|
39
cli/util.go
39
cli/util.go
@ -2,19 +2,13 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/hako/durafmt"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api/v0api"
|
"github.com/filecoin-project/lotus/api/v0api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,36 +37,3 @@ func parseTipSet(ctx context.Context, api v0api.FullNode, vals []string) (*types
|
|||||||
|
|
||||||
return types.NewTipSet(headers)
|
return types.NewTipSet(headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func EpochTime(curr, e abi.ChainEpoch) string {
|
|
||||||
switch {
|
|
||||||
case curr > e:
|
|
||||||
return fmt.Sprintf("%d (%s ago)", e, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e))).LimitFirstN(2))
|
|
||||||
case curr == e:
|
|
||||||
return fmt.Sprintf("%d (now)", e)
|
|
||||||
case curr < e:
|
|
||||||
return fmt.Sprintf("%d (in %s)", e, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr))).LimitFirstN(2))
|
|
||||||
}
|
|
||||||
|
|
||||||
panic("math broke")
|
|
||||||
}
|
|
||||||
|
|
||||||
// EpochTimeTs is like EpochTime, but also outputs absolute time. `ts` is only
|
|
||||||
// used to provide a timestamp at some epoch to calculate time from. It can be
|
|
||||||
// a genesis tipset.
|
|
||||||
//
|
|
||||||
// Example output: `1944975 (01 Jul 22 08:07 CEST, 10 hours 29 minutes ago)`
|
|
||||||
func EpochTimeTs(curr, e abi.ChainEpoch, ts *types.TipSet) string {
|
|
||||||
timeStr := time.Unix(int64(ts.MinTimestamp()+(uint64(e-ts.Height())*build.BlockDelaySecs)), 0).Format(time.RFC822)
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case curr > e:
|
|
||||||
return fmt.Sprintf("%d (%s, %s ago)", e, timeStr, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e))).LimitFirstN(2))
|
|
||||||
case curr == e:
|
|
||||||
return fmt.Sprintf("%d (%s, now)", e, timeStr)
|
|
||||||
case curr < e:
|
|
||||||
return fmt.Sprintf("%d (%s, in %s)", e, timeStr, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr))).LimitFirstN(2))
|
|
||||||
}
|
|
||||||
|
|
||||||
panic("math broke")
|
|
||||||
}
|
|
||||||
|
46
cli/util/epoch.go
Normal file
46
cli/util/epoch.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package cliutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hako/durafmt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EpochTime(curr, e abi.ChainEpoch) string {
|
||||||
|
switch {
|
||||||
|
case curr > e:
|
||||||
|
return fmt.Sprintf("%d (%s ago)", e, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e))).LimitFirstN(2))
|
||||||
|
case curr == e:
|
||||||
|
return fmt.Sprintf("%d (now)", e)
|
||||||
|
case curr < e:
|
||||||
|
return fmt.Sprintf("%d (in %s)", e, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr))).LimitFirstN(2))
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("math broke")
|
||||||
|
}
|
||||||
|
|
||||||
|
// EpochTimeTs is like EpochTime, but also outputs absolute time. `ts` is only
|
||||||
|
// used to provide a timestamp at some epoch to calculate time from. It can be
|
||||||
|
// a genesis tipset.
|
||||||
|
//
|
||||||
|
// Example output: `1944975 (01 Jul 22 08:07 CEST, 10 hours 29 minutes ago)`
|
||||||
|
func EpochTimeTs(curr, e abi.ChainEpoch, ts *types.TipSet) string {
|
||||||
|
timeStr := time.Unix(int64(ts.MinTimestamp()+(uint64(e-ts.Height())*build.BlockDelaySecs)), 0).Format(time.RFC822)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case curr > e:
|
||||||
|
return fmt.Sprintf("%d (%s, %s ago)", e, timeStr, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e))).LimitFirstN(2))
|
||||||
|
case curr == e:
|
||||||
|
return fmt.Sprintf("%d (%s, now)", e, timeStr)
|
||||||
|
case curr < e:
|
||||||
|
return fmt.Sprintf("%d (%s, in %s)", e, timeStr, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr))).LimitFirstN(2))
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("math broke")
|
||||||
|
}
|
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||||
"github.com/filecoin-project/lotus/journal/alerting"
|
"github.com/filecoin-project/lotus/journal/alerting"
|
||||||
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
||||||
@ -664,7 +665,7 @@ func producedBlocks(ctx context.Context, count int, maddr address.Address, napi
|
|||||||
fmt.Printf("%8d | %s | %s\n", ts.Height(), bh.Cid(), types.FIL(minerReward))
|
fmt.Printf("%8d | %s | %s\n", ts.Height(), bh.Cid(), types.FIL(minerReward))
|
||||||
count--
|
count--
|
||||||
} else if tty && bh.Height%120 == 0 {
|
} else if tty && bh.Height%120 == 0 {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "\r\x1b[0KChecking epoch %s", lcli.EpochTime(head.Height(), bh.Height))
|
_, _ = fmt.Fprintf(os.Stderr, "\r\x1b[0KChecking epoch %s", cliutil.EpochTime(head.Height(), bh.Height))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tsk = ts.Parents()
|
tsk = ts.Parents()
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -185,18 +186,18 @@ var provingInfoCmd = &cli.Command{
|
|||||||
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
|
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
|
||||||
|
|
||||||
fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%cd.WPoStProvingPeriod)
|
fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%cd.WPoStProvingPeriod)
|
||||||
fmt.Printf("Proving Period Start: %s\n", lcli.EpochTimeTs(cd.CurrentEpoch, cd.PeriodStart, head))
|
fmt.Printf("Proving Period Start: %s\n", cliutil.EpochTimeTs(cd.CurrentEpoch, cd.PeriodStart, head))
|
||||||
fmt.Printf("Next Period Start: %s\n\n", lcli.EpochTimeTs(cd.CurrentEpoch, cd.PeriodStart+cd.WPoStProvingPeriod, head))
|
fmt.Printf("Next Period Start: %s\n\n", cliutil.EpochTimeTs(cd.CurrentEpoch, cd.PeriodStart+cd.WPoStProvingPeriod, head))
|
||||||
|
|
||||||
fmt.Printf("Faults: %d (%.2f%%)\n", faults, faultPerc)
|
fmt.Printf("Faults: %d (%.2f%%)\n", faults, faultPerc)
|
||||||
fmt.Printf("Recovering: %d\n", recovering)
|
fmt.Printf("Recovering: %d\n", recovering)
|
||||||
|
|
||||||
fmt.Printf("Deadline Index: %d\n", cd.Index)
|
fmt.Printf("Deadline Index: %d\n", cd.Index)
|
||||||
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
|
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
|
||||||
fmt.Printf("Deadline Open: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.Open))
|
fmt.Printf("Deadline Open: %s\n", cliutil.EpochTime(cd.CurrentEpoch, cd.Open))
|
||||||
fmt.Printf("Deadline Close: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.Close))
|
fmt.Printf("Deadline Close: %s\n", cliutil.EpochTime(cd.CurrentEpoch, cd.Close))
|
||||||
fmt.Printf("Deadline Challenge: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.Challenge))
|
fmt.Printf("Deadline Challenge: %s\n", cliutil.EpochTime(cd.CurrentEpoch, cd.Challenge))
|
||||||
fmt.Printf("Deadline FaultCutoff: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.FaultCutoff))
|
fmt.Printf("Deadline FaultCutoff: %s\n", cliutil.EpochTime(cd.CurrentEpoch, cd.FaultCutoff))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||||
"github.com/filecoin-project/lotus/lib/strle"
|
"github.com/filecoin-project/lotus/lib/strle"
|
||||||
"github.com/filecoin-project/lotus/lib/tablewriter"
|
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||||
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
||||||
@ -485,9 +486,9 @@ var sectorsListCmd = &cli.Command{
|
|||||||
if !inSSet {
|
if !inSSet {
|
||||||
m["Expiration"] = "n/a"
|
m["Expiration"] = "n/a"
|
||||||
} else {
|
} else {
|
||||||
m["Expiration"] = lcli.EpochTime(head.Height(), exp)
|
m["Expiration"] = cliutil.EpochTime(head.Height(), exp)
|
||||||
if st.Early > 0 {
|
if st.Early > 0 {
|
||||||
m["RecoveryTimeout"] = color.YellowString(lcli.EpochTime(head.Height(), st.Early))
|
m["RecoveryTimeout"] = color.YellowString(cliutil.EpochTime(head.Height(), st.Early))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if inSSet && cctx.Bool("initial-pledge") {
|
if inSSet && cctx.Bool("initial-pledge") {
|
||||||
@ -666,10 +667,10 @@ var sectorsCheckExpireCmd = &cli.Command{
|
|||||||
"ID": sector.SectorNumber,
|
"ID": sector.SectorNumber,
|
||||||
"SealProof": sector.SealProof,
|
"SealProof": sector.SealProof,
|
||||||
"InitialPledge": types.FIL(sector.InitialPledge).Short(),
|
"InitialPledge": types.FIL(sector.InitialPledge).Short(),
|
||||||
"Activation": lcli.EpochTime(currEpoch, sector.Activation),
|
"Activation": cliutil.EpochTime(currEpoch, sector.Activation),
|
||||||
"Expiration": lcli.EpochTime(currEpoch, sector.Expiration),
|
"Expiration": cliutil.EpochTime(currEpoch, sector.Expiration),
|
||||||
"MaxExpiration": lcli.EpochTime(currEpoch, MaxExpiration),
|
"MaxExpiration": cliutil.EpochTime(currEpoch, MaxExpiration),
|
||||||
"MaxExtendNow": lcli.EpochTime(currEpoch, MaxExtendNow),
|
"MaxExtendNow": cliutil.EpochTime(currEpoch, MaxExtendNow),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1909,7 +1910,7 @@ var sectorsExpiredCmd = &cli.Command{
|
|||||||
toRemove = append(toRemove, s)
|
toRemove = append(toRemove, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%d%s\t%s\t%s\n", s, rmMsg, st.State, lcli.EpochTime(head.Height(), st.Expiration))
|
fmt.Printf("%d%s\t%s\t%s\n", s, rmMsg, st.State, cliutil.EpochTime(head.Height(), st.Expiration))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user