Skip to content

Commit

Permalink
fix concurrent map write panics in generate_consolidations & `gener…
Browse files Browse the repository at this point in the history
…ate_withdrawal_requests` tasks
  • Loading branch information
pk910 committed Oct 24, 2024
1 parent 56a49cd commit 66f1f6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/coordinator/tasks/generate_consolidations/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (t *Task) Execute(ctx context.Context) error {

consolidationTransactions := []string{}
consolidationReceipts := map[string]*ethtypes.Receipt{}
receiptsMapMutex := sync.Mutex{}

for {
accountIdx := t.nextIndex
Expand All @@ -141,7 +142,9 @@ func (t *Task) Execute(ctx context.Context) error {
<-pendingChan
}

receiptsMapMutex.Lock()
consolidationReceipts[tx.Hash().Hex()] = receipt
receiptsMapMutex.Unlock()

pendingWg.Done()

Expand Down Expand Up @@ -199,6 +202,9 @@ func (t *Task) Execute(ctx context.Context) error {

receiptList := []interface{}{}

receiptsMapMutex.Lock()
defer receiptsMapMutex.Unlock()

for _, txhash := range consolidationTransactions {
var receiptMap map[string]interface{}

Expand Down
6 changes: 6 additions & 0 deletions pkg/coordinator/tasks/generate_withdrawal_requests/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (t *Task) Execute(ctx context.Context) error {
totalCount := 0

withdrawalTransactions := []string{}
receiptsMapMutex := sync.Mutex{}
withdrawalReceipts := map[string]*ethtypes.Receipt{}

for {
Expand All @@ -137,7 +138,9 @@ func (t *Task) Execute(ctx context.Context) error {
<-pendingChan
}

receiptsMapMutex.Lock()
withdrawalReceipts[tx.Hash().Hex()] = receipt
receiptsMapMutex.Unlock()

pendingWg.Done()

Expand Down Expand Up @@ -191,6 +194,9 @@ func (t *Task) Execute(ctx context.Context) error {

receiptList := []interface{}{}

receiptsMapMutex.Lock()
defer receiptsMapMutex.Unlock()

for _, txhash := range withdrawalTransactions {
var receiptMap map[string]interface{}

Expand Down

0 comments on commit 66f1f6f

Please sign in to comment.