Skip to content

Refactor the Sia package

David Vorick requested to merge host into master

Somehow this turned from me bringing back the host functions to me refactoring everything. And the idea of keeping PR's small completely fell apart, probably partially because I've been using my laptop which doesn't have X working right now - just a bunch of ttys.

There are some pretty substantial changes here, and some more on the way but I'm still figuring out the best order to do everything in. I've come up with a convention for working with mutexes which I think will significantly reduce mutex based developer errors. I've already caught a handful of subtle race conditions (which really would probably not ever cause problems but good to fix them anyway) and I find things a lot easier to reason about now. I've increased the documentation for the conventions I've been using, and this can be found in ProgramFlow.info

One of the biggest changes is the introduction of the components package, which moves all of the interfaces of the core into a separate package. This prevents circular dependencies and enables everything to be grabbed from the components package. It allows components to use each other, and to use the state, and it allows the sia package to import each of the component implementations (which are all their own packages).

There's still a decent amount of distance to go unfortunately. Most of the interfaces (except for host and renter, which are still incomplete) are good, but the Core doesn't seem to have a mutex, and it really needs one. And I'm not happy with the way that the Core, State, and components all communicate changes/updates, it's loose and prone to mistakes/errors.

I'm going to slow down the refactoring a bit though so that I can get the renter and hosts working again, and add pruning to the hostdb. But I do feel strongly about changing the way that the core+components+state all stay on the same page, and that might take some time to figure out and implement.

Merge request reports