@@ -18,6 +18,7 @@ package catalyst
18
18
19
19
import (
20
20
"context"
21
+ "sync/atomic"
21
22
"time"
22
23
23
24
"github.com/ethereum/go-ethereum/common"
@@ -32,8 +33,9 @@ type api struct {
32
33
33
34
func (a * api ) loop () {
34
35
var (
35
- newTxs = make (chan core.NewTxsEvent )
36
- sub = a .sim .eth .TxPool ().SubscribeTransactions (newTxs , true )
36
+ committing atomic.Bool
37
+ newTxs = make (chan core.NewTxsEvent )
38
+ sub = a .sim .eth .TxPool ().SubscribeTransactions (newTxs , true )
37
39
)
38
40
defer sub .Unsubscribe ()
39
41
@@ -42,12 +44,24 @@ func (a *api) loop() {
42
44
case <- a .sim .shutdownCh :
43
45
return
44
46
case w := <- a .sim .withdrawals .pending :
47
+ // FIXME: `sealBlock` will block the loop and `newTxs` won't be
48
+ // read. If new TX will be submitted to the pool while we're
49
+ // sealing the block, deadlock will occur.
45
50
withdrawals := append (a .sim .withdrawals .gatherPending (9 ), w )
46
51
if err := a .sim .sealBlock (withdrawals , uint64 (time .Now ().Unix ())); err != nil {
47
52
log .Warn ("Error performing sealing work" , "err" , err )
48
53
}
49
54
case <- newTxs :
50
- a .sim .Commit ()
55
+ go func () {
56
+ if committing .Swap (true ) {
57
+ return
58
+ }
59
+ a .sim .Commit ()
60
+ // FIXME: This is race-y, if `newTxs` arrive after we
61
+ // `Commit`ted but before we unset `committing`, `newTxs` will
62
+ // be skipped. Needs redesign.
63
+ committing .Store (false )
64
+ }()
51
65
}
52
66
}
53
67
}
0 commit comments