Repository navigation
Persist peers accross restarts - #114
Conversation
3c73a34 to
5feea6d
Compare
5feea6d to
641c8f7
Compare
pzafonte
left a comment
There was a problem hiding this comment.
--connect and addrman comments are the more consequential ones
| Arc::clone(&addrman), | ||
| Arc::clone(&node_state), | ||
| network, | ||
| peers_file, |
There was a problem hiding this comment.
Using --connect the flush thread overwrites peers.bin with only the connect addresses, and on a restart uses those instead of DNS. Not starting the flush thread under --connect fixes it in the same way Core skips anchors.dat.
There was a problem hiding this comment.
You can see this by seeding peers.bin, running once with --connect, and restarting without it.
There was a problem hiding this comment.
Using --connect the flush thread overwrites peers.bin with only the connect addresses, and on a restart uses those instead of DNS. Not starting the flush thread under --connect fixes it in the same way Core skips anchors.dat
I made the peers_file optional and do not pass it when we have dedicated connections. How is that?
| } | ||
|
|
||
| impl AddrTableExt for AddrTable { | ||
| fn load(path: &Path) -> Self { |
There was a problem hiding this comment.
Maybe we could test this to save Core's address to peers.bin, start without --connect, and wait for Core's getconnectioncount to reach 1.
There was a problem hiding this comment.
Added a test to check a seeded peers file creates a connection
| fn save(&self, path: &Path) -> std::io::Result<()> { | ||
| let tmp = path.with_file_name("peers.tmp"); | ||
| File::create(&tmp)?.write_table(self)?; | ||
| fs::rename(&tmp, path) | ||
| } |
There was a problem hiding this comment.
nit: sync peers.tmp before the rename, or a power loss / interruption can leave peers.bin empty.
| fn save(&self, path: &Path) -> std::io::Result<()> { | |
| let tmp = path.with_file_name("peers.tmp"); | |
| File::create(&tmp)?.write_table(self)?; | |
| fs::rename(&tmp, path) | |
| } | |
| fn save(&self, path: &Path) -> std::io::Result<()> { | |
| let tmp = path.with_file_name("peers.tmp"); | |
| let mut file = File::create(&tmp)?; | |
| file.write_table(self)?; | |
| file.sync_data()?; | |
| fs::rename(&tmp, path) | |
| } |
There was a problem hiding this comment.
sync_data is called in the write_table method: https://github.com/2140-dev/bitcoin-address-book/blob/master/src/io.rs#L46
Do we need the extra one here?
641c8f7 to
2be28b4
Compare
Make a test here that ensures if a live peer is available the node is able to file it from the address book file.
2be28b4 to
43d8dc0
Compare
|
Rebased after copying |
|
Tested & ACK 43d8dc0 |
We are continually hitting DNS every time the node starts. This can be a one-time bootstrap on the first run, with subsequent runs just using the peers on disk. Note this uses the
addrmancrateioextensions.I have the current flushing interval at every 10 minutes. The flushing occurs on a minimal background thread, but still needs to temporarily hold the lock of the address book. This table should be no more than a few thousand bytes, so this shouldn't be noticeable at all. Also this fixes a bug where the "source" of the address gossip was using the DNS resolver IP instead of the peer's address. Part of #97