-
Notifications
You must be signed in to change notification settings - Fork 2.2k
string test_getLogHash(txHash) #4986
Conversation
libweb3jsonrpc/Test.cpp
Outdated
if (blockReceipts.receipts.size() != 0) | ||
return exportLog(blockReceipts.receipts[t.transactionIndex()].log()); | ||
} | ||
return toJS(dev::EmptyListSHA3); |
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.
Indentation around here is a bit strange. Did you run git-clang-format?
Codecov Report
@@ Coverage Diff @@
## develop #4986 +/- ##
===========================================
+ Coverage 60.67% 60.94% +0.27%
===========================================
Files 350 350
Lines 28338 28368 +30
Branches 2864 2894 +30
===========================================
+ Hits 17193 17289 +96
+ Misses 10198 10115 -83
- Partials 947 964 +17 |
What about logs bloom filter in transaction receipt - couldn't you just use it instead of this hash? |
current tests has log hash. |
Ok, so it's a part of the filled test format, I see, ok then I guess we need it for client compatibility |
libweb3jsonrpc/Test.cpp
Outdated
using namespace dev::rpc; | ||
using namespace jsonrpc; | ||
|
||
Test::Test(eth::Client& _eth): m_eth(_eth) {} | ||
|
||
string exportLog(eth::LogEntries const& _logs) |
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.
Put free functions into unnamed namespace
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.
"export" seems too generic in this context, I'd name it logsToRlpListHex
libweb3jsonrpc/Test.cpp
Outdated
if (blockReceipts.receipts.size() != 0) | ||
return exportLog(blockReceipts.receipts[t.transactionIndex()].log()); | ||
} | ||
return toJS(dev::EmptyListSHA3); |
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 should it be empty list in case transaction not found? This way the user of the method can't understand whether the transaction produced no log or it doesn't exist at all.
Maybe we should return error in case transaction not found?
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.
hmm. that is a good question. the issue is that we don't have like interclient standart for this case.
as it is a test method. do you think its ok to return 0x00 hash in case of error?
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 returning error is cleaner than magic value of hash.
You should also be able to make the error more specific by adding error message like throw JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS, "Transaction not found")
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.
Or you could introduce new error code and return it like throw JsonRpcException(TxNotFoundErrorCode)
Maybe check what geth returns from eth_getTransactionByHash
in this case
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.
ideally all json requests response should have a common scheme that all clients follow.
libweb3jsonrpc/Test.cpp
Outdated
|
||
string Test::test_getLogHash(string const& _txHash) | ||
{ | ||
if (m_eth.blockChain().isKnownTransaction(h256(_txHash))) |
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 when you send here invalid hash string? Does it crash or is appropriate error returned?
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.
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<dev::BadHexCharacter>'
what(): /home/wins/Ethereum/cpp-ethereum/libdevcore/CommonData.cpp(93): Throw in function dev::bytes dev::fromHex(const string&, dev::WhenError)
Dynamic exception type: boost::exception_detail::clone_impl<dev::BadHexCharacter>
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 you should catch it here and rethrow as JsonRpcException
, then method will correctly return error.
libweb3jsonrpc/Test.h
Outdated
@@ -42,8 +42,8 @@ class Test: public TestFace | |||
{ | |||
return RPCModules{RPCModule{"test", "1.0"}}; | |||
} | |||
|
|||
virtual bool test_setChainParams(const Json::Value ¶m1) override; | |||
virtual std::string test_getLogHash(std::string const& param1) override; |
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.
_
prefix for parameters
libweb3jsonrpc/Test.cpp
Outdated
s.appendList(_logs.size()); | ||
for (eth::LogEntry const& l : _logs) | ||
l.streamRLP(s); | ||
return toHexPrefixed(sha3(s.out())); |
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.
It would be the same result, but for consistency I'd use either toHexPrefixed
or toJS
in both places - here and in return toJS(dev::EmptyListSHA3);
libweb3jsonrpc/Test.cpp
Outdated
|
||
if (m_eth.blockChain().isKnownTransaction(txHash)) | ||
{ | ||
LocalisedTransaction t = m_eth.localisedTransaction(txHash); |
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 could throw, too (that would mean something is not right in DB), so I would wrap all of this if
in try..catch
, too and rethrow as JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR)
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.
Yeap, I thought of that
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.
Please also convert all tabs to spaces in Test.h
to avoid mixing them
{ | ||
txHash = h256(_txHash); | ||
} | ||
catch (BadHexCharacter const&) |
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.
Let's not mask all possible errors, but only catch the errors of parsing the hexstring. If at some point (maybe in the future) it start to throw other exceptions, we won't fail with confusing "invalid params" error.
Oh wait I made a mistake, I didn't mean to throw an enum |
you could squash the changes then and make a one finale commit |
Didn't squash all of them, sorry |
} | ||
catch (BadHexCharacter const&) | ||
{ | ||
throw JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS); |
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 no any sense really in using BOOST_THROW_EXCEPTION
for JsonRpcException
which is not a boost exception
} | ||
catch (std::exception const& ex) | ||
{ | ||
cwarn << ex.what(); |
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.
When something goes wrong we don't want to just silently return "internal error", we'd like to have a way to understand what happened, so let's output the error to the log.
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.
_ex ?
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 could still use boost exception for nicer error output like this:
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR, _ex.what()));
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.
No
BOOST_THROW_EXCEPTION
wraps your exception with additional info like filename and line in debug build, but it can be useful only if it's caught and accessed with boost.exception facilities. HereJsonRpcException
is always caught by our JSON-RPC framework, which doesn't know anything about boost.exception and just transforms it into JSON response.- The second argument to
JsonRpcException
constructor will also be added to JSON response, butwhat()
string is usually for our exceptions not user-friendly at all, I don't think it will look appropriate at the client side. We should just log it in our log.
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.
ex
is not a function parameter, so no _
prefix needed
Ok now, but I still think returning empty list for "not found" is not the best design. |
the function should return in all it's paths. some compilers does not allow not returning the value. actually in many throw cases right now client will just silently return json rpc internall error without any comment. |
Sure it's allowed
That should be fixed |
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.
string test_getLogHash(string _txHash)
Get pre-calculated log has of the _txHash. hash of emptyRLPList if transaction not found.
Log hash could be calculated from transaction receipt, but some transactions has too many logs, so we need a method to get just the log hash.
looks like this would be an optional method. because it is not required for state tests to check log hash.
ethereum/retesteth#7