@@ -20,23 +20,27 @@ type BroadcastedTransaction struct {
20
20
DeclaredClass core.Class
21
21
}
22
22
23
- // storageElem defines a node for both the
24
- // in-memory and persistent linked-list
25
- type storageElem struct {
23
+ // runtime mempool txn
24
+ type memPoolTxn struct {
25
+ Txn BroadcastedTransaction
26
+ Next * memPoolTxn
27
+ }
28
+
29
+ // persistent db txn value
30
+ type dbPoolTxn struct {
26
31
Txn BroadcastedTransaction
27
- NextHash * felt.Felt // persistent db
28
- Next * storageElem // in-memory
32
+ NextHash * felt.Felt
29
33
}
30
34
31
- // memTxnList represents a linked list of user transactions at runtime"
35
+ // memTxnList represents a linked list of user transactions at runtime
32
36
type memTxnList struct {
33
- head * storageElem
34
- tail * storageElem
37
+ head * memPoolTxn
38
+ tail * memPoolTxn
35
39
len int
36
40
mu sync.Mutex
37
41
}
38
42
39
- func (t * memTxnList ) push (newNode * storageElem ) {
43
+ func (t * memTxnList ) push (newNode * memPoolTxn ) {
40
44
t .mu .Lock ()
41
45
defer t .mu .Unlock ()
42
46
if t .tail != nil {
@@ -130,24 +134,24 @@ func (p *Pool) LoadFromDB() error {
130
134
// loop through the persistent pool and push nodes to the in-memory pool
131
135
currentHash := headValue
132
136
for currentHash != nil {
133
- curElem , err := p .readDBElem (txn , currentHash )
137
+ curDBElem , err := p .readDBElem (txn , currentHash )
134
138
if err != nil {
135
139
return err
136
140
}
137
- newNode := & storageElem {
138
- Txn : curElem .Txn ,
141
+ newMemPoolTxn := & memPoolTxn {
142
+ Txn : curDBElem .Txn ,
139
143
}
140
- if curElem .NextHash != nil {
141
- nxtElem , err := p .readDBElem (txn , curElem .NextHash )
144
+ if curDBElem .NextHash != nil {
145
+ nextDBTxn , err := p .readDBElem (txn , curDBElem .NextHash )
142
146
if err != nil {
143
147
return err
144
148
}
145
- newNode .Next = & storageElem {
146
- Txn : nxtElem .Txn ,
149
+ newMemPoolTxn .Next = & memPoolTxn {
150
+ Txn : nextDBTxn .Txn ,
147
151
}
148
152
}
149
- p .memTxnList .push (newNode )
150
- currentHash = curElem .NextHash
153
+ p .memTxnList .push (newMemPoolTxn )
154
+ currentHash = curDBElem .NextHash
151
155
}
152
156
return nil
153
157
})
@@ -163,12 +167,12 @@ func (p *Pool) writeToDB(userTxn *BroadcastedTransaction) error {
163
167
}
164
168
tailValue = nil
165
169
}
166
- if err := p .setDBElem (dbTxn , & storageElem {Txn : * userTxn }); err != nil {
170
+ if err := p .setDBElem (dbTxn , & dbPoolTxn {Txn : * userTxn }); err != nil {
167
171
return err
168
172
}
169
173
if tailValue != nil {
170
174
// Update old tail to point to the new item
171
- var oldTailElem storageElem
175
+ var oldTailElem dbPoolTxn
172
176
oldTailElem , err := p .readDBElem (dbTxn , tailValue )
173
177
if err != nil {
174
178
return err
@@ -215,7 +219,7 @@ func (p *Pool) Push(userTxn *BroadcastedTransaction) error {
215
219
}
216
220
}
217
221
218
- newNode := & storageElem {Txn : * userTxn , Next : nil }
222
+ newNode := & memPoolTxn {Txn : * userTxn , Next : nil }
219
223
p .memTxnList .push (newNode )
220
224
221
225
select {
@@ -339,16 +343,16 @@ func (p *Pool) updateTail(txn db.Transaction, tail *felt.Felt) error {
339
343
return txn .Set (db .MempoolTail .Key (), tail .Marshal ())
340
344
}
341
345
342
- func (p * Pool ) readDBElem (txn db.Transaction , itemKey * felt.Felt ) (storageElem , error ) {
343
- var item storageElem
346
+ func (p * Pool ) readDBElem (txn db.Transaction , itemKey * felt.Felt ) (dbPoolTxn , error ) {
347
+ var item dbPoolTxn
344
348
keyBytes := itemKey .Bytes ()
345
349
err := txn .Get (db .MempoolNode .Key (keyBytes [:]), func (b []byte ) error {
346
350
return encoder .Unmarshal (b , & item )
347
351
})
348
352
return item , err
349
353
}
350
354
351
- func (p * Pool ) setDBElem (txn db.Transaction , item * storageElem ) error {
355
+ func (p * Pool ) setDBElem (txn db.Transaction , item * dbPoolTxn ) error {
352
356
itemBytes , err := encoder .Marshal (item )
353
357
if err != nil {
354
358
return err
0 commit comments