Skip to content

Commit

Permalink
Fix data race on HermesChannel
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Litvinov <[email protected]>
  • Loading branch information
Zensey committed Mar 6, 2024
1 parent 08e0f70 commit a63270d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions session/pingpong/hermes_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,40 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/jinzhu/copier"
"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/payments/client"
)

// NewHermesChannel creates HermesChannel model.
func NewHermesChannel(channelID string, id identity.Identity, hermesID common.Address, channel client.ProviderChannel, promise HermesPromise, beneficiary common.Address) HermesChannel {

// in order to prevent data race over *big.Int and other referential type fileds used in hc
var channel_ client.ProviderChannel
var promise_ HermesPromise
if err := copier.CopyWithOption(&channel_, channel, copier.Option{DeepCopy: true}); err != nil {
panic(err)
}
if err := copier.CopyWithOption(&promise_, promise, copier.Option{DeepCopy: true}); err != nil {
panic(err)
}

return HermesChannel{
ChannelID: channelID,
Identity: id,
HermesID: hermesID,
Channel: channel,
lastPromise: promise,
Channel: channel_,
lastPromise: promise_,
Beneficiary: beneficiary,
}
}

// HermesChannel represents opened payment channel between identity and hermes.
type HermesChannel struct {
ChannelID string
Identity identity.Identity
HermesID common.Address
ChannelID string
Identity identity.Identity
HermesID common.Address

Channel client.ProviderChannel
lastPromise HermesPromise
Beneficiary common.Address
Expand Down

0 comments on commit a63270d

Please sign in to comment.