stellar_spectrum 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82171102575548c02b4566a049a7959544daea5bb1e4509df7a5ce1e78dd1a2e
4
- data.tar.gz: 88a64d56566dacc96206c78be2fb0f4aa37ba36a0565009c9db048f55feaa3f8
3
+ metadata.gz: b1f612b68e42b96844627bd1b79a6bd3fc6af1cae0c58d61a6f71390b6514886
4
+ data.tar.gz: 9aa9ae6bbf9dc14a972b0eb544d3e335689ad932afbf9ffa9d9b9e7c32d02eae
5
5
  SHA512:
6
- metadata.gz: 548ca98342523d4b589461d1a8f5ea210778a0d97acc6e0844b83c38d9ca36c9d250ef04e73b9dd5fa906ee063f5f103ac409f4f7dbfaeb1fa496e4e80260e38
7
- data.tar.gz: 398063e01bf565768e527af8eba2dce1dae26d0c5f914363a76de8a7a3bde7398d1581315e032647ea33f991610cbee71892ffe3104d3e261776b26fed4ced46
6
+ metadata.gz: baf26711abdfea3e88212dbd5255fa8b50ae12f0c57081f9b3438306f50c3ae11ecb2a9375a3cb1114c66504574897e3f8689add2cfdacab8679c25a243d8b79
7
+ data.tar.gz: 47bbc538c0706fe459060bbb5c22ed5d002443ac56e471777a9209af5d1c77d9226602429bd2362a16708117b2f95e5eb693c011ffaae3c456792bb571201bce
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.1.1] - 2018-12-13
8
+ ### Fixed
9
+ - [Make unlocking strategy safer](https://github.com/bloom-solutions/stellar_spectrum-ruby/pull/9)
10
+
7
11
  ## [1.1.0] - 2018-12-12
8
12
  ### Added
9
13
  - Retry when timeout is encountered [#6](https://github.com/bloom-solutions/stellar_spectrum-ruby/pull/6)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stellar_spectrum (1.1.0)
4
+ stellar_spectrum (1.1.1)
5
5
  activesupport
6
6
  gem_config
7
7
  light-service
@@ -7,7 +7,6 @@ require "redis"
7
7
  require "active_support/core_ext/hash/except"
8
8
  require "active_support/core_ext/object/blank"
9
9
  require 'active_support/core_ext/integer/inflections'
10
- require "stellar_spectrum/services/get_channel_account_info"
11
10
  require "stellar_spectrum/services/get_available_channels"
12
11
  require "stellar_spectrum/services/get_channel_accounts"
13
12
  require "stellar_spectrum/services/get_key_for_address"
@@ -19,13 +18,9 @@ require "stellar_spectrum/services/init_stellar_client"
19
18
  require "stellar_spectrum/services/lock_channel"
20
19
  require "stellar_spectrum/services/pick_channel"
21
20
  require "stellar_spectrum/services/send_payment"
22
- require "stellar_spectrum/services/sending_payment/attempt_release_lock"
23
21
  require "stellar_spectrum/services/sending_payment/retry"
24
22
  require "stellar_spectrum/services/sending_payment/send_asset"
25
- require "stellar_spectrum/services/unlocking/attempt_release"
26
- require "stellar_spectrum/services/unlocking/check_sequence_number"
27
- require "stellar_spectrum/services/unlocking/get_account_to_unlock"
28
- require "stellar_spectrum/services/unlocking/unlock"
23
+ require "stellar_spectrum/services/unlock"
29
24
 
30
25
  module StellarSpectrum
31
26
 
@@ -7,7 +7,7 @@ module StellarSpectrum
7
7
  attr_accessor :logger
8
8
 
9
9
  LOG_TAG = "[StellarSpectrum]"
10
- MAX_LOCK_TIME_IN_SECONDS = 30
10
+ MAX_LOCK_TIME_IN_SECONDS = 120
11
11
 
12
12
  def initialize(
13
13
  redis_url: StellarSpectrum.configuration.redis_url,
@@ -26,7 +26,6 @@ module StellarSpectrum
26
26
  to:,
27
27
  amount:,
28
28
  memo: nil,
29
- tries: 0,
30
29
  transaction_source: nil,
31
30
  sequence: nil
32
31
  )
@@ -40,7 +40,7 @@ module StellarSpectrum
40
40
  reduce_if(->(c) {c[:force_transaction_source].nil?}, [
41
41
  GetLockedAccounts,
42
42
  GetAvailableChannels,
43
- reduce_if(->(c) { c.available_channels.empty? }, retry_actions),
43
+ reduce_if(->(c) {c.available_channels.empty?}, SendingPayment::Retry),
44
44
  PickChannel,
45
45
  ]),
46
46
  reduce_if(->(c) {c[:force_transaction_source].present?}, [
@@ -48,15 +48,9 @@ module StellarSpectrum
48
48
  ]),
49
49
  GetSequenceNumber,
50
50
  LockChannel,
51
- reduce_if(->(c) {!c.successfully_locked}, retry_actions),
51
+ reduce_if(->(c) {!c.successfully_locked}, SendingPayment::Retry),
52
52
  SendingPayment::SendAsset,
53
- ]
54
- end
55
-
56
- def self.retry_actions
57
- [
58
- SendingPayment::AttemptReleaseLock,
59
- SendingPayment::Retry,
53
+ Unlock,
60
54
  ]
61
55
  end
62
56
 
@@ -0,0 +1,14 @@
1
+ module StellarSpectrum
2
+ class Unlock
3
+
4
+ extend LightService::Action
5
+ expects :redis, :channel_account
6
+ promises :unlock_response
7
+
8
+ executed do |c|
9
+ address_key = GetKeyForAddress.execute(c.channel_account.address)
10
+ c.unlock_response = c.redis.del(address_key)
11
+ end
12
+
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module StellarSpectrum
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar_spectrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
@@ -176,7 +176,6 @@ files:
176
176
  - lib/stellar_spectrum.rb
177
177
  - lib/stellar_spectrum/client.rb
178
178
  - lib/stellar_spectrum/services/get_available_channels.rb
179
- - lib/stellar_spectrum/services/get_channel_account_info.rb
180
179
  - lib/stellar_spectrum/services/get_channel_accounts.rb
181
180
  - lib/stellar_spectrum/services/get_key_for_address.rb
182
181
  - lib/stellar_spectrum/services/get_locked_accounts.rb
@@ -187,13 +186,9 @@ files:
187
186
  - lib/stellar_spectrum/services/lock_channel.rb
188
187
  - lib/stellar_spectrum/services/pick_channel.rb
189
188
  - lib/stellar_spectrum/services/send_payment.rb
190
- - lib/stellar_spectrum/services/sending_payment/attempt_release_lock.rb
191
189
  - lib/stellar_spectrum/services/sending_payment/retry.rb
192
190
  - lib/stellar_spectrum/services/sending_payment/send_asset.rb
193
- - lib/stellar_spectrum/services/unlocking/attempt_release.rb
194
- - lib/stellar_spectrum/services/unlocking/check_sequence_number.rb
195
- - lib/stellar_spectrum/services/unlocking/get_account_to_unlock.rb
196
- - lib/stellar_spectrum/services/unlocking/unlock.rb
191
+ - lib/stellar_spectrum/services/unlock.rb
197
192
  - lib/stellar_spectrum/version.rb
198
193
  - stellar_spectrum.gemspec
199
194
  homepage: https://github.com/bloom-solutions/stellar_spectrum-ruby
@@ -1,23 +0,0 @@
1
- module StellarSpectrum
2
- class GetChannelAccountInfo
3
-
4
- extend LightService::Action
5
- expects :locked_accounts, :channel_account
6
- promises :channel_account_info, :unlock_response
7
-
8
- executed do |c|
9
- c.channel_account_info = c.locked_accounts[c.channel_account.address]
10
-
11
- c.unlock_response = nil
12
- next c if c.channel_account_info.present?
13
-
14
- c.unlock_response = true
15
-
16
- message = "#{c.channel_account.address} has been unlocked by some " \
17
- "other mechanism like ttl expiration or by something else, " \
18
- "so this is a success"
19
- c.skip_remaining!(message)
20
- end
21
-
22
- end
23
- end
@@ -1,18 +0,0 @@
1
- module StellarSpectrum
2
- module SendingPayment
3
- class AttemptReleaseLock
4
-
5
- extend LightService::Action
6
- expects :stellar_client, :redis, :channel_accounts
7
-
8
- executed do |c|
9
- Unlocking::AttemptRelease.(
10
- stellar_client: c.stellar_client,
11
- redis: c.redis,
12
- channel_accounts: c.channel_accounts,
13
- )
14
- end
15
-
16
- end
17
- end
18
- end
@@ -1,37 +0,0 @@
1
- module StellarSpectrum
2
- module Unlocking
3
- class AttemptRelease
4
-
5
- extend LightService::Organizer
6
- def self.call(redis:, channel_accounts:, stellar_client:)
7
- result = with(
8
- stellar_client: stellar_client,
9
- redis: redis,
10
- channel_accounts: channel_accounts,
11
- ).reduce(actions)
12
-
13
- if result.failure?
14
- result[:unlock_response] = false
15
- end
16
-
17
- result
18
- end
19
-
20
- def self.actions
21
- [
22
- GetLockedAccounts,
23
- GetAccountToUnlock,
24
- GetSequenceNumber,
25
- # Someone else may have unlocked it while we were taking
26
- # our sweet time fetching the sequence number, so fetch
27
- # the locked accounts again:
28
- GetLockedAccounts,
29
- GetChannelAccountInfo,
30
- CheckSequenceNumber,
31
- Unlock,
32
- ]
33
- end
34
-
35
- end
36
- end
37
- end
@@ -1,25 +0,0 @@
1
- module StellarSpectrum
2
- module Unlocking
3
- class CheckSequenceNumber
4
-
5
- extend LightService::Action
6
- expects :current_sequence_number, :channel_account, :channel_account_info
7
-
8
- executed do |c|
9
- address_sequence_number = c.channel_account_info[:sequence_number].to_i
10
- current_sequence_number = c.current_sequence_number
11
-
12
- next c if current_sequence_number >= address_sequence_number
13
-
14
- address = c.channel_account.address
15
-
16
- message = "Not releasing #{address}: sequence number locked at " \
17
- "#{address_sequence_number} is > current sequence number " \
18
- "#{current_sequence_number}"
19
-
20
- c.fail_and_return! message
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- module StellarSpectrum
2
- module Unlocking
3
- class GetAccountToUnlock
4
-
5
- extend LightService::Action
6
- expects :locked_accounts
7
- promises :channel_account
8
-
9
- executed do |c|
10
- address, info = c.locked_accounts.except(c[:except_address])
11
- .sort_by {|address, info| info[:pttl]}.last
12
-
13
- if address.present?
14
- c.channel_account = Stellar::Account.from_address(address)
15
- else
16
- c.channel_account = nil
17
- c.fail_and_return! "No addresses to unlock"
18
- end
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,16 +0,0 @@
1
- module StellarSpectrum
2
- module Unlocking
3
- class Unlock
4
-
5
- extend LightService::Action
6
- expects :redis, :channel_account
7
- promises :unlock_response
8
-
9
- executed do |c|
10
- address_key = GetKeyForAddress.execute(c.channel_account.address)
11
- c.unlock_response = c.redis.del(address_key)
12
- end
13
-
14
- end
15
- end
16
- end