Skip to content

Commit

Permalink
Change EventTriggerExecuted to contain a success flag rather than an …
Browse files Browse the repository at this point in the history
…error string. It's possible for the error to be non-deterministic.
  • Loading branch information
Matthew Witkowski committed Nov 8, 2023
1 parent 7410f0b commit c6a0e2e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 71 deletions.
2 changes: 1 addition & 1 deletion docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10039,7 +10039,7 @@ EventTriggerExecuted is an event for when a trigger is executed.
| ----- | ---- | ----- | ----------- |
| `trigger_id` | [string](#string) | | trigger_id is a unique identifier of the trigger. |
| `owner` | [string](#string) | | owner is the creator of the trigger. |
| `error` | [string](#string) | | error contains the failure message for an unsuccessful action. |
| `success` | [bool](#bool) | | success indicates if all executed actions were successful. |



Expand Down
4 changes: 2 additions & 2 deletions proto/provenance/trigger/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ message EventTriggerExecuted {
string trigger_id = 1;
// owner is the creator of the trigger.
string owner = 2;
// error contains the failure message for an unsuccessful action.
string error = 3;
// success indicates if all executed actions were successful.
bool success = 3;
}
11 changes: 3 additions & 8 deletions x/trigger/keeper/trigger_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k Keeper) ProcessTriggers(ctx sdk.Context) {

actions := item.GetTrigger().Actions
err := k.runActions(ctx, gasLimit, actions)
k.emitTriggerExecuted(ctx, item.GetTrigger(), err)
k.emitTriggerExecuted(ctx, item.GetTrigger(), err == nil)
}
}

Expand Down Expand Up @@ -123,16 +123,11 @@ func (k Keeper) safeHandle(ctx sdk.Context, msg sdk.Msg, handler baseapp.MsgServ
}

// emitTriggerExecuted Emits an EventTriggerExecuted for the provided trigger.
func (k Keeper) emitTriggerExecuted(ctx sdk.Context, trigger types.Trigger, resultErr error) {
var errString string
if resultErr != nil {
errString = resultErr.Error()
}

func (k Keeper) emitTriggerExecuted(ctx sdk.Context, trigger types.Trigger, success bool) {
eventErr := ctx.EventManager().EmitTypedEvent(&types.EventTriggerExecuted{
TriggerId: fmt.Sprintf("%d", trigger.GetId()),
Owner: trigger.Owner,
Error: errString,
Success: success,
})
if eventErr != nil {
ctx.Logger().Error("unable to emit EventTriggerExecuted", "err", eventErr)
Expand Down
32 changes: 16 additions & 16 deletions x/trigger/keeper/trigger_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
return event
}

executed := func(triggerID uint64, owner, err string) sdk.Event {
executed := func(triggerID uint64, owner string, success bool) sdk.Event {
event, _ := sdk.TypedEventToEvent(&types.EventTriggerExecuted{
TriggerId: fmt.Sprintf("%d", triggerID),
Owner: owner,
Error: err,
Success: success,
})
return event
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
},
gas: []uint64{2000000},
expected: []types.Trigger(nil),
events: []sdk.Event{destroyed(existing1.Id), executed(trigger1.Id, trigger1.Owner, "")},
events: []sdk.Event{destroyed(existing1.Id), executed(trigger1.Id, trigger1.Owner, true)},
blockGas: 2000000,
},
{
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
},
gas: []uint64{2000000},
expected: []types.Trigger(nil),
events: []sdk.Event{executed(emptyTrigger.Id, emptyTrigger.Owner, "")},
events: []sdk.Event{executed(emptyTrigger.Id, emptyTrigger.Owner, true)},
blockGas: 2000000,
},
{
Expand All @@ -116,7 +116,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
},
gas: []uint64{2000000},
expected: []types.Trigger(nil),
events: []sdk.Event{destroyed(existing1.Id), destroyed(existing2.Id), executed(multiActionTrigger.Id, multiActionTrigger.Owner, "")},
events: []sdk.Event{destroyed(existing1.Id), destroyed(existing2.Id), executed(multiActionTrigger.Id, multiActionTrigger.Owner, true)},
blockGas: 2000000,
},
{
Expand All @@ -136,7 +136,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
},
gas: []uint64{1000000, 1000000},
expected: []types.Trigger(nil),
events: []sdk.Event{destroyed(existing1.Id), executed(trigger1.Id, trigger1.Owner, ""), destroyed(existing2.Id), executed(trigger2.Id, trigger2.Owner, "")},
events: []sdk.Event{destroyed(existing1.Id), executed(trigger1.Id, trigger1.Owner, true), destroyed(existing2.Id), executed(trigger2.Id, trigger2.Owner, true)},
blockGas: 2000000,
},
{
Expand All @@ -156,7 +156,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
},
gas: []uint64{2000000, 1000000},
expected: []types.Trigger{existing2},
events: []sdk.Event{destroyed(existing1.Id), executed(trigger1.Id, trigger1.Owner, "")},
events: []sdk.Event{destroyed(existing1.Id), executed(trigger1.Id, trigger1.Owner, true)},
blockGas: 2000000,
},
{
Expand Down Expand Up @@ -198,11 +198,11 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
expected: []types.Trigger{existing2},
events: []sdk.Event{
destroyed(existing1.Id),
executed(trigger1.Id, trigger1.Owner, ""),
executed(trigger3.Id, trigger3.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: trigger not found"),
executed(trigger4.Id, trigger4.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: trigger not found"),
executed(trigger5.Id, trigger5.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: trigger not found"),
executed(trigger6.Id, trigger6.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: trigger not found"),
executed(trigger1.Id, trigger1.Owner, true),
executed(trigger3.Id, trigger3.Owner, false),
executed(trigger4.Id, trigger4.Owner, false),
executed(trigger5.Id, trigger5.Owner, false),
executed(trigger6.Id, trigger6.Owner, false),
},
blockGas: 500000,
},
Expand All @@ -219,7 +219,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
gas: []uint64{1},
expected: []types.Trigger{existing1},
events: []sdk.Event{
executed(trigger1.Id, trigger1.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: gas 1000 exceeded limit 1 for message \"/provenance.trigger.v1.MsgDestroyTriggerRequest\"")},
executed(trigger1.Id, trigger1.Owner, false)},
blockGas: 1,
},
{
Expand All @@ -235,7 +235,7 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
gas: []uint64{6000},
expected: []types.Trigger{existing1, existing2},
events: []sdk.Event{
executed(multiActionTrigger.Id, multiActionTrigger.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: gas 6621 exceeded limit 6000 for message \"/provenance.trigger.v1.MsgDestroyTriggerRequest\""),
executed(multiActionTrigger.Id, multiActionTrigger.Owner, false),
},
blockGas: 6000,
},
Expand All @@ -257,9 +257,9 @@ func (s *KeeperTestSuite) TestProcessTriggers() {
gas: []uint64{1, 1000000},
expected: []types.Trigger{existing1},
events: []sdk.Event{
executed(trigger1.Id, trigger1.Owner, "error processing message /provenance.trigger.v1.MsgDestroyTriggerRequest at position 0: gas 1000 exceeded limit 1 for message \"/provenance.trigger.v1.MsgDestroyTriggerRequest\""),
executed(trigger1.Id, trigger1.Owner, false),
destroyed(existing2.Id),
executed(trigger2.Id, trigger2.Owner, ""),
executed(trigger2.Id, trigger2.Owner, true),
},
blockGas: 1000001,
},
Expand Down
10 changes: 5 additions & 5 deletions x/trigger/spec/05_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Fires when a trigger's event is detected in the EndBlocker.

Fires when a trigger's actions are executed in the BeginBlocker.

| Type | Attribute Key | Attribute Value |
| --------------- | ------------- | ------------------------------------------------------------------------ |
| TriggerExecuted | trigger_id | The ID of the trigger being executed |
| TriggerExecuted | owner | The sdk.Address of the trigger's owner |
| TriggerExecuted | error | The error message received when failing to execute the trigger's actions |
| Type | Attribute Key | Attribute Value |
| --------------- | ------------- | ------------------------------------------------------------- |
| TriggerExecuted | trigger_id | The ID of the trigger being executed |
| TriggerExecuted | owner | The sdk.Address of the trigger's owner |
| TriggerExecuted | success | A boolean indicating if all the actions successfully executed |
68 changes: 29 additions & 39 deletions x/trigger/types/event.pb.go

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

0 comments on commit c6a0e2e

Please sign in to comment.