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

rpc: adjust sendrawtransaction and submitblock RPC calls #1216

Merged
merged 2 commits into from
Jul 22, 2020

Conversation

AnnaShaleva
Copy link
Member

@AnnaShaleva AnnaShaleva commented Jul 21, 2020

These RPC calls should return hashes instead of boolean values.

@AnnaShaleva AnnaShaleva added the rpc RPC server and client label Jul 21, 2020
@AnnaShaleva AnnaShaleva requested a review from fyrchik July 21, 2020 07:46
@AnnaShaleva AnnaShaleva self-assigned this Jul 21, 2020
pkg/rpc/client/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/client/rpc_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 21, 2020

Codecov Report

Merging #1216 into master will increase coverage by 5.83%.
The diff coverage is 53.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1216      +/-   ##
==========================================
+ Coverage   61.05%   66.89%   +5.83%     
==========================================
  Files         199      199              
  Lines       16971    16976       +5     
==========================================
+ Hits        10362    11356     +994     
+ Misses       6055     5011    -1044     
- Partials      554      609      +55     
Impacted Files Coverage Δ
cli/wallet/multisig.go 0.00% <0.00%> (ø)
cli/wallet/nep5.go 0.00% <0.00%> (ø)
pkg/rpc/client/nep5.go 6.95% <0.00%> (+0.11%) ⬆️
pkg/rpc/client/rpc.go 80.12% <71.42%> (-0.73%) ⬇️
pkg/rpc/server/server.go 79.26% <100.00%> (+79.26%) ⬆️
pkg/rpc/client/wsclient.go 83.22% <0.00%> (-1.35%) ⬇️
pkg/consensus/consensus.go 40.31% <0.00%> (+0.77%) ⬆️
pkg/core/dao/dao.go 72.15% <0.00%> (+0.78%) ⬆️
pkg/core/native/native_nep5.go 71.02% <0.00%> (+1.13%) ⬆️
pkg/smartcontract/parameter.go 83.55% <0.00%> (+1.34%) ⬆️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1154e18...889a5d7. Read the comment docs.

@roman-khimov
Copy link
Member

I don't see it being a part of #1130, it's two separate issues. #1130 is just about naming and I think we're already done with that.

@@ -385,18 +385,15 @@ func (c *Client) invokeSomething(method string, p request.RawParams, cosigners [
// The given hex string needs to be signed with a keypair.
// When the result of the response object is true, the TX has successfully
// been broadcasted to the network.
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) error {
func (c *Client) SendRawTransaction(rawTX *transaction.Transaction) (*result.RelayResult, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need RelayResult wrapper? I think this API can be simplified to return Uint256 and an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this wrapper from RPC client, but we still need it in RPC server for proper JSON marshalling.

@@ -453,8 +450,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys
return txHash, errors.Wrap(err, "failed to sign tx")
}
txHash = tx.Hash()
err = c.SendRawTransaction(tx)

_, err = c.SendRawTransaction(tx)
Copy link
Member

Choose a reason for hiding this comment

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

So what if it's different from txHash?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, there was a check, but #1216 (comment). So, should we also return an error in this case?

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't ever happen, but it can. And if it can, it must be handled in some way. At the moment you're just ignoring this potential mismatch and returning txHash, but what's the value of this txHash for the user if it doesn't match server's hash? And it can happen easily with misconfigured client, when you're using some privnet client for mainnet network, for example.

We can of course just not compute this hash client-side, relying on server's answer. Theoretically it would allow us to be network-agnostic on the client, but I don't think we could do it for all the calls and we require proper network setup for the client anyway for everything to function correctly.

So I think we should add this safety check, just in case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added check, now SignAndPushInvocationTx returns an error containing both hashes in case when hashes mismatch.

It should return tx has instead of boolean.
It should return block hash instead of boolean.
@roman-khimov roman-khimov merged commit c4cde44 into master Jul 22, 2020
@roman-khimov roman-khimov deleted the neo3/rpc/sendrawtransaction branch July 22, 2020 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rpc RPC server and client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants