Skip to content

Commit

Permalink
multi: Bug fixes and code improvements (#696)
Browse files Browse the repository at this point in the history
* assets/dcr: fix panic when sync is not active

Signed-off-by: Philemon Ukane <[email protected]>

* libwallet: rework instantswap feature

Signed-off-by: Philemon Ukane <[email protected]>

* exchange: fix order detail page panic when fetching order returns an error

Signed-off-by: Philemon Ukane <[email protected]>

* multi: Fix CEX page

- Fix asset selector dropdown
- Fix asset amount input
- Fix order schedular modal and balance to maintain field
- Fix order settings modal
- Handle error from failed order schedules

Signed-off-by: Philemon Ukane <[email protected]>

* fix contentious lock issue causing hang during dcr sync

Signed-off-by: Philemon Ukane <[email protected]>

* dex: use midGap as default order rate for limit orders

Signed-off-by: Philemon Ukane <[email protected]>

* review changes

Signed-off-by: Philemon Ukane <[email protected]>

* init blockcypher for ltc

Signed-off-by: Philemon Ukane <[email protected]>

* review changes

Signed-off-by: Philemon Ukane <[email protected]>

---------

Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon authored Nov 19, 2024
1 parent 0e35cec commit a63b36c
Show file tree
Hide file tree
Showing 14 changed files with 449 additions and 311 deletions.
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

0 comments on commit a63b36c

Please sign in to comment.