-
Notifications
You must be signed in to change notification settings - Fork 2.2k
JSON accounts: allow loading code from a file #4783
Conversation
libethereum/ChainParams.cpp
Outdated
}; | ||
set<string> const c_knownParamNames = {c_minGasLimit, c_maxGasLimit, c_gasLimitBoundDivisor, | ||
c_homesteadForkBlock, c_EIP150ForkBlock, c_EIP158ForkBlock, c_accountStartNonce, | ||
c_maximumExtraDataSize, c_tieBreakingGas, c_blockReward, c_byzantiumForkBlock, c_eWASMForkBlock, |
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.
Here c_eWASMForkBlock
is added. I missed it previously.
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.
Do you want this into another pull request and merge it now?
libethereum/Account.cpp
Outdated
string const c_storage = "storage"; | ||
string const c_shouldnotexist = "shouldnotexist"; | ||
string const c_precompiled = "precompiled"; | ||
std::set<string> const c_knownAccountFields = { | ||
c_wei, c_finney, c_balance, c_nonce, c_code, c_storage, c_shouldnotexist, | ||
c_wei, c_finney, c_balance, c_nonce, c_code, c_file, c_storage, c_shouldnotexist, |
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 put path to the file with code as an attribute of account object?
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.
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 thought the idea was to load code from file upon loading genesis.json
why would we need to change logic of Accont.h ?
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.
Load a code from a file what do what with it?
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 as I understand currently account's code is loaded from genesis.
could we change it so that upon loading that genesis account code will just be read from external file? other then that it is the same genesis config file loading.
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 understand
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.
in jsonToAccountMap at
if (o[c_code].type() == json_spirit::str_type)
{
if (o[c_code].get_str().substr(0,2) == "//")
read code from file in this link and parse it.
}
I thought we could just do it that way.
so in genesis config file at accounts code it will be
"code": "//path/to/file"
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 it is better making it more explicit than hiding it via special expressions.
libethereum/Account.cpp
Outdated
@@ -88,11 +90,12 @@ namespace | |||
string const c_balance = "balance"; | |||
string const c_nonce = "nonce"; | |||
string const c_code = "code"; | |||
string const c_file = "file"; ///< A file containg a code as bytes. |
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 file
may be misleading to mean loading an account JSON from a file, e.g{accounts: { "0x0044...": { file: "/path" } } }
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.
Back to "codeInFile" or "codeFromFile"?
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, probably the second is more readable.
Codecov Report
@@ Coverage Diff @@
## develop #4783 +/- ##
==========================================
- Coverage 60.7% 60.7% -0.01%
==========================================
Files 348 348
Lines 27384 27405 +21
Branches 2845 2850 +5
==========================================
+ Hits 16624 16636 +12
- Misses 9761 9780 +19
+ Partials 999 989 -10 |
if (codeObj.type() == json_spirit::str_type) | ||
{ | ||
auto& codeStr = codeObj.get_str(); | ||
if (codeStr.find("0x") != 0 && !codeStr.empty()) |
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.
codeStr.find("0x") could produce an error.
0x should be at located at first 2 bytes of the code 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.
If you look at the diff, this code is as is before. No changes.
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 know. I just saw an issue.
11220x3345
will pass.
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 that could be addressed in a separate PR then?
Ready? |
The field name wasn't changed from |
Changed and rebased. One commit less. |
@pirapira okay to merge? |
I couldn't spot the offending failure in AppVeyor with a quick look. Coming back later. |
Can you restart Appveyor? It is in the "random" tests, perhaps the failure is actually random :) |
I cannot restart it. |
Restarted. |
this is probably the issue with blockchain tmp files collision. |
@pirapira appveyor suceeded 🍾 |
Fixes #4774