Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Aug 25, 2022
1 parent 0aa04d3 commit f3d0d2e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion chain/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (t *DataSource) MinerLoad(store adt.Store, act *types.Actor) (miner.State,
return miner.Load(store, act)
}

func (t *DataSource) ShouldBrunFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error) {
func (t *DataSource) ShouldBurnFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error) {
return t.node.BurnFundsFn(ctx, ts)
}

Expand Down
37 changes: 23 additions & 14 deletions lens/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,47 @@ type BlockMessages struct {
SecpMessages []*types.SignedMessage // SECP messages in block `Block`
}

// BlockMessageReceipts contains a block its messages and their corresponding receipts.
// The Receipts are one-to-one with Messages index.
type BlockMessageReceipts struct {
Block *types.BlockHeader
Message []types.ChainMsg
Receipt []*types.MessageReceipt
Block *types.BlockHeader
// Messages contained in Block.
Messages []types.ChainMsg
// Receipts contained in Block.
Receipts []*types.MessageReceipt
// MessageExectionIndex contains a mapping of Messages to their execution order in the tipset they were included.
MessageExecutionIndex map[types.ChainMsg]int
}

type MessageReceiptIterator struct {
idx int
msgs []types.ChainMsg
receipts []*types.MessageReceipt
exeIdx map[types.ChainMsg]int
}

// Iterator returns a MessageReceiptIterator to conveniently iterate messages, their execution index, and their respective receipts.
func (bmr *BlockMessageReceipts) Iterator() (*MessageReceiptIterator, error) {
if len(bmr.Message) != len(bmr.Receipt) {
return nil, fmt.Errorf("invalid construction, expected equal number receipts (%d) and messages (%d)", len(bmr.Receipt), len(bmr.Message))
if len(bmr.Messages) != len(bmr.Receipts) {
return nil, fmt.Errorf("invalid construction, expected equal number receipts (%d) and messages (%d)", len(bmr.Receipts), len(bmr.Messages))
}
return &MessageReceiptIterator{
idx: 0,
msgs: bmr.Message,
receipts: bmr.Receipt,
msgs: bmr.Messages,
receipts: bmr.Receipts,
exeIdx: bmr.MessageExecutionIndex,
}, nil
}

type MessageReceiptIterator struct {
idx int
msgs []types.ChainMsg
receipts []*types.MessageReceipt
exeIdx map[types.ChainMsg]int
}

// HasNext returns `true` while there are messages/receipts to iterate.
func (mri *MessageReceiptIterator) HasNext() bool {
if mri.idx < len(mri.msgs) {
return true
}
return false
}

// Next returns the next message, its execution index, and receipt in the MessageReceiptIterator.
func (mri *MessageReceiptIterator) Next() (types.ChainMsg, int, *types.MessageReceipt) {
if mri.HasNext() {
msg := mri.msgs[mri.idx]
Expand All @@ -135,6 +143,7 @@ func (mri *MessageReceiptIterator) Next() (types.ChainMsg, int, *types.MessageRe
return nil, -1, nil
}

// Reset resets the MessageReceiptIterator to the first message/receipt.
func (mri *MessageReceiptIterator) Reset() {
mri.idx = 0
}
24 changes: 17 additions & 7 deletions lens/lily/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@ func (m *LilyNodeAPI) MessagesForTipSetBlocks(ctx context.Context, ts *types.Tip

// TipSetMessageReceipts returns the blocks and messages in `pts` and their corresponding receipts from `ts` matching block order in tipset (`pts`).
func (m *LilyNodeAPI) TipSetMessageReceipts(ctx context.Context, ts, pts *types.TipSet) ([]*lens.BlockMessageReceipts, error) {
// sanity check args
if ts.Key().IsEmpty() {
return nil, fmt.Errorf("tipset cannot be empty")
}
if pts.Key().IsEmpty() {
return nil, fmt.Errorf("parent tipset cannot be empty")
}
if !types.CidArrsEqual(ts.Parents().Cids(), pts.Cids()) {
return nil, fmt.Errorf("mismatching tipset (%s) and parent tipset (%s)", ts.Key().String(), pts.Key().String())
}
// returned BlockMessages match block order in tipset
blkMsgs, err := m.ChainAPI.Chain.BlockMsgsForTipset(ctx, pts)
if err != nil {
Expand Down Expand Up @@ -597,7 +607,7 @@ func (m *LilyNodeAPI) TipSetMessageReceipts(ctx context.Context, ts, pts *types.
return nil, fmt.Errorf("loading message receipts %w", err)
}
}
// so we only load the receipt array one
// so we only load the receipt array once
getReceipt := func(idx int) (*types.MessageReceipt, error) {
var r types.MessageReceipt
if found, err := rs.Get(uint64(idx), &r); err != nil {
Expand All @@ -622,9 +632,9 @@ func (m *LilyNodeAPI) TipSetMessageReceipts(ctx context.Context, ts, pts *types.
// block containing messages
Block: pts.Blocks()[blkIdx],
// total messages returned equal to sum of bls and secp messages
Message: make([]types.ChainMsg, len(msgs.BlsMessages)+len(msgs.SecpkMessages)),
Messages: make([]types.ChainMsg, len(msgs.BlsMessages)+len(msgs.SecpkMessages)),
// total receipts returned equal to sum of bls and secp messages
Receipt: make([]*types.MessageReceipt, len(msgs.BlsMessages)+len(msgs.SecpkMessages)),
Receipts: make([]*types.MessageReceipt, len(msgs.BlsMessages)+len(msgs.SecpkMessages)),
// index of message indicating execution order.
MessageExecutionIndex: make(map[types.ChainMsg]int),
}
Expand All @@ -634,8 +644,8 @@ func (m *LilyNodeAPI) TipSetMessageReceipts(ctx context.Context, ts, pts *types.
if err != nil {
return nil, err
}
out[blkIdx].Message[msgIdx] = msgs.BlsMessages[blsIdx]
out[blkIdx].Receipt[receiptIdx] = receipt
out[blkIdx].Messages[msgIdx] = msgs.BlsMessages[blsIdx]
out[blkIdx].Receipts[receiptIdx] = receipt
out[blkIdx].MessageExecutionIndex[msgs.BlsMessages[blsIdx]] = executionIndex
msgIdx++
receiptIdx++
Expand All @@ -647,8 +657,8 @@ func (m *LilyNodeAPI) TipSetMessageReceipts(ctx context.Context, ts, pts *types.
if err != nil {
return nil, err
}
out[blkIdx].Message[msgIdx] = msgs.SecpkMessages[secpIdx]
out[blkIdx].Receipt[receiptIdx] = receipt
out[blkIdx].Messages[msgIdx] = msgs.SecpkMessages[secpIdx]
out[blkIdx].Receipts[receiptIdx] = receipt
out[blkIdx].MessageExecutionIndex[msgs.SecpkMessages[secpIdx]] = executionIndex
msgIdx++
receiptIdx++
Expand Down
2 changes: 1 addition & 1 deletion tasks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ type DataSource interface {

MinerLoad(store adt.Store, act *types.Actor) (miner.State, error)

ShouldBrunFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error)
ShouldBurnFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error)
}
2 changes: 1 addition & 1 deletion tasks/messages/gasoutput/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
var burnFn lens.ShouldBurnFn
grp.Go(func() error {
var err error
burnFn, err = t.node.ShouldBrunFn(grpCtx, executed)
burnFn, err = t.node.ShouldBurnFn(grpCtx, executed)
if err != nil {
return fmt.Errorf("getting should burn function: %w", err)
}
Expand Down

0 comments on commit f3d0d2e

Please sign in to comment.