Merge pull request #1254 from filecoin-project/feat/no-ffi-in-types

Remove ffi from types package
This commit is contained in:
Whyrusleeping 2020-02-17 11:13:56 -08:00 committed by GitHub
commit fc227561ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 24 deletions

View File

@ -21,6 +21,8 @@ func SupportedSectorSize(ssize uint64) bool {
return false return false
} }
const SectorChallengeRatioDiv = 25
// ///// // /////
// Payments // Payments

View File

@ -6,8 +6,6 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
@ -483,7 +481,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
} }
activeFaults := uint64(0) activeFaults := uint64(0)
var sectorInfos []ffi.PublicSectorInfo var sectorInfos []types.PublicSectorInfo
if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error { if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error {
if faults[id] { if faults[id] {
activeFaults++ activeFaults++
@ -494,7 +492,7 @@ func (sma StorageMinerActor) SubmitFallbackPoSt(act *types.Actor, vmctx types.VM
if err := cbor.DecodeInto(v.Raw, &comms); err != nil { if err := cbor.DecodeInto(v.Raw, &comms); err != nil {
return xerrors.New("could not decode comms") return xerrors.New("could not decode comms")
} }
si := ffi.PublicSectorInfo{ si := types.PublicSectorInfo{
SectorID: id, SectorID: id,
} }
commR := comms[0] 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 proverID := vmctx.Message().To // TODO: normalize to ID address
var candidates []sectorbuilder.EPostCandidate var candidates []types.Candidate
for _, t := range params.Candidates { for _, t := range params.Candidates {
var partial [32]byte var partial [32]byte
copy(partial[:], t.Partial) copy(partial[:], t.Partial)
candidates = append(candidates, sectorbuilder.EPostCandidate{ candidates = append(candidates, types.Candidate{
PartialTicket: partial, PartialTicket: partial,
SectorID: t.SectorID, SectorID: t.SectorID,
SectorChallengeIndex: t.ChallengeIndex, 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, 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 { if lerr != nil {
// TODO: study PoST errors // TODO: study PoST errors
return nil, aerrors.Absorb(lerr, 4, "PoST error") return nil, aerrors.Absorb(lerr, 4, "PoST error")

View File

@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
ffi "github.com/filecoin-project/filecoin-ffi"
amt2 "github.com/filecoin-project/go-amt-ipld/v2" amt2 "github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
@ -331,7 +330,7 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V
} }
activeFaults := uint64(0) activeFaults := uint64(0)
var sectorInfos []ffi.PublicSectorInfo var sectorInfos []types.PublicSectorInfo
if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error { if err := pss.ForEach(func(id uint64, v *cbg.Deferred) error {
if faults[id] { if faults[id] {
activeFaults++ activeFaults++
@ -342,7 +341,7 @@ func (sma StorageMinerActor2) SubmitFallbackPoSt(act *types.Actor, vmctx types.V
if err := cbor.DecodeInto(v.Raw, &comms); err != nil { if err := cbor.DecodeInto(v.Raw, &comms); err != nil {
return xerrors.New("could not decode comms") return xerrors.New("could not decode comms")
} }
si := ffi.PublicSectorInfo{ si := types.PublicSectorInfo{
SectorID: id, SectorID: id,
} }
commR := comms[0] 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 proverID := vmctx.Message().To // TODO: normalize to ID address
var candidates []sectorbuilder.EPostCandidate var candidates []types.Candidate
for _, t := range params.Candidates { for _, t := range params.Candidates {
var partial [32]byte var partial [32]byte
copy(partial[:], t.Partial) copy(partial[:], t.Partial)
candidates = append(candidates, sectorbuilder.EPostCandidate{ candidates = append(candidates, types.Candidate{
PartialTicket: partial, PartialTicket: partial,
SectorID: t.SectorID, SectorID: t.SectorID,
SectorChallengeIndex: t.ChallengeIndex, 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, 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 { if lerr != nil {
// TODO: study PoST errors // TODO: study PoST errors
return nil, aerrors.Absorb(lerr, 4, "PoST error") return nil, aerrors.Absorb(lerr, 4, "PoST error")

View File

@ -4,8 +4,6 @@ import (
"bytes" "bytes"
"math/big" "math/big"
"github.com/filecoin-project/go-sectorbuilder"
block "github.com/ipfs/go-block-format" block "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/minio/sha256-simd" "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 { 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 { func (t *Ticket) Equals(ot *Ticket) bool {

View File

@ -2,11 +2,11 @@ package types
import ( import (
"context" "context"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-amt-ipld" "github.com/filecoin-project/go-amt-ipld"
"github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/aerrors"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld" hamt "github.com/ipfs/go-hamt-ipld"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
@ -46,14 +46,28 @@ type VMContext interface {
Context() context.Context 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 { type VMSyscalls struct {
ValidatePoRep func(context.Context, address.Address, uint64, []byte, []byte, []byte, []byte, []byte, uint64) (bool, aerrors.ActorError) ValidatePoRep func(context.Context, address.Address, uint64, []byte, []byte, []byte, []byte, []byte, uint64) (bool, aerrors.ActorError)
VerifyFallbackPost func(ctx context.Context, VerifyFallbackPost func(ctx context.Context,
sectorSize uint64, sectorSize uint64,
sectorInfo sectorbuilder.SortedPublicSectorInfo, sectorInfo []PublicSectorInfo,
challengeSeed []byte, challengeSeed []byte,
proof []byte, proof []byte,
candidates []sectorbuilder.EPostCandidate, candidates []Candidate,
proverID address.Address, proverID address.Address,
faults uint64) (bool, error) faults uint64) (bool, error)
} }

View File

@ -2,6 +2,8 @@ package vm
import ( import (
"context" "context"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
@ -24,6 +26,44 @@ func Syscalls(verifier sectorbuilder.Verifier) *types.VMSyscalls {
return ok, nil 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,
)
},
} }
} }

View File

@ -3,7 +3,7 @@ package main
import ( import (
"os" "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) { func notifyHandler(n string, ch chan interface{}, sCh chan os.Signal) (string, error) {

4
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/GeertJohan/go.rice v1.0.0 github.com/GeertJohan/go.rice v1.0.0
github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect 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/docker/go-units v0.4.0
github.com/filecoin-project/chain-validation v0.0.3 github.com/filecoin-project/chain-validation v0.0.3
github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590 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/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi 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