gofmt
This commit is contained in:
parent
c760a88c22
commit
9dcb42328e
@ -5,8 +5,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
@ -56,32 +54,6 @@ type Runtime struct {
|
|||||||
allowInternal bool
|
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 {
|
func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount {
|
||||||
total := types.FromFil(build.TotalFilecoin)
|
total := types.FromFil(build.TotalFilecoin)
|
||||||
|
|
||||||
@ -133,9 +105,12 @@ type notFoundErr interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool {
|
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
|
var nfe notFoundErr
|
||||||
if xerrors.As(err, &nfe) && nfe.IsNotFound() {
|
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
|
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 {
|
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 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))
|
panic(aerrors.Fatalf("failed to put cbor object: %s", err))
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
47
chain/vm/runtime_test.go
Normal file
47
chain/vm/runtime_test.go
Normal file
@ -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")
|
||||||
|
}
|
4
go.mod
4
go.mod
@ -53,7 +53,7 @@ require (
|
|||||||
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
|
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
|
||||||
github.com/ipfs/go-ipfs-files v0.0.7
|
github.com/ipfs/go-ipfs-files v0.0.7
|
||||||
github.com/ipfs/go-ipfs-routing v0.1.0
|
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-ipld-format v0.0.2
|
||||||
github.com/ipfs/go-log v1.0.4
|
github.com/ipfs/go-log v1.0.4
|
||||||
github.com/ipfs/go-log/v2 v2.0.5
|
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/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/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
|
||||||
|
5
go.sum
5
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-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 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
|
||||||
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
|
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.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 h1:OVAGlyYT6JPZ0pEfGntFPS40lfrDmaDbQwNHEY2G9Zs=
|
||||||
github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf0INGQgiKf9k=
|
github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf0INGQgiKf9k=
|
||||||
|
Loading…
Reference in New Issue
Block a user