diff --git a/session/pingpong/hermes_channel.go b/session/pingpong/hermes_channel.go index f2aa4cdce9..8674dfdc21 100644 --- a/session/pingpong/hermes_channel.go +++ b/session/pingpong/hermes_channel.go @@ -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