address PR review
This commit is contained in:
parent
98f252da65
commit
eba3f4af86
@ -3,6 +3,7 @@ package actors
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -74,9 +75,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StorageDealProposal struct {
|
type StorageDealProposal struct {
|
||||||
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
|
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
|
||||||
PieceSize uint64
|
PieceSize uint64
|
||||||
PieceSerialization SerializationMode // Needs to be here as it tells how data in the sector maps to PieceRef cid
|
|
||||||
|
|
||||||
Client address.Address
|
Client address.Address
|
||||||
Provider address.Address
|
Provider address.Address
|
||||||
@ -133,9 +133,8 @@ func (sdp *StorageDealProposal) Verify() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OnChainDeal struct {
|
type OnChainDeal struct {
|
||||||
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
|
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
|
||||||
PieceSize uint64
|
PieceSize uint64
|
||||||
PieceSerialization SerializationMode // Needs to be here as it tells how data in the sector maps to PieceRef cid
|
|
||||||
|
|
||||||
Client address.Address
|
Client address.Address
|
||||||
Provider address.Address
|
Provider address.Address
|
||||||
@ -230,9 +229,15 @@ func (sma StorageMarketActor) AddBalance(act *types.Actor, vmctx types.VMContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setMarketBalances(vmctx types.VMContext, nd *hamt.Node, set map[address.Address]StorageParticipantBalance) (cid.Cid, ActorError) {
|
func setMarketBalances(vmctx types.VMContext, nd *hamt.Node, set map[address.Address]StorageParticipantBalance) (cid.Cid, ActorError) {
|
||||||
// TODO: iterating over a map might happen in the wrong order, this could have gas implications
|
keys := make([]address.Address, 0, len(set))
|
||||||
for addr, b := range set {
|
for k := range set {
|
||||||
balance := b // to stop linter complaining
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Slice(keys, func(i, j int) bool {
|
||||||
|
return bytes.Compare(keys[i].Bytes(), keys[j].Bytes()) < 0
|
||||||
|
})
|
||||||
|
for _, addr := range keys {
|
||||||
|
balance := set[addr]
|
||||||
if err := nd.Set(vmctx.Context(), string(addr.Bytes()), &balance); err != nil {
|
if err := nd.Set(vmctx.Context(), string(addr.Bytes()), &balance); err != nil {
|
||||||
return cid.Undef, aerrors.HandleExternalError(err, "setting new balance")
|
return cid.Undef, aerrors.HandleExternalError(err, "setting new balance")
|
||||||
}
|
}
|
||||||
@ -329,9 +334,8 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := deals.Set(self.NextDealID, &OnChainDeal{
|
err := deals.Set(self.NextDealID, &OnChainDeal{
|
||||||
PieceRef: deal.PieceRef,
|
PieceRef: deal.PieceRef,
|
||||||
PieceSize: deal.PieceSize,
|
PieceSize: deal.PieceSize,
|
||||||
PieceSerialization: deal.PieceSerialization, // TODO: this isnt needed anymore, right?
|
|
||||||
|
|
||||||
Client: deal.Client,
|
Client: deal.Client,
|
||||||
Provider: deal.Provider,
|
Provider: deal.Provider,
|
||||||
|
@ -3159,7 +3159,7 @@ func (t *StorageDealProposal) MarshalCBOR(w io.Writer) error {
|
|||||||
_, err := w.Write(cbg.CborNull)
|
_, err := w.Write(cbg.CborNull)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := w.Write([]byte{138}); err != nil {
|
if _, err := w.Write([]byte{137}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3176,11 +3176,6 @@ func (t *StorageDealProposal) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.PieceSerialization (uint64) (uint64)
|
|
||||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PieceSerialization))); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// t.t.Client (address.Address) (struct)
|
// t.t.Client (address.Address) (struct)
|
||||||
if err := t.Client.MarshalCBOR(w); err != nil {
|
if err := t.Client.MarshalCBOR(w); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -3229,7 +3224,7 @@ func (t *StorageDealProposal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array")
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 10 {
|
if extra != 9 {
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3260,16 +3255,6 @@ func (t *StorageDealProposal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("wrong type for uint64 field")
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
}
|
}
|
||||||
t.PieceSize = uint64(extra)
|
t.PieceSize = uint64(extra)
|
||||||
// t.t.PieceSerialization (uint64) (uint64)
|
|
||||||
|
|
||||||
maj, extra, err = cbg.CborReadHeader(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if maj != cbg.MajUnsignedInt {
|
|
||||||
return fmt.Errorf("wrong type for uint64 field")
|
|
||||||
}
|
|
||||||
t.PieceSerialization = uint64(extra)
|
|
||||||
// t.t.Client (address.Address) (struct)
|
// t.t.Client (address.Address) (struct)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -3627,7 +3612,7 @@ func (t *OnChainDeal) MarshalCBOR(w io.Writer) error {
|
|||||||
_, err := w.Write(cbg.CborNull)
|
_, err := w.Write(cbg.CborNull)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := w.Write([]byte{138}); err != nil {
|
if _, err := w.Write([]byte{137}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3644,11 +3629,6 @@ func (t *OnChainDeal) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.PieceSerialization (uint64) (uint64)
|
|
||||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PieceSerialization))); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// t.t.Client (address.Address) (struct)
|
// t.t.Client (address.Address) (struct)
|
||||||
if err := t.Client.MarshalCBOR(w); err != nil {
|
if err := t.Client.MarshalCBOR(w); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -3697,7 +3677,7 @@ func (t *OnChainDeal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array")
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 10 {
|
if extra != 9 {
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3728,16 +3708,6 @@ func (t *OnChainDeal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("wrong type for uint64 field")
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
}
|
}
|
||||||
t.PieceSize = uint64(extra)
|
t.PieceSize = uint64(extra)
|
||||||
// t.t.PieceSerialization (uint64) (uint64)
|
|
||||||
|
|
||||||
maj, extra, err = cbg.CborReadHeader(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if maj != cbg.MajUnsignedInt {
|
|
||||||
return fmt.Errorf("wrong type for uint64 field")
|
|
||||||
}
|
|
||||||
t.PieceSerialization = uint64(extra)
|
|
||||||
// t.t.Client (address.Address) (struct)
|
// t.t.Client (address.Address) (struct)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -206,7 +206,6 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, erro
|
|||||||
dealProposal := &actors.StorageDealProposal{
|
dealProposal := &actors.StorageDealProposal{
|
||||||
PieceRef: commP,
|
PieceRef: commP,
|
||||||
PieceSize: uint64(pieceSize),
|
PieceSize: uint64(pieceSize),
|
||||||
PieceSerialization: actors.SerializationUnixFSv0,
|
|
||||||
Client: p.Client,
|
Client: p.Client,
|
||||||
Provider: p.ProviderAddress,
|
Provider: p.ProviderAddress,
|
||||||
ProposalExpiration: p.ProposalExpiration,
|
ProposalExpiration: p.ProposalExpiration,
|
||||||
|
@ -42,13 +42,6 @@ func (p *Provider) handle(ctx context.Context, deal MinerDeal, cb providerHandle
|
|||||||
|
|
||||||
// ACCEPTED
|
// ACCEPTED
|
||||||
func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal), error) {
|
func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal), error) {
|
||||||
switch deal.Proposal.PieceSerialization {
|
|
||||||
//case SerializationRaw:
|
|
||||||
//case SerializationIPLD:
|
|
||||||
case actors.SerializationUnixFSv0:
|
|
||||||
default:
|
|
||||||
return nil, xerrors.Errorf("deal proposal with unsupported serialization: %s", deal.Proposal.PieceSerialization)
|
|
||||||
}
|
|
||||||
|
|
||||||
head, err := p.full.ChainHead(ctx)
|
head, err := p.full.ChainHead(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,7 +212,6 @@ func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors
|
|||||||
cdeals[i] = &actors.OnChainDeal{
|
cdeals[i] = &actors.OnChainDeal{
|
||||||
PieceRef: deal.PieceRef,
|
PieceRef: deal.PieceRef,
|
||||||
PieceSize: deal.PieceSize,
|
PieceSize: deal.PieceSize,
|
||||||
PieceSerialization: deal.PieceSerialization,
|
|
||||||
Client: deal.Client,
|
Client: deal.Client,
|
||||||
Provider: deal.Provider,
|
Provider: deal.Provider,
|
||||||
ProposalExpiration: deal.ProposalExpiration,
|
ProposalExpiration: deal.ProposalExpiration,
|
||||||
|
@ -142,7 +142,6 @@ func createDeals(m *genesis.GenesisMiner, k *wallet.Key, maddr address.Address,
|
|||||||
proposal := &actors.StorageDealProposal{
|
proposal := &actors.StorageDealProposal{
|
||||||
PieceRef: pref, // just one deal so this == CommP
|
PieceRef: pref, // just one deal so this == CommP
|
||||||
PieceSize: sectorbuilder.UserBytesForSectorSize(ssize),
|
PieceSize: sectorbuilder.UserBytesForSectorSize(ssize),
|
||||||
PieceSerialization: actors.SerializationUnixFSv0,
|
|
||||||
Client: k.Address,
|
Client: k.Address,
|
||||||
Provider: maddr,
|
Provider: maddr,
|
||||||
ProposalExpiration: 9000, // TODO: allow setting
|
ProposalExpiration: 9000, // TODO: allow setting
|
||||||
|
1
go.mod
1
go.mod
@ -80,6 +80,7 @@ require (
|
|||||||
github.com/onsi/ginkgo v1.9.0 // indirect
|
github.com/onsi/ginkgo v1.9.0 // indirect
|
||||||
github.com/onsi/gomega v1.6.0 // indirect
|
github.com/onsi/gomega v1.6.0 // indirect
|
||||||
github.com/opentracing/opentracing-go v1.1.0
|
github.com/opentracing/opentracing-go v1.1.0
|
||||||
|
github.com/otiai10/copy v1.0.2 // indirect
|
||||||
github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a
|
github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a
|
||||||
github.com/smartystreets/assertions v1.0.1 // indirect
|
github.com/smartystreets/assertions v1.0.1 // indirect
|
||||||
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
|
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
|
||||||
|
5
go.sum
5
go.sum
@ -510,6 +510,11 @@ github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
|
|||||||
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
||||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||||
|
github.com/otiai10/copy v1.0.2 h1:DDNipYy6RkIkjMwy+AWzgKiNTyj2RUI9yEMeETEpVyc=
|
||||||
|
github.com/otiai10/copy v1.0.2/go.mod h1:c7RpqBkwMom4bYTSkLSym4VSJz/XtncWRAj/J4PEIMY=
|
||||||
|
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
|
||||||
|
github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc=
|
||||||
|
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
@ -33,7 +33,6 @@ func (m *Miner) storeGarbage(ctx context.Context, sectorID uint64, existingPiece
|
|||||||
sdp := actors.StorageDealProposal{
|
sdp := actors.StorageDealProposal{
|
||||||
PieceRef: commP[:],
|
PieceRef: commP[:],
|
||||||
PieceSize: size,
|
PieceSize: size,
|
||||||
PieceSerialization: actors.SerializationUnixFSv0,
|
|
||||||
Client: m.worker,
|
Client: m.worker,
|
||||||
Provider: m.maddr,
|
Provider: m.maddr,
|
||||||
ProposalExpiration: math.MaxUint64,
|
ProposalExpiration: math.MaxUint64,
|
||||||
|
@ -223,7 +223,7 @@ func (m *Miner) handleCommitWait(ctx context.Context, sector SectorInfo) *sector
|
|||||||
|
|
||||||
if mw.Receipt.ExitCode != 0 {
|
if mw.Receipt.ExitCode != 0 {
|
||||||
log.Errorf("UNHANDLED: submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.Proof)
|
log.Errorf("UNHANDLED: submitting sector proof failed (exit=%d, msg=%s) (t:%x; s:%x(%d); p:%x)", mw.Receipt.ExitCode, sector.CommitMessage, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.Proof)
|
||||||
return sector.upd().fatal(xerrors.New("UNHANDLED: submitting sector proof failed (exit: %d)", mw.Receipt.ExitCode))
|
return sector.upd().fatal(xerrors.Errorf("UNHANDLED: submitting sector proof failed (exit: %d)", mw.Receipt.ExitCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
return sector.upd().to(api.Proving).state(func(info *SectorInfo) {
|
return sector.upd().to(api.Proving).state(func(info *SectorInfo) {
|
||||||
|
Loading…
Reference in New Issue
Block a user