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

discovery+graph: track job set dependencies in vb #9241

Merged
merged 4 commits into from
Jan 24, 2025

Conversation

Crypt-iQ
Copy link
Collaborator

@Crypt-iQ Crypt-iQ commented Nov 1, 2024

This PR changes the ValidationBarrier to track abstract job dependencies. This just means that every time a child job comes in (i.e. channel update or node announcement), we track the set of possible parent jobs that are related to it (channel announcement(s)) that have registered via InitJobDependencies. The goroutines containing the child jobs will then wait to be notified every time one of their parent jobs completes. From the child job's POV, this just works as ref-counting except that you're only counting the parent jobs you're interested in.

With this, we can now extend the ValidationBarrier to track any sort of abstract job that requires both concurrency and waiting for another job to finish. It also makes it possible in a future PR to very easily make node announcements depend on channel announcements. See the commit messages for more details.

Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Crypt-iQ Crypt-iQ force-pushed the fix_vb branch 3 times, most recently from 7acf321 to fc00572 Compare November 4, 2024 18:56
@Crypt-iQ Crypt-iQ changed the title [DRAFT] graph: fix validation barrier [DRAFT] discovery+graph: track job set dependencies in ValidationBarrier Nov 4, 2024
@Crypt-iQ Crypt-iQ changed the title [DRAFT] discovery+graph: track job set dependencies in ValidationBarrier [DRAFT] discovery+graph: track job set dependencies in vb Nov 4, 2024
@Crypt-iQ Crypt-iQ force-pushed the fix_vb branch 3 times, most recently from fc72083 to 7d95cd2 Compare November 6, 2024 18:19
@Crypt-iQ Crypt-iQ marked this pull request as ready for review November 6, 2024 18:46
@Crypt-iQ Crypt-iQ changed the title [DRAFT] discovery+graph: track job set dependencies in vb discovery+graph: track job set dependencies in vb Nov 6, 2024
@saubyk saubyk added this to the v0.19.0 milestone Nov 7, 2024
@saubyk
Copy link
Collaborator

saubyk commented Nov 7, 2024

cc: @gijswijs for review

graph/builder.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
fn/set.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@ProofOfKeags ProofOfKeags left a comment

Choose a reason for hiding this comment

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

I'm finding the distinction between parent and child jobs here both confusing and unnecessary. What we have here is a dependency graph of undifferentiated jobIDs. once all of the dependencies have run we can run. once we run we want to signal all of our dependents. We should be able to accomplish this with a single removeJob that does this index cleanup and dependent signaling.

The main difficulty I'm noticing in this PR is that we have multiple IDs that we want to be able to map to JobIDs from disjoint domains. My recommendation here is to make the core algebra of this component undifferentiated and then have auxilliary mappings that help recover the relevant JobID from the other unique protocol identifiers.

fn/set.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
annID = msg.ShortChannelID

// TODO: If ok is false, we have serious issues.
parentJobIDs, ok = v.jobDependencies[childJobID]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does this read not need a mutex lock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's locked above no?

graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
Comment on lines 417 to 421
// We don't want to block when sending out the signal.
select {
case notifyChan <- struct{}{}:
default:
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we ok with swallowing the signal instead? Seems like this could case jobs to never be run, particularly if lastJob is true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what you mean here. 1. How would jobs not be run in the current scenario? 2. What does swallowing the signal look like here?

graph/validation_barrier.go Outdated Show resolved Hide resolved
@saubyk
Copy link
Collaborator

saubyk commented Nov 19, 2024

cc: @gijswijs for review

@Crypt-iQ
Copy link
Collaborator Author

Crypt-iQ commented Dec 6, 2024

Outstanding things to do:

  • change from any to a union for map keys
  • update fn package to have a set copy method

@ellemouton
Copy link
Collaborator

@Crypt-iQ - is this ready for re-review given the itest failures?

@Crypt-iQ
Copy link
Collaborator Author

Crypt-iQ commented Dec 9, 2024

@Crypt-iQ - is this ready for re-review given the itest failures?

Sorry no, it seems like I broke something

@Crypt-iQ
Copy link
Collaborator Author

@Crypt-iQ - defs ready given all the failures?

now it is, the fn change broke it

@Crypt-iQ
Copy link
Collaborator Author

change from any to a union for map keys

I could not figure out a decent way to use generics to accomplish this, so jobInfoMap just has string keys now.

update fn package to have a set copy method

will update this code with Copy once #9374 is merged and a new fn is tagged

Copy link
Collaborator

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

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

I really like this change. 👍 Somehow, for me, the old solution with the depency maps is harder to reason about. I like the concept of jobInfoMap better.

One thing I found (somewhat in line with @ProofOfKeags earlier comment) is that the usage of the words dependency, dependent and parent, child respectively is inconsistent throughout. The code would be more readable if we would stick to one pair. If we choose parent/child we don't need to fight anymore about british vs us spelling, which is an added benefit.

Apart from that I made some small comments in the code.

graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
jobDesc = fmt.Sprintf("job=lnwire.NodeAnnouncement, pub=%s",
vertex)
route.Vertex(msg.NodeID))

// Other types of jobs can be executed immediately, so we'll just
// return directly.
case *lnwire.AnnounceSignatures1:
// TODO(roasbeef): need to wait on chan ann?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe return nil here and remove the following block below:

// If it's not ok, it means either the job is not a dependent type, or
	// it doesn't have a dependency signal. Either way, we can return
	// early.
	if !ok {
		return nil
	}

Same for the case after this one.

Less loc and to my mind clearer intent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

graph/validation_barrier.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
@@ -120,11 +131,19 @@ func TestValidationBarrierQuit(t *testing.T) {
// Signal completion for the first half of tasks, but only allow
// dependents to be processed as well for the second quarter.
case i < numTasks/4:
barrier.SignalDependants(anns[i], false)
err := barrier.SignalDependents(
Copy link
Collaborator

@gijswijs gijswijs Dec 20, 2024

Choose a reason for hiding this comment

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

Without the deny and allow logic the first case can be removed. There is no difference with the second case anymore, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, good catch

graph/validation_barrier_test.go Outdated Show resolved Hide resolved
graph/validation_barrier.go Outdated Show resolved Hide resolved
@Crypt-iQ
Copy link
Collaborator Author

Crypt-iQ commented Jan 3, 2025

Addressed comments, but may need to hold off on upgrading the fn package since there were some changes that prevents me from upgrading to 2.0.7.. We can still get this through without changing fn if we misuse the API a little bit (in a safe way).

@ellemouton
Copy link
Collaborator

@Crypt-iQ is this ready for another round or do you want to address CI first?

@Crypt-iQ
Copy link
Collaborator Author

Crypt-iQ commented Jan 7, 2025

@Crypt-iQ is this ready for another round or do you want to address CI first?

I think for this to be ready for review, the changes made to the fn package need to propagate to other packages o/w we can't upgrade fn here

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

think those fn updates are all in now so can rebase here 👍

@lightninglabs-deploy
Copy link

@ellemouton: review reminder
@gijswijs: review reminder
@Crypt-iQ, remember to re-request review from reviewers when ready

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

looks good, but there is go-routine leak that should be addressed 🙏

it is fixed if the validation barrier is completely removed from the graphdb.Builder

Comment on lines -678 to -681
// If this message has an existing dependency, then we'll wait until
// that has been fully validated before we proceed.
err := vb.WaitForDependants(update.msg)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

shall we move this to the discovery package since it is only used there now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah - i see there is still an instantiation of it here - but do we need it at all?
afaict, it has no effect anymore since the only call we do on it is CompleteJob which only serves a purpose if other processes are taking tokens out of the semaphore as well.

In fact, I actually think because of how it is used now: All calls to CompleteJob will actually hang until the builder shuts down. The only reason it shuts down successfully now is cause of the quit channel of the builder (and hence the validation barrier's quit channel) gets closed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great catch

graph/builder.go Outdated
Comment on lines 690 to 691
// concerned about.
if notError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can just

if err != nil {
		// Log as a debug message if this is not an error we need to be
		// concerned about.
		if IsError(err, ErrIgnored, ErrOutdated) {
			log.Debugf("process network updates got: %v", err)
		} else {
			log.Errorf("process network updates got: %v", err)
		}

		return
	}

no need for the noError variable. It will also only ever be checked if err != nil so no need for the err == nil clause

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup

}

return
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

just want to note that in future, we will likely have the Builder's AddNode/AddChannel/UpdateChannel calls be exposed via RPC for clients who dont want to sync the graph themselves. So initially i was thinking we may want to keep the validation barrier for that use case but after having thought about it more, i think it is fine to remove since those clients will always be trusted AND those calls will be done in sync with the gossiper calls performed by those clients.

So, ACK from my side for removal here 👍

Copy link
Collaborator Author

@Crypt-iQ Crypt-iQ Jan 23, 2025

Choose a reason for hiding this comment

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

As long as they're done in sync with the gossiper calls and the semaphore logic of the VB is used, that all sounds good and should work fine.

This omits calls to InitJobDependencies, SignalDependants, and
WaitForDependants. These changes have been made here because
the router / builder code does not actually need job dependency
management. Calls to the builder code (i.e. AddNode, AddEdge,
UpdateEdge) are all blocking in the gossiper. This, combined
with the fact that child jobs are run after parent jobs in the
gossiper, means that the calls to the router will happen in the
proper dependency order.
This commit does two things:
- removes the concept of allow / deny. Having this in place was a
  minor optimization and removing it makes the solution simpler.
- changes the job dependency tracking to track sets of abstact
  parent jobs rather than individual parent jobs.

As a note, the purpose of the ValidationBarrier is that it allows us
to launch gossip validation jobs in goroutines while still ensuring
that the validation order of these goroutines is adhered to when it
comes to validating ChannelAnnouncement _before_ ChannelUpdate and
_before_ NodeAnnouncement.
@Crypt-iQ
Copy link
Collaborator Author

Addressed comments @ellemouton , whenever you're ready

Copy link
Collaborator

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

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

I did a thorough review and I have no further remarks, so 🎉

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

thanks for the updates! 🙏

@Roasbeef Roasbeef merged commit c3cbfd8 into lightningnetwork:master Jan 24, 2025
31 of 35 checks passed
@Crypt-iQ Crypt-iQ deleted the fix_vb branch January 24, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants