Skip to content

Commit

Permalink
feat: display msg params in the mpool UI (#1471)
Browse files Browse the repository at this point in the history
* show msg params

* fix: mpool nil pointer

* fix width

---------

Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
  • Loading branch information
LexLuthr and dirkmc authored May 30, 2023
1 parent 9e05810 commit f31a218
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 96 deletions.
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

0 comments on commit f31a218

Please sign in to comment.