-
Notifications
You must be signed in to change notification settings - Fork 5
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
Implement Syncer.Synced() #9
Conversation
I confess that I have always found
Now, it is usually the case that the answer to all of these questions is the same (whether that answer is yes or no). But it is not guaranteed. Maybe you are getting eclipse-attacked. Maybe the public explorer got hacked. Maybe your wallet hasn't had any activity for hundreds of thousands of blocks. Maybe your transaction will be valid despite being a little outdated. My understanding is that generally, apps want a I realize I'm probably in the minority here, so perhaps @n8maninger or @ChrisSchinnerl could weigh in with their thoughts. Anyway, I do appreciate you taking the time to understand and modify the Syncer code. The implementation itself looks fine to me. |
I think having a That said I think waiting for at least 10 minutes before considering us I think a reasonable assumption would be to check 2 things.
That's probably the best any node in a trustless, distributed environment can do anyway without a trusted entity which we don't want to rely on for the security of our daemons. |
The method returns true in two cases:
In my tests on Zen, I usually gain the minimum peer count within less than a minute. On Anagami, though, I have to wait 10 minutes, because I usually don't get to connect to 5 peers there. Regarding 3), it's possible to have the last block mined more than 1 hour ago (especially on Anagami), in that case we're not synced anymore. |
I don't see a reason not to add it. I would suggest a few changes, though:
Anagami is a special (temporary) case; nothing should be built with Anagami in mind. |
@ChrisSchinnerl If your Separately: what if instead of adding |
Exposing all that info in a different way would be fine as well imo. Maybe even better since we can tweak it ourselves and even have users make their own choices. |
For the record: this is the logic that
|
IIRC, |
I wonder if this is something we could address in RHPv4. Like, if the host thinks the renter is behind, it could send a header chain proving it. Anyway, I think some combination of:
should be sufficient for anyone's needs. Unless there are further objections, I suggest we add the type Peer struct {
UniqueID UniqueID
Version string
Addr string
ConnAddr string
Inbound bool
smux *smux.Session // for v1
mux *mux.Mux // for v2
mu sync.Mutex
synced bool
err error
}
// Synced returns the peer's sync status.
func (p *Peer) Synced() bool {
p.mu.Lock()
defer p.mu.Unlock()
return p.synced
}
// SetSynced sets the peer's sync status.
func (p *Peer) SetSynced(synced bool) {
p.mu.Lock()
defer p.mu.Unlock()
p.synced = synced
} and call |
I see no reason to export |
True, but |
Yeah, that should be fine. I can take over the PRs, if nobody minds. |
We will be moving |
@mike76-dev now that #10 is merged, feel free to proceed |
Can you rebase so we get a clean history? |
Thanks! |
I need this method, otherwise I have to implement my own Syncer. Later on, it might prove helpful when porting
hostd
andrenterd
, too.It has been working fine in my tests so far. If needed,
minSyncedPeers
andminTimeUntilSynceed
can be added to the config options.