Skip to content

Commit

Permalink
feat: add new columns for receipts table (#1248)
Browse files Browse the repository at this point in the history
* Add new columns for receipts
  • Loading branch information
Terryhung authored Jul 27, 2023
1 parent 6490d85 commit a4d5020
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions model/messages/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type Receipt struct {
Idx int `pg:",use_zero"`
ExitCode int64 `pg:",use_zero"`
GasUsed int64 `pg:",use_zero"`

Return []byte
// Result returned from executing a message parsed and serialized as a JSON object.
ParsedReturn string `pg:",type:jsonb"`
}

func (r *Receipt) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error {
Expand Down
14 changes: 14 additions & 0 deletions schemas/v1/29_add_parsed_return_to_receipt_returns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package v1

func init() {
patches.Register(
29,
`
ALTER TABLE {{ .SchemaName | default "public"}}.receipts
ADD COLUMN IF NOT EXISTS "return" bytea;
ALTER TABLE {{ .SchemaName | default "public"}}.receipts
ADD COLUMN IF NOT EXISTS "parsed_return" JSONB;
`,
)
}
11 changes: 11 additions & 0 deletions tasks/messages/receipt/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"

"github.com/filecoin-project/lily/lens/util"
"github.com/filecoin-project/lily/model"
messagemodel "github.com/filecoin-project/lily/model/messages"
visormodel "github.com/filecoin-project/lily/model/visor"
Expand Down Expand Up @@ -50,6 +51,8 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
return nil, report, nil
}

getActorCode, makeActorCodeRuncErr := util.MakeGetActorCodeFunc(ctx, t.node.Store(), current, executed)

var (
receiptResults = make(messagemodel.Receipts, 0, len(blkMsgRect))
errorsDetected = make([]*messages.MessageError, 0, len(blkMsgRect))
Expand Down Expand Up @@ -85,6 +88,14 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
Idx: index,
ExitCode: int64(rec.ExitCode),
GasUsed: rec.GasUsed,
Return: rec.Return,
}
toCode, found := getActorCode(ctx, msg.VMMessage().To)
if found && rec.ExitCode.IsSuccess() && makeActorCodeRuncErr == nil {
parsedReturn, _, err := util.ParseReturn(rec.Return, msg.VMMessage().Method, toCode)
if err == nil {
rcpt.ParsedReturn = parsedReturn
}
}
receiptResults = append(receiptResults, rcpt)
}
Expand Down

0 comments on commit a4d5020

Please sign in to comment.