diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index ca55f2b36..bb5149ff8 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -116,7 +116,7 @@ type FullNodeStruct struct { StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, *abi.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` - StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*miner.DeadlineInfo, error) `perm:"read"` + StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*miner.DeadlineInfo, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) `perm:"read"` @@ -504,7 +504,7 @@ func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address. return c.Internal.StateMinerProvingSet(ctx, addr, tsk) } -func (c *FullNodeStruct) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*miner.DeadlineInfo, error) { +func (c *FullNodeStruct) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*miner.DeadlineInfo, error) { return c.Internal.StateMinerProvingDeadline(ctx, addr, tsk) } diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 3fb5879f4..536b2d32f 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -5,8 +5,6 @@ import ( "context" "encoding/binary" "fmt" - "io" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" @@ -56,32 +54,6 @@ type Runtime struct { allowInternal bool } -type safeCBORMarshaler struct { - m cbg.CBORMarshaler -} - -func (s *safeCBORMarshaler) MarshalCBOR(w io.Writer) error { - if err := s.m.MarshalCBOR(w); err != nil { - panic(aerrors.Newf(exitcode.ErrSerialization,"failed to marshal cbor object %s", err)) - } - - return nil -} - -type safeCBORUnmarshaler struct { - m cbg.CBORUnmarshaler -} - -func (s *safeCBORUnmarshaler) UnmarshalCBOR(r io.Reader) error { - if err := s.m.UnmarshalCBOR(r); err != nil { - panic(aerrors.Newf(exitcode.ErrSerialization,"failed to unmarshal cbor object %s", err)) - } - - return nil -} - -var _ cbg.CBORUnmarshaler = &safeCBORUnmarshaler{} - func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount { total := types.FromFil(build.TotalFilecoin) @@ -133,9 +105,12 @@ type notFoundErr interface { } func (rs *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool { - if err := rs.cst.Get(context.TODO(), c, &safeCBORUnmarshaler{o}); err != nil { + if err := rs.cst.Get(context.TODO(), c, o); err != nil { var nfe notFoundErr if xerrors.As(err, &nfe) && nfe.IsNotFound() { + if xerrors.As(err, new(cbor.SerializationError)) { + panic(aerrors.Newf(exitcode.ErrSerialization, "failed to unmarshal cbor object %s", err)) + } return false } @@ -145,8 +120,11 @@ func (rs *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool { } func (rs *Runtime) Put(x vmr.CBORMarshaler) cid.Cid { - c, err := rs.cst.Put(context.TODO(), &safeCBORMarshaler{x}) + c, err := rs.cst.Put(context.TODO(), x) if err != nil { + if xerrors.As(err, new(cbor.SerializationError)) { + panic(aerrors.Newf(exitcode.ErrSerialization, "failed to marshal cbor object %s", err)) + } panic(aerrors.Fatalf("failed to put cbor object: %s", err)) } return c diff --git a/chain/vm/runtime_test.go b/chain/vm/runtime_test.go new file mode 100644 index 000000000..d6b2429e5 --- /dev/null +++ b/chain/vm/runtime_test.go @@ -0,0 +1,47 @@ +package vm + +import ( + "io" + "testing" + + cbor "github.com/ipfs/go-ipld-cbor" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" + + "github.com/filecoin-project/lotus/chain/actors/aerrors" +) + +type NotAVeryGoodMarshaler struct {} + +func (*NotAVeryGoodMarshaler) MarshalCBOR(writer io.Writer) error { + return xerrors.Errorf("no") +} + +var _ cbg.CBORMarshaler = &NotAVeryGoodMarshaler{} + +func TestRuntimePutErrors(t *testing.T) { + defer func() { + err := recover() + if err == nil { + t.Fatal("expected non-nil recovery") + } + + aerr := err.(aerrors.ActorError) + if aerr.IsFatal() { + t.Fatal("expected non-fatal actor error") + } + + if aerr.RetCode() != exitcode.ErrSerialization { + t.Fatal("expected serialization error") + } + }() + + rt := Runtime{ + cst: cbor.NewCborStore(nil), + } + + rt.Put(&NotAVeryGoodMarshaler{}) + t.Error("expected panic") +} diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index bb6c16e51..c397d68f7 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -107,7 +107,7 @@ var provingInfoCmd = &cli.Command{ fmt.Printf("Chain Period Start: %s\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch/miner.WPoStProvingPeriod)*miner.WPoStProvingPeriod)) fmt.Printf("Chain Period End: %s\n\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch/miner.WPoStProvingPeriod+1)*miner.WPoStProvingPeriod)) - fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart % miner.WPoStProvingPeriod) + fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%miner.WPoStProvingPeriod) fmt.Printf("Proving Period Start: %s\n", epochTime(cd.CurrentEpoch, cd.PeriodStart)) fmt.Printf("Next Period Start: %s\n\n", epochTime(cd.CurrentEpoch, cd.PeriodStart+miner.WPoStProvingPeriod)) diff --git a/go.mod b/go.mod index a7a547cd4..febd17677 100644 --- a/go.mod +++ b/go.mod @@ -53,7 +53,7 @@ require ( github.com/ipfs/go-ipfs-exchange-offline v0.0.1 github.com/ipfs/go-ipfs-files v0.0.7 github.com/ipfs/go-ipfs-routing v0.1.0 - github.com/ipfs/go-ipld-cbor v0.0.5-0.20200204214505-252690b78669 + github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf github.com/ipfs/go-ipld-format v0.0.2 github.com/ipfs/go-log v1.0.4 github.com/ipfs/go-log/v2 v2.0.5 @@ -115,3 +115,5 @@ replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0 + +replace github.com/ipfs/go-ipld-cbor => /home/magik6k/gohack/github.com/ipfs/go-ipld-cbor diff --git a/go.sum b/go.sum index 047814ead..033346094 100644 --- a/go.sum +++ b/go.sum @@ -372,11 +372,6 @@ github.com/ipfs/go-ipfs-routing v0.1.0 h1:gAJTT1cEeeLj6/DlLX6t+NxD9fQe2ymTO6qWRD github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY= 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.2/go.mod h1:wTBtrQZA3SoFKMVkp6cn6HMRteIB1VsmHA0AQFOn7Nc= -github.com/ipfs/go-ipld-cbor v0.0.3/go.mod h1:wTBtrQZA3SoFKMVkp6cn6HMRteIB1VsmHA0AQFOn7Nc= -github.com/ipfs/go-ipld-cbor v0.0.4/go.mod h1:BkCduEx3XBCO6t2Sfo5BaHzuok7hbhdMm9Oh8B2Ftq4= -github.com/ipfs/go-ipld-cbor v0.0.5-0.20200204214505-252690b78669 h1:jIVle1vGSzxyUhseYNEqd7qcDVRrIbJ7UxGwao70cF0= -github.com/ipfs/go-ipld-cbor v0.0.5-0.20200204214505-252690b78669/go.mod h1:BkCduEx3XBCO6t2Sfo5BaHzuok7hbhdMm9Oh8B2Ftq4= github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms= github.com/ipfs/go-ipld-format v0.0.2 h1:OVAGlyYT6JPZ0pEfGntFPS40lfrDmaDbQwNHEY2G9Zs= github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf0INGQgiKf9k= diff --git a/node/builder.go b/node/builder.go index 0d2b4d9a0..e73366beb 100644 --- a/node/builder.go +++ b/node/builder.go @@ -73,15 +73,15 @@ type special struct{ id int } //nolint:golint var ( - DefaultTransportsKey = special{0} // Libp2p option - DiscoveryHandlerKey = special{2} // Private type - AddrsFactoryKey = special{3} // Libp2p option - SmuxTransportKey = special{4} // Libp2p option - RelayKey = special{5} // Libp2p option - SecurityKey = special{6} // Libp2p option - BaseRoutingKey = special{7} // fx groups + multiret - NatPortMapKey = special{8} // Libp2p option - ConnectionManagerKey = special{9} // Libp2p option + DefaultTransportsKey = special{0} // Libp2p option + DiscoveryHandlerKey = special{2} // Private type + AddrsFactoryKey = special{3} // Libp2p option + SmuxTransportKey = special{4} // Libp2p option + RelayKey = special{5} // Libp2p option + SecurityKey = special{6} // Libp2p option + BaseRoutingKey = special{7} // fx groups + multiret + NatPortMapKey = special{8} // Libp2p option + ConnectionManagerKey = special{9} // Libp2p option AutoNATSvcKey = special{10} // Libp2p option ) diff --git a/storage/miner.go b/storage/miner.go index b15b67019..9088e26d6 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -102,7 +102,7 @@ func (m *Miner) Run(ctx context.Context) error { evts := events.NewEvents(ctx, m.api) adaptedAPI := NewSealingAPIAdapter(m.api) - pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, 10000000, md.PeriodStart % miner.WPoStProvingPeriod) + pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, 10000000, md.PeriodStart%miner.WPoStProvingPeriod) m.sealing = sealing.New(adaptedAPI, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp) go m.sealing.Run(ctx)