Skip to content

Commit

Permalink
Fix: restore secret
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jan 20, 2022
1 parent d0c5283 commit ac9f837
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/market_maker/atomex.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (mm *MarketMaker) handleAtomexSwapUpdate(swap atomex.Swap) error {
return errors.Wrap(err, "atomexSwapToInternal")
}

mm.swaps.LoadOrStore(chain.Hex(swap.SecretHash), s)
mm.swaps.Store(chain.Hex(swap.SecretHash), s)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/market_maker/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ func (swaps *SwapsMap) Load(hashedSecret chain.Hex) (*tools.Swap, bool) {
return val, ok
}

// Set -
// Store -
func (swaps *SwapsMap) Store(hashedSecret chain.Hex, swap *tools.Swap) {
swaps.mx.Lock()
swaps.m[hashedSecret] = swap
swaps.mx.Unlock()
}

// Load -
// LoadOrStore -
func (swaps *SwapsMap) LoadOrStore(hashedSecret chain.Hex, swap *tools.Swap) *tools.Swap {
val, ok := swaps.Load(hashedSecret)
if ok {
Expand Down
35 changes: 19 additions & 16 deletions cmd/market_maker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (mm *MarketMaker) listenTracker(ctx context.Context) {
current.Status = swap.Status
current.Acceptor.Status = swap.Acceptor.Status
current.Initiator.Status = swap.Initiator.Status
if len(current.Secret) == 0 {
if current.Secret.IsEmpty() {
current.Secret = swap.Secret
}

Expand All @@ -40,14 +40,15 @@ func (mm *MarketMaker) listenTracker(ctx context.Context) {

mm.log.Info().Str("hashed_secret", current.HashedSecret.String()).Msg("swap is initiated. redeeming...")

if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil {
mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex")
continue
}

if len(current.Secret) == 0 {
mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before redeem")
continue
if current.Secret.IsEmpty() {
if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil {
mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex")
continue
}
if current.Secret.IsEmpty() {
mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before redeem")
continue
}
}

if err := mm.tracker.Redeem(ctx, *current, current.Acceptor); err != nil {
Expand All @@ -62,13 +63,15 @@ func (mm *MarketMaker) listenTracker(ctx context.Context) {

mm.log.Info().Str("hashed_secret", current.HashedSecret.String()).Msg("counterparty refunded swap. refunding...")

if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil {
mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex")
continue
}
if len(current.Secret) == 0 {
mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before refund")
continue
if current.Secret.IsEmpty() {
if err := mm.restoreSecretFromTrackerAtomex(ctx, current); err != nil {
mm.log.Err(err).Msg("restoreSecretFromTrackerAtomex")
continue
}
if current.Secret.IsEmpty() {
mm.log.Error().Str("hashed_secret", current.HashedSecret.String()).Msg("empty secret before refund")
continue
}
}

if err := mm.tracker.Refund(ctx, *current, current.Initiator); err != nil {
Expand Down

0 comments on commit ac9f837

Please sign in to comment.