Commit 37a99ccf authored by 董子豪's avatar 董子豪

remove package filecoin-project/*

parent e3979676
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"runtime" "runtime"
"sync" "sync"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
var MTTresh = uint64(32 << 20) var MTTresh = uint64(32 << 20)
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
type unpadReader struct { type unpadReader struct {
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"fil_integrate/extern/sector-storage/fr32" "fil_integrate/extern/sector-storage/fr32"
) )
......
...@@ -3,7 +3,7 @@ package fr32 ...@@ -3,7 +3,7 @@ package fr32
import ( import (
"math/bits" "math/bits"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
func subPieces(in abi.UnpaddedPieceSize) []abi.UnpaddedPieceSize { func subPieces(in abi.UnpaddedPieceSize) []abi.UnpaddedPieceSize {
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"fil_integrate/build/fr32" "fil_integrate/build/fr32"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
const NODE_SIZE = 32 const NODE_SIZE = 32
......
package proof package proof
import ( import (
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
) )
...@@ -16,7 +16,6 @@ type Proof []byte ...@@ -16,7 +16,6 @@ type Proof []byte
type SealVerifyInfo struct { type SealVerifyInfo struct {
SealType abi.RegisteredSealProof SealType abi.RegisteredSealProof
SectorID abi.SectorID SectorID abi.SectorID
DealIDs []abi.DealID
Randomness abi.SealRandomness Randomness abi.SealRandomness
InteractiveRandomness abi.InteractiveSealRandomness InteractiveRandomness abi.InteractiveSealRandomness
SealProof Proof SealProof Proof
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/big" "fil_integrate/build/state-types/big"
) )
// SectorNumber is a numeric identifier for a sector. It is usually relative to a miner. // SectorNumber is a numeric identifier for a sector. It is usually relative to a miner.
...@@ -420,6 +420,8 @@ func (p RegisteredPoStProof) ProofSize() (uint64, error) { ...@@ -420,6 +420,8 @@ func (p RegisteredPoStProof) ProofSize() (uint64, error) {
return info.ProofSize, nil return info.ProofSize, nil
} }
type Randomness []byte
type SealRandomness Randomness type SealRandomness Randomness
type InteractiveSealRandomness Randomness type InteractiveSealRandomness Randomness
type PoStRandomness Randomness type PoStRandomness Randomness
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
func TestSectorSizeString(t *testing.T) { func TestSectorSizeString(t *testing.T) {
......
...@@ -3,10 +3,7 @@ package big ...@@ -3,10 +3,7 @@ package big
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"math/big" "math/big"
cbg "github.com/whyrusleeping/cbor-gen"
) )
// BigIntMaxSerializedLen is the max length of a byte slice representing a CBOR serialized big. // BigIntMaxSerializedLen is the max length of a byte slice representing a CBOR serialized big.
...@@ -275,68 +272,6 @@ func (bi *Int) UnmarshalBinary(buf []byte) error { ...@@ -275,68 +272,6 @@ func (bi *Int) UnmarshalBinary(buf []byte) error {
return nil return nil
} }
func (bi *Int) MarshalCBOR(w io.Writer) error {
if bi.Int == nil {
zero := Zero()
return zero.MarshalCBOR(w)
}
enc, err := bi.Bytes()
if err != nil {
return err
}
encLen := len(enc)
if encLen > BigIntMaxSerializedLen {
return fmt.Errorf("big integer byte array too long (%d bytes)", encLen)
}
header := cbg.CborEncodeMajorType(cbg.MajByteString, uint64(encLen))
if _, err := w.Write(header); err != nil {
return err
}
if _, err := w.Write(enc); err != nil {
return err
}
return nil
}
func (bi *Int) UnmarshalCBOR(br io.Reader) error {
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajByteString {
return fmt.Errorf("cbor input for fil big int was not a byte string (%x)", maj)
}
if extra == 0 {
bi.Int = big.NewInt(0)
return nil
}
if extra > BigIntMaxSerializedLen {
return fmt.Errorf("big integer byte array too long (%d bytes)", extra)
}
buf := make([]byte, extra)
if _, err := io.ReadFull(br, buf); err != nil {
return err
}
i, err := FromBytes(buf)
if err != nil {
return err
}
*bi = i
return nil
}
func (bi *Int) IsZero() bool { func (bi *Int) IsZero() bool {
return bi.Int.Sign() == 0 return bi.Int.Sign() == 0
} }
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
cbg "github.com/whyrusleeping/cbor-gen"
) )
func TestBigIntSerializationRoundTrip(t *testing.T) { func TestBigIntSerializationRoundTrip(t *testing.T) {
...@@ -192,41 +191,3 @@ func TestFromString(t *testing.T) { ...@@ -192,41 +191,3 @@ func TestFromString(t *testing.T) {
expected := Int{Int: big.NewInt(12345)} expected := Int{Int: big.NewInt(12345)}
assert.Equal(t, expected, res) assert.Equal(t, expected, res)
} }
func TestCBOR(t *testing.T) {
t.Run("happy", func(t *testing.T) {
ints := []Int{
NewInt(0),
NewInt(-1),
NewInt(1),
NewInt(1e18),
Lsh(NewInt(1), 80),
}
for _, n := range ints {
var b bytes.Buffer
assert.NoError(t, n.MarshalCBOR(&b))
var out Int
assert.NoError(t, out.UnmarshalCBOR(&b))
assert.Equal(t, n, out)
}
})
t.Run("fails to marshal too large", func(t *testing.T) {
giant := Lsh(NewInt(1), 8*(BigIntMaxSerializedLen-1))
var b bytes.Buffer
assert.Error(t, giant.MarshalCBOR(&b))
})
t.Run("fails to unmarshal too large", func(t *testing.T) {
// Construct CBOR for a too-large byte array
var b bytes.Buffer
header := cbg.CborEncodeMajorType(cbg.MajByteString, uint64(BigIntMaxSerializedLen+1))
_, err := b.Write(header)
require.NoError(t, err)
_, err = b.Write(make([]byte, BigIntMaxSerializedLen+1))
require.NoError(t, err)
var out Int
assert.Error(t, out.UnmarshalCBOR(&b))
})
}
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"fil_integrate/build/storiface" "fil_integrate/build/storiface"
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
var ErrSectorNotFound = errors.New("sector not found") var ErrSectorNotFound = errors.New("sector not found")
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
) )
const ( const (
......
...@@ -3,8 +3,8 @@ package build ...@@ -3,8 +3,8 @@ package build
import ( import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/filecoin-project/go-state-types/network" "fil_integrate/build/state-types/network"
) )
func SealProofTypeFromSectorSize(ssize abi.SectorSize, nv network.Version) (abi.RegisteredSealProof, error) { func SealProofTypeFromSectorSize(ssize abi.SectorSize, nv network.Version) (abi.RegisteredSealProof, error) {
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"os" "os"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
package ffi package ffi
import ( import (
"fil_integrate/build/state-types/abi"
"github.com/filecoin-project/filecoin-ffi/generated" "github.com/filecoin-project/filecoin-ffi/generated"
"github.com/filecoin-project/go-state-types/abi"
"github.com/pkg/errors" "github.com/pkg/errors"
"fil_integrate/build/proof" "fil_integrate/build/proof"
......
...@@ -1638,6 +1638,7 @@ func (x *FilPoStProof) Ref() *C.fil_PoStProof { ...@@ -1638,6 +1638,7 @@ func (x *FilPoStProof) Ref() *C.fil_PoStProof {
// Free invokes alloc map's free mechanism that cleanups any allocated memory using C free. // Free invokes alloc map's free mechanism that cleanups any allocated memory using C free.
// Does nothing if struct is nil or has no allocation map. // Does nothing if struct is nil or has no allocation map.
func (x *FilPoStProof) Free() { func (x *FilPoStProof) Free() {
fmt.Println("free")
if x != nil && x.allocs3451bfa != nil { if x != nil && x.allocs3451bfa != nil {
x.allocs3451bfa.(*cgoAllocMap).Free() x.allocs3451bfa.(*cgoAllocMap).Free()
x.ref3451bfa = nil x.ref3451bfa = nil
...@@ -1771,6 +1772,7 @@ func (x *FilGenerateWindowPoStResponse) Ref() *C.fil_GenerateWindowPoStResponse ...@@ -1771,6 +1772,7 @@ func (x *FilGenerateWindowPoStResponse) Ref() *C.fil_GenerateWindowPoStResponse
// Free invokes alloc map's free mechanism that cleanups any allocated memory using C free. // Free invokes alloc map's free mechanism that cleanups any allocated memory using C free.
// Does nothing if struct is nil or has no allocation map. // Does nothing if struct is nil or has no allocation map.
func (x *FilGenerateWindowPoStResponse) Free() { func (x *FilGenerateWindowPoStResponse) Free() {
fmt.Println("free1")
if x != nil && x.allocs2a5f3ba8 != nil { if x != nil && x.allocs2a5f3ba8 != nil {
x.allocs2a5f3ba8.(*cgoAllocMap).Free() x.allocs2a5f3ba8.(*cgoAllocMap).Free()
x.ref2a5f3ba8 = nil x.ref2a5f3ba8 = nil
...@@ -1843,8 +1845,7 @@ func (x *FilGenerateWindowPoStResponse) Deref() { ...@@ -1843,8 +1845,7 @@ func (x *FilGenerateWindowPoStResponse) Deref() {
return return
} }
x.ErrorMsg = packPCharString(x.ref2a5f3ba8.error_msg) x.ErrorMsg = packPCharString(x.ref2a5f3ba8.error_msg)
x.ProofsLen = (uint)(x.ref2a5f3ba8.proofs_len) x.Proof = *NewFilPoStProofRef(unsafe.Pointer(&x.ref2a5f3ba8.proof))
x.Proof = *NewFilPoStProofRef(unsafe.Pointer(&x.ref2a5f3ba8.proofs_ptr))
// packSFilPoStProof(x.ProofsPtr, x.ref2a5f3ba8.proofs_ptr) // packSFilPoStProof(x.ProofsPtr, x.ref2a5f3ba8.proofs_ptr)
x.FaultySectorsLen = (uint)(x.ref2a5f3ba8.faulty_sectors_len) x.FaultySectorsLen = (uint)(x.ref2a5f3ba8.faulty_sectors_len)
hxf0d18b7 := (*sliceHeader)(unsafe.Pointer(&x.FaultySectorsPtr)) hxf0d18b7 := (*sliceHeader)(unsafe.Pointer(&x.FaultySectorsPtr))
......
...@@ -4,7 +4,6 @@ go 1.13 ...@@ -4,7 +4,6 @@ go 1.13
require ( require (
github.com/filecoin-project/go-fil-commcid v0.1.0 github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-state-types v0.1.1-0.20210506134452-99b279731c48
github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-cid v0.0.7
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
...@@ -13,5 +12,3 @@ require ( ...@@ -13,5 +12,3 @@ require (
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
modernc.org/golex v1.0.1 // indirect modernc.org/golex v1.0.1 // indirect
) )
replace github.com/filecoin-project/go-state-types => ../go-state-types
...@@ -2,24 +2,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 ...@@ -2,24 +2,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/filecoin-project/go-amt-ipld/v2 v2.1.0/go.mod h1:nfFPoGyX0CU9SkXX8EoCcSuHN1XcbN0c6KBh7yvP5fs=
github.com/filecoin-project/go-amt-ipld/v3 v3.0.0/go.mod h1:Qa95YNAbtoVCTSVtX38aAC1ptBnJfPma1R/zZsKmx4o=
github.com/filecoin-project/go-bitfield v0.2.0/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM=
github.com/filecoin-project/go-bitfield v0.2.3/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM=
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMXdBnCiXjfCYx/hLqFxccPoqsSveQFxVLvNxy9bus=
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88OqLYEo6roi+GiIeOh8= github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88OqLYEo6roi+GiIeOh8=
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24=
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0/go.mod h1:7aWZdaQ1b16BVoQUYR+eEvrDCGJoPLxFpDynFjYfBjI=
github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1/go.mod h1:gXpNmr3oQx8l3o7qkGyDjJjYSRX7hp/FGOStdqrWyDI=
github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.1-0.20210506134452-99b279731c48 h1:Jc4OprDp3bRDxbsrXNHPwJabZJM3iDy+ri8/1e0ZnX4=
github.com/filecoin-project/go-state-types v0.1.1-0.20210506134452-99b279731c48/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
...@@ -120,16 +106,6 @@ github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKw ...@@ -120,16 +106,6 @@ github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKw
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/warpfork/go-wish v0.0.0-20190328234359-8b3e70f8e830 h1:8kxMKmKzXXL4Ru1nyhvdms/JjWt+3YLpvRb/bAjO/y0= github.com/warpfork/go-wish v0.0.0-20190328234359-8b3e70f8e830 h1:8kxMKmKzXXL4Ru1nyhvdms/JjWt+3YLpvRb/bAjO/y0=
github.com/warpfork/go-wish v0.0.0-20190328234359-8b3e70f8e830/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/warpfork/go-wish v0.0.0-20190328234359-8b3e70f8e830/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
github.com/whyrusleeping/cbor-gen v0.0.0-20200504204219-64967432584d/go.mod h1:W5MvapuoHRP8rz4vxjwCK1pDqF1aQcWsV5PZ+AHbqdg=
github.com/whyrusleeping/cbor-gen v0.0.0-20200715143311-227fab5a2377/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200723185710-6a3894a6352b/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200806213330-63aa96ca5488/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200810223238-211df3b9e24c/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200812213548-958ddffe352c/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20210118024343-169e9d70c0c2 h1:7HzUKl5d/dELS9lLeT4W6YvliZx+s9k/eOOIdHKrA/w=
github.com/whyrusleeping/cbor-gen v0.0.0-20210118024343-169e9d70c0c2/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb h1:/7/dQyiKnxAOj9L69FhST7uMe17U015XPzX7cy+5ykM= github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb h1:/7/dQyiKnxAOj9L69FhST7uMe17U015XPzX7cy+5ykM=
github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb/go.mod h1:pbNsDSxn1ICiNn9Ct4ZGNrwzfkkwYbx/lw8VuyutFIg= github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb/go.mod h1:pbNsDSxn1ICiNn9Ct4ZGNrwzfkkwYbx/lw8VuyutFIg=
github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245 h1:Sw125DKxZhPUI4JLlWugkzsrlB50jR9v2khiD9FxuSo= github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245 h1:Sw125DKxZhPUI4JLlWugkzsrlB50jR9v2khiD9FxuSo=
......
...@@ -14,8 +14,8 @@ import ( ...@@ -14,8 +14,8 @@ import (
"unsafe" "unsafe"
// "fmt" // "fmt"
"fil_integrate/build/state-types/abi"
commcid "github.com/filecoin-project/go-fil-commcid" commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/xerrors" "golang.org/x/xerrors"
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
commcid "github.com/filecoin-project/go-fil-commcid" commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"sort" "sort"
spproof "fil_integrate/build/proof" spproof "fil_integrate/build/proof"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
) )
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
spproof "fil_integrate/build/proof" spproof "fil_integrate/build/proof"
...@@ -146,7 +146,6 @@ func WorkflowProofsLifecycle(t TestHelper) { ...@@ -146,7 +146,6 @@ func WorkflowProofsLifecycle(t TestHelper) {
SealedCID: sealedCID, SealedCID: sealedCID,
SealType: sealProofType, SealType: sealProofType,
SealProof: proof, SealProof: proof,
DealIDs: []abi.DealID{},
Randomness: ticket, Randomness: ticket,
InteractiveRandomness: seed, InteractiveRandomness: seed,
UnsealedCID: unsealedCID, UnsealedCID: unsealedCID,
......
version: 2.1
orbs:
go: gotest/tools@0.0.9
codecov: codecov/codecov@1.0.2
executors:
golang:
docker:
- image: circleci/golang:1.13
resource_class: small
commands:
install-deps:
steps:
- go/install-ssh
- go/install: {package: git}
prepare:
parameters:
linux:
default: true
description: is a linux build environment?
type: boolean
steps:
- checkout
- when:
condition: << parameters.linux >>
steps:
- run: sudo apt-get update
build-all:
jobs:
mod-tidy-check:
executor: golang
steps:
- install-deps
- prepare
- go/mod-download
- go/mod-tidy-check
build-all:
executor: golang
steps:
- install-deps
- prepare
- go/mod-download
- run:
command: make build
- store_artifacts:
path: go-state-types
- store_artifacts:
path: go-state-types
check-gen:
executor: golang
steps:
- install-deps
- prepare
- go/mod-download
- run:
name: "Install goimports"
command: |
cd / && go get golang.org/x/tools/cmd/goimports
- run:
name: "Ensure we don't need to run 'make gen'"
command: |
make gen && git diff --exit-code
test-all:
executor: golang
steps:
- install-deps
- prepare
- go/mod-download
- run:
command: |
make test-coverage
mkdir -p /tmp/artifacts
mv coverage.out /tmp/artifacts/coverage.out
- codecov/upload:
file: /tmp/artifacts/coverage.out
- store_artifacts:
path: go-state-types
lint: &lint
description: |
Run golangci-lint.
parameters:
executor:
type: executor
default: golang
golangci-lint-version:
type: string
default: 1.23.1
concurrency:
type: string
default: '2'
description: |
Concurrency used to run linters. Defaults to 2 because NumCPU is not
aware of container CPU limits.
args:
type: string
default: ''
description: |
Arguments to pass to golangci-lint
executor: << parameters.executor >>
steps:
- install-deps
- prepare
- run:
command: make build
- go/install-golangci-lint:
gobin: $HOME/.local/bin
version: << parameters.golangci-lint-version >>
- run:
name: Lint
command: |
$HOME/.local/bin/golangci-lint run -v --skip-dirs-use-default=false\
--concurrency << parameters.concurrency >> << parameters.args >>
lint-all:
<<: *lint
workflows:
version: 2.1
ci:
jobs:
- lint-all
- mod-tidy-check
- build-all
- test-all
- check-gen
Copyright 2020. Protocol Labs, Inc.
This library is dual-licensed under Apache 2.0 and MIT terms.
Copyright 2020. Protocol Labs, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2020. Protocol Labs, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
GO_BIN ?= go
GOLINT ?= golangci-lint
all: build lint test tidy
.PHONY: all
build:
$(GO_BIN) build ./...
.PHONY: build
test:
$(GO_BIN) test ./...
.PHONY: test
test-coverage:
$(GO_BIN) test -coverprofile=coverage.out ./...
.PHONY: test-coverage
tidy:
$(GO_BIN) mod tidy
.PHONY: tidy
gen:
$(GO_BIN) run ./gen/gen.go
.PHONY: gen
lint:
$(GOLINT) run ./...
.PHONY: lint
# Filecoin state types
[![CircleCI](https://circleci.com/gh/filecoin-project/go-state-types.svg?style=svg)](https://circleci.com/gh/filecoin-project/go-state-types)
[![codecov](https://codecov.io/gh/filecoin-project/go-state-types/branch/master/graph/badge.svg)](https://codecov.io/gh/filecoin-project/go-state-types)
This repository contains primitive and low level types used in the Filecoin blockchain state representation.
These are primarily intended for use by [Actors](https://github.com/filecoin-project/specs-actors) and other
modules that read chain state directly.
## Versioning
Blockchain state versioning does not naturally align with common semantic versioning conventions.
Any change in behaviour, including repairing any error that may have affected blockchain evaluation,
must be released in a major version change. We intend that to be a rare event for the contents of
this repository.
## License
This repository is dual-licensed under Apache 2.0 and MIT terms.
Copyright 2020. Protocol Labs, Inc.
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
package abi
import (
"fmt"
"io"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)
var _ = xerrors.Errorf
var lengthBufPieceInfo = []byte{130}
func (t *PieceInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write(lengthBufPieceInfo); err != nil {
return err
}
scratch := make([]byte, 9)
// t.Size (abi.PaddedPieceSize) (uint64)
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Size)); err != nil {
return err
}
// t.PieceCID (cid.Cid) (struct)
if err := cbg.WriteCidBuf(scratch, w, t.PieceCID); err != nil {
return xerrors.Errorf("failed to write cid field t.PieceCID: %w", err)
}
return nil
}
func (t *PieceInfo) UnmarshalCBOR(r io.Reader) error {
*t = PieceInfo{}
br := cbg.GetPeeker(r)
scratch := make([]byte, 8)
maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.Size (abi.PaddedPieceSize) (uint64)
{
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Size = PaddedPieceSize(extra)
}
// t.PieceCID (cid.Cid) (struct)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.PieceCID: %w", err)
}
t.PieceCID = c
}
return nil
}
var lengthBufSectorID = []byte{130}
func (t *SectorID) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write(lengthBufSectorID); err != nil {
return err
}
scratch := make([]byte, 9)
// t.Miner (abi.ActorID) (uint64)
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Miner)); err != nil {
return err
}
// t.Number (abi.SectorNumber) (uint64)
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Number)); err != nil {
return err
}
return nil
}
func (t *SectorID) UnmarshalCBOR(r io.Reader) error {
*t = SectorID{}
br := cbg.GetPeeker(r)
scratch := make([]byte, 8)
maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.Miner (abi.ActorID) (uint64)
{
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Miner = ActorID(extra)
}
// t.Number (abi.SectorNumber) (uint64)
{
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Number = SectorNumber(extra)
}
return nil
}
package abi
import (
"strconv"
"github.com/filecoin-project/go-state-types/big"
)
// Epoch number of the chain state, which acts as a proxy for time within the VM.
type ChainEpoch int64
func (e ChainEpoch) String() string {
return strconv.FormatInt(int64(e), 10)
}
// TokenAmount is an amount of Filecoin tokens. This type is used within
// the VM in message execution, to account movement of tokens, payment
// of VM gas, and more.
//
// BigInt types are aliases rather than new types because the latter introduce incredible amounts of noise converting to
// and from types in order to manipulate values. We give up some type safety for ergonomics.
type TokenAmount = big.Int
func NewTokenAmount(t int64) TokenAmount {
return big.NewInt(t)
}
// Randomness is a string of random bytes
type Randomness []byte
// RandomnessLength is the length of the randomness slice.
const RandomnessLength = 32
package abi
import (
cid "github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
)
var (
// HashFunction is the default hash function for computing CIDs.
//
// This is currently Blake2b-256.
HashFunction = uint64(mh.BLAKE2B_MIN + 31)
// When producing a CID for an IPLD block less than or equal to CIDInlineLimit
// bytes in length, the identity hash function will be used instead of
// HashFunction. This will effectively "inline" the block into the CID, allowing
// it to be extracted directly from the CID with no disk/network operations.
//
// This is currently -1 for "disabled".
//
// This is exposed for testing. Do not modify unless you know what you're doing.
CIDInlineLimit = -1
)
type cidBuilder struct {
codec uint64
}
func (cidBuilder) WithCodec(c uint64) cid.Builder {
return cidBuilder{codec: c}
}
func (b cidBuilder) GetCodec() uint64 {
return b.codec
}
func (b cidBuilder) Sum(data []byte) (cid.Cid, error) {
hf := HashFunction
if len(data) <= CIDInlineLimit {
hf = mh.IDENTITY
}
return cid.V1Builder{Codec: b.codec, MhType: hf}.Sum(data)
}
// CidBuilder is the default CID builder for Filecoin.
//
// - The default codec is CBOR. This can be changed with CidBuilder.WithCodec.
// - The default hash function is 256bit blake2b.
var CidBuilder cid.Builder = cidBuilder{codec: cid.DagCBOR}
package abi
import "github.com/filecoin-project/go-state-types/big"
type DealID uint64
// BigInt types are aliases rather than new types because the latter introduce incredible amounts of noise
// converting to and from types in order to manipulate values.
// We give up some type safety for ergonomics.
type DealWeight = big.Int // units: byte-epochs
package abi
import (
"fmt"
"io"
cbg "github.com/whyrusleeping/cbor-gen"
)
// The empty value represents absence of a value. It is used for parameter and return types for actor methods
// that don't take/return any data. This saves a byte in serialization of messages and receipts: the serialized
// form is an empty byte slice, rather than a byte slice containing a single byte CBOR encoding of nil/empty/etc.
//
// The only expected use of this is as the type of a nil reference. Don't instantiate this type.
//
// This is primarily necessary due to Go's lack of a void type and our interface-based serialization scheme.
type EmptyValue struct{}
// A typed nil pointer to EmptyValue.
var Empty *EmptyValue = nil
var _ cbg.CBORMarshaler = (*EmptyValue)(nil)
var _ cbg.CBORUnmarshaler = (*EmptyValue)(nil)
func (v *EmptyValue) MarshalCBOR(_ io.Writer) error {
// An attempt to serialize a non-nil value indicates a caller mis-using this type.
if v != nil {
return fmt.Errorf("cannot marshal empty value, try nil instead")
}
// Allow nil to write zero bytes as a convenience so callers don't need to nil-check all values before
// attempting serialization.
return nil
}
func (v *EmptyValue) UnmarshalCBOR(_ io.Reader) error {
// Read zero bytes.
return nil
}
package abi
import (
"encoding/binary"
"errors"
// "github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
)
// Keyer defines an interface required to put values in mapping.
type Keyer interface {
Key() string
}
// Adapts an address as a mapping key.
// type AddrKey address.Address
// func (k AddrKey) Key() string {
// return string(address.Address(k).Bytes())
// }
type CidKey cid.Cid
func (k CidKey) Key() string {
return cid.Cid(k).KeyString()
}
// Adapts an int64 as a mapping key.
type intKey struct {
int64
}
//noinspection GoExportedFuncWithUnexportedType
func IntKey(k int64) intKey {
return intKey{k}
}
func (k intKey) Key() string {
buf := make([]byte, 10)
n := binary.PutVarint(buf, k.int64)
return string(buf[:n])
}
//noinspection GoUnusedExportedFunction
func ParseIntKey(k string) (int64, error) {
i, n := binary.Varint([]byte(k))
if n != len(k) {
return 0, errors.New("failed to decode varint key")
}
return i, nil
}
// Adapts a uint64 as a mapping key.
type uintKey struct {
uint64
}
//noinspection GoExportedFuncWithUnexportedType
func UIntKey(k uint64) uintKey {
return uintKey{k}
}
func (k uintKey) Key() string {
buf := make([]byte, 10)
n := binary.PutUvarint(buf, k.uint64)
return string(buf[:n])
}
func ParseUIntKey(k string) (uint64, error) {
i, n := binary.Uvarint([]byte(k))
if n != len(k) {
return 0, errors.New("failed to decode varint key")
}
return i, nil
}
package cbor
import "io"
// These interfaces are intended to match those from whyrusleeping/cbor-gen, such that code generated from that
// system is automatically usable here (but not mandatory).
type Marshaler interface {
MarshalCBOR(w io.Writer) error
}
type Unmarshaler interface {
UnmarshalCBOR(r io.Reader) error
}
type Er interface {
Marshaler
Unmarshaler
}
package crypto
// Specifies a domain for randomness generation.
type DomainSeparationTag int64
const (
DomainSeparationTag_TicketProduction DomainSeparationTag = 1 + iota
DomainSeparationTag_ElectionProofProduction
DomainSeparationTag_WinningPoStChallengeSeed
DomainSeparationTag_WindowedPoStChallengeSeed
DomainSeparationTag_SealRandomness
DomainSeparationTag_InteractiveSealChallengeSeed
DomainSeparationTag_WindowedPoStDeadlineAssignment
DomainSeparationTag_MarketDealCronSeed
DomainSeparationTag_PoStChainCommit
)
package crypto
import (
"bytes"
"fmt"
"io"
"math"
cbg "github.com/whyrusleeping/cbor-gen"
)
type SigType byte
const (
SigTypeUnknown = SigType(math.MaxUint8)
SigTypeSecp256k1 = SigType(iota)
SigTypeBLS
)
func (t SigType) Name() (string, error) {
switch t {
case SigTypeUnknown:
return "unknown", nil
case SigTypeSecp256k1:
return "secp256k1", nil
case SigTypeBLS:
return "bls", nil
default:
return "", fmt.Errorf("invalid signature type: %d", t)
}
}
const SignatureMaxLength = 200
type Signature struct {
Type SigType
Data []byte
}
func (s *Signature) Equals(o *Signature) bool {
if s == nil || o == nil {
return s == o
}
return s.Type == o.Type && bytes.Equal(s.Data, o.Data)
}
func (s *Signature) MarshalCBOR(w io.Writer) error {
if s == nil {
_, err := w.Write(cbg.CborNull)
return err
}
header := cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(s.Data)+1))
if _, err := w.Write(header); err != nil {
return err
}
if _, err := w.Write([]byte{byte(s.Type)}); err != nil {
return err
}
if _, err := w.Write(s.Data); err != nil {
return err
}
return nil
}
func (s *Signature) UnmarshalCBOR(br io.Reader) error {
maj, l, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajByteString {
return fmt.Errorf("not a byte string")
}
if l > SignatureMaxLength {
return fmt.Errorf("string too long")
}
if l == 0 {
return fmt.Errorf("string empty")
}
buf := make([]byte, l)
if _, err = io.ReadFull(br, buf); err != nil {
return err
}
switch SigType(buf[0]) {
default:
return fmt.Errorf("invalid signature type in cbor input: %d", buf[0])
case SigTypeSecp256k1:
s.Type = SigTypeSecp256k1
case SigTypeBLS:
s.Type = SigTypeBLS
}
s.Data = buf[1:]
return nil
}
func (s *Signature) MarshalBinary() ([]byte, error) {
bs := make([]byte, len(s.Data)+1)
bs[0] = byte(s.Type)
copy(bs[1:], s.Data)
return bs, nil
}
func (s *Signature) UnmarshalBinary(bs []byte) error {
if len(bs) > SignatureMaxLength {
return fmt.Errorf("invalid signature bytes, too long (%d)", len(bs))
}
if len(bs) == 0 {
return fmt.Errorf("invalid signature bytes of length 0")
}
switch SigType(bs[0]) {
default:
// Do not error during unmarshal but leave a standard value.
// unmarshal(marshal(zero valued sig)) is valuable for test
// and type needs to be checked by caller anyway.
s.Type = SigTypeUnknown
case SigTypeSecp256k1:
s.Type = SigTypeSecp256k1
case SigTypeBLS:
s.Type = SigTypeBLS
}
s.Data = bs[1:]
return nil
}
package crypto_test
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-state-types/crypto"
)
func TestEquality(t *testing.T) {
a := crypto.Signature{
Type: crypto.SigTypeSecp256k1,
Data: []byte{1, 2, 3, 4},
}
assert.True(t, a.Equals(&a))
assert.False(t, a.Equals(&crypto.Signature{
Type: crypto.SigTypeBLS,
Data: a.Data,
}))
assert.False(t, a.Equals(&crypto.Signature{
Type: a.Type,
Data: []byte{1, 1, 1, 1},
}))
}
func TestCBOR(t *testing.T) {
a := crypto.Signature{
Type: crypto.SigTypeSecp256k1,
Data: []byte{1, 2, 3, 4},
}
b := crypto.Signature{
Type: crypto.SigTypeBLS,
Data: []byte{5, 6, 7, 8},
}
t.Run("round trip secp", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, a.MarshalCBOR(&buf))
require.NoError(t, out.UnmarshalCBOR(&buf))
require.True(t, out.Equals(&a))
})
t.Run("round trip bls", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, b.MarshalCBOR(&buf))
require.NoError(t, out.UnmarshalCBOR(&buf))
require.True(t, out.Equals(&b))
})
t.Run("require byte string", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, cbg.CborWriteHeader(&buf, cbg.MajArray, 10))
assert.EqualError(t, out.UnmarshalCBOR(&buf), "not a byte string")
})
t.Run("require max length", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, cbg.CborWriteHeader(&buf, cbg.MajByteString, crypto.SignatureMaxLength+1))
assert.EqualError(t, out.UnmarshalCBOR(&buf), "string too long")
})
t.Run("require non-empty", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, cbg.CborWriteHeader(&buf, cbg.MajByteString, 0))
assert.EqualError(t, out.UnmarshalCBOR(&buf), "string empty")
})
t.Run("require correct length", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, cbg.CborWriteHeader(&buf, cbg.MajByteString, 10))
buf.WriteString("7 bytes")
assert.EqualError(t, out.UnmarshalCBOR(&buf), "unexpected EOF")
})
t.Run("require valid type", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, cbg.CborWriteHeader(&buf, cbg.MajByteString, 4))
buf.Write([]byte{byte(crypto.SigTypeUnknown)})
buf.WriteString("sig")
assert.EqualError(t, out.UnmarshalCBOR(&buf), "invalid signature type in cbor input: 255")
})
t.Run("happy decode", func(t *testing.T) {
var buf bytes.Buffer
var out crypto.Signature
require.NoError(t, cbg.CborWriteHeader(&buf, cbg.MajByteString, 4))
buf.Write([]byte{byte(crypto.SigTypeSecp256k1)})
buf.WriteString("sig")
assert.NoError(t, out.UnmarshalCBOR(&buf))
})
}
package dline
import "github.com/filecoin-project/go-state-types/abi"
// Deadline calculations with respect to a current epoch.
// "Deadline" refers to the window during which proofs may be submitted.
// Windows are non-overlapping ranges [Open, Close), but the challenge epoch for a window occurs before
// the window opens.
// The current epoch may not necessarily lie within the deadline or proving period represented here.
type Info struct {
// Deadline parameters
CurrentEpoch abi.ChainEpoch // Epoch at which this info was calculated.
PeriodStart abi.ChainEpoch // First epoch of the proving period (<= CurrentEpoch).
Index uint64 // A deadline index, in [0..d.WPoStProvingPeriodDeadlines) unless period elapsed.
Open abi.ChainEpoch // First epoch from which a proof may be submitted (>= CurrentEpoch).
Close abi.ChainEpoch // First epoch from which a proof may no longer be submitted (>= Open).
Challenge abi.ChainEpoch // Epoch at which to sample the chain for challenge (< Open).
FaultCutoff abi.ChainEpoch // First epoch at which a fault declaration is rejected (< Open).
// Protocol parameters
WPoStPeriodDeadlines uint64
WPoStProvingPeriod abi.ChainEpoch // the number of epochs in a window post proving period
WPoStChallengeWindow abi.ChainEpoch
WPoStChallengeLookback abi.ChainEpoch
FaultDeclarationCutoff abi.ChainEpoch
}
// Whether the proving period has begun.
func (d *Info) PeriodStarted() bool {
return d.CurrentEpoch >= d.PeriodStart
}
// Whether the proving period has elapsed.
func (d *Info) PeriodElapsed() bool {
return d.CurrentEpoch >= d.NextPeriodStart()
}
// The last epoch in the proving period.
func (d *Info) PeriodEnd() abi.ChainEpoch {
return d.PeriodStart + d.WPoStProvingPeriod - 1
}
// The first epoch in the next proving period.
func (d *Info) NextPeriodStart() abi.ChainEpoch {
return d.PeriodStart + d.WPoStProvingPeriod
}
// Whether the current deadline is currently open.
func (d *Info) IsOpen() bool {
return d.CurrentEpoch >= d.Open && d.CurrentEpoch < d.Close
}
// Whether the current deadline has already closed.
func (d *Info) HasElapsed() bool {
return d.CurrentEpoch >= d.Close
}
// The last epoch during which a proof may be submitted.
func (d *Info) Last() abi.ChainEpoch {
return d.Close - 1
}
// Epoch at which the subsequent deadline opens.
func (d *Info) NextOpen() abi.ChainEpoch {
return d.Close
}
// Whether the deadline's fault cutoff has passed.
func (d *Info) FaultCutoffPassed() bool {
return d.CurrentEpoch >= d.FaultCutoff
}
// Returns the next instance of this deadline that has not yet elapsed.
func (d *Info) NextNotElapsed() *Info {
// If the deadline hasn't elapsed, do nothing.
if !d.HasElapsed() {
return d
}
// find a nearby period start
// 1. first, find our period's offset from the "global" period
offset := d.PeriodStart % d.WPoStProvingPeriod
// handle negative period starts just in case.
if offset < 0 {
offset += d.WPoStProvingPeriod
}
// 2. determine the global period index.
globalPeriod := (d.CurrentEpoch / d.WPoStProvingPeriod)
// 3. Determine our next period start.
periodStart := globalPeriod*d.WPoStProvingPeriod + offset
// Backtrack so the period starts before the current epoch. This should usually run 0 or 1 times.
for periodStart > d.CurrentEpoch {
periodStart -= d.WPoStProvingPeriod
}
// If the next deadline opens at or after the current epoch, move to the next pp.
if d.CurrentEpoch >= periodStart+abi.ChainEpoch(d.Index+1)*d.WPoStChallengeWindow {
periodStart += d.WPoStProvingPeriod
}
return NewInfo(periodStart, d.Index, d.CurrentEpoch, d.WPoStPeriodDeadlines, d.WPoStProvingPeriod, d.WPoStChallengeWindow, d.WPoStChallengeLookback, d.FaultDeclarationCutoff)
}
// Returns deadline-related calculations for a deadline in some proving period and the current epoch.
func NewInfo(periodStart abi.ChainEpoch, deadlineIdx uint64, currEpoch abi.ChainEpoch, wPoStPeriodDeadlines uint64, wPoStProvingPeriod, wPoStChallengeWindow, wPoStChallengeLookback, faultDeclarationCutoff abi.ChainEpoch) *Info {
if deadlineIdx < wPoStPeriodDeadlines {
deadlineOpen := periodStart + (abi.ChainEpoch(deadlineIdx) * wPoStChallengeWindow)
return &Info{
CurrentEpoch: currEpoch,
PeriodStart: periodStart,
Index: deadlineIdx,
Open: deadlineOpen,
Close: deadlineOpen + wPoStChallengeWindow,
Challenge: deadlineOpen - wPoStChallengeLookback,
FaultCutoff: deadlineOpen - faultDeclarationCutoff,
// parameters
WPoStPeriodDeadlines: wPoStPeriodDeadlines,
WPoStProvingPeriod: wPoStProvingPeriod,
WPoStChallengeWindow: wPoStChallengeWindow,
WPoStChallengeLookback: wPoStChallengeLookback,
FaultDeclarationCutoff: faultDeclarationCutoff,
}
} else {
// Return deadline info for a no-duration deadline immediately after the last real one.
afterLastDeadline := periodStart + wPoStProvingPeriod
return &Info{
CurrentEpoch: currEpoch,
PeriodStart: periodStart,
Index: deadlineIdx,
Open: afterLastDeadline,
Close: afterLastDeadline,
Challenge: afterLastDeadline,
FaultCutoff: 0,
// parameters
WPoStPeriodDeadlines: wPoStPeriodDeadlines,
WPoStProvingPeriod: wPoStProvingPeriod,
WPoStChallengeWindow: wPoStChallengeWindow,
WPoStChallengeLookback: wPoStChallengeLookback,
FaultDeclarationCutoff: faultDeclarationCutoff,
}
}
}
package dline_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/dline"
)
func TestProvingPeriodDeadlines(t *testing.T) {
DLs := uint64(48) // miner.WPoStPeriodDeadlines
PP := abi.ChainEpoch(2880) // miner.WPoStProvingPeriod
CW := abi.ChainEpoch(60) // miner.WPoStChallengeWindow
CL := abi.ChainEpoch(20) // miner.WPoStChallengeLookback
FDC := abi.ChainEpoch(70) // miner.FaultDeclarationCutoff
t.Run("pre-open", func(t *testing.T) {
curr := abi.ChainEpoch(0) // Current is before the period opens.
{
periodStart := FDC + 1
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.Equal(t, curr, di.CurrentEpoch)
assert.Equal(t, periodStart, di.PeriodStart)
assert.Equal(t, uint64(0), di.Index)
assert.Equal(t, periodStart, di.Open)
assert.Equal(t, periodStart+CW, di.Close)
assert.Equal(t, periodStart-CL, di.Challenge)
assert.Equal(t, periodStart-FDC, di.FaultCutoff)
assert.False(t, di.PeriodStarted())
assert.False(t, di.PeriodElapsed())
assert.False(t, di.IsOpen())
assert.False(t, di.HasElapsed())
assert.Equal(t, periodStart+CW-1, di.Last())
assert.Equal(t, periodStart+CW, di.NextOpen())
assert.False(t, di.FaultCutoffPassed())
assert.Equal(t, periodStart+PP-1, di.PeriodEnd())
assert.Equal(t, periodStart+PP, di.NextPeriodStart())
}
{
periodStart := FDC - 1
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.True(t, di.FaultCutoffPassed())
}
})
t.Run("proving period boundary", func(t *testing.T) {
periodStart := abi.ChainEpoch(50000)
{
// Period not yet started
curr := periodStart - 1
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.False(t, di.PeriodStarted()) // Not yet started
assert.False(t, di.PeriodElapsed())
assert.Equal(t, periodStart+PP-1, di.PeriodEnd())
assert.Equal(t, periodStart+PP, di.NextPeriodStart())
}
{
// Period started
curr := periodStart
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.True(t, di.PeriodStarted())
assert.False(t, di.PeriodElapsed())
assert.Equal(t, periodStart+PP-1, di.PeriodEnd())
assert.Equal(t, periodStart+PP, di.NextPeriodStart())
}
{
// Period elapsed
curr := periodStart + PP
di := dline.NewInfo(periodStart, DLs-1, curr, DLs, PP, CW, CL, FDC)
assert.True(t, di.PeriodStarted())
assert.True(t, di.PeriodElapsed())
assert.Equal(t, periodStart+PP-1, di.PeriodEnd())
assert.Equal(t, periodStart+PP, di.NextPeriodStart())
assert.False(t, di.IsOpen())
assert.True(t, di.HasElapsed())
}
})
t.Run("deadline boundaries", func(t *testing.T) {
periodStart := abi.ChainEpoch(50000)
{
// First epoch of deadline zero
curr := periodStart
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.Equal(t, periodStart, di.Open)
assert.Equal(t, periodStart+CW, di.Close)
assert.Equal(t, periodStart-CL, di.Challenge)
assert.Equal(t, periodStart-FDC, di.FaultCutoff)
assert.True(t, di.IsOpen())
assert.False(t, di.HasElapsed())
assert.Equal(t, periodStart+CW-1, di.Last())
assert.Equal(t, periodStart+CW, di.NextOpen())
assert.True(t, di.FaultCutoffPassed())
// The last invalid epoch of a deadline is the first valid epoch for the next.
assert.Equal(t, di.Last()+1, di.NextOpen())
assert.Equal(t, di.Close, di.NextOpen())
}
{
// Before deadline zero opens
curr := periodStart - 1
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.False(t, di.IsOpen()) // Not yet open
assert.False(t, di.HasElapsed())
assert.True(t, di.FaultCutoffPassed())
// The next not-elapsed is this one, because it hasn't even started yet.
nxt := di.NextNotElapsed()
assert.Equal(t, periodStart, nxt.PeriodStart)
assert.Equal(t, uint64(0), nxt.Index)
}
{
// During deadline zero, deadline one isn't open
curr := periodStart
di0 := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.True(t, di0.IsOpen()) // Now open
assert.False(t, di0.HasElapsed())
assert.True(t, di0.FaultCutoffPassed())
// The next not-elapsed is this one, which is not yet
// open, but not elapsed either.
nxt0 := di0.NextNotElapsed()
assert.Equal(t, periodStart, nxt0.PeriodStart)
assert.Equal(t, uint64(0), nxt0.Index)
di1 := dline.NewInfo(periodStart, 1, curr, DLs, PP, CW, CL, FDC)
assert.False(t, di1.IsOpen())
assert.False(t, di1.HasElapsed())
// The fault cutoff is more than one deadline into the future.
assert.True(t, di1.FaultCutoffPassed())
// The next not-elapsed is the upcoming one
nxt1 := di1.NextNotElapsed()
assert.Equal(t, periodStart, nxt1.PeriodStart)
assert.Equal(t, uint64(1), nxt1.Index)
}
{
// Last epoch of deadline zero
curr := periodStart + CW - 1
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.True(t, di.IsOpen())
assert.False(t, di.HasElapsed())
assert.True(t, di.FaultCutoffPassed())
// The next not-elapsed is this one still
nxt := di.NextNotElapsed()
assert.Equal(t, periodStart, nxt.PeriodStart)
assert.Equal(t, uint64(0), nxt.Index)
}
{
// Deadline zero expired
curr := periodStart + CW
di := dline.NewInfo(periodStart, 0, curr, DLs, PP, CW, CL, FDC)
assert.False(t, di.IsOpen())
assert.True(t, di.HasElapsed())
assert.True(t, di.FaultCutoffPassed())
// The next not-elapsed is the subsequent proving period
nxt := di.NextNotElapsed()
assert.Equal(t, periodStart+PP, nxt.PeriodStart)
assert.Equal(t, uint64(0), nxt.Index)
}
})
t.Run("period expired", func(t *testing.T) {
periodStart := abi.ChainEpoch(0)
curr := periodStart + PP
d := dline.NewInfo(periodStart, DLs, curr, DLs, PP, CW, CL, FDC)
assert.True(t, d.PeriodStarted())
assert.True(t, d.PeriodElapsed())
assert.Equal(t, DLs, d.Index)
assert.False(t, d.IsOpen())
assert.True(t, d.HasElapsed())
assert.True(t, d.FaultCutoffPassed())
assert.Equal(t, PP-1, d.PeriodEnd())
assert.Equal(t, PP, d.NextPeriodStart())
})
t.Run("period start", func(t *testing.T) {
periodStart := abi.ChainEpoch(0)
f := func(t *testing.T) {
for curr := -99999; curr < 99999; curr++ {
d := dline.NewInfo(periodStart, DLs, abi.ChainEpoch(curr), DLs, PP, CW, CL, FDC)
actual := d.NextNotElapsed()
expected := d
for expected.HasElapsed() {
expected = dline.NewInfo(expected.PeriodStart+PP, DLs, abi.ChainEpoch(curr), DLs, PP, CW, CL, FDC)
}
assert.Equal(t, *expected, *actual)
}
}
periodStart = 60
t.Run("small", f)
periodStart = PP + 60
t.Run("next", f)
periodStart = 5*PP + 60
t.Run("later", f)
periodStart = 60 - PP
t.Run("negative", f)
})
}
package exitcode
// Common error codes that may be shared by different actors.
// Actors may also define their own codes, including redefining these values.
const (
// Indicates a method parameter is invalid.
ErrIllegalArgument = FirstActorErrorCode + iota
// Indicates a requested resource does not exist.
ErrNotFound
// Indicates an action is disallowed.
ErrForbidden
// Indicates a balance of funds is insufficient.
ErrInsufficientFunds
// Indicates an actor's internal state is invalid.
ErrIllegalState
// Indicates de/serialization failure within actor code.
ErrSerialization
// Common error codes stop here. If you define a common error code above
// this value it will have conflicting interpretations
FirstActorSpecificExitCode = ExitCode(32)
)
package exitcode
import (
"errors"
"fmt"
"strconv"
"golang.org/x/xerrors"
)
type ExitCode int64
func (x ExitCode) IsSuccess() bool {
return x == Ok
}
func (x ExitCode) IsError() bool {
return !x.IsSuccess()
}
// Whether an exit code indicates a message send failure.
// A send failure means that the caller's CallSeqNum is not incremented and the caller has not paid
// gas fees for the message (because the caller doesn't exist or can't afford it).
// A receipt with send failure does not indicate that the message (or another one carrying the same CallSeqNum)
// could not apply in the future, against a different state.
func (x ExitCode) IsSendFailure() bool {
return x == SysErrSenderInvalid || x == SysErrSenderStateInvalid
}
// A non-canonical string representation for human inspection.
func (x ExitCode) String() string {
name, ok := names[x]
if ok {
return fmt.Sprintf("%s(%d)", name, x)
}
return strconv.FormatInt(int64(x), 10)
}
// Implement error to trigger Go compiler checking of exit code return values.
func (x ExitCode) Error() string {
return x.String()
}
// Wrapf attaches an error message, and possibly an error, to the exit
// code.
//
// err := ErrIllegalArgument.Wrapf("my description: %w", err)
// exitcode.Unwrap(exitcode.ErrIllegalState, err) == exitcode.ErrIllegalArgument
func (x ExitCode) Wrapf(msg string, args ...interface{}) error {
return &wrapped{
exitCode: x,
cause: xerrors.Errorf(msg, args...),
}
}
type wrapped struct {
exitCode ExitCode
cause error
}
func (w *wrapped) String() string {
return w.Error()
}
func (w *wrapped) Error() string {
// Don't include the exit code. That will be handled by the runtime and
// this error has likely been wrapped multiple times.
return w.cause.Error()
}
// implements the interface required by errors.As
func (w *wrapped) As(target interface{}) bool {
return errors.As(w.exitCode, target) || errors.As(w.cause, target)
}
// implements the interface required by errors.Is
func (w *wrapped) Is(target error) bool {
if _, ok := target.(ExitCode); ok {
// If the target is an exit code, make sure we shadow lower exit
// codes.
return w.exitCode == target
}
return errors.Is(w.cause, target)
}
// Unwrap extracts an exit code from an error, defaulting to the passed default
// exit code.
//
// err := ErrIllegalState.WithContext("my description: %w", err)
// exitcode.Unwrap(exitcode.ErrIllegalState, err) == exitcode.ErrIllegalArgument
func Unwrap(err error, defaultExitCode ExitCode) (code ExitCode) {
if errors.As(err, &code) {
return code
}
return defaultExitCode
}
package exitcode_test
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/exitcode"
)
func TestWithContext(t *testing.T) {
baseErr := errors.New("base error")
codedErr := exitcode.ErrForbidden.Wrapf("coded: %w", baseErr)
wrappedErr := xerrors.Errorf("wrapper: %w", codedErr)
shadowedErr := exitcode.ErrIllegalState.Wrapf("shadow: %w", codedErr)
// Test default.
assert.Equal(t, exitcode.Ok, exitcode.Unwrap(baseErr, exitcode.Ok))
assert.Equal(t, exitcode.ErrIllegalState, exitcode.Unwrap(baseErr, exitcode.ErrIllegalState))
assert.True(t, errors.Is(baseErr, baseErr))
// Test coded.
assert.Equal(t, exitcode.ErrForbidden, exitcode.Unwrap(codedErr, exitcode.Ok))
assert.True(t, errors.Is(wrappedErr, codedErr))
assert.False(t, errors.Is(codedErr, wrappedErr))
assert.False(t, errors.Is(wrappedErr, exitcode.Ok))
// Test wrapped
assert.Equal(t, exitcode.ErrForbidden, exitcode.Unwrap(wrappedErr, exitcode.Ok))
assert.True(t, errors.Is(wrappedErr, codedErr))
assert.True(t, errors.Is(wrappedErr, wrappedErr))
assert.False(t, errors.Is(wrappedErr, exitcode.Ok))
// Test shadowed
assert.Equal(t, exitcode.ErrIllegalState, exitcode.Unwrap(shadowedErr, exitcode.Ok))
assert.True(t, errors.Is(shadowedErr, exitcode.ErrIllegalState))
assert.False(t, errors.Is(shadowedErr, exitcode.ErrForbidden))
}
package exitcode
// The system error codes are reserved for use by the runtime.
// No actor may use one explicitly. Correspondingly, no runtime invocation should abort with an exit
// code outside this list.
// We could move these definitions out of this package and into the runtime spec.
const (
Ok = ExitCode(0)
// Indicates that the actor identified as the sender of a message is not valid as a message sender:
// - not present in the state tree
// - not an account actor (for top-level messages)
// - code CID is not found or invalid
// (not found in the state tree, not an account, has no code).
SysErrSenderInvalid = ExitCode(1)
// Indicates that the sender of a message is not in a state to send the message:
// - invocation out of sequence (mismatched CallSeqNum)
// - insufficient funds to cover execution
SysErrSenderStateInvalid = ExitCode(2)
// Indicates failure to find a method in an actor.
SysErrInvalidMethod = ExitCode(3)
// Unused.
SysErrReserved1 = ExitCode(4)
// Indicates that the receiver of a message is not valid (and cannot be implicitly created).
SysErrInvalidReceiver = ExitCode(5)
// Indicates that a message sender has insufficient balance for the value being sent.
// Note that this is distinct from SysErrSenderStateInvalid when a top-level sender can't cover
// value transfer + gas. This code is only expected to come from inter-actor sends.
SysErrInsufficientFunds = ExitCode(6)
// Indicates message execution (including subcalls) used more gas than the specified limit.
SysErrOutOfGas = ExitCode(7)
// Indicates message execution is forbidden for the caller by runtime caller validation.
SysErrForbidden = ExitCode(8)
// Indicates actor code performed a disallowed operation. Disallowed operations include:
// - mutating state outside of a state acquisition block
// - failing to invoke caller validation
// - aborting with a reserved exit code (including success or a system error).
SysErrorIllegalActor = ExitCode(9)
// Indicates an invalid argument passed to a runtime method.
SysErrorIllegalArgument = ExitCode(10)
// Unused
SysErrReserved2 = ExitCode(11)
SysErrReserved3 = ExitCode(12)
SysErrReserved4 = ExitCode(13)
SysErrReserved5 = ExitCode(14)
SysErrReserved6 = ExitCode(15)
)
// The initial range of exit codes is reserved for system errors.
// Actors may define codes starting with this one.
const FirstActorErrorCode = ExitCode(16)
var names = map[ExitCode]string{
Ok: "Ok",
SysErrSenderInvalid: "SysErrSenderInvalid",
SysErrSenderStateInvalid: "SysErrSenderStateInvalid",
SysErrInvalidMethod: "SysErrInvalidMethod",
SysErrReserved1: "SysErrReserved1",
SysErrInvalidReceiver: "SysErrInvalidReceiver",
SysErrInsufficientFunds: "SysErrInsufficientFunds",
SysErrOutOfGas: "SysErrOutOfGas",
SysErrForbidden: "SysErrForbidden",
SysErrorIllegalActor: "SysErrorIllegalActor",
SysErrorIllegalArgument: "SysErrorIllegalArgument",
SysErrReserved2: "SysErrReserved2",
SysErrReserved3: "SysErrReserved3",
SysErrReserved4: "SysErrReserved4",
SysErrReserved5: "SysErrReserved5",
SysErrReserved6: "SysErrReserved6",
}
package main
import (
gen "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-state-types/abi"
)
func main() {
// Common types
if err := gen.WriteTupleEncodersToFile("./abi/cbor_gen.go", "abi",
abi.PieceInfo{},
abi.SectorID{},
); err != nil {
panic(err)
}
}
module github.com/filecoin-project/go-state-types
go 1.13
require (
github.com/ipfs/go-cid v0.0.7
github.com/multiformats/go-multihash v0.0.14
github.com/stretchr/testify v1.6.1
github.com/whyrusleeping/cbor-gen v0.0.0-20200812213548-958ddffe352c
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 h1:2pMXdBnCiXjfCYx/hLqFxccPoqsSveQFxVLvNxy9bus=
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/ipfs/go-block-format v0.0.2 h1:qPDvcP19izTjU8rgo6p7gTXZlkMkF5bz5G3fqIsSCPE=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid v0.0.6/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY=
github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
github.com/ipfs/go-ipld-cbor v0.0.4 h1:Aw3KPOKXjvrm6VjwJvFf1F1ekR/BH3jdof3Bk7OTiSA=
github.com/ipfs/go-ipld-cbor v0.0.4/go.mod h1:BkCduEx3XBCO6t2Sfo5BaHzuok7hbhdMm9Oh8B2Ftq4=
github.com/ipfs/go-ipld-format v0.0.1 h1:HCu4eB/Gh+KD/Q0M8u888RFkorTWNIL3da4oc5dwc80=
github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms=
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52 h1:QG4CGBqCeuBo6aZlGAamSkxWdgWfZGeE49eUOWJPA4c=
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52/go.mod h1:fdg+/X9Gg4AsAIzWpEHwnqd+QY3b7lajxyjE1m4hkq4=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-varint v0.0.5 h1:XVZwSo04Cs3j/jS0uAEPpT3JY6DzMcVLLoWOSnCxOjg=
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 h1:CskT+S6Ay54OwxBGB0R3Rsx4Muto6UnEYTyKJbyRIAI=
github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa h1:E+gaaifzi2xF65PbDmuKI3PhLWY6G5opMLniFq8vmXA=
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 h1:qOpVTI+BrstcjTZLm2Yz/3sOnqkzj3FQoh0g+E5s3Gc=
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
github.com/whyrusleeping/cbor-gen v0.0.0-20200810223238-211df3b9e24c/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200812213548-958ddffe352c h1:otRnI08JoahNBxUFqX3372Ab9GnTj8L5J9iP5ImyxGU=
github.com/whyrusleeping/cbor-gen v0.0.0-20200812213548-958ddffe352c/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package rt
import (
"github.com/filecoin-project/go-state-types/cbor"
"github.com/ipfs/go-cid"
)
// VMActor is a concrete implementation of an actor, to be used by a Filecoin
// VM.
type VMActor interface {
// Exports returns a slice of methods exported by this actor, indexed by
// method number. Skipped/deprecated method numbers will be nil.
Exports() []interface{}
// Code returns the code ID for this actor.
Code() cid.Cid
// State returns a new State object for this actor. This can be used to
// decode the actor's state.
State() cbor.Er
// NOTE: methods like "IsSingleton" are intentionally excluded from this
// interface. That way, we can add additional attributes actors in newer
// specs-actors versions, without having to update previous specs-actors
// versions.
}
// IsSingletonActor returns true if the actor is a singleton actor (i.e., cannot
// be constructed).
func IsSingletonActor(a VMActor) bool {
s, ok := a.(interface{ IsSingleton() bool })
return ok && s.IsSingleton()
}
package rt
// Specifies importance of message, LogLevel numbering is consistent with the uber-go/zap package.
type LogLevel int
const (
// DebugLevel logs are typically voluminous, and are usually disabled in
// production.
DEBUG LogLevel = iota - 1
// InfoLevel is the default logging priority.
INFO
// WarnLevel logs are more important than Info, but don't need individual
// human review.
WARN
// ErrorLevel logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
ERROR
)
...@@ -3,30 +3,22 @@ module fil_integrate ...@@ -3,30 +3,22 @@ module fil_integrate
go 1.16 go 1.16
require ( require (
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
github.com/docker/go-units v0.4.0 github.com/docker/go-units v0.4.0
github.com/elastic/go-sysinfo v1.7.0
github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200910194244-f640612a1a1f github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200910194244-f640612a1a1f
github.com/filecoin-project/go-bitfield v0.2.4
github.com/filecoin-project/go-fil-commcid v0.1.0 github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-state-types v0.1.1-0.20210506134452-99b279731c48
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-log/v2 v2.3.0 github.com/ipfs/go-log/v2 v2.3.0
github.com/kr/pretty v0.2.0 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/minio/md5-simd v1.1.2
github.com/minio/sha256-simd v0.1.1
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0
github.com/whyrusleeping/cbor-gen v0.0.0-20210422071115-ad5b82622e0f
go.opencensus.io v0.23.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
github.com/libp2p/go-libp2p-core v0.8.5 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
github.com/minio/sha256-simd v0.1.1
) )
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
replace github.com/filecoin-project/go-state-types => ./extern/go-state-types
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"path/filepath" "path/filepath"
"sync" "sync"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"fil_integrate/build/storage" "fil_integrate/build/storage"
"fil_integrate/build/storiface" "fil_integrate/build/storiface"
...@@ -129,7 +129,7 @@ func (b *Manager) AcquireUnsealed(ctx context.Context, id storage.SectorRef, exi ...@@ -129,7 +129,7 @@ func (b *Manager) AcquireUnsealed(ctx context.Context, id storage.SectorRef, exi
return storiface.SectorPaths{}, nil, ctx.Err() return storiface.SectorPaths{}, nil, ctx.Err()
} }
path := filepath.Join(b.Root, fileType.String(), "unsealed.dat") path := filepath.Join(b.Root, fileType.String(), storiface.SectorName(id.ID))
prevDone := done prevDone := done
done = func() { done = func() {
......
package seal
import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"fil_integrate/build/state-types/abi"
spieces "fil_integrate/build/pieces"
"fil_integrate/build/storage"
)
//32字节,总共256位
//[has_pre][MetaLen1..MetaLen4][PieceLen1..PieceLen4]
const TagLen uint32 = 8
type Encoder struct {
Root string
}
var _ PieceEncoder = &Encoder{}
// Data contains MetaData and HashData
// Pieces structure is [ Tag | MetaData | HashData ]
func (sp *Encoder) EncodeDataToPieces(
ctx context.Context,
sectorSize abi.SectorSize,
file storage.Data,
) (storage.Piece, []storage.Piece, error) {
var hashData []byte
var pieces []storage.Piece
var prePiece []storage.Piece
root := filepath.Join(sp.Root, "pieces")
err := os.Mkdir(root, 0755)
if err != nil && !os.IsExist(err) { // nolint
return storage.Piece{}, nil, err
}
UnpaddedSectorSize := abi.PaddedPieceSize(sectorSize).Unpadded()
DataLen := (uint32)(UnpaddedSectorSize) - TagLen
buf := make([]byte, DataLen)
for {
MetaLen, err := file.Read(buf[:])
if err != nil && err != io.EOF {
return storage.Piece{}, nil, err
}
if err == io.EOF || uint32(MetaLen) != DataLen {
//encode first sector
prePiece, err = sp.EncodeData(buf[:uint32(MetaLen)], sectorSize, uint32(MetaLen), DataLen, hashData)
if err != nil {
return storage.Piece{}, nil, err
}
break
}
var data *storage.DecodedData = &storage.DecodedData{HasPre: false, Data: buf[:]}
dbuf, err := data.Serialize()
if err != nil {
return storage.Piece{}, nil, err
}
pieceHash, err := spieces.GeneratePieceCommitmentFast(dbuf[:], uint64(len(dbuf)))
if err != nil {
return storage.Piece{}, nil, err
}
filename := filepath.Join(root, fmt.Sprintf("%x.dat", pieceHash[:]))
err = ioutil.WriteFile(filename, dbuf[:], 0644)
if err != nil {
return storage.Piece{}, nil, err
}
// fmt.Printf("encode1: %x.dat\n", pieceHash[:])
hashData = append(hashData, pieceHash[:]...)
pieces = append(pieces, storage.Piece{
Commitment: pieceHash,
Size: UnpaddedSectorSize,
})
}
pieces = append(pieces, prePiece...)
return pieces[len(pieces)-1], pieces[:len(pieces)-1], nil
}
func (sp *Encoder) EncodeData(
metadata []byte,
sectorSize abi.SectorSize,
MetaLen uint32,
DataLen uint32,
hashData []byte,
) ([]storage.Piece, error) {
root := filepath.Join(sp.Root, "pieces")
var prePieceHash storage.Hash
var pieces []storage.Piece
var err error
for len(hashData) > 0 {
var buf []byte
//encode next n sector
if pieces != nil {
CommLen := min(uint32(len(hashData)), ((DataLen-32)/32)*32)
var data *storage.DecodedData = &storage.DecodedData{
HasPre: true,
PreHash: prePieceHash,
HashData: hashData[:CommLen],
}
buf, err = data.Serialize()
if err != nil {
return nil, err
}
hashData = hashData[CommLen:]
} else {
CommLen := min(uint32(len(hashData)), ((DataLen-MetaLen)/32)*32)
var data *storage.DecodedData = &storage.DecodedData{
HasPre: false,
Data: metadata,
HashData: hashData[:CommLen],
}
buf, err = data.Serialize()
if err != nil {
return nil, err
}
hashData = hashData[CommLen:]
}
prePieceHash, err = spieces.GeneratePieceCommitmentFast(buf, uint64(len(buf)))
if err != nil {
return nil, err
}
filename := filepath.Join(root, fmt.Sprintf("%x.dat", prePieceHash[:]))
err = ioutil.WriteFile(filename, buf, 0644)
if err != nil {
return nil, err
}
// fmt.Printf("encode2: %x.dat\n", prePieceHash[:])
pieces = append(pieces, storage.Piece{
Commitment: prePieceHash,
Size: abi.UnpaddedPieceSize(len(buf)),
})
}
return pieces, nil
}
func DecodePiece(
ctx context.Context,
sectorSize abi.SectorSize,
in io.Reader,
) (storage.DecodedData, error) {
unpaddedSectorSize := abi.PaddedPieceSize(sectorSize).Unpadded()
buf := make([]byte, unpaddedSectorSize)
read, err := in.Read(buf[:])
if err != nil && err != io.EOF {
return storage.DecodedData{}, err
}
var data *storage.DecodedData = &storage.DecodedData{}
err = data.Deserialize(buf[:read])
return *data, err
}
func min(x, y uint32) uint32 {
if x < y {
return x
}
return y
}
package seal
import (
"encoding/binary"
"io"
"os"
"syscall"
"github.com/detailyang/go-fallocate"
"golang.org/x/xerrors"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
"fil_integrate/build/storiface"
)
const veryLargeRle = 1 << 20
const FallocFlPunchHole = 0x02 // linux/falloc.h
// Sectors can be partially unsealed. We support this by appending a small
// trailer to each unsealed sector file containing an RLE+ marking which bytes
// in a sector are unsealed, and which are not (holes)
// unsealed sector files internally have this structure
// [unpadded (raw) data][rle+][4B LE length fo the rle+ field]
type partialFile struct {
maxPiece abi.PaddedPieceSize
path string
allocated rlepluslazy.RLE
file *os.File
}
func writeTrailer(maxPieceSize int64, w *os.File, r rlepluslazy.RunIterator) error {
trailer, err := rlepluslazy.EncodeRuns(r, nil)
if err != nil {
return xerrors.Errorf("encoding trailer: %w", err)
}
// maxPieceSize == unpadded(sectorSize) == trailer start
if _, err := w.Seek(maxPieceSize, io.SeekStart); err != nil {
return xerrors.Errorf("seek to trailer start: %w", err)
}
rb, err := w.Write(trailer)
if err != nil {
return xerrors.Errorf("writing trailer data: %w", err)
}
if err := binary.Write(w, binary.LittleEndian, uint32(len(trailer))); err != nil {
return xerrors.Errorf("writing trailer length: %w", err)
}
return w.Truncate(maxPieceSize + int64(rb) + 4)
}
func createPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialFile, error) {
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644) // nolint
if err != nil {
return nil, xerrors.Errorf("openning partial file '%s': %w", path, err)
}
err = func() error {
err := fallocate.Fallocate(f, 0, int64(maxPieceSize))
if errno, ok := err.(syscall.Errno); ok {
if errno == syscall.EOPNOTSUPP || errno == syscall.ENOSYS {
log.Warnf("could not allocated space, ignoring: %v", errno)
err = nil // log and ignore
}
}
if err != nil {
return xerrors.Errorf("fallocate '%s': %w", path, err)
}
if err := writeTrailer(int64(maxPieceSize), f, &rlepluslazy.RunSliceIterator{}); err != nil {
return xerrors.Errorf("writing trailer: %w", err)
}
return nil
}()
if err != nil {
_ = f.Close()
return nil, err
}
if err := f.Close(); err != nil {
return nil, xerrors.Errorf("close empty partial file: %w", err)
}
return openPartialFile(maxPieceSize, path)
}
func openPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialFile, error) {
f, err := os.OpenFile(path, os.O_RDWR, 0644) // nolint
if err != nil {
return nil, xerrors.Errorf("openning partial file '%s': %w", path, err)
}
var rle rlepluslazy.RLE
err = func() error {
st, err := f.Stat()
if err != nil {
return xerrors.Errorf("stat '%s': %w", path, err)
}
if st.Size() < int64(maxPieceSize) {
return xerrors.Errorf("sector file '%s' was smaller than the sector size %d < %d", path, st.Size(), maxPieceSize)
}
// read trailer
var tlen [4]byte
_, err = f.ReadAt(tlen[:], st.Size()-int64(len(tlen)))
if err != nil {
return xerrors.Errorf("reading trailer length: %w", err)
}
// sanity-check the length
trailerLen := binary.LittleEndian.Uint32(tlen[:])
expectLen := int64(trailerLen) + int64(len(tlen)) + int64(maxPieceSize)
if expectLen != st.Size() {
return xerrors.Errorf("file '%s' has inconsistent length; has %d bytes; expected %d (%d trailer, %d sector data)", path, st.Size(), expectLen, int64(trailerLen)+int64(len(tlen)), maxPieceSize)
}
if trailerLen > veryLargeRle {
log.Warnf("Partial file '%s' has a VERY large trailer with %d bytes", path, trailerLen)
}
trailerStart := st.Size() - int64(len(tlen)) - int64(trailerLen)
if trailerStart != int64(maxPieceSize) {
return xerrors.Errorf("expected sector size to equal trailer start index")
}
trailerBytes := make([]byte, trailerLen)
_, err = f.ReadAt(trailerBytes, trailerStart)
if err != nil {
return xerrors.Errorf("reading trailer: %w", err)
}
rle, err = rlepluslazy.FromBuf(trailerBytes)
if err != nil {
return xerrors.Errorf("decoding trailer: %w", err)
}
it, err := rle.RunIterator()
if err != nil {
return xerrors.Errorf("getting trailer run iterator: %w", err)
}
f, err := rlepluslazy.Fill(it)
if err != nil {
return xerrors.Errorf("filling bitfield: %w", err)
}
lastSet, err := rlepluslazy.Count(f)
if err != nil {
return xerrors.Errorf("finding last set byte index: %w", err)
}
if lastSet > uint64(maxPieceSize) {
return xerrors.Errorf("last set byte at index higher than sector size: %d > %d", lastSet, maxPieceSize)
}
return nil
}()
if err != nil {
_ = f.Close()
return nil, err
}
return &partialFile{
maxPiece: maxPieceSize,
path: path,
allocated: rle,
file: f,
}, nil
}
func (pf *partialFile) Close() error {
return pf.file.Close()
}
func (pf *partialFile) Writer(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) (io.Writer, error) {
if _, err := pf.file.Seek(int64(offset), io.SeekStart); err != nil {
return nil, xerrors.Errorf("seek piece start: %w", err)
}
{
have, err := pf.allocated.RunIterator()
if err != nil {
return nil, err
}
and, err := rlepluslazy.And(have, pieceRun(offset, size))
if err != nil {
return nil, err
}
c, err := rlepluslazy.Count(and)
if err != nil {
return nil, err
}
if c > 0 {
log.Warnf("getting partial file writer overwriting %d allocated bytes", c)
}
}
return pf.file, nil
}
func (pf *partialFile) MarkAllocated(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) error {
have, err := pf.allocated.RunIterator()
if err != nil {
return err
}
ored, err := rlepluslazy.Or(have, pieceRun(offset, size))
if err != nil {
return err
}
if err := writeTrailer(int64(pf.maxPiece), pf.file, ored); err != nil {
return xerrors.Errorf("writing trailer: %w", err)
}
return nil
}
func (pf *partialFile) Free(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) error {
have, err := pf.allocated.RunIterator()
if err != nil {
return err
}
if err := Deallocate(pf.file, int64(offset), int64(size)); err != nil {
return xerrors.Errorf("deallocating: %w", err)
}
s, err := rlepluslazy.Subtract(have, pieceRun(offset, size))
if err != nil {
return err
}
if err := writeTrailer(int64(pf.maxPiece), pf.file, s); err != nil {
return xerrors.Errorf("writing trailer: %w", err)
}
return nil
}
func (pf *partialFile) Reader(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) (*os.File, error) {
if _, err := pf.file.Seek(int64(offset), io.SeekStart); err != nil {
return nil, xerrors.Errorf("seek piece start: %w", err)
}
{
have, err := pf.allocated.RunIterator()
if err != nil {
return nil, err
}
and, err := rlepluslazy.And(have, pieceRun(offset, size))
if err != nil {
return nil, err
}
c, err := rlepluslazy.Count(and)
if err != nil {
return nil, err
}
if c != uint64(size) {
log.Warnf("getting partial file reader reading %d unallocated bytes", uint64(size)-c)
}
}
return pf.file, nil
}
func (pf *partialFile) Allocated() (rlepluslazy.RunIterator, error) {
return pf.allocated.RunIterator()
}
func (pf *partialFile) HasAllocated(offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error) {
have, err := pf.Allocated()
if err != nil {
return false, err
}
u, err := rlepluslazy.And(have, pieceRun(offset.Padded(), size.Padded()))
if err != nil {
return false, err
}
uc, err := rlepluslazy.Count(u)
if err != nil {
return false, err
}
return abi.PaddedPieceSize(uc) == size.Padded(), nil
}
func pieceRun(offset storiface.PaddedByteIndex, size abi.PaddedPieceSize) rlepluslazy.RunIterator {
var runs []rlepluslazy.Run
if offset > 0 {
runs = append(runs, rlepluslazy.Run{
Val: false,
Len: uint64(offset),
})
}
runs = append(runs, rlepluslazy.Run{
Val: true,
Len: uint64(size),
})
return &rlepluslazy.RunSliceIterator{Runs: runs}
}
func Deallocate(file *os.File, offset int64, length int64) error {
if length == 0 {
return nil
}
err := syscall.Fallocate(int(file.Fd()), FallocFlPunchHole, offset, length)
if errno, ok := err.(syscall.Errno); ok {
if errno == syscall.EOPNOTSUPP || errno == syscall.ENOSYS {
log.Warnf("could not deallocate space, ignoring: %v", errno)
err = nil // log and ignore
}
}
return err
}
This diff is collapsed.
This diff is collapsed.
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"context" "context"
"io" "io"
"github.com/filecoin-project/go-state-types/abi" "fil_integrate/build/state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/minio/blake2b-simd" "github.com/minio/blake2b-simd"
...@@ -25,7 +25,7 @@ type PieceEncoder interface { ...@@ -25,7 +25,7 @@ type PieceEncoder interface {
//interface //interface
type SectorSealer interface { type SectorSealer interface {
AddPiece(ctx context.Context, sid storage.SectorRef, sortedPieces []storage.Piece) ([]abi.PieceInfo, []storage.Piece, error) AddPiece(ctx context.Context, sid storage.SectorRef) ([]abi.PieceInfo, error)
// run pre-commit1 and pre-commit2 phase // run pre-commit1 and pre-commit2 phase
// generate the sealed sector and sector commitment(commd, commr) // generate the sealed sector and sector commitment(commd, commr)
...@@ -35,7 +35,7 @@ type SectorSealer interface { ...@@ -35,7 +35,7 @@ type SectorSealer interface {
GenerateCommitProof(ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (spproof.Proof, error) GenerateCommitProof(ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (spproof.Proof, error)
AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error) AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error)
UnsealedRange(ctx context.Context, sid storage.SectorRef, out io.Writer, commd cid.Cid, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error UnsealedRange(ctx context.Context, out io.Writer, sid storage.SectorRef, commd cid.Cid, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error
GenerateWindowPoStProofs(ctx context.Context, minerID abi.ActorID, sectorInfo []spproof.SectorInfo, randomness abi.PoStRandomness) (spproof.PoStProof, []abi.SectorID, error) GenerateWindowPoStProofs(ctx context.Context, minerID abi.ActorID, sectorInfo []spproof.SectorInfo, randomness abi.PoStRandomness) (spproof.PoStProof, []abi.SectorID, error)
AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.PoStProof, error) AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.PoStProof, error)
......
package seal
import (
"golang.org/x/xerrors"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
"fil_integrate/build/storiface"
)
// merge gaps between ranges which are close to each other
// TODO: more benchmarking to come up with more optimal number
const mergeGaps = 32 << 20
// TODO const expandRuns = 16 << 20 // unseal more than requested for future requests
func computeUnsealRanges(unsealed rlepluslazy.RunIterator, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (rlepluslazy.RunIterator, error) {
todo := pieceRun(offset.Padded(), size.Padded())
todo, err := rlepluslazy.Subtract(todo, unsealed)
if err != nil {
return nil, xerrors.Errorf("compute todo-unsealed: %w", err)
}
return rlepluslazy.JoinClose(todo, mergeGaps)
}
package seal
import (
"sync"
"golang.org/x/xerrors"
"fil_integrate/build/state-types/abi"
spproof "fil_integrate/build/proof"
"fil_integrate/build/storage"
ffi "github.com/filecoin-project/filecoin-ffi"
)
type Verifier struct {
lock *sync.RWMutex
sm map[abi.SectorID]storage.SectorCids
}
var ProofVerifier = Verifier{
lock: new(sync.RWMutex),
sm: make(map[abi.SectorID]storage.SectorCids),
}
var _ SectorVerifier = Verifier{}
func (v Verifier) VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
info.Randomness = Ticket
ok, err := ffi.VerifySeal(info)
if ok && err == nil {
v.lock.Lock()
defer v.lock.Unlock()
v.sm[info.SectorID] = storage.SectorCids{
Sealed: info.SealedCID,
Unsealed: info.UnsealedCID,
}
}
return ok, err
}
func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (bool, error) {
for i, _ := range aggregate.Infos {
aggregate.Infos[i].Randomness = Ticket
}
ok, err := ffi.VerifyAggregateSeals(aggregate)
if ok && err == nil {
v.lock.Lock()
defer v.lock.Unlock()
for _, info := range aggregate.Infos {
sid := abi.SectorID{
Miner: aggregate.Miner,
Number: info.Number,
}
v.sm[sid] = storage.SectorCids{
Sealed: info.SealedCID,
Unsealed: info.UnsealedCID,
}
}
}
return ok, err
}
func (v Verifier) VerifyWindowPoSt(
sectors []storage.SectorRef,
proof spproof.PoStProof,
randomness abi.PoStRandomness,
proverID abi.ActorID,
) (bool, error) {
chanllendedSectors := make([]spproof.SectorInfo, len(sectors))
// minerID = sectors[0].ID.Miner
v.lock.RLock()
// defer m.Lock.RUnLock()
for idx, sid := range sectors {
cids, ok := v.sm[sid.ID]
if !ok {
v.lock.RUnlock()
return false, xerrors.Errorf("can not map the sectorID into sector commitment")
}
chanllendedSectors[idx] = spproof.SectorInfo{
SealType: sid.ProofType,
SectorNumber: sid.ID.Number,
SealedCID: cids.Sealed,
}
}
v.lock.RUnlock()
randomness[31] &= 0x3f
log.Infof("Verifying Window-PoSt Proof")
return ffi.VerifyWindowPoSt(spproof.WindowPoStVerifyInfo{
Randomness: randomness,
Proof: proof,
ChallengedSectors: chanllendedSectors,
Prover: proverID,
})
}
func (v Verifier) VerifyAggregateWindowPostProofs(
sectors [][]storage.SectorRef,
proof spproof.PoStProof,
randomnesses []abi.PoStRandomness,
proverID abi.ActorID,
) (bool, error) {
var sectorInfos []spproof.SectorInfo
sectorCount := make([]uint, len(sectors))
v.lock.RLock()
// defer v.Lock.RUnLock()
for i, sectorRange := range sectors {
sectorCount[i] = uint(len(sectorRange))
for _, sid := range sectorRange {
cids, ok := v.sm[sid.ID]
if !ok {
v.lock.RUnlock()
return false, xerrors.Errorf("can not map the sectorID into sector commitment")
}
sectorInfos = append(sectorInfos, spproof.SectorInfo{
SealType: sid.ProofType,
SectorNumber: sid.ID.Number,
SealedCID: cids.Sealed,
})
}
}
v.lock.RUnlock()
for i, random := range randomnesses {
randomnesses[i][31] = random[31] & 0x3f
}
postType, err := sectorInfos[0].SealType.RegisteredWindowPoStProof()
if err != nil {
return false, err
}
return ffi.VerifyAggregateWindowPostProofs(spproof.AggregateWindowPostInfos{
PoStType: postType,
AggregateType: DefaultAggregationType(),
AggregateProof: proof,
ChallengedSectors: sectorInfos,
SectorCount: sectorCount,
Randomnesses: randomnesses,
Prover: proverID,
})
}
func DefaultAggregationType() abi.RegisteredAggregationProof {
return abi.RegisteredAggregationProof_SnarkPackV1
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment