Skip to content

Commit

Permalink
events: version the MessageReceipt structure.
Browse files Browse the repository at this point in the history
This is implemented as an internal version discriminator. An alternative
would've been to turn MessageReceipt into an interface with two backing
structs for v0 and v1. But that approach would've broken all usage sites.

CBOR serde for MessageReceipt is no longer automatically generated. We
use custom logic to deal with versioning in both directions. This logic
uses the cborgen serde code as a basis.
  • Loading branch information
raulk committed Nov 14, 2022
1 parent 4eccf30 commit 3954733
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 195 deletions.
184 changes: 0 additions & 184 deletions chain/types/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 35 additions & 2 deletions chain/types/message_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,52 @@ package types
import (
"bytes"

"github.com/filecoin-project/go-state-types/exitcode"
"github.com/ipfs/go-cid"
)

"github.com/filecoin-project/go-state-types/exitcode"
type MessageReceiptVersion byte

const (
// MessageReceiptVersion0 refers to pre FIP-0049 receipts.
MessageReceiptVersion0 MessageReceiptVersion = 0
// MessageReceiptVersion1 refers to post FIP-0049 receipts.
MessageReceiptVersion1 MessageReceiptVersion = 1
)

type MessageReceipt struct {
version MessageReceiptVersion

ExitCode exitcode.ExitCode
Return []byte
GasUsed int64
EventsRoot *cid.Cid // Root of Event AMT
}

// NewMessageReceiptV0 creates a new pre FIP-0049 receipt with no capability to
// convey events.
func NewMessageReceiptV0(exitcode exitcode.ExitCode, ret []byte, gasUsed int64) MessageReceipt {
return MessageReceipt{
version: MessageReceiptVersion0,
ExitCode: exitcode,
Return: ret,
GasUsed: gasUsed,
}
}

// NewMessageReceiptV1 creates a new pre FIP-0049 receipt with the ability to
// convey events.
func NewMessageReceiptV1(exitcode exitcode.ExitCode, ret []byte, gasUsed int64, eventsRoot *cid.Cid) MessageReceipt {
return MessageReceipt{
version: MessageReceiptVersion1,
ExitCode: exitcode,
Return: ret,
GasUsed: gasUsed,
EventsRoot: eventsRoot,
}
}

func (mr *MessageReceipt) Equals(o *MessageReceipt) bool {
return mr.ExitCode == o.ExitCode && bytes.Equal(mr.Return, o.Return) && mr.GasUsed == o.GasUsed &&
return mr.version == mr.version && mr.ExitCode == o.ExitCode && bytes.Equal(mr.Return, o.Return) && mr.GasUsed == o.GasUsed &&
(mr.EventsRoot == o.EventsRoot || (mr.EventsRoot != nil && o.EventsRoot != nil && *mr.EventsRoot == *o.EventsRoot))
}
Loading

0 comments on commit 3954733

Please # to comment.