Skip to content

Commit

Permalink
feat(store/v2): Commit SS and SC Async (cosmos#19313)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jan 31, 2024
1 parent b026ab5 commit f86f753
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions store/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
golang.org/x/sync v0.5.0
)

require (
Expand Down
29 changes: 22 additions & 7 deletions store/root/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/cockroachdb/errors"
"golang.org/x/sync/errgroup"

coreheader "cosmossdk.io/core/header"
"cosmossdk.io/log"
Expand Down Expand Up @@ -298,14 +299,28 @@ func (s *Store) Commit(cs *store.Changeset) ([]byte, error) {
s.logger.Debug("commit header and version mismatch", "header_height", s.commitHeader.Height, "version", version)
}

// commit SS
if err := s.stateStore.ApplyChangeset(version, cs); err != nil {
return nil, fmt.Errorf("failed to commit SS: %w", err)
}
eg := new(errgroup.Group)

// commit SS async
eg.Go(func() error {
if err := s.stateStore.ApplyChangeset(version, cs); err != nil {
return fmt.Errorf("failed to commit SS: %w", err)
}

return nil
})

// commit SC async
eg.Go(func() error {
if err := s.commitSC(cs); err != nil {
return fmt.Errorf("failed to commit SC: %w", err)
}

return nil
})

// commit SC
if err := s.commitSC(cs); err != nil {
return nil, fmt.Errorf("failed to commit SC stores: %w", err)
if err := eg.Wait(); err != nil {
return nil, err
}

if s.commitHeader != nil {
Expand Down

0 comments on commit f86f753

Please sign in to comment.