Skip to content

Commit

Permalink
Fix data race on hcr.channels (2)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Litvinov <[email protected]>
  • Loading branch information
Zensey committed Mar 25, 2024
1 parent 031c7fe commit e5d0518
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions session/pingpong/hermes_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func NewHermesChannel(channelID string, id identity.Identity, hermesID common.Ad
lastPromise: promise,
Beneficiary: beneficiary,
}
return hc.Copy()
return hc
}

// Copy returns a deep copy of channel
func (hc *HermesChannel) Copy() HermesChannel {
func (hc HermesChannel) Copy() HermesChannel {
var hcCopy HermesChannel
if err := copier.CopyWithOption(&hcCopy, *hc, copier.Option{DeepCopy: true}); err != nil {
if err := copier.CopyWithOption(&hcCopy, hc, copier.Option{DeepCopy: true}); err != nil {
panic(err)
}
return hcCopy
Expand Down
6 changes: 4 additions & 2 deletions session/pingpong/hermes_channel_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ func (hcr *HermesChannelRepository) fetchChannel(chainID int64, channelID string
if err != nil {
return HermesChannel{}, fmt.Errorf("could not get provider beneficiary for %v, hermes %v: %w", id, hermesID.Hex(), err)
}
hermesChannel := NewHermesChannel(channelID, id, hermesID, channel, promise, benef)
hermesChannel := NewHermesChannel(channelID, id, hermesID, channel, promise, benef).
Copy()

hcr.updateChannel(chainID, hermesChannel)

Expand All @@ -456,7 +457,8 @@ func (hcr *HermesChannelRepository) updateChannelWithLatestPromise(chainID int64
return err
}

hermesChannel := NewHermesChannel(channelID, id, hermesID, gotten.Channel, promise, gotten.Beneficiary)
hermesChannel := NewHermesChannel(channelID, id, hermesID, gotten.Channel, promise, gotten.Beneficiary).
Copy()

// protect hcr.channels: handleHermesPromiseReceived -> updateChannelWithLatestPromise -> updateChannel
if protectChannels {
Expand Down

0 comments on commit e5d0518

Please sign in to comment.