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

multi: Bug fixes and code improvements #696

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ require (
github.com/decred/slog v1.2.0
github.com/decred/vspd/client/v3 v3.0.0
github.com/decred/vspd/types/v2 v2.1.0
github.com/decred/vspd/types/v3 v3.0.0
github.com/dgraph-io/badger v1.6.2
github.com/gen2brain/beeep v0.0.0-20220402123239-6a3042f4b71a
github.com/gomarkdown/markdown v0.0.0-20230922105210-14b16010c2ee
Expand Down Expand Up @@ -126,7 +127,6 @@ require (
github.com/decred/dcrtime v0.0.0-20191018193024-8d8b4ef0458e // indirect
github.com/decred/go-socks v1.1.0 // indirect
github.com/decred/vspd/client/v4 v4.0.0 // indirect
github.com/decred/vspd/types/v3 v3.0.0 // indirect
github.com/dgraph-io/ristretto v0.0.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions libwallet/assets/dcr/dex_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,12 @@ func (dw *DEXWallet) medianTime(ctx context.Context, iBlkHeader *wire.BlockHeade
// GetBlock returns the *wire.MsgBlock.
// Part of the Wallet interface.
func (dw *DEXWallet) GetBlock(ctx context.Context, blockHash *chainhash.Hash) (*wire.MsgBlock, error) {
if dw.syncData == nil || dw.syncData.activeSyncData == nil {
return nil, errors.New("invalid sync state")
}

// TODO: Use a block cache.
blocks, err := dw.syncData.syncer.Blocks(ctx, []*chainhash.Hash{blockHash})
blocks, err := dw.syncData.activeSyncData.syncer.Blocks(ctx, []*chainhash.Hash{blockHash})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -547,7 +551,7 @@ func (dw *DEXWallet) UnlockAccount(ctx context.Context, pass []byte, _ string) e
// Part of the Wallet interface.
func (dw *DEXWallet) SyncStatus(_ context.Context) (*dexasset.SyncStatus, error) {
ss := new(dexasset.SyncStatus)
if dw.syncData != nil && dw.ctx.Err() == nil { // dex might call this method during wallet shutdown.
if dw.syncData != nil && dw.syncData.activeSyncData != nil {
ss.Synced = dw.syncData.isSynced()
ss.Blocks = uint64(dw.syncData.syncedTo())
ss.TargetHeight = uint64(dw.syncData.targetHeight())
Expand Down
34 changes: 20 additions & 14 deletions libwallet/assets/dcr/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type SyncData struct {
rescanning bool
numOfConnectedPeers int32

*activeSyncData
activeSyncData *activeSyncData
}

func (s *SyncData) isSynced() bool {
Expand All @@ -57,7 +57,10 @@ func (s *SyncData) syncedTo() int32 {
func (s *SyncData) targetHeight() int32 {
s.mu.RLock()
defer s.mu.RUnlock()
return s.scanStartHeight
if s.activeSyncData == nil {
return 0
}
return s.activeSyncData.scanStartHeight
}

func (s *SyncData) connectedPeers() int32 {
Expand All @@ -69,7 +72,10 @@ func (s *SyncData) connectedPeers() int32 {
func (s *SyncData) generalSyncProgress() *sharedW.GeneralSyncProgress {
s.mu.RLock()
defer s.mu.RUnlock()
return s.genSyncProgress
if s.activeSyncData == nil {
return nil
}
return s.activeSyncData.genSyncProgress
}

// reading/writing of properties of this struct are protected by syncData.mu.
Expand Down Expand Up @@ -167,10 +173,10 @@ func (asset *Asset) SyncInactiveForPeriod(totalInactiveDuration time.Duration) {
return
}

asset.syncData.totalInactiveDuration += totalInactiveDuration
asset.syncData.activeSyncData.totalInactiveDuration += totalInactiveDuration
if asset.syncData.numOfConnectedPeers == 0 {
// assume it would take another 60 seconds to reconnect to peers
asset.syncData.totalInactiveDuration += secondsToDuration(60.0)
asset.syncData.activeSyncData.totalInactiveDuration += secondsToDuration(60.0)
}
}

Expand Down Expand Up @@ -228,7 +234,7 @@ func (asset *Asset) SpvSync() error {
asset.syncData.syncing = true
asset.syncData.cancelSync = cancel
asset.syncData.syncCanceled = make(chan struct{})
asset.syncData.syncer = syncer
asset.syncData.activeSyncData.syncer = syncer
asset.syncData.mu.Unlock()

for _, listener := range asset.syncProgressListeners() {
Expand Down Expand Up @@ -326,8 +332,8 @@ func (asset *Asset) CurrentSyncStage() utils.SyncStage {
asset.syncData.mu.RLock()
defer asset.syncData.mu.RUnlock()

if asset.syncData != nil && asset.syncData.syncing {
return asset.syncData.syncStage
if asset.syncData != nil && asset.syncData.syncing && asset.syncData.activeSyncData != nil {
return asset.syncData.activeSyncData.syncStage
}
return InvalidSyncStage
}
Expand All @@ -336,8 +342,8 @@ func (asset *Asset) IsAddressDiscovering() bool {
asset.syncData.mu.RLock()
defer asset.syncData.mu.RUnlock()

if asset.syncData != nil && asset.syncData.syncing {
return asset.syncData.isAddressDiscovery
if asset.syncData != nil && asset.syncData.syncing && asset.syncData.activeSyncData != nil {
return asset.syncData.activeSyncData.isAddressDiscovery
}

return false
Expand All @@ -347,8 +353,8 @@ func (asset *Asset) IsSycnRescanning() bool {
asset.syncData.mu.RLock()
defer asset.syncData.mu.RUnlock()

if asset.syncData != nil && asset.syncData.syncing {
return asset.syncData.isRescanning
if asset.syncData != nil && asset.syncData.syncing && asset.syncData.activeSyncData != nil {
return asset.syncData.activeSyncData.isRescanning
}

return false
Expand All @@ -370,11 +376,11 @@ func (asset *Asset) SyncData() *SyncData {
}

func (asset *Asset) PeerInfoRaw() ([]sharedW.PeerInfo, error) {
if !asset.IsConnectedToDecredNetwork() {
if !asset.IsConnectedToDecredNetwork() || asset.syncData.activeSyncData == nil {
return nil, errors.New(utils.ErrNotConnected)
}

syncer := asset.syncData.syncer
syncer := asset.syncData.activeSyncData.syncer

infos := make([]sharedW.PeerInfo, 0, len(syncer.GetRemotePeers()))
for _, rp := range syncer.GetRemotePeers() {
Expand Down
Loading
Loading