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
5 changes: 5 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ func NewSimApp(
}
}

// validate SigningContext to pre-fill internal signers funcs map
if err = app.interfaceRegistry.SigningContext().Validate(); err != nil {
panic(err)
}

return app
}

Expand Down
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
8 changes: 7 additions & 1 deletion x/tx/signing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package signing
import (
"errors"
"fmt"
"sync"

cosmos_proto "github.com/cosmos/cosmos-proto"
gogoproto "github.com/cosmos/gogoproto/proto"
Expand All @@ -29,9 +30,11 @@ type Context struct {
typeResolver protoregistry.MessageTypeResolver
addressCodec address.Codec
validatorAddressCodec address.Codec
getSignersFuncs map[protoreflect.FullName]GetSignersFunc
customGetSignerFuncs map[protoreflect.FullName]GetSignersFunc
maxRecursionDepth int

mtx sync.Mutex
getSignersFuncs map[protoreflect.FullName]GetSignersFunc
}

// Options are options for creating Context which will be used for signing operations.
Expand Down Expand Up @@ -110,6 +113,7 @@ func NewContext(options Options) (*Context, error) {
typeResolver: protoTypes,
addressCodec: options.AddressCodec,
validatorAddressCodec: options.ValidatorAddressCodec,
mtx: sync.Mutex{},
getSignersFuncs: map[protoreflect.FullName]GetSignersFunc{},
customGetSignerFuncs: customGetSignerFuncs,
maxRecursionDepth: options.MaxRecursionDepth,
Expand Down Expand Up @@ -336,6 +340,8 @@ func (c *Context) getGetSignersFn(messageDescriptor protoreflect.MessageDescript
}
f, ok = c.getSignersFuncs[messageDescriptor.FullName()]
if !ok {
c.mtx.Lock()
defer c.mtx.Unlock()
var err error
f, err = c.makeGetSignersFunc(messageDescriptor)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm because makeGetSignersFunc is stateless right? so worst case we get multiple blocked writes which will quickly resolve

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, before the worst case would bring the node down, now the worst case just creates some tiny delays

if err != nil {
Expand Down