Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x/tx): concurrent map writes when calling GetSigners #21073

Merged
merged 9 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions x/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Since v0.13.0, x/tx follows Cosmos SDK semver: https://github.com/cosmos/cosmos-

## [Unreleased]

### Improvements

* [#21073](https://github.com/cosmos/cosmos-sdk/pull/21073) Add write-only mutex in Context to protect `getSignersFuncs` map from concurrent writes.

## [v0.13.3](https://github.com/cosmos/cosmos-sdk/releases/tag/x/tx/v0.13.3) - 2024-04-22

### Improvements
Expand Down
4 changes: 4 additions & 0 deletions x/tx/signing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func NewContext(options Options) (*Context, error) {
maxRecursionDepth: options.MaxRecursionDepth,
}

if err := c.Validate(); err != nil {
return nil, err
}

return c, nil
}

Expand Down
27 changes: 27 additions & 0 deletions x/tx/signing/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@ var deeplyNestedRepeatedSigner = &testpb.DeeplyNestedRepeatedSigner{
},
}

func TestGetGetSignersFnConcurrent(t *testing.T) {
ctx, err := NewContext(Options{
AddressCodec: dummyAddressCodec{},
ValidatorAddressCodec: dummyValidatorAddressCodec{},
})
require.NoError(t, err)

msg := &bankv1beta1.MsgSend{
FromAddress: hex.EncodeToString([]byte("foo")),
}

desc := msg.ProtoReflect().Descriptor()

// err = ctx.Validate()
// require.NoError(t, err)

for i := 0; i < 100; i++ {
go func() {
_, _ = ctx.getGetSignersFn(desc)
}()
}

// signers, err := fn(msg)
// require.NoError(t, err)
// require.Equal(t, [][]byte{[]byte("foo")}, signers)
}

func TestGetSigners(t *testing.T) {
ctx, err := NewContext(Options{
AddressCodec: dummyAddressCodec{},
Expand Down
Loading