test fastPledgeCommitment
This commit is contained in:
parent
25f544f3db
commit
ba542cf67a
@ -5,54 +5,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"math/bits"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
|
||||||
|
|
||||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
"github.com/hashicorp/go-multierror"
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *Sealing) fastPledgeCommitment(size uint64, parts uint64) (commP [sectorbuilder.CommLen]byte, err error) {
|
|
||||||
parts = 1 << bits.Len64(parts) // round down to nearest power of 2
|
|
||||||
|
|
||||||
piece := sectorbuilder.UserBytesForSectorSize((size/127 + size) / parts)
|
|
||||||
out := make([]sectorbuilder.PublicPieceInfo, parts)
|
|
||||||
var lk sync.Mutex
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(int(parts))
|
|
||||||
for i := uint64(0); i < parts; i++ {
|
|
||||||
go func(i uint64) {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
commP, perr := sectorbuilder.GeneratePieceCommitment(io.LimitReader(rand.New(rand.NewSource(42+int64(i))), int64(piece)), piece)
|
|
||||||
|
|
||||||
lk.Lock()
|
|
||||||
if perr != nil {
|
|
||||||
err = multierror.Append(err, perr)
|
|
||||||
}
|
|
||||||
out[i] = sectorbuilder.PublicPieceInfo{
|
|
||||||
Size: piece,
|
|
||||||
CommP: commP,
|
|
||||||
}
|
|
||||||
lk.Unlock()
|
|
||||||
}(i)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return [32]byte{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return sectorbuilder.GenerateDataCommitment(m.sb.SectorSize(), out)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Sealing) pledgeReader(size uint64, parts uint64) io.Reader {
|
func (m *Sealing) pledgeReader(size uint64, parts uint64) io.Reader {
|
||||||
piece := sectorbuilder.UserBytesForSectorSize((size/127 + size) / parts)
|
piece := sectorbuilder.UserBytesForSectorSize((size/127 + size) / parts)
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package sealing
|
package sealing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
|
"math/rand"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
|
|
||||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
)
|
)
|
||||||
@ -42,6 +47,41 @@ func fillersFromRem(toFill uint64) ([]uint64, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Sealing) fastPledgeCommitment(size uint64, parts uint64) (commP [sectorbuilder.CommLen]byte, err error) {
|
||||||
|
parts = 1 << bits.Len64(parts) // round down to nearest power of 2
|
||||||
|
|
||||||
|
piece := sectorbuilder.UserBytesForSectorSize(size / parts)
|
||||||
|
out := make([]sectorbuilder.PublicPieceInfo, parts)
|
||||||
|
var lk sync.Mutex
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(int(parts))
|
||||||
|
for i := uint64(0); i < parts; i++ {
|
||||||
|
go func(i uint64) {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
commP, perr := sectorbuilder.GeneratePieceCommitment(io.LimitReader(rand.New(rand.NewSource(42+int64(i))), int64(piece)), piece)
|
||||||
|
|
||||||
|
lk.Lock()
|
||||||
|
if perr != nil {
|
||||||
|
err = multierror.Append(err, perr)
|
||||||
|
}
|
||||||
|
out[i] = sectorbuilder.PublicPieceInfo{
|
||||||
|
Size: piece,
|
||||||
|
CommP: commP,
|
||||||
|
}
|
||||||
|
lk.Unlock()
|
||||||
|
}(i)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return [32]byte{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sectorbuilder.GenerateDataCommitment(m.sb.SectorSize(), out)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Sealing) ListSectors() ([]SectorInfo, error) {
|
func (m *Sealing) ListSectors() ([]SectorInfo, error) {
|
||||||
var sectors []SectorInfo
|
var sectors []SectorInfo
|
||||||
if err := m.sectors.List(§ors); err != nil {
|
if err := m.sectors.List(§ors); err != nil {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package sealing
|
package sealing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/filecoin-project/lotus/storage/sbmock"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -42,5 +43,13 @@ func TestFillersFromRem(t *testing.T) {
|
|||||||
ub = sectorbuilder.UserBytesForSectorSize(uint64(9) << i)
|
ub = sectorbuilder.UserBytesForSectorSize(uint64(9) << i)
|
||||||
testFill(t, ub, []uint64{ub1, ub4})
|
testFill(t, ub, []uint64{ub1, ub4})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFastPledge(t *testing.T) {
|
||||||
|
sz := uint64(16 << 20)
|
||||||
|
|
||||||
|
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, sz)}
|
||||||
|
if _, err := s.fastPledgeCommitment(sz, 5); err != nil {
|
||||||
|
t.Fatalf("%+v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user