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

feat: add apply_message_failures post condition #138

Merged
merged 3 commits into from
Sep 11, 2020
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
19 changes: 11 additions & 8 deletions gen/builders/builder_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (b *MessageVectorBuilder) CommitApplies() {
panic("called CommitApplies at the wrong time")
}

for _, am := range b.Messages.All() {
for i, am := range b.Messages.All() {
// apply all messages that are pending application.
if !am.Applied {
b.StateTracker.ApplyMessage(am)
Expand All @@ -113,16 +113,19 @@ func (b *MessageVectorBuilder) CommitApplies() {
Epoch: &epoch,
})

// 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{
if am.Failed {
b.vector.Post.ApplyMessageFailures = append(b.vector.Post.ApplyMessageFailures, i)
}

var receipt *schema.Receipt
if !am.Failed {
receipt = &schema.Receipt{
ExitCode: int64(am.Result.ExitCode),
ReturnValue: am.Result.Return,
GasUsed: am.Result.GasUsed,
})
} else {
b.vector.Post.Receipts = append(b.vector.Post.Receipts, nil)
}
}
b.vector.Post.Receipts = append(b.vector.Post.Receipts, receipt)
}

// update the internal state.
Expand Down Expand Up @@ -152,7 +155,7 @@ func (b *MessageVectorBuilder) Finish(w io.Writer) {
msgs := b.Messages.All()
traces := make([]types.ExecutionTrace, 0, len(msgs))
for _, msg := range msgs {
if msg.Result != nil {
if !msg.Failed {
traces = append(traces, msg.Result.ExecutionTrace)
}
}
Expand Down
3 changes: 3 additions & 0 deletions gen/builders/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type ApplicableMessage struct {
// not safe to rely on non-nil Result as indication of application
// since applied messages may fail without a result.
Applied bool
// Failed is true if this message was attempted to be applied and failed.
// In this case ApplicableMessage.Result will be nil.
Failed bool
}

func (m *Messages) Sugar() *sugarMsg {
Expand Down
25 changes: 12 additions & 13 deletions gen/builders/messages_typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/actors/runtime/proof"
"github.com/filecoin-project/specs-actors/actors/util/adt"

"github.com/filecoin-project/go-address"
)
Expand All @@ -37,7 +36,7 @@ func AccountConstructor(params *address.Address) TypedCall {
}
}

func AccountPubkeyAddress(params *adt.EmptyValue) TypedCall {
func AccountPubkeyAddress(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsAccount.PubkeyAddress, MustSerialize(params)
}
Expand All @@ -47,7 +46,7 @@ func AccountPubkeyAddress(params *adt.EmptyValue) TypedCall {
// | MARKET
// ----------------------------------------------------------------------------

func MarketConstructor(params *adt.EmptyValue) TypedCall {
func MarketConstructor(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsMarket.Constructor, MustSerialize(params)
}
Expand Down Expand Up @@ -88,7 +87,7 @@ func MarketComputeDataCommitment(params *market.ComputeDataCommitmentParams) Typ
return builtin.MethodsMarket.ComputeDataCommitment, MustSerialize(params)
}
}
func MarketCronTick(params *adt.EmptyValue) TypedCall {
func MarketCronTick(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsMarket.CronTick, MustSerialize(params)
}
Expand All @@ -103,7 +102,7 @@ func MinerConstructor(params *power.MinerConstructorParams) TypedCall {
return builtin.MethodsMiner.Constructor, MustSerialize(params)
}
}
func MinerControlAddresses(params *adt.EmptyValue) TypedCall {
func MinerControlAddresses(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsMiner.ControlAddresses, MustSerialize(params)
}
Expand Down Expand Up @@ -238,7 +237,7 @@ func MultisigChangeNumApprovalsThreshold(params *multisig.ChangeNumApprovalsThre
// | POWER
// ----------------------------------------------------------------------------

func PowerConstructor(params *adt.EmptyValue) TypedCall {
func PowerConstructor(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsPower.Constructor, MustSerialize(params)
}
Expand All @@ -258,7 +257,7 @@ func PowerEnrollCronEvent(params *power.EnrollCronEventParams) TypedCall {
return builtin.MethodsPower.EnrollCronEvent, MustSerialize(params)
}
}
func PowerOnEpochTickEnd(params *adt.EmptyValue) TypedCall {
func PowerOnEpochTickEnd(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsPower.OnEpochTickEnd, MustSerialize(params)
}
Expand All @@ -278,7 +277,7 @@ func PowerSubmitPoRepForBulkVerify(params *proof.SealVerifyInfo) TypedCall {
return builtin.MethodsPower.SubmitPoRepForBulkVerify, MustSerialize(params)
}
}
func PowerCurrentTotalPower(params *adt.EmptyValue) TypedCall {
func PowerCurrentTotalPower(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsPower.CurrentTotalPower, MustSerialize(params)
}
Expand All @@ -288,7 +287,7 @@ func PowerCurrentTotalPower(params *adt.EmptyValue) TypedCall {
// | REWARD
// ----------------------------------------------------------------------------

func RewardConstructor(params *adt.EmptyValue) TypedCall {
func RewardConstructor(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsReward.Constructor, MustSerialize(params)
}
Expand All @@ -298,7 +297,7 @@ func RewardAwardBlockReward(params *reward.AwardBlockRewardParams) TypedCall {
return builtin.MethodsReward.AwardBlockReward, MustSerialize(params)
}
}
func RewardThisEpochReward(params *adt.EmptyValue) TypedCall {
func RewardThisEpochReward(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsReward.ThisEpochReward, MustSerialize(params)
}
Expand All @@ -323,12 +322,12 @@ func PaychUpdateChannelState(params *paych.UpdateChannelStateParams) TypedCall {
return builtin.MethodsPaych.UpdateChannelState, MustSerialize(params)
}
}
func PaychSettle(params *adt.EmptyValue) TypedCall {
func PaychSettle(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsPaych.Settle, MustSerialize(params)
}
}
func PaychCollect(params *adt.EmptyValue) TypedCall {
func PaychCollect(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsPaych.Collect, MustSerialize(params)
}
Expand All @@ -343,7 +342,7 @@ func CronConstructor(params *cron.ConstructorParams) TypedCall {
return builtin.MethodsCron.Constructor, MustSerialize(params)
}
}
func CronEpochTick(params *adt.EmptyValue) TypedCall {
func CronEpochTick(params *abi.EmptyValue) TypedCall {
return func() (abi.MethodNum, []byte) {
return builtin.MethodsCron.EpochTick, MustSerialize(params)
}
Expand Down
7 changes: 4 additions & 3 deletions gen/builders/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func MessageReturns(expect cbg.CBORMarshaler) ApplyRetPredicate {
}
}

// Nil returns an ApplyRetPredicate that passes if the message receipt is nil.
func Nil() ApplyRetPredicate {
// Failed returns an ApplyRetPredicate that passes if the message failed to be
// applied i.e. the receipt is nil.
func Failed() ApplyRetPredicate {
return func(ret *vm.ApplyRet) error {
if ret != nil {
return fmt.Errorf("message receipt was not nil: %+v", ret)
return fmt.Errorf("message did not fail: %+v", ret)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions gen/builders/state_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (st *StateTracker) ApplyMessage(am *ApplicableMessage) {
am.Applied = true
am.Result, postRoot, err = st.Driver.ExecuteMessage(st.Stores.Blockstore, st.CurrRoot, am.Epoch, am.Message)
if err != nil {
am.Failed = true
return
}

Expand Down
3 changes: 1 addition & 2 deletions gen/suites/nested/nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/filecoin-project/specs-actors/actors/util/adt"
typegen "github.com/whyrusleeping/cbor-gen"

"github.com/filecoin-project/lotus/conformance/chaos"
Expand Down Expand Up @@ -190,7 +189,7 @@ func nestedSends_FailMissingParams(v *MessageVectorBuilder) {
stage := prepareStage(v, acctDefaultBalance, multisigBalance)
balanceBefore := v.StateTracker.Balance(stage.creator)

params := adt.Empty // Missing params required by AddSigner
params := abi.Empty // Missing params required by AddSigner
amtSent := abi.NewTokenAmount(1)
result := stage.sendOk(stage.msAddr, amtSent, builtin.MethodsMultisig.AddSigner, params, nonce)

Expand Down
10 changes: 5 additions & 5 deletions gen/suites/vm_violations/actor_abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func actorAbort(abortCode exitcode.ExitCode, msg string, expectedCode exitcode.E
v.Messages.Raw(
sender.ID,
chaos.Address,
chaos.MethodAbort,
MustSerialize(&chaos.AbortArgs{Code: abortCode, Message: msg}),
chaos.MethodAbortWith,
MustSerialize(&chaos.AbortWithArgs{Code: abortCode, Message: msg}),
Value(big.Zero()),
Nonce(0),
)
Expand All @@ -41,13 +41,13 @@ func actorPanic(msg string) func(*MessageVectorBuilder) {
v.Messages.Raw(
sender.ID,
chaos.Address,
chaos.MethodAbort,
MustSerialize(&chaos.AbortArgs{NoCode: true, Message: msg}),
chaos.MethodAbortWith,
MustSerialize(&chaos.AbortWithArgs{Uncontrolled: true, Message: msg}),
Value(big.Zero()),
Nonce(0),
)
v.CommitApplies()

v.Assert.LastMessageResultSatisfies(Nil())
v.Assert.LastMessageResultSatisfies(Failed())
}
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/filecoin-project/go-address v0.0.3
github.com/filecoin-project/go-bitfield v0.2.0
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-state-types v0.0.0-20200905071437-95828685f9df
github.com/filecoin-project/lotus v0.6.2-0.20200909104030-159be5b543fd
github.com/filecoin-project/specs-actors v0.9.7
github.com/filecoin-project/go-state-types v0.0.0-20200911004822-964d6c679cfc
github.com/filecoin-project/lotus v0.7.0
github.com/filecoin-project/specs-actors v0.9.8
github.com/filecoin-project/test-vectors/schema v0.0.1
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-blockservice v0.1.4-0.20200624145336-a978cec6e834
Expand Down
Loading