-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a TypedEvent
conversion trait for ABCI events.
#1288
Conversation
c27244f
to
0b927bf
Compare
Codecov Report
@@ Coverage Diff @@
## main #1288 +/- ##
=======================================
+ Coverage 64.1% 64.2% +0.1%
=======================================
Files 271 271
Lines 24328 24450 +122
=======================================
+ Hits 15596 15717 +121
- Misses 8732 8733 +1
... and 7 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Sounds good! While we're at it, can we also derive Can you also please expand a bit on this part of your comment? Or perhaps open another issue/PR for this, with the rationale behind the change?
|
Let's also merge |
This commit adds a marker trait for types that can be converted to and from [`Event`]s. It doesn't make any assumptions about how the conversion is performed, but it does allow downstream users to declare a single source of truth about how event data is structured.
Sure, sounds good to me. I'll merge this after making those changes.
Sorry about that, the description was in a commit that I dropped because it did cause some minor breakage. Basically, there's a stray |
As suggested by @romac, this also adds `hash_ignoring_index` methods that ignore the nondeterministic `index` field.
@hdevalence Thanks for the explanation! Now tracked in #1299 |
Downstream users of ABCI need to encode data in ABCI
Event
s. Different consumers of these events may have different requirements on the event structure. For instance, the Go IBC relayer expects to see an event with a hex-encoded representation of a client state.To ensure that there's a single source of truth for these kinds of encodings, it would be useful for downstream users of the
abci::Event
type to be able to write custom domain types for particular event types. This PR adds anabci::TypedEvent
trait that captures the conversion relationships between anEvent
and a domain type. It also defines a contract about how the conversion between raw events and domain types should handle index information, which is nondeterministic: ifT: TypedEvent
, then:T::try_from(e) == Ok(t)
for allt: T, e: Event
whereEvent::from(t).eq_ignoring_index(e) == true
.Event::from(T::try_from(e).unwrap()).eq_ignoring_index(e) == true
for alle: Event
whereT::try_from(e)
returnsOk(_)
.This allows downstream code to separate concerns between the event data itself (in
T
), and instance-specific configuration of indexing of the event's attributes (e.g., by structuring the application so that outbound events are passed through a filter that adjusts theindex
fields based on configuration data).Finally, I also removed an erroneousEDIT: Removed as it broke other code in the repo; I still think it is a bug.Serialize
implementation onEvent
. As explained in the commit, this is a bugfix, not a breaking change, and I believe it should be included in an0.30.1
release rather than an0.31.0
release. (If other developers feel differently, our preference would be for it to be pulled out, so that we can start usingTypedEvent
on the0.30.x
series).