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

refactor auths broadcast cmd in alignment with #6216 #6713

Merged
merged 10 commits into from
Jul 17, 2020

Conversation

clevinson
Copy link
Contributor

@clevinson clevinson commented Jul 14, 2020

Description

Ref #6213

Changes:

  • add protobuf definitions for TxResponse and ABCIMessageLog, for use in x/auth's broadcast commands
  • update corresponding functions to return TxResponse by reference instead of by value
  • update UnpackInterfaces implementation of TxResponse to not unpack Tx fields when nil

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Jul 14, 2020

Codecov Report

Merging #6713 into master will decrease coverage by 0.03%.
The diff coverage is 41.37%.

@@            Coverage Diff             @@
##           master    #6713      +/-   ##
==========================================
- Coverage   59.87%   59.83%   -0.04%     
==========================================
  Files         513      513              
  Lines       31470    31483      +13     
==========================================
- Hits        18842    18838       -4     
- Misses      11192    11209      +17     
  Partials     1436     1436              

@clevinson
Copy link
Contributor Author

I think i've covered all the components I need to pull out from #6216, but some integration tests are still failing and i'm not exactly sure why.

Getting a invalid memory address or nil pointer dereference error on all failing tests, which are calling UnpackInterfaces on the TxResponse to unpack the underlying Tx. Is there some work that I need to do involving RegisterInterface that i'm missing here @aaronc ?

@amaury1093
Copy link
Contributor

amaury1093 commented Jul 16, 2020

I'm maybe missing some context here. iiuc @clevinson you're tackling the "migrate x/auth commands to use TxGenerator and SignatureV2 -> broadcast" item in #6213, but afaict, it has been already done?

https://github.com/cosmos/cosmos-sdk/pull/6391/files#diff-95109ccb95ab5a6a697971116e43119bR39

edit: indeed the other commands still need to be converted, but broadcast seems done to me.

@clevinson
Copy link
Contributor Author

clevinson commented Jul 16, 2020

@amaurymartiny yes indeed there was some work on actually migrating the broadcast command that was done, but one of hte larger missing pieces was that TxResponse needed to get converted to a protobuf message (along with ABCIMessageLog), and this was deemed part of the broadcast migration as there weren't any other cli commands using it.

After switching that over, there were a number of minor changes to properly handle the proto TxResponse, namely:

  • TxResponse packs the tx inside an Any and needs some custom UnsafePackAny capabilities that were used in Implement SIGN_MODE_DIRECT #6216
  • a few other functions made use of TxResponse that I migrated over:
    • SearchTxResponse
    • subsequently some components of gov's queriers make use of SearchTxResponse here

@clevinson
Copy link
Contributor Author

clevinson commented Jul 17, 2020

I fixed the integration tests by updating TxResponse's implementation of UnpackInterfaces to not call into UnpackAny if the Tx inside of TxResponse is nil. This is similar to the approach I saw for implementing UnpackInterfaces on Tx here.

An alternative that I was less sure about could have involved calling UnsafePackAny to pack the nil value inside an any with a cachedValue = nil, so that UnpackAny could be called on TxResponse regardless of whether an underlying Tx is has a value. But I didn't see that as a convention, and it seemed a bit messy.

Also, just flagging that i'm not sure what breakout issue from this epic will take care of adding the MarshalAny and UnmarshalAny interfaces that were done initially as part of #6216 (see here). Should that be taken care of in this PR, or is it being accomplished by some other component of #6213 ?

@clevinson clevinson added this to the v0.40 [Stargate] milestone Jul 17, 2020
@clevinson clevinson marked this pull request as ready for review July 17, 2020 15:19
@aaronc
Copy link
Member

aaronc commented Jul 17, 2020

I fixed the integration tests by updating TxResponse's implementation of UnpackInterfaces to not call into UnpackAny if the Tx inside of TxResponse is nil. This is similar to the approach I saw for implementing UnpackInterfaces on Tx here.

An alternative that I was less sure about could have involved calling UnsafePackAny to pack the nil value inside an any with a cachedValue = nil, so that UnpackAny could be called on TxResponse regardless of whether an underlying Tx is has a value. But I didn't see that as a convention, and it seemed a bit messy.

Also, just flagging that i'm not sure what breakout issue from this epic will take care of adding the MarshalAny and UnmarshalAny interfaces that were done initially as part of #6216 (see here). Should that be taken care of in this PR, or is it being accomplished by some other component of #6213 ?

Is the Marshal/UnmarshalAny needed for this PR?

Comment on lines +101 to +116
message TxResponse {
option (gogoproto.goproto_getters) = false;

int64 height = 1;
string txhash = 2 [(gogoproto.customname) = "TxHash"];
string codespace = 3;
uint32 code = 4;
string data = 5;
string raw_log = 6;
repeated ABCIMessageLog logs = 7 [(gogoproto.castrepeated) = "ABCIMessageLogs", (gogoproto.nullable) = false];
string info = 8;
int64 gas_wanted = 9;
int64 gas_used = 10;
google.protobuf.Any tx = 11;
string timestamp = 12;
}
Copy link
Member

@aaronc aaronc Jul 17, 2020

Choose a reason for hiding this comment

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

I do want to note that I do think this stuff should live in the root cosmos proto package. I'm not sure where it should go but I don't feel comfortable with it here. Any thoughts?

I'd also like to take out the other Result, SimulationResponse, etc. stuff and leave just Coin, DecCoin & Int/DecProto preferably before 0.40 is done.

Copy link
Contributor Author

@clevinson clevinson Jul 17, 2020

Choose a reason for hiding this comment

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

This makes sense. I can tackle this as another PR.

Copy link
Member

Choose a reason for hiding this comment

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

Great 👍

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

LGTM. Would be nice to clean up cosmos.proto, but maybe as a separate PR.

@clevinson
Copy link
Contributor Author

Is the Marshal/UnmarshalAny needed for this PR?

Nope, not necessary for this PR, just flagging that I want to make sure it is covered somewhere to be tackled in the #6213 bullet list if we want to include it in 0.40

@aaronc
Copy link
Member

aaronc commented Jul 17, 2020

Is the Marshal/UnmarshalAny needed for this PR?

Nope, not necessary for this PR, just flagging that I want to make sure it is covered somewhere to be tackled in the #6213 bullet list if we want to include it in 0.40

The MarshalAny stuff is more relevant for #6190

@aaronc aaronc added the A:automerge Automatically merge PR once all prerequisites pass. label Jul 17, 2020
@mergify mergify bot merged commit 32de79d into master Jul 17, 2020
@mergify mergify bot deleted the clevinson/6216-extract-broadcast-cmd branch July 17, 2020 17:17
func NewABCIMessageLog(i uint16, log string, events Events) ABCIMessageLog {
return ABCIMessageLog{
MsgIndex: i,
MsgIndex: uint32(i),
Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a need to cast here, rather the function should just accept a uint32.

// in the case of a packing failure, keeps the cached value. This should only
// be used in situations where compatibility is needed with amino. Amino-only
// values can safely be packed using this method when they will only be
// marshaled with amino and not protobuf
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing puncuation.

@clevinson clevinson mentioned this pull request Jul 18, 2020
9 tasks
@aaronc aaronc mentioned this pull request Jul 20, 2020
27 tasks
chengwenxi pushed a commit to irisnet/cosmos-sdk that referenced this pull request Jul 22, 2020
* refactor auths broadcast cmd in alignment with cosmos#6216

* add TxResponse proto definition, and related refactoring

* re-run make proto-gen, updating staking.pb.go

* cleanup TxResponse tests to handle nil return values

* properly handle nil Tx value in TxResponse's implementation of UnpackInterfaces

Co-authored-by: Federico Kunze <[email protected]>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants