Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ github.com/quasilyte/go-ruleguard/rules v0.0.0-20211022131956-028d6511ab71 h1:CN
github.com/quasilyte/go-ruleguard/rules v0.0.0-20211022131956-028d6511ab71/go.mod h1:4cgAphtvu7Ftv7vOT2ZOYhC6CvBxZixcasr8qIOTA50=
github.com/quasilyte/gogrep v0.0.0-20220828223005-86e4605de09f/go.mod h1:Cm9lpz9NZjEoL1tgZ2OgeUKPIxL1meE7eo60Z6Sk+Ng=
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0=
github.com/quicksilver-zone/quicksilver v1.9.0/go.mod h1:usPseXkervkElaIfwtefU8O1+tp900IpywJLL8HBEZs=
github.com/rabbitmq/amqp091-go v1.2.0 h1:1pHBxAsQh54R9eX/xo679fUEAfv3loMqi0pvRFOj2nk=
github.com/rabbitmq/amqp091-go v1.2.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
Expand Down
2 changes: 1 addition & 1 deletion icq-relayer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/go-kit/log v0.2.1
github.com/mitchellh/go-homedir v1.1.0
github.com/prometheus/client_golang v1.22.0
github.com/quicksilver-zone/quicksilver v1.8.0-beta.11
github.com/quicksilver-zone/quicksilver v1.9.0
github.com/rs/zerolog v1.34.0
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
Expand Down
1 change: 0 additions & 1 deletion xcclookup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/go-kit/log v0.2.1
github.com/golangci/golangci-lint/v2 v2.2.2
github.com/gorilla/mux v1.8.1
github.com/quicksilver-zone/quicksilver v1.8.2-0.20250707101051-6cb838a1fa0e
github.com/stretchr/testify v1.10.0
go.uber.org/multierr v1.11.0
golang.org/x/tools v0.35.0
Expand Down
30 changes: 27 additions & 3 deletions xcclookup/pkgs/types/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
Messages []prewards.MsgSubmitClaim `json:"messages"`
Assets map[string][]Asset `json:"assets"`
Errors *ErrorString `json:"errors,omitempty"`
mu sync.RWMutex `json:"-"` // mutex for thread-safe access

Check failure on line 63 in xcclookup/pkgs/types/rpc.go

View workflow job for this annotation

GitHub Actions / lint-xcclookup

struct-tag: tag on not-exported field mu (revive)
}

func (response *Response) Update(ctx context.Context, messages map[string]prewards.MsgSubmitClaim, assets map[string]sdk.Coins, assetType string) {
log := logger.FromContext(ctx)
m := sync.Mutex{}
m.Lock()
defer m.Unlock()
response.mu.Lock()
defer response.mu.Unlock()

for _, message := range messages {
if message.ClaimType == types.ClaimTypeUndefined {
Expand All @@ -88,6 +88,30 @@
}
}

// GetAssets returns a copy of the assets map for thread-safe reading
func (response *Response) GetAssets() map[string][]Asset {
response.mu.RLock()
defer response.mu.RUnlock()

// Create a deep copy to avoid race conditions
result := make(map[string][]Asset)
for k, v := range response.Assets {
result[k] = append([]Asset{}, v...)
}
return result
}

// GetMessages returns a copy of the messages slice for thread-safe reading
func (response *Response) GetMessages() []prewards.MsgSubmitClaim {
response.mu.RLock()
defer response.mu.RUnlock()

// Create a copy to avoid race conditions
result := make([]prewards.MsgSubmitClaim, len(response.Messages))
copy(result, response.Messages)
return result
}

type Asset struct {
Type string
Amount sdk.Coins
Expand Down
52 changes: 52 additions & 0 deletions xcclookup/pkgs/types/rpc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package types

import (
"sync"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 7 in xcclookup/pkgs/types/rpc_test.go

View workflow job for this annotation

GitHub Actions / lint-xcclookup

File is not properly formatted (gci)
"github.com/stretchr/testify/assert"
)

func TestResponse_Mutex_Exists(t *testing.T) {
// Test that the Response struct can be created and has the mutex field
response := &Response{
Assets: make(map[string][]Asset),
}

// Test that we can access the Assets field
assert.NotNil(t, response.Assets)

// Test that the GetAssets method works
assets := response.GetAssets()
assert.NotNil(t, assets)
}

func TestResponse_GetAssets_ThreadSafe(t *testing.T) {
response := &Response{
Assets: make(map[string][]Asset),
}

// Add some initial data
response.Assets["chain1"] = []Asset{
{Type: "test", Amount: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(100)))}}

Check failure on line 32 in xcclookup/pkgs/types/rpc_test.go

View workflow job for this annotation

GitHub Actions / lint-xcclookup

File is not properly formatted (gofumpt)

// Test concurrent reads
numGoroutines := 10
var wg sync.WaitGroup

for i := 0; i < numGoroutines; i++ {
wg.Add(1)
go func(id int) {

Check failure on line 40 in xcclookup/pkgs/types/rpc_test.go

View workflow job for this annotation

GitHub Actions / lint-xcclookup

TestResponse_GetAssets_ThreadSafe$1 - id is unused (unparam)
defer wg.Done()

// Read assets multiple times
for j := 0; j < 100; j++ {
assets := response.GetAssets()
assert.NotNil(t, assets)
}
}(i)
}

wg.Wait()
}
Loading