More fixes

This commit is contained in:
Łukasz Magiera 2020-09-14 20:28:47 +02:00
parent 381a6cdfac
commit e9d25e5919
5 changed files with 54 additions and 21 deletions

View File

@ -146,7 +146,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
scratch := make([]byte, 9) scratch := make([]byte, 9)
// t.Status (blocksync.status) (uint64) // t.Status (exchange.status) (uint64)
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil {
return err return err
@ -164,7 +164,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.Chain ([]*blocksync.BSTipSet) (slice) // t.Chain ([]*exchange.BSTipSet) (slice)
if len(t.Chain) > cbg.MaxLength { if len(t.Chain) > cbg.MaxLength {
return xerrors.Errorf("Slice value in field t.Chain was too long") return xerrors.Errorf("Slice value in field t.Chain was too long")
} }
@ -198,7 +198,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.Status (blocksync.status) (uint64) // t.Status (exchange.status) (uint64)
{ {
@ -222,7 +222,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.ErrorMessage = string(sval) t.ErrorMessage = string(sval)
} }
// t.Chain ([]*blocksync.BSTipSet) (slice) // t.Chain ([]*exchange.BSTipSet) (slice)
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil { if err != nil {
@ -567,7 +567,7 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error {
} }
} }
// t.Messages (blocksync.CompactedMessages) (struct) // t.Messages (exchange.CompactedMessages) (struct)
if err := t.Messages.MarshalCBOR(w); err != nil { if err := t.Messages.MarshalCBOR(w); err != nil {
return err return err
} }
@ -621,7 +621,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error {
t.Blocks[i] = &v t.Blocks[i] = &v
} }
// t.Messages (blocksync.CompactedMessages) (struct) // t.Messages (exchange.CompactedMessages) (struct)
{ {

View File

@ -17,7 +17,6 @@ func (t *Call) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
return err return err
} }
panic("cbg")
if _, err := w.Write([]byte{162}); err != nil { if _, err := w.Write([]byte{162}); err != nil {
return err return err
} }
@ -40,7 +39,7 @@ func (t *Call) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.Result (typegen.Deferred) (struct) // t.Result ([]uint8) (slice)
if len("Result") > cbg.MaxLength { if len("Result") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Result\" was too long") return xerrors.Errorf("Value in field \"Result\" was too long")
} }
@ -52,6 +51,17 @@ func (t *Call) MarshalCBOR(w io.Writer) error {
return err return err
} }
if len(t.Result) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.Result was too long")
}
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Result))); err != nil {
return err
}
if _, err := w.Write(t.Result[:]); err != nil {
return err
}
return nil return nil
} }
@ -103,11 +113,27 @@ func (t *Call) UnmarshalCBOR(r io.Reader) error {
t.State = CallState(extra) t.State = CallState(extra)
} }
// t.Result (typegen.Deferred) (struct) // t.Result ([]uint8) (slice)
case "Result": case "Result":
{ maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
return err
}
if extra > cbg.ByteArrayMaxLen {
return fmt.Errorf("t.Result: byte array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
if extra > 0 {
t.Result = make([]uint8, extra)
}
if _, err := io.ReadFull(br, t.Result[:]); err != nil {
return err
} }
default: default:

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
"io" "io"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
@ -31,6 +30,7 @@ import (
ffi "github.com/filecoin-project/filecoin-ffi" ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper/basicfs" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper/basicfs"
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
) )
func init() { func init() {
@ -206,7 +206,7 @@ func post(t *testing.T, sealer *Sealer, skipped []abi.SectorID, seals ...seal) {
} }
func corrupt(t *testing.T, sealer *Sealer, id abi.SectorID) { func corrupt(t *testing.T, sealer *Sealer, id abi.SectorID) {
paths, done, err := sealer.sectors.AcquireSector(context.Background(), id, stores.FTSealed, 0, stores.PathStorage) paths, done, err := sealer.sectors.AcquireSector(context.Background(), id, storiface.FTSealed, 0, storiface.PathStorage)
require.NoError(t, err) require.NoError(t, err)
defer done() defer done()

View File

@ -108,29 +108,34 @@ type returnType string
// in: func(WorkerReturn, context.Context, CallID, err string) // in: func(WorkerReturn, context.Context, CallID, err string)
// in: func(WorkerReturn, context.Context, CallID, ret T, err string) // in: func(WorkerReturn, context.Context, CallID, ret T, err string)
func rfunc(in interface{}) func(context.Context, storiface.WorkerReturn, interface{}, error) error { func rfunc(in interface{}) func(context.Context, storiface.CallID, storiface.WorkerReturn, interface{}, error) error {
rf := reflect.ValueOf(in) rf := reflect.ValueOf(in)
ft := rf.Type() ft := rf.Type()
withRet := ft.NumIn() == 4 withRet := ft.NumIn() == 5
return func(ctx context.Context, wr storiface.WorkerReturn, i interface{}, err error) error { return func(ctx context.Context, ci storiface.CallID, wr storiface.WorkerReturn, i interface{}, err error) error {
rctx := reflect.ValueOf(ctx) rctx := reflect.ValueOf(ctx)
rwr := reflect.ValueOf(wr) rwr := reflect.ValueOf(wr)
rerr := reflect.ValueOf(errstr(err)) rerr := reflect.ValueOf(errstr(err))
rci := reflect.ValueOf(ci)
var ro []reflect.Value var ro []reflect.Value
if withRet { if withRet {
ro = rf.Call([]reflect.Value{rwr, rctx, reflect.ValueOf(i), rerr}) ro = rf.Call([]reflect.Value{rwr, rctx, rci, reflect.ValueOf(i), rerr})
} else { } else {
ro = rf.Call([]reflect.Value{rwr, rctx, rerr}) ro = rf.Call([]reflect.Value{rwr, rctx, rci, rerr})
} }
return ro[0].Interface().(error) if !ro[0].IsNil() {
return ro[0].Interface().(error)
}
return nil
} }
} }
var returnFunc = map[returnType]func(context.Context, storiface.WorkerReturn, interface{}, error) error{ var returnFunc = map[returnType]func(context.Context, storiface.CallID, storiface.WorkerReturn, interface{}, error) error{
"AddPiece": rfunc(storiface.WorkerReturn.ReturnAddPiece), "AddPiece": rfunc(storiface.WorkerReturn.ReturnAddPiece),
"SealPreCommit1": rfunc(storiface.WorkerReturn.ReturnSealPreCommit1), "SealPreCommit1": rfunc(storiface.WorkerReturn.ReturnSealPreCommit1),
"SealPreCommit2": rfunc(storiface.WorkerReturn.ReturnSealPreCommit2), "SealPreCommit2": rfunc(storiface.WorkerReturn.ReturnSealPreCommit2),
@ -156,7 +161,7 @@ func (l *LocalWorker) asyncCall(ctx context.Context, sector abi.SectorID, rt ret
go func() { go func() {
res, err := work(ci) res, err := work(ci)
if err := returnFunc[rt](ctx, l.ret, res, err); err != nil { if err := returnFunc[rt](ctx, ci, l.ret, res, err); err != nil {
log.Errorf("return error: %s: %+v", rt, err) log.Errorf("return error: %s: %+v", rt, err)
} }
}() }()

View File

@ -108,7 +108,9 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema
curTime := time.Now() curTime := time.Now()
for time.Since(curTime) < addPieceRetryTimeout { for time.Since(curTime) < addPieceRetryTimeout {
if !xerrors.Is(err, sealing.ErrTooManySectorsSealing) { if !xerrors.Is(err, sealing.ErrTooManySectorsSealing) {
log.Errorf("failed to addPiece for deal %d, err: %w", deal.DealID, err) if err != nil {
log.Errorf("failed to addPiece for deal %d, err: %w", deal.DealID, err)
}
break break
} }
select { select {