Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
feat: null receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Sep 8, 2020
1 parent 00cc255 commit 7c115c4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
19 changes: 12 additions & 7 deletions gen/builders/builder_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,32 @@ func (b *MessageVectorBuilder) CommitApplies() {

for _, am := range b.Messages.All() {
// apply all messages that are pending application.
if am.Result == nil {
if !am.Applied {
b.StateTracker.ApplyMessage(am)
}

b.vector.ApplyMessages = append(b.vector.ApplyMessages, schema.Message{
Bytes: MustSerialize(am.Message),
Epoch: &am.Epoch,
})
b.vector.Post.Receipts = append(b.vector.Post.Receipts, &schema.Receipt{
ExitCode: am.Result.ExitCode,
ReturnValue: am.Result.Return,
GasUsed: am.Result.GasUsed,
})

// am.Result may still be nil if the message failed to be applied
if am.Result != nil {
b.vector.Post.Receipts = append(b.vector.Post.Receipts, &schema.Receipt{
ExitCode: am.Result.ExitCode,
ReturnValue: am.Result.Return,
GasUsed: am.Result.GasUsed,
})
} else {
b.vector.Post.Receipts = append(b.vector.Post.Receipts, nil)
}
}

// update the internal state.
b.PostRoot = b.StateTracker.CurrRoot
b.vector.Post.StateTree = &schema.StateTree{RootCID: b.PostRoot}
b.Stage = StageChecks
b.Assert.enterStage(StageChecks)

}

// Finish signals to the builder that the checks stage is complete and that the
Expand Down
4 changes: 4 additions & 0 deletions gen/builders/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type ApplicableMessage struct {
Epoch abi.ChainEpoch
Message *types.Message
Result *vm.ApplyRet
// Applied is true if this message has already been applied. Note it's
// not safe to rely on non-nil Result as indication of application
// since applied messages may fail without a result.
Applied bool
}

func (m *Messages) Sugar() *sugarMsg {
Expand Down
14 changes: 8 additions & 6 deletions gen/builders/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ func MessageReturns(expect cbg.CBORMarshaler) ApplyRetPredicate {
}
}

// PanickedRet represents a non-return value, a placeholder for when an actor panicked while applying a message.
var PanickedRet = vm.ApplyRet{}

// Panicked returns an ApplyRetPredicate that passes if the message response is the PanickedRet.
func Panicked() ApplyRetPredicate {
return MessageReturns(&PanickedRet)
// Nil returns an ApplyRetPredicate that passes if the message receipt is nil.
func Nil() ApplyRetPredicate {
return func(ret *vm.ApplyRet) error {
if ret != nil {
return fmt.Errorf("message receipt was not nil: %+v", ret)
}
return nil
}
}

// BalanceUpdated returns a ActorPredicate that checks whether the balance
Expand Down
10 changes: 8 additions & 2 deletions gen/builders/state_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ func (st *StateTracker) Flush() cid.Cid {
// root, refreshes the state tree, and updates the underlying vector with the
// message and its receipt.
func (st *StateTracker) ApplyMessage(am *ApplicableMessage) {
var postRoot cid.Cid
var err error
am.Result, st.CurrRoot, err = st.Driver.ExecuteMessage(st.Stores.Blockstore, st.CurrRoot, am.Epoch, am.Message)
st.bc.Assert.NoError(err)

am.Applied = true
am.Result, postRoot, err = st.Driver.ExecuteMessage(st.Stores.Blockstore, st.CurrRoot, am.Epoch, am.Message)
if err != nil {
return
}

st.CurrRoot = postRoot
// replace the state tree.
st.StateTree, err = state.LoadStateTree(st.Stores.CBORStore, st.CurrRoot)
st.bc.Assert.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion gen/suites/vm_violations/actor_abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ func actorPanic(msg string) func(*MessageVectorBuilder) {
)
v.CommitApplies()

v.Assert.LastMessageResultSatisfies(Panicked())
v.Assert.LastMessageResultSatisfies(Nil())
}
}
9 changes: 8 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@
"type": "array",
"additionalItems": false,
"items": {
"$ref": "#/definitions/receipt"
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/receipt"
}
]
}
},
"receipts_roots": {
Expand Down

0 comments on commit 7c115c4

Please sign in to comment.