Merge pull request #1627 from filecoin-project/fix/safe-actor-serialization
vm: Don't treat actor state serialization errors as fatal
This commit is contained in:
commit
cd5cbcfe4f
@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
@ -110,6 +109,9 @@ func (rs *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@ -121,6 +123,9 @@ 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(), 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
|
||||
|
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")
|
||||
}
|
2
go.mod
2
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
|
||||
|
3
go.sum
3
go.sum
@ -375,8 +375,9 @@ github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyB
|
||||
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-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf h1:PRCy+w3GocY77CBEwTprp6hn7PLiEU1YToKe7B+1FVk=
|
||||
github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf/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=
|
||||
|
Loading…
Reference in New Issue
Block a user