Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

light-client: in what scenarios can a primary have no trusted LightBlock #395

Closed
xla opened this issue Jun 30, 2020 · 11 comments
Closed

light-client: in what scenarios can a primary have no trusted LightBlock #395

xla opened this issue Jun 30, 2020 · 11 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request light-client Issues/features which involve the light client question Further information is requested

Comments

@xla
Copy link
Contributor

xla commented Jun 30, 2020

In reference to the thread in #394 (comment) where the question came up when a primary can have no trusted LightBlock. What is referred to here is this method of the Instance:

pub fn latest_trusted(&self) -> Option<LightBlock> {
self.state.light_store.highest(Status::Trusted)
}

By returning an optional it indicates that its presence is not always guaranteed or expected. When can that be the case for the primary of the Supervisor? And if so is it okay to treat it as a Maybe? /cc @brapse @milosevic @romac

@xla xla added documentation Improvements or additions to documentation enhancement New feature or request question Further information is requested light-client Issues/features which involve the light client labels Jun 30, 2020
@romac
Copy link
Member

romac commented Jun 30, 2020

We should probably ensure somewhere that the returned light block is still within the trusting period, otherwise it's not really a trusted block, right @milosevic?

Perhaps that should even be the responsibility of the light store? WDYT?

@OStevan
Copy link
Contributor

OStevan commented Jun 30, 2020

A somewhat related question to this (I can open a separate issue if other thinks it is not related to the discussion started here).

I noticed that we are maintaining Instances with associated state for each LightClient. However when doing fork detection we are using InMemory state so we never update the state associated states. Moreover, when we pass the fork detection the only light block which becomes trusted is the one for the primary.

Now, given this behaviour, one could imagine a situation where the primary does not change for a sufficiently long period of time such that the initially trusted light block (which is also the only trusted light block for all witness states) moves out of the trusted period and becomes no longer valid. In this situation an error for any of the subsequent verification requests on the primary would trigger primary swap and would bring a Supervisor in a state where it simply can not verify any new light blocks as the state we are using has only expired light blocks.

(and finally the question 😄 ) @romac @brapse @milosevic Is this behaviour something which is correct or we expect to swap primaries relatively frequently so that the latest trusted light block never falls out of the trusted period?

@milosevic
Copy link
Contributor

Light client starts with a trusted light block (subjective initialisation) that must be within trusted period. There should always be a trusted light block in the store that is within its trusted period; once this is not anymore the case we should exit and require user to re-initialise the light client. Therefore, a primary should always have trusted light block in the store, so no need for Option. @josef-widder We should check if we have clarified this in the spec, as introducing trusted light block recently maybe introduce some ambiguity.

@OStevan
Copy link
Contributor

OStevan commented Jul 3, 2020

@milosevic I had a bit of different issue in mind, which more about how we deal with state of different peers. During the Supervisor verification the only instance which updates it's LightBlockStore is the primary, while during fork detection the witnesses are using freshly created in memory stores which after that get discarded. Therefore, even though we have stored a LightBlock which we consider trusted if at any point in time we find out the primary is faulty we swap it and use the State associated with the new primary instance and as soon as we do that we basically go back in time to the state before any verification. For me this behaviours is strange as the history of previously verified LightBlocks is lost and we might need to restart the light client just because the primary was faulty.

@josef-widder
Copy link
Member

Light client starts with a trusted light block (subjective initialisation) that must be within trusted period. There should always be a trusted light block in the store that is within its trusted period; once this is not anymore the case we should exit and require user to re-initialise the light client. Therefore, a primary should always have trusted light block in the store, so no need for Option. @josef-widder We should check if we have clarified this in the spec, as introducing trusted light block recently maybe introduce some ambiguity.

Right now we have this covered in the English spec as follows:

[LCV-INV-TP.1]:

It is always the case that LightStore.LatestTrusted.Header.Time > now - trustingPeriod.

If the invariant is violated, the light client does not have a header it can trust. A trusted header must be obtained externally, its trust can only be based on social consensus.

@josef-widder
Copy link
Member

Regarding the question of an option, there is a separate question: In Fastsync we first check the height of a peer and only request blocks less than that height. In the Lightclient specs, we gloss over that, and (implicitly) assume that the primary is always synchronized.
Similarly, there is the question what should happen if VerifyToTarget is called for a height that does not exist yet on the blockchain. In this case the primary cannot return a block obviously.
I am not sure how relevant these cases are, or whether they cannot happen in the use cases. But I guess we should clarify that? What do you think @milosevic ?

@josef-widder
Copy link
Member

@milosevic I had a bit of different issue in mind, which more about how we deal with state of different peers. During the Supervisor verification the only instance which updates it's LightBlockStore is the primary, while during fork detection the witnesses are using freshly created in memory stores which after that get discarded. Therefore, even though we have stored a LightBlock which we consider trusted if at any point in time we find out the primary is faulty we swap it and use the State associated with the new primary instance and as soon as we do that we basically go back in time to the state before any verification. For me this behaviours is strange as the history of previously verified LightBlocks is lost and we might need to restart the light client just because the primary was faulty.

I think once a LightBlock is trusted, it should stay trusted forever, even if the primary fails later. Otherwise, it is not clear what is the meaning of "trusted".

@brapse
Copy link
Contributor

brapse commented Jul 8, 2020

@xla are we happy with the answer here or are their additional details that can be added before closing this issue?

@xla
Copy link
Contributor Author

xla commented Jul 10, 2020

Follow up captured by @romac in #420 - thanks everyone for contributing to the conversation.

Do we need to capture this in any other place like the specs? @josef-widder @milosevic

@josef-widder
Copy link
Member

I guess we said we miss a high-level supervisor spec of the light client, respectively and ADR. This needs to go into such a document. I am not sure whether we have an issue for that or what is the specific plan to move forward. @brapse

@brapse
Copy link
Contributor

brapse commented Jul 14, 2020

Yes we do lack a Supervisor spec as well as clarity around its utility.

For now I think #420 captures the conclusion of the discussion and we can perhaps explore the idea a bit more in #446.

@brapse brapse closed this as completed Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request light-client Issues/features which involve the light client question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants