From 4107c49db2ca06c05372b72890b10661135a3d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 6 Oct 2019 02:37:28 +0200 Subject: [PATCH] pond: Fix block explorer after stateroot refactor --- api/api.go | 7 ++++++- api/struct.go | 4 ++-- cli/chain.go | 13 +++++++++++-- lotuspond/front/src/App.css | 2 +- lotuspond/front/src/Block.js | 21 +++++++-------------- lotuspond/front/src/ChainExplorer.js | 4 ++-- node/impl/full/chain.go | 9 ++++++--- 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/api/api.go b/api/api.go index 758ed2de9..d40f2dc76 100644 --- a/api/api.go +++ b/api/api.go @@ -55,7 +55,7 @@ type FullNode interface { ChainGetBlock(context.Context, cid.Cid) (*types.BlockHeader, error) ChainGetBlockMessages(context.Context, cid.Cid) (*BlockMessages, error) ChainGetParentReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error) - ChainGetParentMessages(context.Context, cid.Cid) ([]cid.Cid, error) + ChainGetParentMessages(context.Context, cid.Cid) ([]Message, error) ChainGetTipSetByHeight(context.Context, uint64, *types.TipSet) (*types.TipSet, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error) @@ -202,6 +202,11 @@ type BlockMessages struct { Cids []cid.Cid } +type Message struct { + Cid cid.Cid + Message *types.Message +} + type SectorInfo struct { SectorID uint64 CommD []byte diff --git a/api/struct.go b/api/struct.go index 983a55f09..25b3cbee8 100644 --- a/api/struct.go +++ b/api/struct.go @@ -45,7 +45,7 @@ type FullNodeStruct struct { ChainGetBlock func(context.Context, cid.Cid) (*types.BlockHeader, error) `perm:"read"` ChainGetBlockMessages func(context.Context, cid.Cid) (*BlockMessages, error) `perm:"read"` ChainGetParentReceipts func(context.Context, cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"` - ChainGetParentMessages func(context.Context, cid.Cid) ([]cid.Cid, error) `perm:"read"` + ChainGetParentMessages func(context.Context, cid.Cid) ([]Message, error) `perm:"read"` ChainGetTipSetByHeight func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) `perm:"read"` ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"` @@ -284,7 +284,7 @@ func (c *FullNodeStruct) ChainGetParentReceipts(ctx context.Context, b cid.Cid) return c.Internal.ChainGetParentReceipts(ctx, b) } -func (c *FullNodeStruct) ChainGetParentMessages(ctx context.Context, b cid.Cid) ([]cid.Cid, error) { +func (c *FullNodeStruct) ChainGetParentMessages(ctx context.Context, b cid.Cid) ([]Message, error) { return c.Internal.ChainGetParentMessages(ctx, b) } diff --git a/cli/chain.go b/cli/chain.go index 4eef95f5e..984d55828 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -4,11 +4,12 @@ import ( "encoding/json" "fmt" + cid "github.com/ipfs/go-cid" "golang.org/x/xerrors" "gopkg.in/urfave/cli.v2" + "github.com/filecoin-project/go-lotus/api" types "github.com/filecoin-project/go-lotus/chain/types" - cid "github.com/ipfs/go-cid" ) var chainCmd = &cli.Command{ @@ -113,7 +114,7 @@ var chainGetBlock = &cli.Command{ cblock.BlsMessages = msgs.BlsMessages cblock.SecpkMessages = msgs.SecpkMessages cblock.ParentReceipts = recpts - cblock.ParentMessages = pmsgs + cblock.ParentMessages = apiMsgCids(pmsgs) out, err := json.MarshalIndent(cblock, "", " ") if err != nil { @@ -126,6 +127,14 @@ var chainGetBlock = &cli.Command{ }, } +func apiMsgCids(in []api.Message) []cid.Cid { + out := make([]cid.Cid, len(in)) + for k, v := range in { + out[k] = v.Cid + } + return out +} + var chainReadObjCmd = &cli.Command{ Name: "read-obj", Usage: "Read the raw bytes of an object", diff --git a/lotuspond/front/src/App.css b/lotuspond/front/src/App.css index 5a7a99095..bb6440036 100644 --- a/lotuspond/front/src/App.css +++ b/lotuspond/front/src/App.css @@ -168,7 +168,7 @@ a:hover { .Block { user-select: text; font-family: monospace; - min-width: 50em; + min-width: 60em; display: inline-block; } diff --git a/lotuspond/front/src/Block.js b/lotuspond/front/src/Block.js index 5ccb36b59..28ef69b42 100644 --- a/lotuspond/front/src/Block.js +++ b/lotuspond/front/src/Block.js @@ -14,21 +14,14 @@ class Block extends React.Component { async loadHeader() { const header = await this.props.conn.call('Filecoin.ChainGetBlock', [this.props.cid]) - let messages = await this.props.conn.call('Filecoin.ChainGetBlockMessages', [this.props.cid]) - let receipts = await this.props.conn.call('Filecoin.ChainGetBlockReceipts', [this.props.cid]) + let messages = await this.props.conn.call('Filecoin.ChainGetParentMessages', [this.props.cid]) + let receipts = await this.props.conn.call('Filecoin.ChainGetParentReceipts', [this.props.cid]) - const mcids = messages.Cids - - messages = [ - ...(messages.BlsMessages.map(m => ({...m, type: 'BLS'}))), - ...(messages.SecpkMessages.map(m => ({...(m.Message), type: 'Secpk'}))) - ] - - messages = messages.map((msg, k) => ({...msg, receipt: receipts[k]})) + messages = messages.map((msg, k) => ({...msg.Message, cid: msg.Cid, receipt: receipts[k]})) messages = await Promise.all(messages.map(async (msg, i) => { if (msg.receipt.ExitCode !== 0) { - let reply = await this.props.conn.call('Filecoin.StateReplay', [{Cids: [this.props.cid], Blocks: [header], Height: header.Height}, mcids[i]]) + let reply = await this.props.conn.call('Filecoin.StateReplay', [{Cids: [this.props.cid], Blocks: [header], Height: header.Height}, msg.Cid]) if(!reply.Error) { reply.Error = "reply: no error" } @@ -65,15 +58,15 @@ class Block extends React.Component {
Weight: {head.ParentWeight}
Miner: {
}
Messages: {head.Messages['/']} {/*TODO: link to message explorer */}
-
Receipts: {head.MessageReceipts['/']}
-
State Root: {head.StateRoot['/']}
+
Parent Receipts: {head.ParentMessageReceipts['/']}
+
Parent State Root: {head.ParentStateRoot['/']}
----
{messages}
) } - return ( + return ( {content} ) } diff --git a/lotuspond/front/src/ChainExplorer.js b/lotuspond/front/src/ChainExplorer.js index 5aa6dbf06..6520d74ed 100644 --- a/lotuspond/front/src/ChainExplorer.js +++ b/lotuspond/front/src/ChainExplorer.js @@ -38,7 +38,7 @@ class ChainExplorer extends React.Component { } async updateMessages(cids, msgcache) { - const msgs = await Promise.all(cids.map(async cid => [cid['/'], await this.props.client.call('Filecoin.ChainGetBlockMessages', [cid])])) + const msgs = await Promise.all(cids.map(async cid => [cid['/'], await this.props.client.call('Filecoin.ChainGetParentMessages', [cid])])) msgs.forEach(([cid, msg]) => msgcache[cid] = msg) } @@ -118,7 +118,7 @@ class ChainExplorer extends React.Component { let msgc = -1 if(ts.Cids[0] && this.state.messages[ts.Cids[0]['/']]) { // TODO: get from all blks - msgc = this.state.messages[ts.Cids[0]['/']].SecpkMessages.length + this.state.messages[ts.Cids[0]['/']].BlsMessages.length + msgc = this.state.messages[ts.Cids[0]['/']].length } if(msgc > 0) { msgc = {msgc} diff --git a/node/impl/full/chain.go b/node/impl/full/chain.go index 29814cbd8..5def261ae 100644 --- a/node/impl/full/chain.go +++ b/node/impl/full/chain.go @@ -91,7 +91,7 @@ func (a *ChainAPI) ChainGetBlockMessages(ctx context.Context, msg cid.Cid) (*api }, nil } -func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]cid.Cid, error) { +func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]api.Message, error) { b, err := a.Chain.GetBlock(bcid) if err != nil { return nil, err @@ -113,9 +113,12 @@ func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([] return nil, err } - var out []cid.Cid + var out []api.Message for _, m := range cm { - out = append(out, m.Cid()) + out = append(out, api.Message{ + Cid: m.Cid(), + Message: m.VMMessage(), + }) } return out, nil