diff --git a/go.mod b/go.mod index bdb841a..b714b70 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( go.etcd.io/bbolt v1.3.8 - go.sia.tech/core v0.2.1-0.20240124010156-3ffae341852c + go.sia.tech/core v0.2.1-0.20240130145801-8067f34b2ecc go.uber.org/zap v1.26.0 golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 lukechampine.com/frand v1.4.2 diff --git a/go.sum b/go.sum index 69e521d..3d17b69 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= -go.sia.tech/core v0.2.1-0.20240124010156-3ffae341852c h1:hFgv4uH2+wf838W7V0dIVgldjMyje2dkZcCLItu874g= -go.sia.tech/core v0.2.1-0.20240124010156-3ffae341852c/go.mod h1:3EoY+rR78w1/uGoXXVqcYdwSjSJKuEMI5bL7WROA27Q= +go.sia.tech/core v0.2.1-0.20240130145801-8067f34b2ecc h1:oUCCTOatQIwYkJ2FUWRvJtgU+i/BwlzmzCxoSvmmJVQ= +go.sia.tech/core v0.2.1-0.20240130145801-8067f34b2ecc/go.mod h1:3EoY+rR78w1/uGoXXVqcYdwSjSJKuEMI5bL7WROA27Q= go.sia.tech/mux v1.2.0 h1:ofa1Us9mdymBbGMY2XH/lSpY8itFsKIo/Aq8zwe+GHU= go.sia.tech/mux v1.2.0/go.mod h1:Yyo6wZelOYTyvrHmJZ6aQfRoer3o4xyKQ4NmQLJrBSo= go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= diff --git a/syncer/peer.go b/syncer/peer.go index 79193d5..7612c60 100644 --- a/syncer/peer.go +++ b/syncer/peer.go @@ -34,6 +34,15 @@ func (p *Peer) String() string { return "->" + p.ConnAddr } +// Addr returns the peer's reported dialback address. +func (p *Peer) Addr() string { return p.t.Addr } + +// Version returns the peer's reported version. +func (p *Peer) Version() string { return p.t.Version } + +// UniqueID returns the peer's reported UniqueID. +func (p *Peer) UniqueID() gateway.UniqueID { return p.t.UniqueID } + // Err returns the error that caused the peer to disconnect, if any. func (p *Peer) Err() error { p.mu.Lock() @@ -51,12 +60,6 @@ func (p *Peer) setErr(err error) error { return p.err } -// Close closes the peer's connection. -func (p *Peer) Close() error { - p.setErr(errors.New("closing")) - return nil -} - // Synced returns the peer's sync status. func (p *Peer) Synced() bool { p.mu.Lock() @@ -70,6 +73,12 @@ func (p *Peer) setSynced(synced bool) { p.synced = synced } +// Close closes the peer's connection. +func (p *Peer) Close() error { + p.setErr(errors.New("closing")) + return nil +} + func (p *Peer) callRPC(r gateway.Object, timeout time.Duration) error { s, err := p.t.DialStream() if err != nil { diff --git a/syncer/syncer.go b/syncer/syncer.go index b3f0371..16fb0e7 100644 --- a/syncer/syncer.go +++ b/syncer/syncer.go @@ -188,9 +188,8 @@ type Syncer struct { } func (s *Syncer) resync(p *Peer, reason string) { - alreadyResyncing := !p.Synced() - p.setSynced(false) - if !alreadyResyncing { + if p.Synced() { + p.setSynced(false) s.log.Debug("resync triggered", zap.String("peer", p.t.Addr), zap.String("reason", reason)) } } diff --git a/wallet/wallet.go b/wallet/wallet.go index 77366af..8921ce5 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -105,8 +105,8 @@ func (t Transaction) EncodeTo(e *types.Encoder) { t.ID.EncodeTo(e) t.Index.EncodeTo(e) t.Transaction.EncodeTo(e) - t.Inflow.EncodeTo(e) - t.Outflow.EncodeTo(e) + types.V2Currency(t.Inflow).EncodeTo(e) + types.V2Currency(t.Outflow).EncodeTo(e) e.WriteString(string(t.Source)) e.WriteTime(t.Timestamp) } @@ -116,8 +116,8 @@ func (t *Transaction) DecodeFrom(d *types.Decoder) { t.ID.DecodeFrom(d) t.Index.DecodeFrom(d) t.Transaction.DecodeFrom(d) - t.Inflow.DecodeFrom(d) - t.Outflow.DecodeFrom(d) + (*types.V2Currency)(&t.Inflow).DecodeFrom(d) + (*types.V2Currency)(&t.Outflow).DecodeFrom(d) t.Source = TransactionSource(d.ReadString()) t.Timestamp = d.ReadTime() }