support fvm gas tracing
This commit is contained in:
parent
30f66578e1
commit
92cc24fca2
@ -8,13 +8,12 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
abi "github.com/filecoin-project/go-state-types/abi"
|
||||
market "github.com/filecoin-project/go-state-types/builtin/v8/market"
|
||||
paych "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
|
@ -8,11 +8,10 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
types "github.com/filecoin-project/lotus/chain/types"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
types "github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
|
@ -8,14 +8,13 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
abi "github.com/filecoin-project/go-state-types/abi"
|
||||
crypto "github.com/filecoin-project/go-state-types/crypto"
|
||||
exitcode "github.com/filecoin-project/go-state-types/exitcode"
|
||||
proof "github.com/filecoin-project/go-state-types/proof"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
|
@ -8,11 +8,10 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
types "github.com/filecoin-project/lotus/chain/types"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
types "github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
@ -20,7 +19,7 @@ var _ = cid.Undef
|
||||
var _ = math.E
|
||||
var _ = sort.Sort
|
||||
|
||||
var lengthBufFvmExecutionTrace = []byte{132}
|
||||
var lengthBufFvmExecutionTrace = []byte{133}
|
||||
|
||||
func (t *FvmExecutionTrace) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
@ -56,6 +55,20 @@ func (t *FvmExecutionTrace) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.GasCharges ([]vm.FvmGasCharge) (slice)
|
||||
if len(t.GasCharges) > cbg.MaxLength {
|
||||
return xerrors.Errorf("Slice value in field t.GasCharges was too long")
|
||||
}
|
||||
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.GasCharges))); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range t.GasCharges {
|
||||
if err := v.MarshalCBOR(cw); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// t.Subcalls ([]vm.FvmExecutionTrace) (slice)
|
||||
if len(t.Subcalls) > cbg.MaxLength {
|
||||
return xerrors.Errorf("Slice value in field t.Subcalls was too long")
|
||||
@ -91,7 +104,7 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
return fmt.Errorf("cbor input should be of type array")
|
||||
}
|
||||
|
||||
if extra != 4 {
|
||||
if extra != 5 {
|
||||
return fmt.Errorf("cbor input had wrong number of fields")
|
||||
}
|
||||
|
||||
@ -143,6 +156,35 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
|
||||
t.Error = string(sval)
|
||||
}
|
||||
// t.GasCharges ([]vm.FvmGasCharge) (slice)
|
||||
|
||||
maj, extra, err = cr.ReadHeader()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if extra > cbg.MaxLength {
|
||||
return fmt.Errorf("t.GasCharges: array too large (%d)", extra)
|
||||
}
|
||||
|
||||
if maj != cbg.MajArray {
|
||||
return fmt.Errorf("expected cbor array")
|
||||
}
|
||||
|
||||
if extra > 0 {
|
||||
t.GasCharges = make([]FvmGasCharge, extra)
|
||||
}
|
||||
|
||||
for i := 0; i < int(extra); i++ {
|
||||
|
||||
var v FvmGasCharge
|
||||
if err := v.UnmarshalCBOR(cr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.GasCharges[i] = v
|
||||
}
|
||||
|
||||
// t.Subcalls ([]vm.FvmExecutionTrace) (slice)
|
||||
|
||||
maj, extra, err = cr.ReadHeader()
|
||||
@ -174,3 +216,175 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var lengthBufFvmGasCharge = []byte{132}
|
||||
|
||||
func (t *FvmGasCharge) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
return err
|
||||
}
|
||||
|
||||
cw := cbg.NewCborWriter(w)
|
||||
|
||||
if _, err := cw.Write(lengthBufFvmGasCharge); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.Name (string) (string)
|
||||
if len(t.Name) > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field t.Name was too long")
|
||||
}
|
||||
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(w, string(t.Name)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.TotalGas (int64) (int64)
|
||||
if t.TotalGas >= 0 {
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TotalGas)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TotalGas-1)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// t.ComputeGas (int64) (int64)
|
||||
if t.ComputeGas >= 0 {
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.ComputeGas)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.ComputeGas-1)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// t.StorageGas (int64) (int64)
|
||||
if t.StorageGas >= 0 {
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.StorageGas)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.StorageGas-1)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *FvmGasCharge) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
*t = FvmGasCharge{}
|
||||
|
||||
cr := cbg.NewCborReader(r)
|
||||
|
||||
maj, extra, err := cr.ReadHeader()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
}()
|
||||
|
||||
if maj != cbg.MajArray {
|
||||
return fmt.Errorf("cbor input should be of type array")
|
||||
}
|
||||
|
||||
if extra != 4 {
|
||||
return fmt.Errorf("cbor input had wrong number of fields")
|
||||
}
|
||||
|
||||
// t.Name (string) (string)
|
||||
|
||||
{
|
||||
sval, err := cbg.ReadString(cr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.Name = string(sval)
|
||||
}
|
||||
// t.TotalGas (int64) (int64)
|
||||
{
|
||||
maj, extra, err := cr.ReadHeader()
|
||||
var extraI int64
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch maj {
|
||||
case cbg.MajUnsignedInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 positive overflow")
|
||||
}
|
||||
case cbg.MajNegativeInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 negative oveflow")
|
||||
}
|
||||
extraI = -1 - extraI
|
||||
default:
|
||||
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
||||
}
|
||||
|
||||
t.TotalGas = int64(extraI)
|
||||
}
|
||||
// t.ComputeGas (int64) (int64)
|
||||
{
|
||||
maj, extra, err := cr.ReadHeader()
|
||||
var extraI int64
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch maj {
|
||||
case cbg.MajUnsignedInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 positive overflow")
|
||||
}
|
||||
case cbg.MajNegativeInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 negative oveflow")
|
||||
}
|
||||
extraI = -1 - extraI
|
||||
default:
|
||||
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
||||
}
|
||||
|
||||
t.ComputeGas = int64(extraI)
|
||||
}
|
||||
// t.StorageGas (int64) (int64)
|
||||
{
|
||||
maj, extra, err := cr.ReadHeader()
|
||||
var extraI int64
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch maj {
|
||||
case cbg.MajUnsignedInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 positive overflow")
|
||||
}
|
||||
case cbg.MajNegativeInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 negative oveflow")
|
||||
}
|
||||
extraI = -1 - extraI
|
||||
default:
|
||||
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
||||
}
|
||||
|
||||
t.StorageGas = int64(extraI)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -49,13 +49,20 @@ type FvmExtern struct {
|
||||
base cid.Cid
|
||||
}
|
||||
|
||||
type FvmGasCharge struct {
|
||||
Name string
|
||||
TotalGas int64
|
||||
ComputeGas int64
|
||||
StorageGas int64
|
||||
}
|
||||
|
||||
// This may eventually become identical to ExecutionTrace, but we can make incremental progress towards that
|
||||
type FvmExecutionTrace struct {
|
||||
Msg *types.Message
|
||||
MsgRct *types.MessageReceipt
|
||||
Error string
|
||||
|
||||
Subcalls []FvmExecutionTrace
|
||||
Msg *types.Message
|
||||
MsgRct *types.MessageReceipt
|
||||
Error string
|
||||
GasCharges []FvmGasCharge `cborgen:"maxlen=1000000000"`
|
||||
Subcalls []FvmExecutionTrace `cborgen:"maxlen=1000000000"`
|
||||
}
|
||||
|
||||
func (t *FvmExecutionTrace) ToExecutionTrace() types.ExecutionTrace {
|
||||
@ -70,6 +77,18 @@ func (t *FvmExecutionTrace) ToExecutionTrace() types.ExecutionTrace {
|
||||
Subcalls: nil, // Should be nil when there are no subcalls for backwards compatibility
|
||||
}
|
||||
|
||||
if len(t.GasCharges) > 0 {
|
||||
ret.GasCharges = make([]*types.GasTrace, len(t.GasCharges))
|
||||
for i, v := range t.GasCharges {
|
||||
ret.GasCharges[i] = &types.GasTrace{
|
||||
Name: v.Name,
|
||||
TotalGas: v.TotalGas,
|
||||
ComputeGas: v.ComputeGas,
|
||||
StorageGas: v.StorageGas,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(t.Subcalls) > 0 {
|
||||
ret.Subcalls = make([]types.ExecutionTrace, len(t.Subcalls))
|
||||
|
||||
|
@ -41,6 +41,7 @@ func main() {
|
||||
|
||||
err = gen.WriteTupleEncodersToFile("./chain/vm/cbor_gen.go", "vm",
|
||||
vm.FvmExecutionTrace{},
|
||||
vm.FvmGasCharge{},
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -8,11 +8,10 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
abi "github.com/filecoin-project/go-state-types/abi"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
abi "github.com/filecoin-project/go-state-types/abi"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
|
@ -8,12 +8,11 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
address "github.com/filecoin-project/go-address"
|
||||
paych "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
address "github.com/filecoin-project/go-address"
|
||||
paych "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
|
@ -8,11 +8,10 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
sealtasks "github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
|
||||
sealtasks "github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
||||
)
|
||||
|
||||
var _ = xerrors.Errorf
|
||||
|
Loading…
Reference in New Issue
Block a user