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

perf: add cache to address codec #20122

Merged
merged 23 commits into from
Jun 13, 2024
Merged

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Apr 22, 2024

Description

ref:
#13140
#7448

Benchmark

goos: darwin
goarch: arm64
pkg: [github.com/cosmos/cosmos-sdk/codec/address](http://github.com/cosmos/cosmos-sdk/codec/address)
BenchmarkCodecWithCache
BenchmarkCodecWithCache-8      	19053944	        60.81 ns/op	      32 B/op	       1 allocs/op
BenchmarkCodecWithoutCache
BenchmarkCodecWithoutCache-8   	 2752668	       444.3 ns/op	      96 B/op	       2 allocs/op

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a caching mechanism for Bech32 address encoding and decoding to improve performance.
    • Added options for creating cached Bech32 codecs.
  • Tests

    • Added unit tests for various Bech32 codec functionalities, including cache handling and race conditions.
    • Implemented benchmark tests for comparing performance with and without caching.
    • Introduced fuzz testing for address codecs to ensure robustness and reliability.

@JulianToledano JulianToledano requested a review from a team as a code owner April 22, 2024 08:26
Copy link
Contributor

coderabbitai bot commented Apr 22, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The changes introduce a caching mechanism to the Bech32 codec for improved performance, including a new cachedBech32Codec type. This involves adding cache and mutex handling to store and retrieve Bech32 conversion results efficiently. Additional tests and benchmarks ensure the reliability and performance of the caching feature.

Changes

File Summary of Changes
codec/address/bech32_codec.go Introduced cachedBech32Codec type, caching options, and new functions for Bech32 codec creation and conversion methods.
codec/address/bech32_codec_test.go Added test functions for creating cached Bech32 codecs, handling multiple codecs, and testing race conditions.
codec/address/bench_test.go Added benchmark tests for encoding and decoding addresses with and without caching.
codec/address/fuzz_test.go Added fuzz testing functions for address codecs and supporting functions.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant Bech32Codec
    participant Cache
    participant Mutex

    Client->>Bech32Codec: NewCachedBech32Codec(prefix, opts)
    Bech32Codec->>Cache: Initialize Cache
    Bech32Codec->>Mutex: Initialize Mutex
    Bech32Codec-->>Client: Return cachedBech32Codec instance

    Client->>Bech32Codec: BytesToString(bz)
    Bech32Codec->>Mutex: Lock
    alt Cache Hit
        Bech32Codec->>Cache: Retrieve from Cache
        Cache-->>Bech32Codec: Cached Result
    else Cache Miss
        Bech32Codec->>Bech32Codec: Perform Conversion
        Bech32Codec->>Cache: Store in Cache
    end
    Bech32Codec->>Mutex: Unlock
    Bech32Codec-->>Client: Return Result

    Client->>Bech32Codec: StringToBytes(text)
    Bech32Codec->>Mutex: Lock
    alt Cache Hit
        Bech32Codec->>Cache: Retrieve from Cache
        Cache-->>Bech32Codec: Cached Result
    else Cache Miss
        Bech32Codec->>Bech32Codec: Perform Conversion
        Bech32Codec->>Cache: Store in Cache
    end
    Bech32Codec->>Mutex: Unlock
    Bech32Codec-->>Client: Return Result
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

codec/address/bech32_codec.go Outdated Show resolved Hide resolved
codec/address/bech32_codec.go Outdated Show resolved Hide resolved
codec/address/bech32_codec.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Good start! 🏃
I added some thoughts and ideas although I have only limited context on this feature.

When it comes to caching, I also have telemetry on my list to learn about the utilization. This may be overkill but just sharing this collector as example.

codec/address/bech32_codec.go Outdated Show resolved Hide resolved
codec/address/bech32_codec.go Outdated Show resolved Hide resolved
codec/address/bech32_codec.go Outdated Show resolved Hide resolved

addr, err := cbc.codec.StringToBytes(text)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 it can be worth to cache failures, too. Some benchmarks would be interesting.

codec/address/bech32_codec.go Show resolved Hide resolved
codec/address/bech32_codec.go Outdated Show resolved Hide resolved
codec/address/bech32_codec_test.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Out of diff range and nitpick comments (1)
codec/address/bech32_codec.go (1)

39-54: Consider consolidating cache types or making cache configuration more flexible, as multiple cache types might not be necessary and could complicate maintenance.

codec/address/bech32_codec.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7ffa4a7 and 37bf7f5.
Files selected for processing (2)
  • codec/address/bech32_codec.go (2 hunks)
  • codec/address/bech32_codec_test.go (1 hunks)
Additional Context Used
Path-based Instructions (2)
codec/address/bech32_codec_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

codec/address/bech32_codec.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (6)
codec/address/bech32_codec_test.go (2)

17-66: The unit tests in TestNewBech32Codec effectively validate the caching mechanism and address conversions. Good coverage of different prefixes and cache interactions.


70-92: The tests in TestMultipleBech32Codec correctly ensure that separate caches for different codecs do not interfere with each other and validate the caching behavior.

codec/address/bech32_codec.go (4)

39-53: Initialization of caches and mutexes is correctly implemented, ensuring separate caches for different address types and appropriate error handling.


69-91: The NewBech32Codec function is well-implemented, correctly handling the selection of caches and mutexes based on the prefix and the caching condition.


Line range hint 91-133: Methods StringToBytes and BytesToString in Bech32Codec are correctly implemented with comprehensive error handling and validation.


134-168: Methods in cachedBech32Codec are correctly implemented with thread safety and caching. Consider optimizing the locking strategy to improve performance, as discussed in previous comments.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 37bf7f5 and 469ac79.
Files selected for processing (1)
  • codec/address/bech32_codec_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • codec/address/bech32_codec_test.go

@JulianToledano
Copy link
Contributor Author

Benchmark results

goos: darwin
goarch: arm64
pkg: [github.com/cosmos/cosmos-sdk/codec/address](http://github.com/cosmos/cosmos-sdk/codec/address)
BenchmarkCodecWithCache
BenchmarkCodecWithCache-8      	19053944	        60.81 ns/op	      32 B/op	       1 allocs/op
BenchmarkCodecWithoutCache
BenchmarkCodecWithoutCache-8   	 2752668	       444.3 ns/op	      96 B/op	       2 allocs/op

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 469ac79 and f5ccb72.
Files selected for processing (4)
  • codec/address/bech32_codec.go (2 hunks)
  • codec/address/bech32_codec_test.go (1 hunks)
  • codec/address/bench_test.go (1 hunks)
  • codec/address/fuzz_test.go (1 hunks)
Additional Context Used
Path-based Instructions (4)
codec/address/bench_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

codec/address/fuzz_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

codec/address/bech32_codec_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

codec/address/bech32_codec.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (17)
codec/address/bench_test.go (3)

11-14: Benchmark function for codec with cache looks good.


16-19: Benchmark function for codec without cache looks good.


21-32: Helper function for benchmarking BytesToString looks good.

codec/address/fuzz_test.go (3)

14-27: Fuzz test for codec with cache looks good.


30-43: Fuzz test for codec without cache looks good.


46-61: Helper function for checking address conversion looks good.

codec/address/bech32_codec_test.go (5)

17-24: Helper function for generating addresses looks good.


26-77: Unit test for creating Bech32 codec with cache looks good.


79-100: Unit test for creating multiple Bech32 codecs with cache looks good.


102-124: Unit test for Bech32 codec race conditions looks good.


126-148: Helper function for testing Bech32 codec race conditions looks good.

codec/address/bech32_codec.go (6)

41-56: Initialization of cache variables looks good.


73-93: Function for creating new Bech32 codec with optional caching looks good.


Line range hint 98-113: Function for converting Bech32 string to bytes looks good.


Line range hint 122-134: Function for converting bytes to Bech32 string looks good.


136-157: Function for converting bytes to Bech32 string with caching looks good.


159-174: Function for converting Bech32 string to bytes with caching looks good.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between f5ccb72 and 726d5fc.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional Context Used
Path-based Instructions (1)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9868c7f and 9db0b77.
Files selected for processing (1)
  • codec/address/bench_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • codec/address/bench_test.go

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Thanks for the updates. This looks good for me to start. I would love to see more configuration options and metrics but this can go into a new PR if needed.
Good work!

codec/address/bech32_codec_test.go Outdated Show resolved Hide resolved
codec/address/bech32_codec_test.go Show resolved Hide resolved
codec/address/bech32_codec_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9db0b77 and 5d5ab90.
Files selected for processing (1)
  • codec/address/bech32_codec_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • codec/address/bech32_codec_test.go

Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

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

LGTM, but I'd prefer this option you listed here:

Store a map in the LRU with prefix as keys (e.g., map["cosmos"] = "cosmos1dr3...")

It would reduce the amount of code and complexity. Also no hardcoded constants.

We would need to figure out how set the size of the cache, but maybe that's something we'd like to have anyway?


// cache variables
var (
accAddrMu sync.Mutex
Copy link
Member

@kocubinski kocubinski May 28, 2024

Choose a reason for hiding this comment

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

If we want to avoid globals, we should consider adding a NewBech32CodecWithOptions constructor which keeps references to the cache in the codec struct. This would (I think) solve the problem of what looks like 3 global caches; we'd instead of 3 instances of an address codec in the application. This is easily done with depinject but can be handled manually too.

@kocubinski kocubinski self-assigned this May 28, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Outside diff range and nitpick comments (2)
codec/address/bech32_codec.go (2)

Line range hint 71-91: Refactor to improve error handling in StringToBytes.

- if len(bz) > sdkAddress.MaxAddrLen {
-     return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", sdkAddress.MaxAddrLen, len(bz))
- }
+ if len(bz) > sdkAddress.MaxAddrLen {
+     return nil, sdkerrors.ErrUnknownAddress
+ }

Line range hint 99-110: Refactor to improve error handling in BytesToString.

- if len(bz) > sdkAddress.MaxAddrLen {
-     return "", errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", sdkAddress.MaxAddrLen, len(bz))
- }
+ if len(bz) > sdkAddress.MaxAddrLen {
+     return "", sdkerrors.ErrUnknownAddress
+ }
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5d5ab90 and 62a7228.

Files selected for processing (4)
  • codec/address/bech32_codec.go (2 hunks)
  • codec/address/bech32_codec_test.go (1 hunks)
  • codec/address/bench_test.go (1 hunks)
  • codec/address/fuzz_test.go (1 hunks)
Additional context used
Path-based instructions (4)
codec/address/bench_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

codec/address/fuzz_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

codec/address/bech32_codec.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

codec/address/bech32_codec_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (5)
codec/address/bench_test.go (2)

16-19: LGTM! Proper use of the Bech32Codec without cache for benchmarking.


11-14: Ensure proper initialization of lru and mu before use in BenchmarkCodecWithCache.

codec/address/fuzz_test.go (2)

32-48: LGTM! Proper use of the Bech32Codec without cache for fuzz testing.


14-30: Ensure proper initialization of lru and mu before use in FuzzCachedAddressCodec.

Verification successful

Let's perform a more comprehensive search to verify the initialization of lru and mu.


The search results indicate that lru and mu are indeed initialized in the codebase:

  • lru is initialized in codec/address/bech32_codec_test.go with the line lru, _ = simplelru.NewLRU(500, nil).
  • mu is initialized in codec/address/bech32_codec_test.go with the line mu = &sync.Mutex{}.

These initializations confirm that lru and mu are properly set up before being used in the FuzzCachedAddressCodec function.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `lru` and `mu` are properly initialized before use.

# Test: Search for their initialization in the codebase.
rg --type go 'lru, _ := simplelru.NewLRU' && rg --type go 'mu := &sync.Mutex{}'

Length of output: 43



Script:

#!/bin/bash
# Description: Verify that `lru` and `mu` are properly initialized before use.

# Test: Search for the initialization of `lru` and `mu` in the codebase.
rg --type go 'simplelru.NewLRU' && rg --type go 'sync.Mutex'

Length of output: 1977

codec/address/bech32_codec_test.go (1)

34-84: Ensure proper initialization of lru and mu before use in TestNewBech32Codec.

Verification successful

Let's perform a more comprehensive search to verify the initialization of lru and mu.


The initialization of lru and mu is confirmed within the codec/address/bech32_codec_test.go file:

  • lru is initialized with simplelru.NewLRU(500, nil).
  • mu is initialized with &sync.Mutex{}.

This ensures that the test setup is correct and the review comment is valid.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `lru` and `mu` are properly initialized before use.

# Test: Search for their initialization in the codebase.
rg --type go 'lru, _ := simplelru.NewLRU' && rg --type go 'mu := &sync.Mutex{}'

Length of output: 43



Script:

#!/bin/bash
# Description: Verify that `lru` and `mu` are properly initialized before use.

# Test: Search for their initialization in the codebase.
rg --type go 'simplelru.NewLRU' && rg --type go 'sync.Mutex'

Length of output: 1977

codec/address/bench_test.go Show resolved Hide resolved
codec/address/fuzz_test.go Show resolved Hide resolved
codec/address/bech32_codec.go Outdated Show resolved Hide resolved
codec/address/bech32_codec.go Show resolved Hide resolved
codec/address/bech32_codec.go Show resolved Hide resolved
codec/address/bech32_codec_test.go Outdated Show resolved Hide resolved
codec/address/bech32_codec_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 62a7228 and ebb9b89.

Files selected for processing (4)
  • codec/address/bech32_codec.go (2 hunks)
  • codec/address/bech32_codec_test.go (1 hunks)
  • codec/address/bench_test.go (1 hunks)
  • codec/address/fuzz_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • codec/address/bech32_codec.go
  • codec/address/bech32_codec_test.go
  • codec/address/bench_test.go
  • codec/address/fuzz_test.go

@JulianToledano
Copy link
Contributor Author

@coderabbitai pause

Copy link
Contributor

coderabbitai bot commented Jun 3, 2024

Actions performed

Reviews paused.

Copy link
Member

@kocubinski kocubinski left a comment

Choose a reason for hiding this comment

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

LGTM, just one nit

func NewCachedBech32Codec(prefix string, opts CachedCodecOptions) (address.Codec, error) {
ac := Bech32Codec{prefix}
if opts.Mu == nil {
return nil, errors.New("mutex cannot be nil")
Copy link
Member

Choose a reason for hiding this comment

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

would it be so bad to provide some sane default instead of erroring on nil?

@JulianToledano JulianToledano added this pull request to the merge queue Jun 13, 2024
Merged via the queue into main with commit 4611311 Jun 13, 2024
65 of 66 checks passed
@JulianToledano JulianToledano deleted the julian/address-codec-cache branch June 13, 2024 09:32
alpe added a commit that referenced this pull request Jun 13, 2024
* main:
  fix(x/staking): stop validators from rotating to the same key on the same block (#20649)
  perf: add cache to address codec (#20122)
  build(deps): Bump google.golang.org/protobuf from 1.34.1 to 1.34.2 (#20632)
  fix: remove recipient amount from map (#20625)
  fix(proto): remove conditional preventing proper generated file placement (#20650)
  (serverv2/cometbft) Read config from commands & handle `FlagNode` (#20621)
  fix(x/consensus): fix .proto file placement (#20646)
  fix(store): avoid nil error on not exhausted payload stream (#20644)
  fix (x/accounts): Fix genesis condition check (#20645)
  feat(accounts): add genesis account initialization (#20642)
  fix(x/gov): limit execution in gov (#20348)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants