Merge pull request #291 from filecoin-project/fix/blockviewer
pond: Fix block explorer after stateroot refactor
This commit is contained in:
commit
8618e724ed
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
13
cli/chain.go
13
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",
|
||||
|
@ -168,7 +168,7 @@ a:hover {
|
||||
.Block {
|
||||
user-select: text;
|
||||
font-family: monospace;
|
||||
min-width: 50em;
|
||||
min-width: 60em;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
<div>Weight: {head.ParentWeight}</div>
|
||||
<div>Miner: {<Address client={this.props.conn} addr={head.Miner} mountWindow={this.props.mountWindow}/>}</div>
|
||||
<div>Messages: {head.Messages['/']} {/*TODO: link to message explorer */}</div>
|
||||
<div>Receipts: {head.MessageReceipts['/']}</div>
|
||||
<div>State Root: {head.StateRoot['/']}</div>
|
||||
<div>Parent Receipts: {head.ParentMessageReceipts['/']}</div>
|
||||
<div>Parent State Root: {head.ParentStateRoot['/']}</div>
|
||||
<div>----</div>
|
||||
<div>{messages}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (<Window className="CristalScroll" initialSize={{width: 700, height: 400}} onClose={this.props.onClose} title={`Block ${this.props.cid['/']}`}>
|
||||
return (<Window className="CristalScroll" initialSize={{width: 850, height: 400}} onClose={this.props.onClose} title={`Block ${this.props.cid['/']}`}>
|
||||
{content}
|
||||
</Window>)
|
||||
}
|
||||
|
@ -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 = <b>{msgc}</b>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user