-
Notifications
You must be signed in to change notification settings - Fork 95
non utf8 support for asset strings #577
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
Conversation
| ap.AssetName = strings.ReplaceAll(ap.AssetName, "\000", "") | ||
| ap.UnitName = strings.ReplaceAll(ap.UnitName, "\000", "") | ||
| ap.URL = strings.ReplaceAll(ap.URL, "\000", "") |
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.
This looks incorrect, but I'm probably not understanding the context :
going from imported AssetParams to persisted AssetParams should base64 the result into the "XXXBytes" variant only when needed. Otherwise, it should remain in the original variable.
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.
This part is for the transaction's JSON format, these fields happen to be unused but I left it in like this in case Anya wants to use it.
|
|
||
| // In case the DB layer filled the name with non-printable utf8 | ||
| if asset.Params.Name != nil { | ||
| name := util.PrintableUTF8OrEmpty(*asset.Params.Name) |
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.
while it's ok to add this, I would suggest you'll add a logging here to indicate that it happened, as it implies there is an issue elsewhere.
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 was imagining another DB implemented the API. I don't think it's strictly an issue for the DB layer to ignore this presentation requirement. For Postgres, the tests verify that this case would never be triggered.
Codecov Report
@@ Coverage Diff @@
## develop #577 +/- ##
===========================================
+ Coverage 43.80% 47.14% +3.34%
===========================================
Files 24 25 +1
Lines 3801 3873 +72
===========================================
+ Hits 1665 1826 +161
+ Misses 1873 1767 -106
- Partials 263 280 +17
Continue to review full report at Codecov.
|
|
Looks good overall. Left some comments in the code. Could you also add tests in |
| URLBytes: []byte(params.URL), | ||
| } | ||
|
|
||
| ret.AssetName = util.PrintableUTF8OrEmpty(params.AssetName) |
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.
Might be simpler to do:
if params.AssetName is not printable {
params.AssetNameBytes = ...
params.AssetName = nil
}
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 copied this function from the go-algorand implementation, it lets us skip 16 if statements which is pretty nice. Some discussion about the different versions here if you're curious: algorand/go-algorand#2555 (comment)
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, most of the times it is better. But in this function we set AssetNameBytes and then conditionally unset it, which took me some effort to understand. I suggest IsPrintableUTF8() is factored out of PrintableUTF8OrEmpty() and used here.
| '"reserve": "EQJSQTOITX64CPGA5VRKBKLEJR57YXVNLTW5DKZMESIPTEOLRDNWQIJCGU"' \ | ||
| '"total": 1000000000000' \ | ||
| '"unit-name": "bogo"' \ | ||
| '"unit-name-b64": "Ym9nbw=="' |
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 think we also need tests where the strings are not utf-8-printable. I think a go test will suffice.
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.
Unfortunately, I don't have a good way to test the HTTP layer. You're right that this is missing the final check for removing name/unit-name/url if they contain non-utf8 characters.
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.
Mock IndexerDb and test the api functions? Ideally, we would test api functions with an implementation (implementations) of IndexerDb, but a bit of refactoring will need to be done beforehand.
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 now, I have run some tests manually.
I think it would be good to do some refactoring to the api.Serve, the pattern used by the block generator is pretty nice and allowed me to start/stop the server multiple times for the performance test runner.
|
LGTM. I will let @tsachiherman and @brianolson take a look as well. |
brianolson
left a comment
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.
Gave it another read and generally looks good but one quibble over file layout.
| "github.com/algorand/indexer/types" | ||
| ) | ||
|
|
||
| type assetParams struct { |
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 don't like the split of types.go/encode.go/decode.go
I'd rather see one type declaration and its encode and decode in one file (OOP style). Easier to make sure encode and decode match that way. Easier to find the type being referred to.
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.
This split makes a lot more sense in the context of Tolik's rewrite, this pattern is used to wrap many more objects than I've done here.
I would probably opt for a single file, only because it would let you use simple text searches to find everything. But don't have a strong opinion either way. For now, I'd like to match his PR to make the merge slightly easier, maybe we can postpone this discussion for the rewrite PR?
Reference: https://github.com/algorand/indexer/blob/tolik/acct-rewrite4/idb/postgres/internal/encoding/types.go
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 won't block over it but I still don't like it. I still want type-encode-decode bundled together in one file. types.go makes the most sense when the only thing happening to them is via reflection (e.g. go-codec loading and storing serialization forms).
| "github.com/algorand/go-algorand-sdk/encoding/json" | ||
| "github.com/algorand/indexer/types" | ||
|
|
||
| sdk_types "github.com/algorand/go-algorand-sdk/types" |
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 grouping here is weird; it should have been like this, right ?
import(
"github.com/algorand/go-algorand-sdk/encoding/json"
sdk_types "github.com/algorand/go-algorand-sdk/types"
"github.com/algorand/indexer/types"
)
tsachiherman
left a comment
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.
looks good to me.
Summary
If asset strings contain non-printable characters they are stored in a byte array.
Return
-b64asset strings in most endpoints.Test Plan
New unit test