-
Notifications
You must be signed in to change notification settings - Fork 32
Conversation
what is the rationale for replacing binary with encoded format? |
To convert the address field to encoded format is easy for a developer to view data directly into REST return. Example:
|
"directly into REST return" Since the field name has been reused, how does the change ensure not breaking existing REST service clients? How about external apps that potentially we don't even know they exist? |
I always critizise loading backends with formatting features when the only purpose is making it easier or more readable for the user, because it comes at the expense of increasing the workload of a backend service, where little penalties can produce big effects as they serve many users. |
This seems to be a 'breaking' change to all the client apps. But worth having It imo. We Will discuss with other teams see how we can handle the impact |
@mm-s the problem is that this "binary" isn't actually binary, it's hex-encoded which makes it longer than usual base32 we use to represent as strings... but yeah, if it's breaking change, shouldn't there be "old" / "new" APIs with "old" being deprecated (and removed in some future update?) |
The SDKs will handle the impact for clients using the SDKs. All our apps are using SDKs. SDK hides how an unresolved address is mapped to an Address/Alias Object. The mappers will create the objects from friendly addresses and alias Ids instead of the hex values. The release needs to be synchronized with the SDKs upgrades. Unresolved Addresses are everywhere, so probably we would need both APIs to work at the same time |
I think this PR definitely needs to synchronize with the SDKs upgrades, I don't think it's urgent to merge. Do we need to support If Yes, then will add |
rest/src/db/dbUtils.js
Outdated
*/ | ||
bufferToAddressBase32: addressBinary => { | ||
const hexToUint8 = convert.hexToUint8(addressBinary.toString('hex')); | ||
bufferToResolvedAddress: binary => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name would be bufferToUnresolvedAddress
. The function is returning an Encoded Address or a Namespace Id Hex.
98b4fbb
to
a418822
Compare
rest/src/db/dbUtils.js
Outdated
bufferToUnresolvedAddress: binary => { | ||
if (!(binary instanceof MongoDb.Binary)) | ||
return undefined; | ||
|
||
const hex = binary.toString('hex'); | ||
const bit0 = convert.hexToUint8(hex.substr(1, 2))[0]; | ||
|
||
if (16 === (bit0 & 16)) { | ||
// only 8 bytes are relevant to resolve the NamespaceId | ||
const namespaceId = hex.substr(2, 16); | ||
|
||
// retun as namespace Id | ||
return convert.uint8ToHex(convert.hexToUint8Reverse(namespaceId)); | ||
} | ||
|
||
// return as Address base 32 | ||
const hexToUint8 = convert.hexToUint8(hex); | ||
return address.addressToString(hexToUint8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this instead of always addressToString? that is how we normally represent aliases, i think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @gimer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for my understanding, addressToString
method is the only way to convert Uint8 to an encoded address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i meant returning alias as namespace id seems strange to me. i don't think we use that representation anywhere else, so i'd just use addressToString
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got what you mean now, the reason to add namespace id is to handle Alias address
.
This is the simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the expected result, if that is namespace Id hex on recipientAddress
?
or we should not allow namespace id to appear on "recipientAddress"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be better to return the encoded address from padded namespaceId, but also have an extra field addressAlias
for the actual namespace?
e.g.
{ "recipientAddress": "NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA35C4KNQ"}
or
"recipientAddress": "NATNE7Q5BITMUTRRN6IBAAAAAAAAAAAAAAAAAA", "addressAlias": "291F837E059AE13C"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Atm, Rest, Catbuffer and Mongo represent unresolved addresses like this (hex or byte array):
Address:
recipientAddress: 981DFFB44F83E5FA8DE3A564A0A95449848272050AD4F5EC
Alias:
recipientAddress: 99C1ED94FF2D65C0AF000000000000000000000000000000
When a rest client is processing that payload, it "IFs" to get the right address or namespace id object.
In my mind, this PR just updates that rest payload representation to a "friendly" one:
Address:
recipientAddress: TAO77NCPQPS7VDPDUVSKBKKUJGCIE4QFBLKPL3A
Alias:
recipientAddress: AFC0652DFF94EDC1
A rest client would need to do a similar "IF", just from a different format to get the address or namespace id object. The OLD sdk buffers this changge.
If you check the catbuffer schemas, there are at least 12 attributes that use unresolved addresses (metadata targetAddress
, multisig modification addressAdditions
, addressDeletions
, etc)
Resolving the aliases would be nice, but it is more than just changing the format of the unresolved address value and it needs to be replicated to all those fields. Resolving an alias needs at least a call to the database and the time of the transaction in order to get the right original address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like rg911 suggestion to return object with encoded address and optional alias namespace id. or even just always returning encoded address might be sufficient.
i think it would be confusing for consumers to return either encoded address or namespace id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe our goal is to solve the confusion problem for the API.
I will support always returning encoded addresses for the address field will be great.
We need another PR for this.
- Always resolve the
alias
toaddress
(I believe it may needs to sacrifice performance)
8adbd14
to
83fd5e7
Compare
Approved, we would need to review and merge these ones too symbol/symbol-openapi#272 |
f1cbd39
d881b70
to
f1cbd39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would prefer to change the alias formatting before merging
f1cbd39
to
4700469
Compare
@AnthonyLaw do you have examples of what is this PR rendering for unresolved address fields? What rest returns when |
@fboucquez sorry for the late reply.
98E0D138EAF2AC342C015FF0B631EC3622E8AFFA04BFCC56 -> TDQNCOHK6KWDILABL7YLMMPMGYRORL72AS74YVQ
No, but this is what we need to solve: #652 We should fix issue 652, before merge this. |
* @returns {string} AddressBase32|NamespaceId | ||
*/ | ||
bufferToUnresolvedAddress: binary => { | ||
if (!(binary instanceof MongoDb.Binary)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the binary is an alias? Like 0x99C1ED94FF2D65C0AF000000000000000000000000000000 ?
It seems like the address.addressToString(binary.buffer);
only renders address binaries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is only for Addresses.
The output for 0x99C1ED94FF2D65C0AF000000000000000000000000000000
--> THBIMC3THGH5RUYAAAAAAAAAAAAAAAAAAAAAAAA
which is we should not allow alias on the Address field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catbuffer allows aliases in the (unresolved)address fields and mongo stores it. Rest needs to render that, AAAA doesn't seem right to me...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this PR and it doesn't render aliases correctly.
All the "addresses" we are formating here are actually unresolved addresses, where the value can either be a real address or a namespace id.
If you try this PR against testnet, you will see this:
http://localhost:3000/transactions/confirmed?height=141765
The same happens with all the unresolved addresses
The namespace id format is incorrect, it's not either the current hex format or a namespace id
When the "address" field is actually an alias, we should either render the binary hex or the namespace friendly id as explained before, at least in this pr. Resolving the alias could be done in another PR, but this pr should not break the alias rendering. Be aware that resolving the alias would require db access, it's a feature change.
Note: to try testnet:
got to ./rest and run
yarn bootstrap-start-testnet
and then in another terminal
yarn start:dev
Wait for testnet to be synced a little bit, another (lower) example of this issue is:
http://localhost:3000/transactions/confirmed?height=846
You can pull more examples of blocks with aliases
http://localhost:3000/statements/resolutions/address?order=asc
@@ -239,4 +239,15 @@ describe('db formatting rules', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
it('can format encodedAddress type', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a case where the unresolved address is an alias, 0x99C1ED94FF2D65C0AF000000000000000000000000000000
@Jaguar0625 , do you think that rendering aliases as an invalid address is ok? Please see the screenshots above with all the AAAAs |
yes, that is a valid unresolved address. i'm not sure i see the problem? |
I'm not sure what you're saying, this technically is a valid address... (not valid in the sense of IsValidAddress) |
Yes, I'm talking in the sense of IsValidAddress This is the spec for the related open API symbol/symbol-openapi#272 You can see that the OR links to a NamespaceId.yml which is a user-friendly namespace identifier 16 hex format like: 85BBEA6CC462B244, a 16 chars hex. I think the AAAA style address could be confusing and it cannot be used as a query or path param like the 16 hex. Examples: http://ngl-dual-101.testnet.symboldev.network:3000/namespaces (16 hex id) https://github.com/symbol/symbol-openapi/blob/main/spec/parameters/path/namespaceId.yml One benefit of this PR is that you can use the real address from the payload as a query param, ideally, the namespace id can be used as a query param too (at least until we figure out the alias resolution). The AAAAA parsing/mapping to a usable namespace id could get a bit funny If you think the AAAA addresses are fine, ok to merge. |
i think this PR is fine to merge. longer term we might want to consider @rg911 suggestion: #611 (comment) |
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
Fix
encodedAddress
in modelType.bufferToResolvedAddress
function to convert buffer to Base32 Address and NamespaceIdTodo:
Resolved: #604