-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
index.js
Outdated
|
||
var Account = module.exports = function (data) { | ||
// Define Properties | ||
var fields = [{ | ||
name: 'nonce', | ||
default: new Buffer([]) | ||
default: Buffer.from([]) |
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.
Buffer.allocUnsafe(0) ?
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.
Thanks.
Sorry, I'm not really aware of the implications, can someone explain? Is this only for nonce
?
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.
Buffer.from([])
returns an empty buffer. Buffer.allocUnsafe(0)
does the same but is faster.
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.
My intentions mostly was that alloc*(0)
is more explicit than .from([])
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.
So maybe we should avoid using the unsafe
version all together in ethereumjs
context, for not risking to leak a private key or stuff like this?@axic ?
Just tested both alloc
versions on the console, there was not some noticeable lag on the output, feels like it doesn't really make a difference - at least for one-time operations.
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.
Replaced this with alloc
, actually feel better with this.
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.
You did not see the difference, because alloc(0)
and allocUnsafe(0)
return same.
alloc: https://github.com/nodejs/node/blob/28a0af358ac998f94052199dc62a8140e8a11ac5/lib/buffer.js#L269
allocUnsafe: https://github.com/nodejs/node/blob/28a0af358ac998f94052199dc62a8140e8a11ac5/lib/buffer.js#L278 & https://github.com/nodejs/node/blob/28a0af358ac998f94052199dc62a8140e8a11ac5/lib/buffer.js#L307
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.
alloc(0)
will be the same since there is 0 bytes to clean after allocation.
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.
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 mind which is used, just make sure to update -util and -vm accordingly. -vm only uses alloc
, -util uses allocUnsafe
also in a combination of allocUnsafe
+fill
(which should really be just alloc
).
utACK |
Looks good apart from @fanatid's comment. |
cf74009
to
10f5bfb
Compare
Done (for all 4 occurrences). Are there any occasions where to consider the |
Yes. |
…fer.from() (also fixes linting)
10f5bfb
to
84991a1
Compare
This fixes the travis build by updating the Node versions tested and use non-deprecated (safe-buffer) initialization.