@@ -5,24 +5,24 @@ import (
5
5
"time"
6
6
)
7
7
8
- // Queue manages the submission queue for a single source account. The
8
+ // AccountTxSubmissionQueue manages the submission queue for a single source account. The
9
9
// transaction system uses Push to enqueue submissions for given sequence
10
10
// numbers.
11
11
//
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
14
14
// being managed, queued submissions that can be acted upon will be unblocked.
15
15
//
16
- type Queue struct {
16
+ type AccountTxSubmissionQueue struct {
17
17
lastActiveAt time.Time
18
18
timeout time.Duration
19
19
nextSequence uint64
20
20
queue pqueue
21
21
}
22
22
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 {
26
26
lastActiveAt : time .Now (),
27
27
timeout : 10 * time .Second ,
28
28
queue : nil ,
@@ -34,7 +34,7 @@ func NewQueue() *Queue {
34
34
}
35
35
36
36
// Size returns the count of currently buffered submissions in the queue.
37
- func (q * Queue ) Size () int {
37
+ func (q * AccountTxSubmissionQueue ) Size () int {
38
38
return len (q .queue )
39
39
}
40
40
@@ -43,26 +43,26 @@ func (q *Queue) Size() int {
43
43
// to do so.
44
44
//
45
45
// 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
47
47
// the same as the provided sequence, to keep internal complexity much lower.
48
48
// Given that, the recommended usage pattern is:
49
49
//
50
50
// 1. Push the submission onto the queue
51
51
// 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
53
53
// possible
54
- func (q * Queue ) Push (sequence uint64 ) <- chan error {
54
+ func (q * AccountTxSubmissionQueue ) Push (sequence uint64 ) <- chan error {
55
55
ch := make (chan error , 1 )
56
56
heap .Push (& q .queue , item {sequence , ch })
57
57
return ch
58
58
}
59
59
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
61
61
// seen value for the account that this queue manages submissions for.
62
62
//
63
63
// This function is monotonic... calling it with a sequence number lower than
64
64
// the latest seen sequence number is a noop.
65
- func (q * Queue ) Update (sequence uint64 ) {
65
+ func (q * AccountTxSubmissionQueue ) NotifyLastAccountSequence (sequence uint64 ) {
66
66
if q .nextSequence <= sequence {
67
67
q .nextSequence = sequence + 1
68
68
}
@@ -113,7 +113,7 @@ func (q *Queue) Update(sequence uint64) {
113
113
}
114
114
115
115
// helper function for interacting with the priority queue
116
- func (q * Queue ) head () (chan error , uint64 ) {
116
+ func (q * AccountTxSubmissionQueue ) head () (chan error , uint64 ) {
117
117
if len (q .queue ) == 0 {
118
118
return nil , uint64 (0 )
119
119
}
@@ -122,7 +122,7 @@ func (q *Queue) head() (chan error, uint64) {
122
122
}
123
123
124
124
// helper function for interacting with the priority queue
125
- func (q * Queue ) pop () (chan error , uint64 ) {
125
+ func (q * AccountTxSubmissionQueue ) pop () (chan error , uint64 ) {
126
126
i := heap .Pop (& q .queue ).(item )
127
127
128
128
return i .Chan , i .Sequence
@@ -134,7 +134,7 @@ type item struct {
134
134
Chan chan error
135
135
}
136
136
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
138
138
// implements heap.Interface.
139
139
type pqueue []item
140
140
0 commit comments