diff --git a/docs/proto-docs.md b/docs/proto-docs.md index ea4329f923..cbcf40e138 100644 --- a/docs/proto-docs.md +++ b/docs/proto-docs.md @@ -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. | diff --git a/proto/provenance/trigger/v1/event.proto b/proto/provenance/trigger/v1/event.proto index fdaaa51b8c..0b64273289 100644 --- a/proto/provenance/trigger/v1/event.proto +++ b/proto/provenance/trigger/v1/event.proto @@ -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; } \ No newline at end of file diff --git a/x/trigger/keeper/trigger_dispatcher.go b/x/trigger/keeper/trigger_dispatcher.go index 1ba2a64626..5ef0eb0363 100644 --- a/x/trigger/keeper/trigger_dispatcher.go +++ b/x/trigger/keeper/trigger_dispatcher.go @@ -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) } } @@ -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) diff --git a/x/trigger/keeper/trigger_dispatcher_test.go b/x/trigger/keeper/trigger_dispatcher_test.go index 04b2bbbdb5..fa17998ab6 100644 --- a/x/trigger/keeper/trigger_dispatcher_test.go +++ b/x/trigger/keeper/trigger_dispatcher_test.go @@ -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 } @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, @@ -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, }, { @@ -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, }, @@ -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, }, diff --git a/x/trigger/spec/05_events.md b/x/trigger/spec/05_events.md index 81d2990f31..ed3b29f011 100644 --- a/x/trigger/spec/05_events.md +++ b/x/trigger/spec/05_events.md @@ -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 | diff --git a/x/trigger/types/event.pb.go b/x/trigger/types/event.pb.go index 7d3315cba9..1931271b7e 100644 --- a/x/trigger/types/event.pb.go +++ b/x/trigger/types/event.pb.go @@ -166,8 +166,8 @@ type EventTriggerExecuted struct { TriggerId string `protobuf:"bytes,1,opt,name=trigger_id,json=triggerId,proto3" json:"trigger_id,omitempty"` // owner is the creator of the trigger. Owner string `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"` - // error contains the failure message for an unsuccessful action. - Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` + // success indicates if all executed actions were successful. + Success bool `protobuf:"varint,3,opt,name=success,proto3" json:"success,omitempty"` } func (m *EventTriggerExecuted) Reset() { *m = EventTriggerExecuted{} } @@ -217,11 +217,11 @@ func (m *EventTriggerExecuted) GetOwner() string { return "" } -func (m *EventTriggerExecuted) GetError() string { +func (m *EventTriggerExecuted) GetSuccess() bool { if m != nil { - return m.Error + return m.Success } - return "" + return false } func init() { @@ -234,7 +234,7 @@ func init() { func init() { proto.RegisterFile("provenance/trigger/v1/event.proto", fileDescriptor_9c1b9c75d8690469) } var fileDescriptor_9c1b9c75d8690469 = []byte{ - // 242 bytes of a gzipped FileDescriptorProto + // 249 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2c, 0x28, 0xca, 0x2f, 0x4b, 0xcd, 0x4b, 0xcc, 0x4b, 0x4e, 0xd5, 0x2f, 0x29, 0xca, 0x4c, 0x4f, 0x4f, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x45, @@ -242,15 +242,15 @@ var fileDescriptor_9c1b9c75d8690469 = []byte{ 0x08, 0x39, 0x17, 0xa5, 0x26, 0x96, 0xa4, 0xa6, 0x08, 0xc9, 0x72, 0x71, 0x41, 0x15, 0xc5, 0x67, 0xa6, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x71, 0x42, 0x45, 0x3c, 0x53, 0x94, 0xcc, 0xb8, 0x44, 0x91, 0x75, 0xb9, 0xa4, 0x16, 0x97, 0x14, 0xe5, 0x57, 0x12, 0xd6, 0x67, 0xca, 0x25, 0x82, - 0xaa, 0xaf, 0x24, 0x35, 0x99, 0x08, 0xeb, 0x12, 0x51, 0xb5, 0xb9, 0x56, 0xa4, 0x26, 0x97, 0x12, + 0xaa, 0xaf, 0x24, 0x35, 0x99, 0x08, 0xeb, 0x52, 0x51, 0xb5, 0xb9, 0x56, 0xa4, 0x26, 0x97, 0x12, 0xd6, 0x26, 0x24, 0xc2, 0xc5, 0x9a, 0x5f, 0x9e, 0x97, 0x5a, 0x24, 0xc1, 0x04, 0x96, 0x81, 0x70, - 0x40, 0xa2, 0xa9, 0x45, 0x45, 0xf9, 0x45, 0x12, 0xcc, 0x10, 0x51, 0x30, 0xc7, 0x29, 0xf3, 0xc4, - 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, - 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xb8, 0x24, 0x32, 0xf3, 0xf5, 0xb0, 0x86, 0x5d, - 0x00, 0x63, 0x94, 0x71, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x42, - 0x8d, 0x6e, 0x66, 0x3e, 0x12, 0x4f, 0xbf, 0x02, 0x1e, 0x25, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, - 0x6c, 0xe0, 0x08, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0xd7, 0x15, 0x4f, 0xb5, 0x01, - 0x00, 0x00, + 0x84, 0x24, 0xb8, 0xd8, 0x8b, 0x4b, 0x93, 0x93, 0x53, 0x8b, 0x8b, 0x25, 0x98, 0x15, 0x18, 0x35, + 0x38, 0x82, 0x60, 0x5c, 0xa7, 0xcc, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, + 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0xe0, + 0x92, 0xc8, 0xcc, 0xd7, 0xc3, 0x1a, 0x7e, 0x01, 0x8c, 0x51, 0xc6, 0xe9, 0x99, 0x25, 0x19, 0xa5, + 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x08, 0x35, 0xba, 0x99, 0xf9, 0x48, 0x3c, 0xfd, 0x0a, 0x78, + 0xb4, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x23, 0xc5, 0x18, 0x10, 0x00, 0x00, 0xff, + 0xff, 0xeb, 0x5b, 0x38, 0xbe, 0xb9, 0x01, 0x00, 0x00, } func (m *EventTriggerCreated) Marshal() (dAtA []byte, err error) { @@ -363,12 +363,15 @@ func (m *EventTriggerExecuted) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Error) > 0 { - i -= len(m.Error) - copy(dAtA[i:], m.Error) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Error))) + if m.Success { + i-- + if m.Success { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x18 } if len(m.Owner) > 0 { i -= len(m.Owner) @@ -451,9 +454,8 @@ func (m *EventTriggerExecuted) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = len(m.Error) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) + if m.Success { + n += 2 } return n } @@ -804,10 +806,10 @@ func (m *EventTriggerExecuted) Unmarshal(dAtA []byte) error { m.Owner = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Success", wireType) } - var stringLen uint64 + var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -817,24 +819,12 @@ func (m *EventTriggerExecuted) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Error = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex + m.Success = bool(v != 0) default: iNdEx = preIndex skippy, err := skipEvent(dAtA[iNdEx:])