Skip to content

Commit

Permalink
fix: set lock on state root handling directly (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Oct 28, 2024
1 parent 88a4e0d commit 900d470
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
6 changes: 0 additions & 6 deletions chains/evm/listener/handlers/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"math/big"
"slices"
"strings"
"sync"

ethereumABI "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -56,7 +55,6 @@ type DepositEventHandler struct {
slotIndex uint8
genericResources []string
msgChan chan []*message.Message
lock sync.Mutex
}

func NewDepositEventHandler(
Expand All @@ -76,14 +74,10 @@ func NewDepositEventHandler(
genericResources: genericResources,
msgChan: msgChan,
domainID: domainID,
lock: sync.Mutex{},
}
}

func (h *DepositEventHandler) HandleEvents(destination uint8, startBlock *big.Int, endBlock *big.Int, slot *big.Int) error {
h.lock.Lock()
defer h.lock.Unlock()

deposits, err := h.fetchDeposits(destination, startBlock, endBlock)
if err != nil {
return err
Expand Down
6 changes: 0 additions & 6 deletions chains/evm/listener/handlers/hashi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"math/big"
"strings"
"sync"

"github.com/attestantio/go-eth2-client/api"
apiv1 "github.com/attestantio/go-eth2-client/api/v1"
Expand Down Expand Up @@ -54,7 +53,6 @@ type HashiEventHandler struct {
beaconClient BeaconClient
client Client
chainIDS map[uint8]uint64
lock sync.Mutex
}

func NewHashiEventHandler(
Expand All @@ -78,14 +76,10 @@ func NewHashiEventHandler(
rootProver: rootProver,
chainIDS: chainIDS,
msgChan: msgChan,
lock: sync.Mutex{},
}
}

func (h *HashiEventHandler) HandleEvents(destination uint8, startBlock *big.Int, endBlock *big.Int, slot *big.Int) error {
h.lock.Lock()
defer h.lock.Unlock()

logs, err := h.fetchMessages(startBlock, endBlock)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions chains/evm/message/stateRoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/hex"
"math/big"
"sync"

"github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec"
Expand Down Expand Up @@ -54,6 +55,7 @@ type StateRootHandler struct {
eventHandlers []EventHandler
startBlock *big.Int
domainID uint8
lock sync.Mutex
}

func NewStateRootHandler(
Expand All @@ -69,12 +71,16 @@ func NewStateRootHandler(
domainID: domainID,
startBlock: startBlock,
eventHandlers: eventHandlers,
lock: sync.Mutex{},
}
}

// HandleMessage fetches deposits for the given state root and submits a transfer message
// with execution state proofs per transfer
func (h *StateRootHandler) HandleMessage(m *message.Message) (*proposal.Proposal, error) {
h.lock.Lock()
defer h.lock.Unlock()

stateRoot := m.Data.(StateRootData)
log.Debug().Uint8(
"domainID", m.Destination).Str(
Expand Down

0 comments on commit 900d470

Please sign in to comment.