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

Cache warnets on the server #304

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

willcl-ark
Copy link
Contributor

@willcl-ark willcl-ark commented Mar 5, 2024

Avoids repeated rebuilding of the warnet when calling commands

Closes #155

@@ -269,7 +278,8 @@ def network_export(self, network: str) -> str:
Export all data for sim-ln to subdirectory
"""
try:
wn = Warnet.from_network(network)
wn = self.get_warnet(network)
self.warnets[network] = wn
Copy link
Contributor

Choose a reason for hiding this comment

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

why would you need to set this wn again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good question, I think it's a mistake.

@@ -424,7 +434,7 @@ def scenarios_list_running(self) -> list[dict]:
return running

def network_up(self, network: str = "warnet") -> str:
def thread_start(wn):
def thread_start(server: Server, network):
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think server is used in the function here? Also im not sure but there is a self.backend -- i think that self IS the server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now using server (I find it makes more sense in a thread than using self from the outer scope?)

@@ -440,7 +450,8 @@ def thread_start(wn):

try:
wn = Warnet.from_network(network, self.backend)
t = threading.Thread(target=lambda: thread_start(wn))
self.warnets[network] = wn
Copy link
Contributor

Choose a reason for hiding this comment

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

here, too ?

@@ -456,11 +467,12 @@ def network_from_file(
Run a warnet with topology loaded from a <graph_file>
"""

def thread_start(wn, lock: threading.Lock):
with lock:
def thread_start(server: Server, network):
Copy link
Contributor

Choose a reason for hiding this comment

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

here too, too. Just not sure why server needs to be passed in

t.daemon = True
t.start()
return wn._warnet_dict_representation()
return self.warnets[network]._warnet_dict_representation()
Copy link
Contributor

Choose a reason for hiding this comment

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

okay... or you could keep the local wn variable and add it to self.warnets right after start()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's the same thing? Just referencing the dict here

Copy link
Contributor

Choose a reason for hiding this comment

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

it is, its fine thought it looked prettier without the extra dict reference

Copy link
Contributor

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

concept ACK, havent tested yet but this is super duper important and badly needed THANK YOU.

One additional comment: if --force is passed to network start we MUST clear the cached warnet with the same name!

update: okay i think this is already happening in network_from_file

@willcl-ark
Copy link
Contributor Author

Thanks for the review, I will re-view it now and incorporate any needed changes.

@willcl-ark
Copy link
Contributor Author

@pinheadmz wdyt of the changes now? I think I addressed all comments

Copy link
Contributor

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

👍
🚢 IT

@pinheadmz pinheadmz merged commit ee9b41c into bitcoin-dev-project:main Mar 7, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Cache active networks on server
2 participants