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: integration test #431

Merged
merged 12 commits into from
Jul 10, 2020
Merged

Conversation

romac
Copy link
Member

@romac romac commented Jul 9, 2020

cf. #373

Adds an integration test for the light client.

The test spins up a light client against a single Tendermint node, where both the primary and a single witness point to that node.
It tries to verify to the highest block 20 times, at an interval of 800ms to give the chain time to advance.
The test uses a custom evidence reporter which panics if the supervisor tries to report a fork, as no fork should happen with this setup.

This PR also fixes a bug where the postcondition of LightClient::verify_to_target was only looking for verified but not trusted blocks in the light store. This bug occurs when the highest block is still the initial trusted block, which happens in this case because we start syncing to the latest height right after fetching and initializing the trusted block.


  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGES.md


let mut peer_map = HashMap::new();
peer_map.insert(primary, node_address.clone());
peer_map.insert(witness, node_address);
Copy link
Member

Choose a reason for hiding this comment

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

Here the same RPC end-point is used twice. Do you think it makes sense add a comment that in a realistic scenario these would be different and that you'd check if the peerId matches?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in 4128382.

@@ -12,6 +12,7 @@ pub fn trusted_store_contains_block_at_target_height(
target_height: Height,
) -> bool {
light_store.get(target_height, Status::Verified).is_some()
|| light_store.get(target_height, Status::Trusted).is_some()
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if there are more places like this. reminded me a little of #419

Copy link
Member Author

@romac romac Jul 9, 2020

Choose a reason for hiding this comment

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

Yeah I thought I had caught them all in #419 but evidently not. Will go over the codebase again to make sure.

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

Dope! 👍

Unfortunately, the test fails:

running 1 test
test sync ... FAILED

failures:

---- sync stdout ----
[info ] - iteration 1/20
[info ] synced to block 351
[info ] - iteration 2/20
[error] sync failed: no witness left
thread 'sync' panicked at 'failed to sync to highest: no witness left', light-client/tests/integration.rs:115:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@liamsi liamsi self-requested a review July 9, 2020 18:53
Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

Sorry, didn't mean to approve :-D Great work 👍 but we should investigate why the test fails first.

@romac
Copy link
Member Author

romac commented Jul 9, 2020

@liamsi Looking into it!

@romac
Copy link
Member Author

romac commented Jul 9, 2020

The failure came from a ~2min clock drift between the Docker container and the GitHub CI worker. Increasing the clock drift parameter to 5min (to be safe) has fixed it. @liamsi Does that seem like an acceptable fix to you?

/// Correction parameter dealing with only approximately synchronized clocks.
/// The local clock should always be ahead of timestamps from the blockchain; this
/// is the maximum amount that the local clock may drift behind a timestamp from the
/// blockchain.
pub clock_drift: Duration,
/// The current time
pub now: Time,
Copy link
Member

@liamsi liamsi Jul 9, 2020

Choose a reason for hiding this comment

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

I'm actually using these "Options" in #430 too. I was wondering how now made sense as an option. Much clearer when it isn't 👍

@liamsi
Copy link
Member

liamsi commented Jul 9, 2020

@liamsi Does that seem like an acceptable fix to you?

Does sound reasonable. Do you understand why the clock drift is so large?

liamsi
liamsi previously approved these changes Jul 9, 2020
Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

Cool, cool! LGTM 💪

@romac
Copy link
Member Author

romac commented Jul 9, 2020

Do you understand why the clock drift is so large?

I unfortunately don't, would require more investigation. Perhaps someone else knows better? @greg-szabo?

@liamsi
Copy link
Member

liamsi commented Jul 9, 2020

BTW, I also get a lot of [error] sync failed: no witness left in #430
Is that always clock drift issue?

xla
xla previously approved these changes Jul 10, 2020
Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

Couple of things inline, otherwise dope!

🎓 🕷 ⬆️ 🛋

.github/workflows/rust.yml Show resolved Hide resolved
light-client/src/predicates.rs Show resolved Hide resolved
light-client/tests/integration.rs Show resolved Hide resolved
light-client/tests/integration.rs Show resolved Hide resolved
@xla xla changed the title Add integration test to the light-client crate light-client: integration test Jul 10, 2020
@xla xla added light-client Issues/features which involve the light client tests labels Jul 10, 2020
@xla xla mentioned this pull request Jul 10, 2020
5 tasks
@romac
Copy link
Member Author

romac commented Jul 10, 2020

BTW, I also get a lot of [error] sync failed: no witness left in #430
Is that always clock drift issue?

@liamsi Hard to say like that. Might need to add some logging statements to figure out what's the underlying error. Perhaps we could/should even track those somehow.

@romac romac dismissed stale reviews from xla and liamsi via 6c62254 July 10, 2020 10:20
xla
xla previously approved these changes Jul 10, 2020
Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

📦 👾 ⏩ 🗄

@romac
Copy link
Member Author

romac commented Jul 10, 2020

@xla @liamsi Can one of you please you approve for merging? :)

Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

(╹◡╹)

@romac romac merged commit b1252c6 into master Jul 10, 2020
@romac romac deleted the romain/light-client-integration-test branch July 10, 2020 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
light-client Issues/features which involve the light client tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants