Skip to content

Commit 184ec1a

Browse files
committed
Rename methods and functions in submission system
It's the first time I get into this code and the naming has made it hard to understand. So, I decided to make the naming more understandable.
1 parent 105173d commit 184ec1a

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

services/horizon/internal/txsub/sequence/queue.go renamed to services/horizon/internal/txsub/sequence/account_tx_submission_queue.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import (
55
"time"
66
)
77

8-
// Queue manages the submission queue for a single source account. The
8+
// AccountTxSubmissionQueue manages the submission queue for a single source account. The
99
// transaction system uses Push to enqueue submissions for given sequence
1010
// numbers.
1111
//
12-
// Queue maintains a priority queue of pending submissions, and when updated
13-
// (via the Update() method) with the current sequence number of the account
12+
// AccountTxSubmissionQueue maintains a priority queue of pending submissions, and when updated
13+
// (via the NotifyLastAccountSequence() method) with the current sequence number of the account
1414
// being managed, queued submissions that can be acted upon will be unblocked.
1515
//
16-
type Queue struct {
16+
type AccountTxSubmissionQueue struct {
1717
lastActiveAt time.Time
1818
timeout time.Duration
1919
nextSequence uint64
2020
queue pqueue
2121
}
2222

23-
// NewQueue creates a new *Queue
24-
func NewQueue() *Queue {
25-
result := &Queue{
23+
// NewAccountTxSubmissionQueue creates a new *AccountTxSubmissionQueue
24+
func NewAccountTxSubmissionQueue() *AccountTxSubmissionQueue {
25+
result := &AccountTxSubmissionQueue{
2626
lastActiveAt: time.Now(),
2727
timeout: 10 * time.Second,
2828
queue: nil,
@@ -34,7 +34,7 @@ func NewQueue() *Queue {
3434
}
3535

3636
// Size returns the count of currently buffered submissions in the queue.
37-
func (q *Queue) Size() int {
37+
func (q *AccountTxSubmissionQueue) Size() int {
3838
return len(q.queue)
3939
}
4040

@@ -43,26 +43,26 @@ func (q *Queue) Size() int {
4343
// to do so.
4444
//
4545
// Push does not perform any triggering (which
46-
// occurs in Update(), even if the current sequence number for this queue is
46+
// occurs in NotifyLastAccountSequence(), even if the current sequence number for this queue is
4747
// the same as the provided sequence, to keep internal complexity much lower.
4848
// Given that, the recommended usage pattern is:
4949
//
5050
// 1. Push the submission onto the queue
5151
// 2. Load the current sequence number for the source account from the DB
52-
// 3. Call Update() with the result from step 2 to trigger the submission if
52+
// 3. Call NotifyLastAccountSequence() with the result from step 2 to trigger the submission if
5353
// possible
54-
func (q *Queue) Push(sequence uint64) <-chan error {
54+
func (q *AccountTxSubmissionQueue) Push(sequence uint64) <-chan error {
5555
ch := make(chan error, 1)
5656
heap.Push(&q.queue, item{sequence, ch})
5757
return ch
5858
}
5959

60-
// Update notifies the queue that the provided sequence number is the latest
60+
// NotifyLastAccountSequence notifies the queue that the provided sequence number is the latest
6161
// seen value for the account that this queue manages submissions for.
6262
//
6363
// This function is monotonic... calling it with a sequence number lower than
6464
// the latest seen sequence number is a noop.
65-
func (q *Queue) Update(sequence uint64) {
65+
func (q *AccountTxSubmissionQueue) NotifyLastAccountSequence(sequence uint64) {
6666
if q.nextSequence <= sequence {
6767
q.nextSequence = sequence + 1
6868
}
@@ -113,7 +113,7 @@ func (q *Queue) Update(sequence uint64) {
113113
}
114114

115115
// helper function for interacting with the priority queue
116-
func (q *Queue) head() (chan error, uint64) {
116+
func (q *AccountTxSubmissionQueue) head() (chan error, uint64) {
117117
if len(q.queue) == 0 {
118118
return nil, uint64(0)
119119
}
@@ -122,7 +122,7 @@ func (q *Queue) head() (chan error, uint64) {
122122
}
123123

124124
// helper function for interacting with the priority queue
125-
func (q *Queue) pop() (chan error, uint64) {
125+
func (q *AccountTxSubmissionQueue) pop() (chan error, uint64) {
126126
i := heap.Pop(&q.queue).(item)
127127

128128
return i.Chan, i.Sequence
@@ -134,7 +134,7 @@ type item struct {
134134
Chan chan error
135135
}
136136

137-
// pqueue is a priority queue used by Queue to manage buffered submissions. It
137+
// pqueue is a priority queue used by AccountTxSubmissionQueue to manage buffered submissions. It
138138
// implements heap.Interface.
139139
type pqueue []item
140140

services/horizon/internal/txsub/sequence/queue_test.go renamed to services/horizon/internal/txsub/sequence/account_tx_submission_queue_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
type QueueTestSuite struct {
1616
suite.Suite
1717
ctx context.Context
18-
queue *Queue
18+
queue *AccountTxSubmissionQueue
1919
}
2020

2121
func (suite *QueueTestSuite) SetupTest() {
2222
suite.ctx = test.Context()
23-
suite.queue = NewQueue()
23+
suite.queue = NewAccountTxSubmissionQueue()
2424
}
2525

2626
//Push adds the provided channel on to the priority queue
@@ -43,35 +43,35 @@ func (suite *QueueTestSuite) TestQueue_Push() {
4343

4444
// Tests the update method
4545
func (suite *QueueTestSuite) TestQueue_Update() {
46-
// Update removes sequences that are submittable or in the past
46+
// NotifyLastAccountSequence removes sequences that are submittable or in the past
4747
results := []<-chan error{
4848
suite.queue.Push(1),
4949
suite.queue.Push(2),
5050
suite.queue.Push(3),
5151
suite.queue.Push(4),
5252
}
5353

54-
suite.queue.Update(2)
54+
suite.queue.NotifyLastAccountSequence(2)
5555

5656
// the update above signifies that 2 is the accounts current sequence,
5757
// meaning that 3 is submittable, and so only 4 should still be queued
5858
assert.Equal(suite.T(), 1, suite.queue.Size())
5959
_, s := suite.queue.head()
6060
assert.Equal(suite.T(), uint64(4), s)
6161

62-
suite.queue.Update(4)
62+
suite.queue.NotifyLastAccountSequence(4)
6363
assert.Equal(suite.T(), 0, suite.queue.Size())
6464

6565
assert.Equal(suite.T(), ErrBadSequence, <-results[0])
6666
assert.Equal(suite.T(), ErrBadSequence, <-results[1])
6767
assert.Equal(suite.T(), nil, <-results[2])
6868
assert.Equal(suite.T(), ErrBadSequence, <-results[3])
6969

70-
// Update clears the queue if the head has not been released within the time limit
70+
// NotifyLastAccountSequence clears the queue if the head has not been released within the time limit
7171
suite.queue.timeout = 1 * time.Millisecond
7272
result := suite.queue.Push(2)
7373
<-time.After(10 * time.Millisecond)
74-
suite.queue.Update(0)
74+
suite.queue.NotifyLastAccountSequence(0)
7575

7676
assert.Equal(suite.T(), 0, suite.queue.Size())
7777
assert.Equal(suite.T(), ErrBadSequence, <-result)

services/horizon/internal/txsub/sequence/manager.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
type Manager struct {
1515
mutex sync.Mutex
1616
MaxSize int
17-
queues map[string]*Queue
17+
queues map[string]*AccountTxSubmissionQueue
1818
}
1919

2020
// NewManager returns a new manager
2121
func NewManager() *Manager {
2222
return &Manager{
2323
MaxSize: 1024, //TODO: make MaxSize configurable
24-
queues: map[string]*Queue{},
24+
queues: map[string]*AccountTxSubmissionQueue{},
2525
}
2626
}
2727

@@ -70,15 +70,15 @@ func (m *Manager) Push(address string, sequence uint64) <-chan error {
7070

7171
aq, ok := m.queues[address]
7272
if !ok {
73-
aq = NewQueue()
73+
aq = NewAccountTxSubmissionQueue()
7474
m.queues[address] = aq
7575
}
7676

7777
return aq.Push(sequence)
7878
}
7979

8080
// Update notifies the manager of newly loaded account sequence information. The manager uses this information
81-
// to notify requests to submit that they should proceed. See Queue#Update for the actual meat of the logic.
81+
// to notify requests to submit that they should proceed. See AccountTxSubmissionQueue#NotifyLastAccountSequence for the actual meat of the logic.
8282
func (m *Manager) Update(updates map[string]uint64) {
8383
m.mutex.Lock()
8484
defer m.mutex.Unlock()
@@ -89,7 +89,7 @@ func (m *Manager) Update(updates map[string]uint64) {
8989
continue
9090
}
9191

92-
queue.Update(seq)
92+
queue.NotifyLastAccountSequence(seq)
9393
if queue.Size() == 0 {
9494
delete(m.queues, address)
9595
}

services/horizon/internal/txsub/sequence/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestManager_Push(t *testing.T) {
2020
assert.Equal(t, 1, mgr.queues["2"].Size())
2121
}
2222

23-
// Test the Update method
23+
// Test the NotifyLastAccountSequence method
2424
func TestManager_Update(t *testing.T) {
2525
mgr := NewManager()
2626
results := []<-chan error{

services/horizon/internal/txsub/submitter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (sub *submitter) Submit(ctx context.Context, env string) (result Submission
5050
return
5151
}
5252

53-
// interpet response
53+
// interpret response
5454
if cresp.IsException() {
5555
result.Err = errors.Errorf("stellar-core exception: %s", cresp.Exception)
5656
return

0 commit comments

Comments
 (0)