Merge pull request #595 from filecoin-project/feat/small-fixes
Bunch of small fixes / improvements, gofmt
This commit is contained in:
commit
37c0967fa8
@ -1,7 +1,6 @@
|
|||||||
package chain
|
package chain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
@ -16,15 +15,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrMessageTooBig = fmt.Errorf("message too big")
|
ErrMessageTooBig = errors.New("message too big")
|
||||||
|
|
||||||
ErrMessageValueTooHigh = fmt.Errorf("cannot send more filecoin than will ever exist")
|
ErrMessageValueTooHigh = errors.New("cannot send more filecoin than will ever exist")
|
||||||
|
|
||||||
ErrNonceTooLow = fmt.Errorf("message nonce too low")
|
ErrNonceTooLow = errors.New("message nonce too low")
|
||||||
|
|
||||||
ErrNotEnoughFunds = fmt.Errorf("not enough funds to execute transaction")
|
ErrNotEnoughFunds = errors.New("not enough funds to execute transaction")
|
||||||
|
|
||||||
ErrInvalidToAddr = fmt.Errorf("message had invalid to address")
|
ErrInvalidToAddr = errors.New("message had invalid to address")
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessagePool struct {
|
type MessagePool struct {
|
||||||
@ -81,7 +80,13 @@ func NewMessagePool(sm *stmgr.StateManager, ps *pubsub.PubSub) *MessagePool {
|
|||||||
maxTxPoolSize: 100000,
|
maxTxPoolSize: 100000,
|
||||||
blsSigCache: cache,
|
blsSigCache: cache,
|
||||||
}
|
}
|
||||||
sm.ChainStore().SubscribeHeadChanges(mp.HeadChange)
|
sm.ChainStore().SubscribeHeadChanges(func(rev, app []*types.TipSet) error {
|
||||||
|
err := mp.HeadChange(rev, app)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("mpool head notif handler error: %+v", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
return mp
|
return mp
|
||||||
}
|
}
|
||||||
@ -102,7 +107,7 @@ func (mp *MessagePool) Push(m *types.SignedMessage) error {
|
|||||||
func (mp *MessagePool) Add(m *types.SignedMessage) error {
|
func (mp *MessagePool) Add(m *types.SignedMessage) error {
|
||||||
// big messages are bad, anti DOS
|
// big messages are bad, anti DOS
|
||||||
if m.Size() > 32*1024 {
|
if m.Size() > 32*1024 {
|
||||||
return ErrMessageTooBig
|
return xerrors.Errorf("mpool message too large (%dB): %w", m.Size(), ErrMessageTooBig)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Message.To == address.Undef {
|
if m.Message.To == address.Undef {
|
||||||
@ -124,7 +129,7 @@ func (mp *MessagePool) Add(m *types.SignedMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if snonce > m.Message.Nonce {
|
if snonce > m.Message.Nonce {
|
||||||
return ErrNonceTooLow
|
return xerrors.Errorf("minimum expected nonce is %d: %w", snonce, ErrNonceTooLow)
|
||||||
}
|
}
|
||||||
|
|
||||||
balance, err := mp.getStateBalance(m.Message.From)
|
balance, err := mp.getStateBalance(m.Message.From)
|
||||||
@ -133,7 +138,7 @@ func (mp *MessagePool) Add(m *types.SignedMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if balance.LessThan(m.Message.RequiredFunds()) {
|
if balance.LessThan(m.Message.RequiredFunds()) {
|
||||||
return ErrNotEnoughFunds
|
return xerrors.Errorf("not enough funds (required: %s, balance: %s): %w", types.FIL(m.Message.RequiredFunds()), types.FIL(balance), ErrNotEnoughFunds)
|
||||||
}
|
}
|
||||||
|
|
||||||
mp.lk.Lock()
|
mp.lk.Lock()
|
||||||
|
@ -73,7 +73,7 @@ func HandleIncomingMessages(ctx context.Context, mpool *chain.MessagePool, msub
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := mpool.Add(m); err != nil {
|
if err := mpool.Add(m); err != nil {
|
||||||
log.Errorf("failed to add message from network to message pool: %s", err)
|
log.Errorf("failed to add message from network to message pool (From: %s, To: %s, Nonce: %d, Value: %s): %+v", m.Message.From, m.Message.To, m.Message.Nonce, types.FIL(m.Message.Value), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,10 @@ func BigDiv(a, b BigInt) BigInt {
|
|||||||
return BigInt{big.NewInt(0).Div(a.Int, b.Int)}
|
return BigInt{big.NewInt(0).Div(a.Int, b.Int)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BigMod(a, b BigInt) BigInt {
|
||||||
|
return BigInt{big.NewInt(0).Mod(a.Int, b.Int)}
|
||||||
|
}
|
||||||
|
|
||||||
func BigAdd(a, b BigInt) BigInt {
|
func BigAdd(a, b BigInt) BigInt {
|
||||||
return BigInt{big.NewInt(0).Add(a.Int, b.Int)}
|
return BigInt{big.NewInt(0).Add(a.Int, b.Int)}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func (mf *MessageFactory) MakeMessage(from, to state.Address, method chain.Metho
|
|||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mf *MessageFactory) FromSingletonAddress(addr state.SingletonActorID) (state.Address) {
|
func (mf *MessageFactory) FromSingletonAddress(addr state.SingletonActorID) state.Address {
|
||||||
return fromSingletonAddress(addr)
|
return fromSingletonAddress(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ func TestMessageFactory(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
bfAddr := factory.FromSingletonAddress(state.BurntFundsAddress)
|
bfAddr := factory.FromSingletonAddress(state.BurntFundsAddress)
|
||||||
m, err := p.Transfer(state.Address(sender.Bytes()), bfAddr,0, 1)
|
m, err := p.Transfer(state.Address(sender.Bytes()), bfAddr, 0, 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
messages := p.Messages()
|
messages := p.Messages()
|
||||||
|
@ -114,7 +114,7 @@ func (s *StateWrapper) SetActor(addr vstate.Address, code vstate.ActorCodeID, ba
|
|||||||
return actr, s.storage, s.flush(tree)
|
return actr, s.storage, s.flush(tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance vstate.AttoFIL) (vstate.Actor, vstate.Storage, error){
|
func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance vstate.AttoFIL) (vstate.Actor, vstate.Storage, error) {
|
||||||
vaddr := fromSingletonAddress(addr)
|
vaddr := fromSingletonAddress(addr)
|
||||||
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,7 +43,7 @@ var infoCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Sector Size: %s\n", sizeStr(sizeByte))
|
fmt.Printf("Sector Size: %s\n", sizeStr(types.NewInt(sizeByte)))
|
||||||
|
|
||||||
pow, err := api.StateMinerPower(ctx, maddr, nil)
|
pow, err := api.StateMinerPower(ctx, maddr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -51,7 +51,7 @@ var infoCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower)
|
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000)), pow.TotalPower)
|
||||||
fmt.Printf("Power: %s / %s (%0.2f%%)\n", pow.MinerPower, pow.TotalPower, float64(percI.Int64())/1000*100)
|
fmt.Printf("Power: %s / %s (%0.4f%%)\n", sizeStr(pow.MinerPower), sizeStr(pow.TotalPower), float64(percI.Int64())/100000*10000)
|
||||||
|
|
||||||
// TODO: indicate whether the post worker is in use
|
// TODO: indicate whether the post worker is in use
|
||||||
wstat, err := nodeApi.WorkerStats(ctx)
|
wstat, err := nodeApi.WorkerStats(ctx)
|
||||||
@ -90,16 +90,16 @@ var infoCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB"}
|
var Units = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
|
||||||
|
|
||||||
func sizeStr(size uint64) string {
|
func sizeStr(size types.BigInt) string {
|
||||||
|
size = types.BigMul(size, types.NewInt(100))
|
||||||
i := 0
|
i := 0
|
||||||
unitSize := float64(size)
|
for types.BigCmp(size, types.NewInt(102400)) >= 0 && i < len(Units)-1 {
|
||||||
for unitSize >= 1024 && i < len(Units)-1 {
|
size = types.BigDiv(size, types.NewInt(1024))
|
||||||
unitSize = unitSize / 1024
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%g %s", unitSize, Units[i])
|
return fmt.Sprintf("%s.%s %s", types.BigDiv(size, types.NewInt(100)), types.BigMod(size, types.NewInt(100)), Units[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
|
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
|
||||||
|
@ -30,7 +30,7 @@ var sectorsCmd = &cli.Command{
|
|||||||
Usage: "interact with sector store",
|
Usage: "interact with sector store",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
sectorsStatusCmd,
|
sectorsStatusCmd,
|
||||||
sectorsStagedListCmd,
|
sectorsListCmd,
|
||||||
sectorsRefsCmd,
|
sectorsRefsCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -74,24 +74,71 @@ var sectorsStatusCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var sectorsStagedListCmd = &cli.Command{
|
var sectorsListCmd = &cli.Command{
|
||||||
Name: "list-staged", // TODO: nest this under a 'staged' subcommand? idk
|
Name: "list",
|
||||||
Usage: "List staged sectors",
|
Usage: "List sectors",
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
|
fullApi, closer2, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer2()
|
||||||
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
staged, err := nodeApi.SectorsList(ctx)
|
list, err := nodeApi.SectorsList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range staged {
|
maddr, err := nodeApi.ActorAddress(ctx)
|
||||||
fmt.Println(s)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pset, err := fullApi.StateMinerProvingSet(ctx, maddr, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
provingIDs := make(map[uint64]struct{}, len(pset))
|
||||||
|
for _, info := range pset {
|
||||||
|
provingIDs[info.SectorID] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
sset, err := fullApi.StateMinerSectors(ctx, maddr, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
commitedIDs := make(map[uint64]struct{}, len(pset))
|
||||||
|
for _, info := range sset {
|
||||||
|
commitedIDs[info.SectorID] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range list {
|
||||||
|
st, err := nodeApi.SectorsStatus(ctx, s)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%d:\tError: %s\n", s, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, inSSet := commitedIDs[s]
|
||||||
|
_, inPSet := provingIDs[s]
|
||||||
|
|
||||||
|
fmt.Printf("%d: %s\tsSet: %s\tpSet: %s\ttktH: %d\tseedH: %d\tdeals: %v\n",
|
||||||
|
s,
|
||||||
|
api.SectorStateStr(st.State),
|
||||||
|
yesno(inSSet),
|
||||||
|
yesno(inPSet),
|
||||||
|
st.Ticket.BlockHeight,
|
||||||
|
st.Seed.BlockHeight,
|
||||||
|
st.Deals,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -122,3 +169,10 @@ var sectorsRefsCmd = &cli.Command{
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func yesno(b bool) string {
|
||||||
|
if b {
|
||||||
|
return "YES"
|
||||||
|
}
|
||||||
|
return "NO"
|
||||||
|
}
|
||||||
|
@ -205,6 +205,9 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
|
|||||||
m.handle(ctx, sector, m.preCommitted, api.SectorNoUpdate)
|
m.handle(ctx, sector, m.preCommitted, api.SectorNoUpdate)
|
||||||
case api.Committing:
|
case api.Committing:
|
||||||
m.handle(ctx, sector, m.committing, api.Proving)
|
m.handle(ctx, sector, m.committing, api.Proving)
|
||||||
|
case api.Proving:
|
||||||
|
// TODO: track sector health / expiration
|
||||||
|
log.Infof("Proving sector %d", update.id)
|
||||||
case api.SectorNoUpdate: // noop
|
case api.SectorNoUpdate: // noop
|
||||||
default:
|
default:
|
||||||
log.Errorf("unexpected sector update state: %d", update.newState)
|
log.Errorf("unexpected sector update state: %d", update.newState)
|
||||||
|
Loading…
Reference in New Issue
Block a user