Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Fix for deserialization of BroadcastTx which was missing the type byte. #453

Merged
merged 1 commit into from
Jan 26, 2017

Conversation

ratranqu
Copy link
Contributor

@ratranqu ratranqu commented Jan 24, 2017

This fixes an issue when deserialising a BroadcastTx json-rpc request over websockets.

Until 0.11.4, such json would be valid:

{
  "id": "57EC1D39-7B3D-4F96-B286-8FC128177AFC4",
  "jsonrpc": "2.0",
  "method": "erisdb.broadcastTx",
  "params": [
    2,
    {
      "address": "5A9083BB0EFFE4C8EB2ADD29174994F73E77D418",
      "data": "2F2397A00000000000000000000000000000000000000000000000000000000000003132",
      "fee": 1,
      "gas_limit": 1000000,
      "input": {
        "address": "BE18FDCBF12BF99F4D75325E17FF2E78F1A35FE8",
        "amount": 1,
        "pub_key": [
          1,
          "8D1611925948DC2EDDF739FB65CE517757D286155A039B28441C3349BE9A8C38"
        ],
        "sequence": 2,
        "signature": [
          1,
          "B090D622F143ECEDA9B9E7B15485CE7504453C05434951CF867B013D80ED1BD2A0CA32846FC175D234CDFB9D5C3D792759E8FE79FD4DB3006B24950EE3C37D00"
        ]
      }
    }
  ]
}

In 0.12.0, the "params" value is wrongly expected to be a dictionary instead of the correct [ type, {dict}].

@silasdavis
Copy link
Contributor

silasdavis commented Jan 25, 2017

Thanks for this. Indeed we seemed to be assuming a CallTx, whereas with this change it can be any transactions type.

I'm a little wary though because presumably it will break what our javascript libraries must be doing for 0.12. @NodeGuy - what do you provide for "params" when calling rpc/v0 from your libaries? @benjaminbollen can you remember why this was like this?

@ratranqu
Copy link
Contributor Author

ratranqu commented Jan 25, 2017 via email

@NodeGuy
Copy link

NodeGuy commented Jan 25, 2017

Here's what's provided for params:

    this.server.transact({
      priv_key: privKey,
      address,
      data,
      gas_limit: gasLimit,
      fee
    }, callback)

https://github.com/eris-ltd/eris-db.js/blob/ab3c1b4cd34a4ab4526cfb9f6cab5abbbb1dce3e/lib/unsafe.js#L82-L88

@ratranqu
Copy link
Contributor Author

ratranqu commented Jan 25, 2017 via email

@benjaminbollen
Copy link
Contributor

Hi Alex,

This is my fault, I got this mixed up in the 0.12 release. This RPC is marked for deprecation, but it is more complete to consider reverting it, before doing so. I will weigh in the opinion of the JS libs, but it seems a valid request.

@ratranqu
Copy link
Contributor Author

ratranqu commented Jan 25, 2017 via email

@benjaminbollen
Copy link
Contributor

Strictly speaking we can merge this without breaking the JS libs as they call the transact method - not the broadcast method - but it is better to reduce complexity and have it aligned for less headaches.

@NodeGuy
Copy link

NodeGuy commented Jan 26, 2017

Actually the JavaScript libraries never sent the type byte so there's nothing for me to revert.

Copy link
Contributor

@silasdavis silasdavis left a comment

Choose a reason for hiding this comment

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

Could you check if this works without the method, I think it should.

@@ -9,5 +9,6 @@ type Codec interface {
EncodeBytes(interface{}) ([]byte, error)
Encode(interface{}, io.Writer) error
DecodeBytes(interface{}, []byte) error
DecodeBytesPtr(interface{}, []byte) error
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 we need this. I think it will work with DecodeBytes, did you try that?

// Decode from a byte array pointer.
func (this *TCodec) DecodeBytesPtr(v interface{}, bts []byte) error {
var err error
wire.ReadJSONPtr(v, bts, &err)
Copy link
Contributor

Choose a reason for hiding this comment

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

wire.ReadJSON should delegate to ReadJSONPtr if it gets a pointer.

@benjaminbollen
Copy link
Contributor

benjaminbollen commented Jan 26, 2017

@silasdavis I wanted to merge this into a feature branch and then we can work on it? cc @ratranqu

@benjaminbollen benjaminbollen changed the base branch from develop to feature-issue453_correct_rpcv0 January 26, 2017 12:51
@benjaminbollen benjaminbollen merged commit 7a21558 into hyperledger-archives:feature-issue453_correct_rpcv0 Jan 26, 2017
@silasdavis
Copy link
Contributor

good idea

@ratranqu
Copy link
Contributor Author

@silasdavis, yes, I think you are right, we can just use the DecodeBytes function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants