bitshares-core icon indicating copy to clipboard operation
bitshares-core copied to clipboard

Change address constructors to explicit

Open abitmore opened this issue 7 years ago • 11 comments

This PR is mainly for making clear how public keys are being ordered in the system, aka explicitly implement

bool operator < ( const public_key_type&, const public_key_type&);

and make sure it's backward-compatible (convert the public keys to addresses and compare the addresses).

More info is here: https://github.com/cryptonomex/graphene/issues/630#issuecomment-199981206 .

The == operators are mainly used in balance_evaluator.cpp, actually I'm not sure whether it's good to have them (does it make sense to compare a pts_address with an address, or compare a public key to an address?), please advise. https://github.com/bitshares/bitshares-core/blob/76ab28eff06d6f29e7836fcd62ffc01a24871f82/libraries/chain/balance_evaluator.cpp#L33-L38

abitmore avatar Jul 18 '18 12:07 abitmore

The equality operator here boils down to a memcmp of the 2 ripemd160 hashes.

https://github.com/bitshares/bitshares-fc/blob/d679377312d715840408d2990f824d2c6e729aea/src/crypto/ripemd160.cpp#L98-L100

Are you attempting to replace the GRAPHENE_ASSERT with something else? What would you suggest they be replaced with?

Perhaps I am misunderstanding why you are questioning whether it is good to have the equality operators.

jmjatlanta avatar Jul 20 '18 12:07 jmjatlanta

My question was: does it make sense to compare a pts_address with an address, or compare a public key to an address?

abitmore avatar Jul 20 '18 17:07 abitmore

As mentioned on Telegram, I'm undecided if we should merge this in the upcoming release.

I generally think explicit constructors are better, because that avoids surprising automatic conversion.

OTOH making existing constructors explicit can have surprising side effects, so the change is a bit dangerous.

pmconrad avatar Jul 28 '18 08:07 pmconrad

Surprising side-effects could be avoided by changing all one-argument constructors to explicit. SonarQube lists 61 such issues in the core code, not counting those in fc nor test suites.

pmconrad avatar Jul 28 '18 08:07 pmconrad

Makes sense. I've removed it from this milestone.

abitmore avatar Jul 28 '18 13:07 abitmore

Is there a desire to revisit this PR for the 201810 Feature Release?

ryanRfox avatar Sep 03 '18 22:09 ryanRfox

Like I said, we should make all one-arg constructors explicit in one go. But I think we have more important stuff and little time for the next release, so I'd drop it from this one.

pmconrad avatar Sep 14 '18 14:09 pmconrad

Moving to next milestone.

abitmore avatar Sep 14 '18 18:09 abitmore

@pmconrad Sorry, my meeting notes are lacking, so request you comment here with proper instructions for this PR. This is what I captured: "recommendation for now until we decide how to do all explicit constructors"

ryanRfox avatar Feb 01 '19 17:02 ryanRfox

See my comment above - merging this now could have unforeseeable side effects. Better to switch all one-arg constructors to explicit at once.

pmconrad avatar Feb 04 '19 14:02 pmconrad