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

fix: use builtin lotus method to get events #1137

Merged
merged 1 commit into from
Feb 17, 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
4 changes: 4 additions & 0 deletions chain/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ type DataSource struct {
diffPreCommitGroup singleflight.Group
}

func (t *DataSource) MessageReceiptEvents(ctx context.Context, root cid.Cid) ([]types.Event, error) {
return t.node.ChainGetEvents(ctx, root)
}

func (t *DataSource) ComputeBaseFee(ctx context.Context, ts *types.TipSet) (abi.TokenAmount, error) {
return t.node.ComputeBaseFee(ctx, ts)
}
Expand Down
3 changes: 3 additions & 0 deletions lens/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type ChainAPI interface {

MessagesForTipSetBlocks(ctx context.Context, ts *types.TipSet) ([]*BlockMessages, error)
TipSetMessageReceipts(ctx context.Context, ts, pts *types.TipSet) ([]*BlockMessageReceipts, error)

// added during hyperspace
ChainGetEvents(ctx context.Context, root cid.Cid) ([]types.Event, error)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

}

type StateAPI interface {
Expand Down
2 changes: 2 additions & 0 deletions tasks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/lily/chain/actors/adt"
"github.com/filecoin-project/lily/chain/actors/builtin/miner"
Expand Down Expand Up @@ -58,6 +59,7 @@ type DataSource interface {
TipSetBlockMessages(ctx context.Context, ts *types.TipSet) ([]*lens.BlockMessages, error)

TipSetMessageReceipts(ctx context.Context, ts, pts *types.TipSet) ([]*lens.BlockMessageReceipts, error)
MessageReceiptEvents(ctx context.Context, root cid.Cid) ([]types.Event, error)

DiffSectors(ctx context.Context, addr address.Address, ts, pts *types.TipSet, pre, cur miner.State) (*miner.SectorChanges, error)
DiffPreCommits(ctx context.Context, addr address.Address, ts, pts *types.TipSet, pre, cur miner.State) (*miner.PreCommitChanges, error)
Expand Down
51 changes: 16 additions & 35 deletions tasks/messages/actorevent/task.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package actorevent

import (
"bytes"
"context"
"fmt"
"math"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-amt-ipld/v4"
"github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/xerrors"

"github.com/filecoin-project/lily/model"
messagemodel "github.com/filecoin-project/lily/model/messages"
Expand Down Expand Up @@ -85,29 +80,25 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
continue
}

evtArr, err := amt.LoadAMT(ctx, t.node.Store(), *rec.EventsRoot, amt.UseTreeBitWidth(types.EventAMTBitwidth))
events, err := t.node.MessageReceiptEvents(ctx, *rec.EventsRoot)
if err != nil {
report.ErrorsDetected = fmt.Errorf("loading actor events amt (%s): %w", *rec.EventsRoot, err)
return nil, report, nil
errorsDetected = append(errorsDetected, &messages.MessageError{
Cid: msg.Cid(),
Error: fmt.Sprintf("failed to get receipt events: %s", err),
})
continue
}
var evt types.Event
err = evtArr.ForEach(ctx, func(evtIdx uint64, deferred *cbg.Deferred) error {
if evtIdx > math.MaxInt {
return xerrors.Errorf("too many events")
}
if err := evt.UnmarshalCBOR(bytes.NewReader(deferred.Raw)); err != nil {
return err
}

emitter, err := address.NewIDAddress(uint64(evt.Emitter))
if err != nil {
errorsDetected = append(errorsDetected, &messages.MessageError{
Cid: msg.Cid(),
Error: fmt.Sprintf("failed to make ID address from event emitter (%s): %s", evt.Emitter, err),
})
return err
}
for _, e := range evt.Entries {
for evtIdx, event := range events {
for _, e := range event.Entries {
emitter, err := address.NewIDAddress(uint64(event.Emitter))
if err != nil {
errorsDetected = append(errorsDetected, &messages.MessageError{
Cid: msg.Cid(),
Error: fmt.Sprintf("failed to make ID address from event emitter (%s): %s", event.Emitter, err),
})
continue
}
out = append(out, &messagemodel.ActorEvent{
Height: int64(current.Height()),
StateRoot: current.ParentState().String(),
Expand All @@ -119,19 +110,9 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
Value: e.Value,
})
}
return nil
})

if err != nil {
errorsDetected = append(errorsDetected, &messages.MessageError{
Cid: msg.Cid(),
Error: fmt.Sprintf("loading actor events amt (%s): %s", *rec.EventsRoot, err),
})
continue
}
}
}

if len(errorsDetected) != 0 {
report.ErrorsDetected = errorsDetected
}
Expand Down