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

test_getPostState #4972

Closed
wants to merge 1 commit into from
Closed

test_getPostState #4972

wants to merge 1 commit into from

Conversation

winsvega
Copy link
Contributor

@winsvega winsvega commented Apr 20, 2018

return current actual post state of the blockchain.

@winsvega winsvega requested review from pirapira and gumb0 April 20, 2018 12:40
continue;

Json::Value o;
if (mapEmpty || _map.at(a.first).hasBalance())
Copy link
Member

Choose a reason for hiding this comment

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

Why is this empty case treated in a special way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is actually a copy of the same method from tests. but that one works with json_spirit.
I guess the account map here could be removed. because it is needed for expect sections with incomplete post states.

@codecov-io
Copy link

codecov-io commented Apr 20, 2018

Codecov Report

Merging #4972 into develop will decrease coverage by 0.13%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4972      +/-   ##
===========================================
- Coverage    61.08%   60.95%   -0.14%     
===========================================
  Files          350      350              
  Lines        28303    28379      +76     
  Branches      2889     2893       +4     
===========================================
+ Hits         17290    17299       +9     
- Misses       10049    10118      +69     
+ Partials       964      962       -2

if (_state.code(a.first).size() > 0)
o["code"] = toHexPrefixed(_state.code(a.first));
else
o["code"] = "";
Copy link
Member

Choose a reason for hiding this comment

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

Do you really need to separate these two cases? What's wrong if o["code"] becomes 0x?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you right. changed this now

else
return toJS(EmptyListSHA3);
}
return "";
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 this case should be an error, rather than just an empty reply.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how do we report an error via RPC reply ?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know, look at other methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well there is BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));

but it stops the client. which is not a good thing. you dont want a client to stop on malicious rpc

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't stop the client, all RPC methods report errors kind of like that and the last time I tried it I saw correct error message on the caller side.

Could you investigate whether it crashes because of unhandled exception or for other reason?

Copy link
Member

Choose a reason for hiding this comment

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

Also related issue is #4726

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no. it does not crash the client. I was wrong. the rpc error is returned.

{
Json::Value out;
Json::FastWriter fastWriter;
if (u256(param1["version"].asString()) == c_postStateJustHashVersion)
Copy link
Member

Choose a reason for hiding this comment

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

Does the RPC method take 1, 2, or 3, indicating different versions? In other parts of the RPC, "latest" means "latest", and so on. I guess strings like "jushash" "fullstate" or "loghash" are easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem here. it could be anything.
the discussion is here
ethereum/retesteth#7

@winsvega winsvega force-pushed the smallrpc3 branch 2 times, most recently from 23615c2 to d37e20c Compare April 20, 2018 15:09
@winsvega
Copy link
Contributor Author

@pirapira do you have any more proposals?
I have one change: missing method note in test.json file

@winsvega
Copy link
Contributor Author

Actually should this method be a test method only ?

@gumb0
Copy link
Member

gumb0 commented Apr 23, 2018

API-design-wise it should better be three different API methods instead of one method doing completely different things based on "version" param
Like getStateRootHash, getState... and I'm not sure why you need the last one

else if (param1["version"].asString() == c_postStateLogHashVersion)
{
if (m_eth.blockChain().receipts().receipts.size() != 0)
return exportLog(m_eth.blockChain().receipts().receipts[0].log());
Copy link
Member

Choose a reason for hiding this comment

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

This gets the receipt of only the first transaction of the block, is this your intention?

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you just use receipts root which is in the block header?

Json::Value out;
Json::FastWriter fastWriter;
if (param1["version"].asString() == c_postStateJustHashVersion)
return toJS(m_eth.postState().state().rootHash());
Copy link
Member

Choose a reason for hiding this comment

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

Is this any different from getting eth.getBlock("latest").stateRoot ?

@@ -33,6 +34,60 @@ using namespace jsonrpc;

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

Json::Value fillJsonWithState(eth::State const& _state)
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 the unnamed namespace

@winsvega
Copy link
Contributor Author

winsvega commented Apr 23, 2018

Casey said there are debug methods specified for mainnet.
ethereum/retesteth#5


I'd favor a simpler primitive that would also be useable on the mainnet: 
debug_accountRangeAt(blockNum, startKey, limit), inspired by storageRangeAt. 
The method would iterate over the leaves of the state trie (starting at startKey), 
and return a list of address hashes (up to the limit). 
Address hashes are returned because most clients (fast sync'd clients in particular) 
do not have the hash preimages, and it is not much effort to maintain
 the hash preimages separately (if the client has them, they can be queried with debug_preimage. 
They can also be imported/exported separately).
 The storage for each account can then be dumped with storageRangeAt.

this getPost state method should probably be implemented with those debug methods.

@chfast
Copy link
Member

chfast commented Apr 23, 2018

API-design-wise it should better be three different API methods instead of one method doing completely different things based on "version" param

I'm also for it. It's better to have many simple RPC methods than not many but complex RPC methods. Having simple ones you can who is using what and why. And also able to deprecate individual methods in future.

@winsvega
Copy link
Contributor Author

This method will be replaced by

debug_accountRangeAt
debug_storageRangeAt

which could work on mainnet. with the first one you could select accounts in state at specific block after specific transaction.

with the second you could select post state values of a specific account in a specific block after specific transaction.

@winsvega winsvega closed this Apr 27, 2018
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.

5 participants