Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Read registry_address from block with REQUEST_CONFIRMATIONS_REQUIRED #8309

Merged
merged 5 commits into from
Apr 6, 2018

Conversation

sorpaas
Copy link
Collaborator

@sorpaas sorpaas commented Apr 4, 2018

Use REQUEST_CONFIRMATIONS_REQUIRED instead of the latest block. Fix one TODO item in code comment.

@sorpaas sorpaas added the A0-pleasereview 🤓 Pull request needs code review. label Apr 4, 2018
@sorpaas sorpaas added this to the 1.11 milestone Apr 4, 2018
@5chdn 5chdn added the M4-core ⛓ Core client code / Rust. label Apr 5, 2018
self.data.write().contract_address = service_contract_addr;
if let Some(block_hash) = get_confirmed_block_hash(&*client, REQUEST_CONFIRMATIONS_REQUIRED) {
// update contract address from registry
let service_contract_addr = client.registry_address(self.name.clone(), BlockId::Hash(block_hash)).unwrap_or_default();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure whether it will work with not archive nodes. cc @tomusdrw

Copy link
Contributor

@rphmeier rphmeier Apr 5, 2018

Choose a reason for hiding this comment

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

right, the state might be pruned get_confirmed_block_hash could return the oldest ancestor possible in that case, but then the call to reigistry_address will race with the pruning. We really need some way to block pruning while we inspect state by using some kind of extended BlockId.

@debris
Copy link
Collaborator

debris commented Apr 5, 2018

this should be also reviewed by @svyatonik

@debris debris requested a review from svyatonik April 5, 2018 10:57
@rphmeier
Copy link
Contributor

rphmeier commented Apr 5, 2018

Using a constant number of confirmations is a little tenuous. Can we add a TODO to do this based on consensus finality where possible instead?

@sorpaas
Copy link
Collaborator Author

sorpaas commented Apr 5, 2018

@rphmeier There were originally a TODO item and I was trying to fix that. Looks like this becomes complicated if pruning is enabled, and I don't think I have a way to fix this...

I think the original TODO comment should be enough as a holder for anyone looks into this. So I'm going to close this PR if that's okay.

@sorpaas sorpaas closed this Apr 5, 2018
@svyatonik
Copy link
Collaborator

@debris @rphmeier Thanks for pointing to this. This code should work only if we're synchronized (!sync.status().is_syncing()) and have a full trust (chain_info().security_level().is_full()) => I guess that's kind of a guarantee that we're dealing with the most up-to-date state (at least that's how updater works). Also, please correct me if I'm wrong (that's what I'm not 100% sure about), but pruning leaves some recent states and since we're dealing with block latest_block - 3, it's state is also not pruned (I believe that recent_states.length > 3). So this means that we have some time to work with this state (until it'll be pruned). So the problem would only arise if we're trying to deal with this state for too long. And in case if state is pruned - trying to read from contract at this state would lead to an error. Am I correct? If so, I wouldn't consider this as a serious problem && I'm for letting this PR merged-in.

@rphmeier I guess number of confirmation is an universal decision (and afair our UI and I guess most of DApps use the similar approach). Thanks for pointing that there's another way, though. @sorpaas could you please add TODO for this.

@sorpaas Thanks for helping with this TODO :) It is a little bigger than just fixing service_contract.rs, though :) And while changing the acl_storage.rs in the same way is arguable (and I wouldn't recommend to do this), changing the client.registry_address call in the key_server_set.rs is desirable. Could you please also change this in the similar way? Or just move original TODO to that file, instead or removing it?

@svyatonik svyatonik reopened this Apr 5, 2018
@sorpaas
Copy link
Collaborator Author

sorpaas commented Apr 5, 2018

@svyatonik Okay. Will do!

@rphmeier
Copy link
Contributor

rphmeier commented Apr 5, 2018

@svyatonik

trying to read from contract at this state would lead to an error

yeah. since it's only 3 blocks behind the head of the chain (minimum pruning we allow for now is 8) this is probably not a problem, but it's an assumption that can be broken well outside of this module. Although if this is triggered while we're importing many blocks and not just at the head of the chain, there is a pretty bad race condition.

The finality stuff isn't useful to most DApps since they're on the mainnet, so their only choice is to rely on confirmations until CasperFFG. But where possible, it's more correct and safer to use finality. It's not something the codebase supports yet but it will soon.

@@ -0,0 +1,12 @@
use ethcore::client::{Client, BlockChainClient, BlockId};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add license preamble to the beginning of the file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or maybe just make this function a member of TrustedClient? Both have similar purpose.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@svyatonik I added license preamble. Looks like for cases using get_confirmed_block_hash we need to directly dealt with a Client reference but not TrustedClient. So just thought this would be less complicated if we don't do some refactoring.

And regarding license preamble, I realized that they still say 2015-2017, do we need to change all of them to 2015-2018?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think so - guess it will be enough for new file only. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay. Got it!

@svyatonik
Copy link
Collaborator

Also please do not forget to add TODO about using finality when possible (see my big comment above). Thanks!

@sorpaas
Copy link
Collaborator Author

sorpaas commented Apr 6, 2018

@svyatonik Sorry I missed that!

Copy link
Collaborator

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

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

LGTM

@svyatonik svyatonik added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Apr 6, 2018
@5chdn 5chdn merged commit d7a7f03 into openethereum:master Apr 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants