From e4044151f08d8c16c821b5b2efbd2682ee0279b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 2 Sep 2021 21:44:26 +0200 Subject: [PATCH 1/4] Show deal sizes is sealing sectors --- api/api_storage.go | 6 ++++++ cmd/lotus-miner/sectors.go | 34 +++++++++++++++++++++++++--------- storage/miner_sealing.go | 7 +++++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index a26080617..6ebee9908 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -267,6 +267,11 @@ type SectorLog struct { Message string } +type SectorPiece struct { + Piece abi.PieceInfo + DealInfo *PieceDealInfo // nil for pieces which do not appear in deals (e.g. filler pieces) +} + type SectorInfo struct { SectorID abi.SectorNumber State SectorState @@ -274,6 +279,7 @@ type SectorInfo struct { CommR *cid.Cid Proof []byte Deals []abi.DealID + Pieces []SectorPiece Ticket SealTicket Seed SealSeed PreCommitMsg *cid.Cid diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index d09605bd9..9770edb90 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -394,10 +394,20 @@ var sectorsListCmd = &cli.Command{ _, inASet := activeIDs[s] dw, vp := .0, .0 - if st.Expiration-st.Activation > 0 { + estimate := st.Expiration-st.Activation <= 0 + if !estimate { rdw := big.Add(st.DealWeight, st.VerifiedDealWeight) dw = float64(big.Div(rdw, big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) vp = float64(big.Div(big.Mul(st.VerifiedDealWeight, big.NewInt(9)), big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) + } else { + for _, piece := range st.Pieces { + if piece.DealInfo != nil { + dw += float64(piece.Piece.Size) + if piece.DealInfo.DealProposal != nil && piece.DealInfo.DealProposal.VerifiedDeal { + vp += float64(piece.Piece.Size) * 9 + } + } + } } var deals int @@ -433,20 +443,26 @@ var sectorsListCmd = &cli.Command{ m["Expiration"] = "n/a" } else { m["Expiration"] = lcli.EpochTime(head.Height(), exp) - - if !fast && deals > 0 { - m["DealWeight"] = units.BytesSize(dw) - if vp > 0 { - m["VerifiedPower"] = color.GreenString(units.BytesSize(vp)) - } - } - if st.Early > 0 { m["RecoveryTimeout"] = color.YellowString(lcli.EpochTime(head.Height(), st.Early)) } } } + if !fast && deals > 0 { + estWrap := func(s string) string { + if !estimate { + return s + } + return fmt.Sprintf("[%s]", s) + } + + m["DealWeight"] = estWrap(units.BytesSize(dw)) + if vp > 0 { + m["VerifiedPower"] = estWrap(color.GreenString(units.BytesSize(vp))) + } + } + if cctx.Bool("events") { var events int for _, sectorLog := range st.Log { diff --git a/storage/miner_sealing.go b/storage/miner_sealing.go index 38b24e8c1..01b9546a6 100644 --- a/storage/miner_sealing.go +++ b/storage/miner_sealing.go @@ -94,10 +94,16 @@ func (m *Miner) SectorsStatus(ctx context.Context, sid abi.SectorNumber, showOnC } deals := make([]abi.DealID, len(info.Pieces)) + pieces := make([]api.SectorPiece, len(info.Pieces)) for i, piece := range info.Pieces { + pieces[i].Piece = piece.Piece if piece.DealInfo == nil { continue } + + pdi := *piece.DealInfo // copy + pieces[i].DealInfo = &pdi + deals[i] = piece.DealInfo.DealID } @@ -118,6 +124,7 @@ func (m *Miner) SectorsStatus(ctx context.Context, sid abi.SectorNumber, showOnC CommR: info.CommR, Proof: info.Proof, Deals: deals, + Pieces: pieces, Ticket: api.SealTicket{ Value: info.TicketValue, Epoch: info.TicketEpoch, From 186c4990dd7cf93f6767250b51fc6db9d7633e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 2 Sep 2021 21:45:55 +0200 Subject: [PATCH 2/4] Reduce nesting in sectors list command --- cmd/lotus-miner/sectors.go | 244 +++++++++++++++++++------------------ 1 file changed, 123 insertions(+), 121 deletions(-) diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index 9770edb90..c97bd0e66 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -389,128 +389,130 @@ var sectorsListCmd = &cli.Command{ continue } - if showRemoved || st.State != api.SectorState(sealing.Removed) { - _, inSSet := commitedIDs[s] - _, inASet := activeIDs[s] - - dw, vp := .0, .0 - estimate := st.Expiration-st.Activation <= 0 - if !estimate { - rdw := big.Add(st.DealWeight, st.VerifiedDealWeight) - dw = float64(big.Div(rdw, big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) - vp = float64(big.Div(big.Mul(st.VerifiedDealWeight, big.NewInt(9)), big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) - } else { - for _, piece := range st.Pieces { - if piece.DealInfo != nil { - dw += float64(piece.Piece.Size) - if piece.DealInfo.DealProposal != nil && piece.DealInfo.DealProposal.VerifiedDeal { - vp += float64(piece.Piece.Size) * 9 - } - } - } - } - - var deals int - for _, deal := range st.Deals { - if deal != 0 { - deals++ - } - } - - exp := st.Expiration - if st.OnTime > 0 && st.OnTime < exp { - exp = st.OnTime // Can be different when the sector was CC upgraded - } - - m := map[string]interface{}{ - "ID": s, - "State": color.New(stateOrder[sealing.SectorState(st.State)].col).Sprint(st.State), - "OnChain": yesno(inSSet), - "Active": yesno(inASet), - } - - if deals > 0 { - m["Deals"] = color.GreenString("%d", deals) - } else { - m["Deals"] = color.BlueString("CC") - if st.ToUpgrade { - m["Deals"] = color.CyanString("CC(upgrade)") - } - } - - if !fast { - if !inSSet { - m["Expiration"] = "n/a" - } else { - m["Expiration"] = lcli.EpochTime(head.Height(), exp) - if st.Early > 0 { - m["RecoveryTimeout"] = color.YellowString(lcli.EpochTime(head.Height(), st.Early)) - } - } - } - - if !fast && deals > 0 { - estWrap := func(s string) string { - if !estimate { - return s - } - return fmt.Sprintf("[%s]", s) - } - - m["DealWeight"] = estWrap(units.BytesSize(dw)) - if vp > 0 { - m["VerifiedPower"] = estWrap(color.GreenString(units.BytesSize(vp))) - } - } - - if cctx.Bool("events") { - var events int - for _, sectorLog := range st.Log { - if !strings.HasPrefix(sectorLog.Kind, "event") { - continue - } - if sectorLog.Kind == "event;sealing.SectorRestart" { - continue - } - events++ - } - - pieces := len(st.Deals) - - switch { - case events < 12+pieces: - m["Events"] = color.GreenString("%d", events) - case events < 20+pieces: - m["Events"] = color.YellowString("%d", events) - default: - m["Events"] = color.RedString("%d", events) - } - } - - if cctx.Bool("seal-time") && len(st.Log) > 1 { - start := time.Unix(int64(st.Log[0].Timestamp), 0) - - for _, sectorLog := range st.Log { - if sectorLog.Kind == "event;sealing.SectorProving" { - end := time.Unix(int64(sectorLog.Timestamp), 0) - dur := end.Sub(start) - - switch { - case dur < 12*time.Hour: - m["SealTime"] = color.GreenString("%s", dur) - case dur < 24*time.Hour: - m["SealTime"] = color.YellowString("%s", dur) - default: - m["SealTime"] = color.RedString("%s", dur) - } - - break - } - } - } - - tw.Write(m) + if !showRemoved && st.State == api.SectorState(sealing.Removed) { + continue } + + _, inSSet := commitedIDs[s] + _, inASet := activeIDs[s] + + dw, vp := .0, .0 + estimate := st.Expiration-st.Activation <= 0 + if !estimate { + rdw := big.Add(st.DealWeight, st.VerifiedDealWeight) + dw = float64(big.Div(rdw, big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) + vp = float64(big.Div(big.Mul(st.VerifiedDealWeight, big.NewInt(9)), big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) + } else { + for _, piece := range st.Pieces { + if piece.DealInfo != nil { + dw += float64(piece.Piece.Size) + if piece.DealInfo.DealProposal != nil && piece.DealInfo.DealProposal.VerifiedDeal { + vp += float64(piece.Piece.Size) * 9 + } + } + } + } + + var deals int + for _, deal := range st.Deals { + if deal != 0 { + deals++ + } + } + + exp := st.Expiration + if st.OnTime > 0 && st.OnTime < exp { + exp = st.OnTime // Can be different when the sector was CC upgraded + } + + m := map[string]interface{}{ + "ID": s, + "State": color.New(stateOrder[sealing.SectorState(st.State)].col).Sprint(st.State), + "OnChain": yesno(inSSet), + "Active": yesno(inASet), + } + + if deals > 0 { + m["Deals"] = color.GreenString("%d", deals) + } else { + m["Deals"] = color.BlueString("CC") + if st.ToUpgrade { + m["Deals"] = color.CyanString("CC(upgrade)") + } + } + + if !fast { + if !inSSet { + m["Expiration"] = "n/a" + } else { + m["Expiration"] = lcli.EpochTime(head.Height(), exp) + if st.Early > 0 { + m["RecoveryTimeout"] = color.YellowString(lcli.EpochTime(head.Height(), st.Early)) + } + } + } + + if !fast && deals > 0 { + estWrap := func(s string) string { + if !estimate { + return s + } + return fmt.Sprintf("[%s]", s) + } + + m["DealWeight"] = estWrap(units.BytesSize(dw)) + if vp > 0 { + m["VerifiedPower"] = estWrap(color.GreenString(units.BytesSize(vp))) + } + } + + if cctx.Bool("events") { + var events int + for _, sectorLog := range st.Log { + if !strings.HasPrefix(sectorLog.Kind, "event") { + continue + } + if sectorLog.Kind == "event;sealing.SectorRestart" { + continue + } + events++ + } + + pieces := len(st.Deals) + + switch { + case events < 12+pieces: + m["Events"] = color.GreenString("%d", events) + case events < 20+pieces: + m["Events"] = color.YellowString("%d", events) + default: + m["Events"] = color.RedString("%d", events) + } + } + + if cctx.Bool("seal-time") && len(st.Log) > 1 { + start := time.Unix(int64(st.Log[0].Timestamp), 0) + + for _, sectorLog := range st.Log { + if sectorLog.Kind == "event;sealing.SectorProving" { + end := time.Unix(int64(sectorLog.Timestamp), 0) + dur := end.Sub(start) + + switch { + case dur < 12*time.Hour: + m["SealTime"] = color.GreenString("%s", dur) + case dur < 24*time.Hour: + m["SealTime"] = color.YellowString("%s", dur) + default: + m["SealTime"] = color.RedString("%s", dur) + } + + break + } + } + } + + tw.Write(m) } return tw.Flush(os.Stdout) From 8b9e9fede44bc2f946c06f6a2457e889e4105ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 2 Sep 2021 21:47:51 +0200 Subject: [PATCH 3/4] docsgen --- build/openrpc/miner.json.gz | Bin 10378 -> 10424 bytes documentation/en/api-v0-methods-miner.md | 1 + 2 files changed, 1 insertion(+) diff --git a/build/openrpc/miner.json.gz b/build/openrpc/miner.json.gz index ce3a4562fddfb864603909f6653548d159031b2a..15dbe3829826b3643edeb650652e0b55304e5138 100644 GIT binary patch delta 2358 zcmV-63CZ?~QMggCoF9K-JB(};{<^{Tof4A&l%<#a$Eiw3Q>1FAY_9>#NIsqZoYqBRK;ny>Ne#OMmXJieF}qjbeWp37WLHD)XK)qP|-4xLf=&!vuQUH^ip$?C`{zL59YoSl7|lp&?gp zcOBYnd)SQowrLe2FHhmV#rsHkh)HR~O*%R-*`L{vWBUP}AkZ1@)uicj^R|q0Q%Ts= z-)`>WZc!l2{?wSa{}U!9ih2hi3;d}mxV4-tA?{}HivNELU^1tG&Ko;g)C@uEY0b7N zRRP*}2b}Z=y#mK+1FZYpxaKG~#e?m7wO|%Z-hDaI)ur+%!Y`t)()fdl>#w&QT@VL- zku~*A<@ZOv_Y=C;kT`Tj5Mv#%J_JD+SYfa%Yw(If?JUGA>kEtpdV9aBCo#h%8BEz8 z#(R3CEpvY(d16xQCY~n~WRu(?1%ujS0pFtX{07S3<6Q%z-f+^ybpzSr{@>-T2_wU? zKwPZUJlFr0XW`KR58F7|2IFMg;QPzbXp)2ZlX1rLrj&JawE)YQul*oRnhOBn-3hFBUD2HIs05X3h*+ zk8n|@rw*-4kagm~x25g+w0+n!WrFzxz&W&QrhvsE|DY4$yqqI~X}f=wLQP_Q5e6 z4~~E4qZvGe6RTr=xV{X-Is*UbXwb3V!!N;A%JTOaB-8jkU66>^sMZZuAuOH4HiE2s z>-+aJr_(WP%WQhpsAJCR48-)YN#r~JCcE4OCzQPyAFiQ|`Bnx6o!&$2!kNJQxMRJY zCVyWehP-=$%dwnH`QHyrKByY55&#%mm74)w?c5_f5yf|zHhw93a&q_Q?%KKjO&Z`jves2Eu4f|clE3=n886Q(ljv|@N~Be5aE@#jdPwo}E~+H~s9@uB zah}pA^1(1q`;7b)g`!PS0*!|DM(LrYkLdQUG~|?(lT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Z|H!k7|0F`Q zlmjK*Lmf9tVrCxIEN&%P`AD&+F3Ac5#J)Rk(^E2<%^aWOVbV1H-uz5g9#;73zGzF|_%TbWcoG4%|Jk_C zzh{wlWXcm$6JEcVTJ(KhH5s3cKZPpz9NBIOX;x5GEeCiVv6fq2t&zGiT2u|iWlU|$ z2#->7!?J#;Ov4D(s(~zJ{Vg4vdZBNPdQ7E%gi&VCT8;4wZ5}FBZ?^v1|X%&BUg{j_DfNL8& zzhmtD&Xsstk$pKD_wzHn{JfIdqFQ`k#zUP*WGS)f6U}n=e8~*48k;>I?;qYTolY=n z(~q8$2z?%#_3ibDD!*QWB2{a(+Haj}lZy-9xtdk5qG%sChx!o!1^-J2Z1dGB!E zw+CZ%=tSkN3n1P=b|<6-g6^yP-YdaVvh?>WVSik2$R7}M>!c@rRUWratU+(kJLvZh z`h%O^@yTFt(mQ|px7D$Jp^W>}zNCy>dpXySI?*`ODp$Z%A2eHxdIi5+D1iNO$68?$ z`<0Fxiq_}Jn5$VoS}fQhq=xdf)}Q9!LSp`E&8fG7f~+0L(E-ORq$_E!n50JC{pYs3 z9vf0elx&=G$am3i^7}FhE-jShhs6p`HY=^+w4Kz@aKV459zn%vQ7%w%rf-^4abGPN zpqh~1N=bCAiv^(`x<-s{JUb>AVo$zW@6qaNxnF}{6LXxQ+hd0lqC@e hY5FnG*q*9VI~rII51$_Xe*gdg|NpH_;jt^$0RY|heb4{^ diff --git a/documentation/en/api-v0-methods-miner.md b/documentation/en/api-v0-methods-miner.md index 1c6891329..dd7a1f88e 100644 --- a/documentation/en/api-v0-methods-miner.md +++ b/documentation/en/api-v0-methods-miner.md @@ -2019,6 +2019,7 @@ Response: "CommR": null, "Proof": "Ynl0ZSBhcnJheQ==", "Deals": null, + "Pieces": null, "Ticket": { "Value": null, "Epoch": 10101 From dfc039276d5d9a0b021e4ee80c270600e435db33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 7 Sep 2021 19:42:52 +0200 Subject: [PATCH 4/4] address review --- cmd/lotus-miner/sectors.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index c97bd0e66..9bfc84900 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -396,18 +396,20 @@ var sectorsListCmd = &cli.Command{ _, inSSet := commitedIDs[s] _, inASet := activeIDs[s] + const verifiedPowerGainMul = 9 + dw, vp := .0, .0 estimate := st.Expiration-st.Activation <= 0 if !estimate { rdw := big.Add(st.DealWeight, st.VerifiedDealWeight) dw = float64(big.Div(rdw, big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) - vp = float64(big.Div(big.Mul(st.VerifiedDealWeight, big.NewInt(9)), big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) + vp = float64(big.Div(big.Mul(st.VerifiedDealWeight, big.NewInt(verifiedPowerGainMul)), big.NewInt(int64(st.Expiration-st.Activation))).Uint64()) } else { for _, piece := range st.Pieces { if piece.DealInfo != nil { dw += float64(piece.Piece.Size) if piece.DealInfo.DealProposal != nil && piece.DealInfo.DealProposal.VerifiedDeal { - vp += float64(piece.Piece.Size) * 9 + vp += float64(piece.Piece.Size) * verifiedPowerGainMul } } } @@ -494,7 +496,7 @@ var sectorsListCmd = &cli.Command{ start := time.Unix(int64(st.Log[0].Timestamp), 0) for _, sectorLog := range st.Log { - if sectorLog.Kind == "event;sealing.SectorProving" { + if sectorLog.Kind == "event;sealing.SectorProving" { // todo: figure out a good way to not hardcode end := time.Unix(int64(sectorLog.Timestamp), 0) dur := end.Sub(start)