Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

string test_getLogHash(txHash) #4986

Merged
merged 3 commits into from
May 9, 2018
Merged

string test_getLogHash(txHash) #4986

merged 3 commits into from
May 9, 2018

Conversation

winsvega
Copy link
Contributor

@winsvega winsvega commented Apr 27, 2018

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

@winsvega winsvega requested review from pirapira and gumb0 April 27, 2018 20:32
if (blockReceipts.receipts.size() != 0)
return exportLog(blockReceipts.receipts[t.transactionIndex()].log());
}
return toJS(dev::EmptyListSHA3);
Copy link
Member

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-io
Copy link

codecov-io commented Apr 27, 2018

Codecov Report

Merging #4986 into develop will increase coverage by 0.27%.
The diff coverage is 0%.

Impacted file tree graph

@@             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

@gumb0
Copy link
Member

gumb0 commented Apr 30, 2018

What about logs bloom filter in transaction receipt - couldn't you just use it instead of this hash?
It's just 256 bytes long.

@winsvega
Copy link
Contributor Author

current tests has log hash.
ask @felix from the go team. he might sometimes be in the berlin office.
He is mainly the one who uses this log hash information.

@gumb0
Copy link
Member

gumb0 commented May 2, 2018

Ok, so it's a part of the filled test format, I see, ok then I guess we need it for client compatibility

using namespace dev::rpc;
using namespace jsonrpc;

Test::Test(eth::Client& _eth): m_eth(_eth) {}

string exportLog(eth::LogEntries const& _logs)
Copy link
Member

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

Copy link
Member

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

if (blockReceipts.receipts.size() != 0)
return exportLog(blockReceipts.receipts[t.transactionIndex()].log());
}
return toJS(dev::EmptyListSHA3);
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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")

Copy link
Member

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

Copy link
Contributor Author

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.


string Test::test_getLogHash(string const& _txHash)
{
if (m_eth.blockChain().isKnownTransaction(h256(_txHash)))
Copy link
Member

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?

Copy link
Contributor Author

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>

Copy link
Member

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.

@@ -42,8 +42,8 @@ class Test: public TestFace
{
return RPCModules{RPCModule{"test", "1.0"}};
}

virtual bool test_setChainParams(const Json::Value &param1) override;
virtual std::string test_getLogHash(std::string const& param1) override;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ prefix for parameters

@pirapira pirapira dismissed their stale review May 3, 2018 16:32

My first complaint has been resolved.

s.appendList(_logs.size());
for (eth::LogEntry const& l : _logs)
l.streamRLP(s);
return toHexPrefixed(sha3(s.out()));
Copy link
Member

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);


if (m_eth.blockChain().isKnownTransaction(txHash))
{
LocalisedTransaction t = m_eth.localisedTransaction(txHash);
Copy link
Member

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)

Copy link
Contributor Author

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

Copy link
Member

@gumb0 gumb0 left a 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&)
Copy link
Member

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.

@gumb0
Copy link
Member

gumb0 commented May 7, 2018

Oh wait I made a mistake, I didn't mean to throw an enum

@winsvega
Copy link
Contributor Author

winsvega commented May 7, 2018

you could squash the changes then and make a one finale commit

@gumb0
Copy link
Member

gumb0 commented May 7, 2018

Didn't squash all of them, sorry

}
catch (BadHexCharacter const&)
{
throw JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS);
Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ex ?

Copy link
Contributor Author

@winsvega winsvega May 8, 2018

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()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

  1. 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. Here JsonRpcException is always caught by our JSON-RPC framework, which doesn't know anything about boost.exception and just transforms it into JSON response.
  2. The second argument to JsonRpcException constructor will also be added to JSON response, but what() 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.

Copy link
Member

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

@gumb0
Copy link
Member

gumb0 commented May 7, 2018

Ok now, but I still think returning empty list for "not found" is not the best design.

@winsvega
Copy link
Contributor Author

winsvega commented May 7, 2018

the function should return in all it's paths. some compilers does not allow not returning the value.
is it ok if you use throw and no return after {} ?

actually in many throw cases right now client will just silently return json rpc internall error without any comment.

@gumb0
Copy link
Member

gumb0 commented May 7, 2018

the function should return in all it's paths. some compilers does not allow not returning the value.
is it ok if you use throw and no return after {} ?

Sure it's allowed

actually in many throw cases right now client will just silently return json rpc internall error without any comment.

That should be fixed

Copy link
Member

@pirapira pirapira left a 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.

@winsvega winsvega merged commit b693018 into develop May 9, 2018
@axic axic deleted the smallrpc3 branch May 10, 2018 10:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants