From 5c3ed4d91a0c1e1e3a748c9c6350f0a38364c2f2 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 12 Feb 2020 18:41:35 +0100 Subject: [PATCH 1/2] Remove ffi from types package Signed-off-by: Jakub Sztandera --- build/params_shared.go | 2 ++ chain/actors/actor_miner.go | 12 +++++------ chain/actors/actor_miner2.go | 11 +++++----- chain/types/blockheader.go | 8 ++++--- chain/types/vmcontext.go | 20 ++++++++++++++--- chain/vm/syscalls.go | 42 +++++++++++++++++++++++++++++++++++- 6 files changed, 75 insertions(+), 20 deletions(-) diff --git a/build/params_shared.go b/build/params_shared.go index 6617d6e6c..ad23b314a 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -21,6 +21,8 @@ func SupportedSectorSize(ssize uint64) bool { return false } +const SectorChallengeRatioDiv = 25 + // ///// // Payments diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index 3afcd1b65..e46b006eb 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -6,8 +6,6 @@ import ( "encoding/binary" "fmt" - ffi "github.com/filecoin-project/filecoin-ffi" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/lotus/build" @@ -483,7 +481,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM } activeFaults := uint64(0) - var sectorInfos []ffi.PublicSectorInfo + var sectorInfos []types.PublicSectorInfo if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error { if faults[id] { activeFaults++ @@ -494,7 +492,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM if err := cbor.DecodeInto(v.Raw, &comms); err != nil { return xerrors.New("could not decode comms") } - si := ffi.PublicSectorInfo{ + si := types.PublicSectorInfo{ SectorID: id, } commR := comms[0] @@ -512,11 +510,11 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM proverID := vmctx.Message().To // TODO: normalize to ID address - var candidates []sectorbuilder.EPostCandidate + var candidates []types.Candidate for _, t := range params.Candidates { var partial [32]byte copy(partial[:], t.Partial) - candidates = append(candidates, sectorbuilder.EPostCandidate{ + candidates = append(candidates, types.Candidate{ PartialTicket: partial, SectorID: t.SectorID, SectorChallengeIndex: t.ChallengeIndex, @@ -524,7 +522,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM } if ok, lerr := vmctx.Sys().VerifyFallbackPost(vmctx.Context(), mi.SectorSize, - sectorbuilder.NewSortedPublicSectorInfo(sectorInfos), seed[:], params.Proof, candidates, proverID, activeFaults); !ok || lerr != nil { + sectorInfos, seed[:], params.Proof, candidates, proverID, activeFaults); !ok || lerr != nil { if lerr != nil { // TODO: study PoST errors return nil, aerrors.Absorb(lerr, 4, "PoST error") diff --git a/chain/actors/actor_miner2.go b/chain/actors/actor_miner2.go index c3639eebc..72b3fa8e0 100644 --- a/chain/actors/actor_miner2.go +++ b/chain/actors/actor_miner2.go @@ -5,7 +5,6 @@ import ( "context" "fmt" - ffi "github.com/filecoin-project/filecoin-ffi" amt2 "github.com/filecoin-project/go-amt-ipld/v2" "github.com/filecoin-project/go-sectorbuilder" @@ -331,7 +330,7 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V } activeFaults := uint64(0) - var sectorInfos []ffi.PublicSectorInfo + var sectorInfos []types.PublicSectorInfo if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error { if faults[id] { activeFaults++ @@ -342,7 +341,7 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V if err := cbor.DecodeInto(v.Raw, &comms); err != nil { return xerrors.New("could not decode comms") } - si := ffi.PublicSectorInfo{ + si := types.PublicSectorInfo{ SectorID: id, } commR := comms[0] @@ -360,11 +359,11 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V proverID := vmctx.Message().To // TODO: normalize to ID address - var candidates []sectorbuilder.EPostCandidate + var candidates []types.Candidate for _, t := range params.Candidates { var partial [32]byte copy(partial[:], t.Partial) - candidates = append(candidates, sectorbuilder.EPostCandidate{ + candidates = append(candidates, types.Candidate{ PartialTicket: partial, SectorID: t.SectorID, SectorChallengeIndex: t.ChallengeIndex, @@ -372,7 +371,7 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V } if ok, lerr := vmctx.Sys().VerifyFallbackPost(vmctx.Context(), mi.SectorSize, - sectorbuilder.NewSortedPublicSectorInfo(sectorInfos), seed[:], params.Proof, candidates, proverID, activeFaults); !ok || lerr != nil { + sectorInfos, seed[:], params.Proof, candidates, proverID, activeFaults); !ok || lerr != nil { if lerr != nil { // TODO: study PoST errors return nil, aerrors.Absorb(lerr, 4, "PoST error") diff --git a/chain/types/blockheader.go b/chain/types/blockheader.go index 87e994fc5..2dca1f99d 100644 --- a/chain/types/blockheader.go +++ b/chain/types/blockheader.go @@ -4,8 +4,6 @@ import ( "bytes" "math/big" - "github.com/filecoin-project/go-sectorbuilder" - block "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/minio/sha256-simd" @@ -205,7 +203,11 @@ func IsTicketWinner(partialTicket []byte, ssizeI uint64, snum uint64, totpow Big } func ElectionPostChallengeCount(sectors uint64, faults uint64) uint64 { - return sectorbuilder.ElectionPostChallengeCount(sectors, faults) + if sectors-faults == 0 { + return 0 + } + // ceil(sectors / SectorChallengeRatioDiv) + return (sectors-faults-1)/build.SectorChallengeRatioDiv + 1 } func (t *Ticket) Equals(ot *Ticket) bool { diff --git a/chain/types/vmcontext.go b/chain/types/vmcontext.go index b6eac6ca2..7faa932d6 100644 --- a/chain/types/vmcontext.go +++ b/chain/types/vmcontext.go @@ -2,11 +2,11 @@ package types import ( "context" - "github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-amt-ipld" "github.com/filecoin-project/lotus/chain/actors/aerrors" + cid "github.com/ipfs/go-cid" hamt "github.com/ipfs/go-hamt-ipld" cbg "github.com/whyrusleeping/cbor-gen" @@ -46,14 +46,28 @@ type VMContext interface { Context() context.Context } +const CommitmentBytesLen = 32 + +type PublicSectorInfo struct { + SectorID uint64 + CommR [CommitmentBytesLen]byte +} + +type Candidate struct { + SectorID uint64 + PartialTicket [32]byte + Ticket [32]byte + SectorChallengeIndex uint64 +} + type VMSyscalls struct { ValidatePoRep func(context.Context, address.Address, uint64, []byte, []byte, []byte, []byte, []byte, uint64) (bool, aerrors.ActorError) VerifyFallbackPost func(ctx context.Context, sectorSize uint64, - sectorInfo sectorbuilder.SortedPublicSectorInfo, + sectorInfo []PublicSectorInfo, challengeSeed []byte, proof []byte, - candidates []sectorbuilder.EPostCandidate, + candidates []Candidate, proverID address.Address, faults uint64) (bool, error) } diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index fa3ea18c9..be6dc76bd 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -2,6 +2,8 @@ package vm import ( "context" + + ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/lotus/chain/actors" @@ -24,6 +26,44 @@ func Syscalls(verifier sectorbuilder.Verifier) *types.VMSyscalls { return ok, nil }, - VerifyFallbackPost: verifier.VerifyFallbackPost, + VerifyFallbackPost: func(ctx context.Context, + sectorSize uint64, + sectorInfo []types.PublicSectorInfo, + challengeSeed []byte, + proof []byte, + candidates []types.Candidate, + proverID address.Address, + faults uint64) (bool, error) { + + sI := make([]ffi.PublicSectorInfo, len(sectorInfo)) + for i, v := range sectorInfo { + sI[i] = ffi.PublicSectorInfo{ + SectorID: v.SectorID, + CommR: v.CommR, + } + } + + cand := make([]sectorbuilder.EPostCandidate, len(candidates)) + for i, v := range candidates { + cand[i] = sectorbuilder.EPostCandidate{ + SectorID: v.SectorID, + PartialTicket: v.PartialTicket, + Ticket: v.Ticket, + SectorChallengeIndex: v.SectorChallengeIndex, + } + } + + return verifier.VerifyFallbackPost( + ctx, + sectorSize, + sectorbuilder.NewSortedPublicSectorInfo(sI), + challengeSeed, + proof, + cand, + proverID, + faults, + ) + + }, } } From 14580b61446876cc324a7c0d22e6b624e3cfa2e9 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 12 Feb 2020 20:44:35 +0100 Subject: [PATCH 2/2] Import go-systemd properly Signed-off-by: Jakub Sztandera --- cmd/lotus-health/notify.go | 2 +- go.mod | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-health/notify.go b/cmd/lotus-health/notify.go index a80dcf2ee..031f0fe2f 100644 --- a/cmd/lotus-health/notify.go +++ b/cmd/lotus-health/notify.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/coreos/go-systemd/dbus" + "github.com/coreos/go-systemd/v22/dbus" ) func notifyHandler(n string, ch chan interface{}, sCh chan os.Signal) (string, error) { diff --git a/go.mod b/go.mod index 50d7d8fb7..504cfd932 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/GeertJohan/go.rice v1.0.0 github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect - github.com/coreos/go-systemd v0.0.0-00010101000000-000000000000 + github.com/coreos/go-systemd/v22 v22.0.0 github.com/docker/go-units v0.4.0 github.com/filecoin-project/chain-validation v0.0.3 github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590 @@ -111,5 +111,3 @@ require ( replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0 replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi - -replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0