Skip to content
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

feat: Value Renderer for repeated #13604

Conversation

joeabbey
Copy link
Contributor

@joeabbey joeabbey commented Oct 20, 2022

closes #12714

Next steps:

  • Repeated for additional types
  • Refining conformance to ADR50
  • Parsing of Lists
  • Parsing of custom value renderers (e.g. Coins)

@joeabbey joeabbey requested a review from a team as a code owner October 20, 2022 17:13
@joeabbey joeabbey force-pushed the joeabbey/textual-repeated-repeated-repeated-render branch from 4a39d19 to 4fcbfd3 Compare October 21, 2022 14:03
@codecov
Copy link

codecov bot commented Oct 21, 2022

Codecov Report

Merging #13604 (5d1cd9d) into main (2739f83) will increase coverage by 0.45%.
The diff coverage is 73.28%.

❗ Current head 5d1cd9d differs from pull request most recent head d771861. Consider uploading reports for the commit d771861 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13604      +/-   ##
==========================================
+ Coverage   56.25%   56.71%   +0.45%     
==========================================
  Files         667      647      -20     
  Lines       56576    55435    -1141     
==========================================
- Hits        31829    31441     -388     
+ Misses      22165    21423     -742     
+ Partials     2582     2571      -11     
Impacted Files Coverage Δ
tx/textual/valuerenderer/coins.go 69.56% <40.00%> (ø)
tx/textual/valuerenderer/message.go 69.62% <73.72%> (ø)
tx/textual/valuerenderer/valuerenderer.go 76.47% <100.00%> (ø)
x/distribution/simulation/operations.go 80.64% <0.00%> (-9.68%) ⬇️
x/gov/abci.go 90.29% <0.00%> (-6.86%) ⬇️
server/config/config.go 69.87% <0.00%> (-2.65%) ⬇️
x/group/internal/math/dec.go 47.14% <0.00%> (-1.39%) ⬇️
x/group/module/module.go 48.05% <0.00%> (-0.10%) ⬇️
server/mock/tx.go 53.33% <0.00%> (ø)
server/config/toml.go 66.66% <0.00%> (ø)
... and 46 more

@joeabbey joeabbey changed the title [STACKED] Value Renderer for repeated feat: Value Renderer for repeated Oct 21, 2022
tx/textual/internal/testdata/repeated.json Outdated Show resolved Hide resolved
tx/textual/internal/testdata/repeated.json Outdated Show resolved Hide resolved
tx/textual/valuerenderer/repeated.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/repeated.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/repeated.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/repeated.go Outdated Show resolved Hide resolved
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Left some comments

tx/textual/valuerenderer/valuerenderer.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/valuerenderer.go Show resolved Hide resolved
tx/textual/internal/testdata/repeated.json Show resolved Hide resolved
tx/textual/valuerenderer/valuerenderer.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/repeated.go Outdated Show resolved Hide resolved
@amaury1093 amaury1093 marked this pull request as draft November 2, 2022 10:26
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I left a comment about removing Kind() from the interface.

tx/textual/valuerenderer/types.go Outdated Show resolved Hide resolved
tx/textual/internal/testpb/1.proto Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message_test.go Outdated Show resolved Hide resolved
tx/textual/internal/testpb/1.proto Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Show resolved Hide resolved
Copy link
Contributor

@JimLarson JimLarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress, and good to hear that you're working on the parse.

docs/architecture/adr-050-sign-mode-textual-annex1.md Outdated Show resolved Hide resolved
docs/architecture/adr-050-sign-mode-textual-annex1.md Outdated Show resolved Hide resolved
docs/architecture/adr-050-sign-mode-textual-annex1.md Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Show resolved Hide resolved
tx/textual/valuerenderer/repeated_test.go Show resolved Hide resolved
@@ -0,0 +1,157 @@
[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add these test cases to message.json instead of using a separate file - allows us to reuse the same test driver code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this one. I still think the reason we put repeated logic in messageValueRenderer is an implementation detail. Conceptually, I prefer them to be 2 different value renderers. I'd love to know how JS implements this.

tx/textual/valuerenderer/valuerenderer.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/valuerenderer.go Outdated Show resolved Hide resolved
docs/architecture/adr-050-sign-mode-textual-annex1.md Outdated Show resolved Hide resolved
@@ -0,0 +1,157 @@
[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this one. I still think the reason we put repeated logic in messageValueRenderer is an implementation detail. Conceptually, I prefer them to be 2 different value renderers. I'd love to know how JS implements this.

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overall LGTM! Nice progress on this PR.

My only requested change is to think about the ParseRepeated function signature.

docs/architecture/adr-050-sign-mode-textual-annex1.md Outdated Show resolved Hide resolved
tx/textual/internal/testpb/1.proto Outdated Show resolved Hide resolved
tx/textual/internal/testdata/repeated.json Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Show resolved Hide resolved
tx/textual/valuerenderer/types.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/repeated_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, thanks @joeabbey!

Just asked a question if we should be more rigorous in Parse, but I'm fine with the current version

func (mr *messageValueRenderer) parseRepeated(ctx context.Context, screens []Screen, l protoreflect.List, vr ValueRenderer) error {

// <int> <field_kind>
headerRegex := *regexp.MustCompile(`(\d+) .+`)
Copy link
Contributor

@amaury1093 amaury1093 Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should parse check that <field_kind> is correct too? We would need to pass fd protoreflect.FieldDescriptor as an arg too.

Maybe it's fine for Parse to not be that strict.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the criteria for <field_kind>? We should perhaps add it into the regex. Also we need to ensure that the regex begins with an integer or permit spaces but essentially perhaps this

headerRegex := regexp.MustCompile(`^\s*(\d+) (\w+|\d+)`)

and no need to dereference the result from regexp.MustCompile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field kind is documented in Annex 1 of ADR 50:

field_kind:

  • if the type of the repeated field is a message, field_kind is the message name
  • if the type of the repeated field is an enum, field_kind is the enum name
  • in any other case, field_kind is the protobuf primitive type (e.g. "string" or "bytes")

@amaury1093 amaury1093 marked this pull request as ready for review November 17, 2022 19:04
@amaury1093
Copy link
Contributor

@facundomedica I'm assigning you here too (if you have bandwidth), since you said you might be interested in looking into Textual.

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this change @joeabbey and great to bump into you here!

I've added some suggestions, please take a look.

tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
func (mr *messageValueRenderer) parseRepeated(ctx context.Context, screens []Screen, l protoreflect.List, vr ValueRenderer) error {

// <int> <field_kind>
headerRegex := *regexp.MustCompile(`(\d+) .+`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the criteria for <field_kind>? We should perhaps add it into the regex. Also we need to ensure that the regex begins with an integer or permit spaces but essentially perhaps this

headerRegex := regexp.MustCompile(`^\s*(\d+) (\w+|\d+)`)

and no need to dereference the result from regexp.MustCompile.

tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/message.go Outdated Show resolved Hide resolved
tx/textual/valuerenderer/valuerenderer.go Outdated Show resolved Hide resolved
@joeabbey joeabbey force-pushed the joeabbey/textual-repeated-repeated-repeated-render branch from 5d1cd9d to 14c5057 Compare November 28, 2022 17:39
@joeabbey joeabbey enabled auto-merge (squash) November 28, 2022 21:20
Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the test proto doesn't seem well formatted but we can solve that later

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 29, 2022
@joeabbey joeabbey merged commit 2cf92ca into cosmos:main Nov 29, 2022
{
return NewIntValueRenderer(), nil
}
return NewIntValueRenderer(), nil

case fd.Kind() == protoreflect.StringKind:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll fix it in my PR then: #13600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. Type: ADR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TEXTUAL Value Renderers for Protobuf repeated fields
6 participants