Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display msg params in the mpool UI #1471

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 19 additions & 95 deletions gql/resolver_mpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"reflect"

"github.com/filecoin-project/lotus/chain/consensus"
cbg "github.com/whyrusleeping/cbor-gen"

gqltypes "github.com/filecoin-project/boost/gql/types"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
stbig "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
)

type msg struct {
Expand Down Expand Up @@ -65,22 +64,24 @@ func (r *resolver) Mpool(ctx context.Context, args struct{ Local bool }) ([]*msg
}
}

method := m.Message.Method.String()
var params string
methodName := m.Message.Method.String()
toact, err := r.fullNode.StateGetActor(ctx, m.Message.To, types.EmptyTSK)
if err == nil {
method = consensus.NewActorRegistry().Methods[toact.Code][m.Message.Method].Name
}

var params string
paramsMsg, err := messageFromBytes(m.Message.Params)
if err != nil {
params = err.Error()
} else {
paramsBytes, err := json.MarshalIndent(paramsMsg, "", " ")
if err != nil {
params = err.Error()
} else {
params = string(paramsBytes)
method, ok := consensus.NewActorRegistry().Methods[toact.Code][m.Message.Method]
if ok {
methodName = method.Name

params = string(m.Message.Params)
p, ok := reflect.New(method.Params.Elem()).Interface().(cbg.CBORUnmarshaler)
if ok {
if err := p.UnmarshalCBOR(bytes.NewReader(m.Message.Params)); err == nil {
b, err := json.MarshalIndent(p, "", " ")
if err == nil {
params = string(b)
}
}
}
}
}

Expand All @@ -92,7 +93,7 @@ func (r *resolver) Mpool(ctx context.Context, args struct{ Local bool }) ([]*msg
GasFeeCap: gqltypes.BigInt{Int: m.Message.GasFeeCap},
GasLimit: gqltypes.Uint64(uint64(m.Message.GasLimit)),
GasPremium: gqltypes.BigInt{Int: m.Message.GasPremium},
Method: method,
Method: methodName,
Params: params,
BaseFee: gqltypes.BigInt{Int: baseFee},
})
Expand All @@ -101,83 +102,6 @@ func (r *resolver) Mpool(ctx context.Context, args struct{ Local bool }) ([]*msg
return gqlmsgs, nil
}

func messageFromBytes(msgb []byte) (types.ChainMsg, error) {
// Signed
{
var msg types.SignedMessage
if err := msg.UnmarshalCBOR(bytes.NewReader(msgb)); err == nil {
return &msg, nil
}
}

// Unsigned
{
var msg types.Message
if err := msg.UnmarshalCBOR(bytes.NewReader(msgb)); err == nil {
return &msg, nil
}
}

// Multisig propose?
{
var pp multisig.ProposeParams
if err := pp.UnmarshalCBOR(bytes.NewReader(msgb)); err == nil {
i, err := address.NewIDAddress(0)
if err != nil {
return nil, err
}

return &types.Message{
// Hack(-ish)
Version: 0x6d736967,
From: i,

To: pp.To,
Value: pp.Value,

Method: pp.Method,
Params: pp.Params,

GasFeeCap: stbig.Zero(),
GasPremium: stbig.Zero(),
}, nil
}
}

// Encoded json???
{
if msg, err := messageFromJson(msgb); err == nil {
return msg, nil
}
}

return nil, errors.New("probably not a cbor-serialized message")
}

func messageFromJson(msgb []byte) (types.ChainMsg, error) {
// Unsigned
{
var msg types.Message
if err := json.Unmarshal(msgb, &msg); err == nil {
if msg.To != address.Undef {
return &msg, nil
}
}
}

// Signed
{
var msg types.SignedMessage
if err := json.Unmarshal(msgb, &msg); err == nil {
if msg.Message.To != address.Undef {
return &msg, nil
}
}
}

return nil, errors.New("probably not a json-serialized message")
}

func mockMessages() []*types.SignedMessage {
to0, _ := address.NewFromString("f01469945")
from0, _ := address.NewFromString("f3uakndzne4lorwykinlitx2d2puuhgburvxw4dpkfskeofmzg33pm7okyzikqe2gzvaqj2k3hpunwayij6haa")
Expand Down
15 changes: 15 additions & 0 deletions react/src/Mpool.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,19 @@
left: 1.5em;
border-left: 1px solid #000;
height: 0.5em;
}

.mpool .params{
width: 1080px;
text-overflow: ellipsis;
cursor: pointer;
word-break: break-all;
overflow: hidden;
white-space: nowrap;
}

.mpool .params:hover{
overflow: visible;
white-space: normal;
width: auto;
}
4 changes: 3 additions & 1 deletion react/src/Mpool.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ function MpoolMessage(props) {
</tr>
<tr key={i+"params"}>
<td>Params</td>
<td>{msg.Params}</td>
<td>
<div className="params">{msg.Params}</div>
</td>
</tr>
<tr key={i+"gas-fee-cap"}>
<td>Gas Fee Cap</td>
Expand Down