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

feat: add Ready method to Node #1216

Merged
merged 10 commits into from
Feb 1, 2024

Conversation

gfanton
Copy link
Member

@gfanton gfanton commented Oct 10, 2023

This PR adds a method to Node that returns a channel, which will close when the node receives its first block. The primary purpose of this is to provide a mechanism to check when the node is ready and can start handling requests.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

mostly to check if the node is ready

Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
@gfanton gfanton requested a review from thehowl October 10, 2023 15:24
@gfanton gfanton self-assigned this Oct 10, 2023
@gfanton gfanton requested review from jaekwon, moul and a team as code owners October 10, 2023 15:24
@github-actions github-actions bot added 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Oct 10, 2023
@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (12b4b45) 56.13% compared to head (170506e) 56.12%.

Files Patch % Lines
tm2/pkg/bft/node/node.go 0.00% 14 Missing ⚠️
gno.land/pkg/integration/testing_node.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1216      +/-   ##
==========================================
- Coverage   56.13%   56.12%   -0.02%     
==========================================
  Files         438      438              
  Lines       66151    66164      +13     
==========================================
  Hits        37134    37134              
- Misses      26126    26139      +13     
  Partials     2891     2891              
Flag Coverage Δ
go-1.21.x ∅ <ø> (∅)
misc ∅ <ø> (∅)
misc-_test.genstd ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
@thehowl thehowl requested a review from piux2 October 12, 2023 16:23
@zivkovicmilos
Copy link
Member

@gfanton

Please don't merge this PR yet, I'm trying to compose some thoughts on this issue

@zivkovicmilos zivkovicmilos self-requested a review October 12, 2023 16:27
Copy link
Contributor

@piux2 piux2 left a comment

Choose a reason for hiding this comment

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

@gfanton Can you provide the use cases with examples why we will need this changes? I thought the integration test supposed to be conducted from outside of tendermint node service instance. Also are we trying to check first block on genesis playback or first block to be committed in consensus?

Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Unblocking this PR, it's been in the freezer long enough

The fact that we can't rely on OnStart ending to say that the node is ready is a bit disturbing. We will tackle this in a future PR, regardless, this PR should be unblocked as it introduces a nice UX moment for tests

gno.land/pkg/integration/testing_integration.go Outdated Show resolved Hide resolved
tm2/pkg/bft/node/node.go Outdated Show resolved Hide resolved
@zivkovicmilos
Copy link
Member

@gfanton please resolve merge conflicts 🙏

Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
@gfanton
Copy link
Member Author

gfanton commented Jan 31, 2024

@zivkovicmilos Done! Perhaps I should rename the method to Ready() or something more explicit to better convey the purpose of this method ?

@piux2 This step is essential for the integration tests to work correctly. Currently, I am using a small external hack (see the code bellow) to ensure that the node is ready and can handle requests properly. With this new method, we provide a more intuitive way to check if the node is ready.
(Apologies for the delayed response.)

func GetNodeReadiness(n *node.Node) <-chan struct{} {
const listenerID = "first_block_listener"
var once sync.Once
nb := make(chan struct{})
ready := func() {
close(nb)
n.EventSwitch().RemoveListener(listenerID)
}
n.EventSwitch().AddListener(listenerID, func(ev events.Event) {
if _, ok := ev.(bft.EventNewBlock); ok {
once.Do(ready)
}
})
if n.BlockStore().Height() > 0 {
once.Do(ready)
}
return nb
}

Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
@gfanton gfanton changed the title feat: add FirstBlockReceived method to Node feat: add Ready method to Node Jan 31, 2024
@gfanton gfanton merged commit 50d426a into gnolang:master Feb 1, 2024
182 of 183 checks passed
@gfanton gfanton deleted the feat/add-first-block-signal branch February 1, 2024 16:28
leohhhn pushed a commit to leohhhn/gno that referenced this pull request Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: Done
Status: Done
Status: 🌟 Wanted for Launch
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants