Skip to content

Commit

Permalink
Merge pull request #212 from filecoin-project/feat-decouple-post-part…
Browse files Browse the repository at this point in the history
…ition

Add new partition post API calls
  • Loading branch information
jennijuju authored Oct 25, 2021
2 parents 4a0ed4a + ad8464d commit 7912389
Show file tree
Hide file tree
Showing 12 changed files with 1,300 additions and 199 deletions.
91 changes: 90 additions & 1 deletion distributed.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package ffi
import (
"github.com/filecoin-project/filecoin-ffi/generated"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/specs-actors/actors/runtime/proof"
"github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -174,3 +174,92 @@ func GenerateWindowPoStWithVanilla(

return out, nil
}

type PartitionProof proof.PoStProof

func GenerateSinglePartitionWindowPoStWithVanilla(
proofType abi.RegisteredPoStProof,
minerID abi.ActorID,
randomness abi.PoStRandomness,
proofs [][]byte,
partitionIndex uint,
) (*PartitionProof, error) {
pp, err := toFilRegisteredPoStProof(proofType)
if err != nil {
return nil, err
}

proverID, err := toProverID(minerID)
if err != nil {
return nil, err
}
fproofs, discard := toVanillaProofs(proofs)
defer discard()

resp := generated.FilGenerateSingleWindowPostWithVanilla(
pp,
to32ByteArray(randomness),
proverID,
fproofs, uint(len(proofs)),
partitionIndex,
)
resp.Deref()

defer generated.FilDestroyGenerateSingleWindowPostWithVanillaResponse(resp)

if resp.StatusCode != generated.FCPResponseStatusFCPNoError {
return nil, errors.New(generated.RawString(resp.ErrorMsg).Copy())
}

dpp, err := fromFilRegisteredPoStProof(resp.PartitionProof.RegisteredProof)
if err != nil {
return nil, err
}

out := PartitionProof{
PoStProof: dpp,
ProofBytes: copyBytes(resp.PartitionProof.ProofPtr, resp.PartitionProof.ProofLen),
}

return &out, nil
}

func MergeWindowPoStPartitionProofs(
proofType abi.RegisteredPoStProof,
partitionProofs []PartitionProof,
) (*proof.PoStProof, error) {
pp, err := toFilRegisteredPoStProof(proofType)
if err != nil {
return nil, err
}

fproofs, discard, err := toPartitionProofs(partitionProofs)
defer discard()
if err != nil {
return nil, err
}

resp := generated.FilMergeWindowPostPartitionProofs(
pp,
fproofs, uint(len(fproofs)),
)
resp.Deref()

defer generated.FilDestroyMergeWindowPostPartitionProofsResponse(resp)

if resp.StatusCode != generated.FCPResponseStatusFCPNoError {
return nil, errors.New(generated.RawString(resp.ErrorMsg).Copy())
}

dpp, err := fromFilRegisteredPoStProof(resp.Proof.RegisteredProof)
if err != nil {
return nil, err
}

out := proof.PoStProof{
PoStProof: dpp,
ProofBytes: copyBytes(resp.Proof.ProofPtr, resp.Proof.ProofLen),
}

return &out, nil
}
Loading

0 comments on commit 7912389

Please sign in to comment.