-
Notifications
You must be signed in to change notification settings - Fork 627
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
Call Pin
during app inisitalization
#5161
Changes from 5 commits
3344e8d
71c6253
ad26127
f362bac
0ed221f
ef2d6d8
5382516
c9c4d11
7b73fce
43a7371
a97ab91
d639b49
f7aa8f7
c6cdffb
4545911
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -229,3 +229,40 @@ func (suite *KeeperTestSuite) TestNewKeeper() { | |||||||||||||||||||||||
}) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (suite *KeeperTestSuite) TestInitializePinnedCodes() { | ||||||||||||||||||||||||
suite.SetupWasmWithMockVM() | ||||||||||||||||||||||||
var capturedChecksums []wasmvm.Checksum | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
suite.mockVM.PinFn = func(checksum wasmvm.Checksum) error { | ||||||||||||||||||||||||
capturedChecksums = append(capturedChecksums, checksum) | ||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
gzippedContract, err := types.GzipIt(append(wasmtesting.WasmMagicNumber, []byte("gzipped-contract")...)) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #5162 might be available too if it gets merged before this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it |
||||||||||||||||||||||||
suite.Require().NoError(err) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
ctx := suite.chainA.GetContext().WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
contracts := [][]byte{wasmtesting.Code, gzippedContract} | ||||||||||||||||||||||||
checksumIDs := make([]types.Checksum, len(contracts)) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should require an updated gas meter here. Also, logical grouping of assignments nit:
Suggested change
|
||||||||||||||||||||||||
// store contract on chain | ||||||||||||||||||||||||
for i, contract := range contracts { | ||||||||||||||||||||||||
signer := authtypes.NewModuleAddress(govtypes.ModuleName).String() | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can also move signer to top of func with captured checksums since we don't need to call it in a loop |
||||||||||||||||||||||||
msg := types.NewMsgStoreCode(signer, contract) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
res, err := wasmClientKeeper.StoreCode(ctx, msg) | ||||||||||||||||||||||||
suite.Require().NoError(err) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
checksumIDs[i] = res.Checksum | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
capturedChecksums = nil | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
gotErr := keeper.InitializePinnedCodes(ctx) | ||||||||||||||||||||||||
suite.NoError(gotErr) | ||||||||||||||||||||||||
damiannolan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
suite.ElementsMatch(checksumIDs, capturedChecksums) | ||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,8 @@ import ( | |
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
tmos "github.com/cometbft/cometbft/libs/os" | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're renaming these in #5158 Can we change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. damn, there's also a |
||
|
||
"github.com/cosmos/ibc-go/modules/capability" | ||
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" | ||
|
@@ -815,6 +817,13 @@ func NewSimApp( | |
if err := app.LoadLatestVersion(); err != nil { | ||
panic(fmt.Errorf("error loading last version: %w", err)) | ||
} | ||
|
||
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) | ||
|
||
// Initialize pinned codes in wasmvm as they are not persisted there | ||
if err := wasmkeeper.InitializePinnedCodes(ctx); err != nil { | ||
tmos.Exit(fmt.Sprintf("failed initialize pinned codes %s", err)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed a commit updating the documentation to add this. Thanks, @vuong177! |
||
} | ||
|
||
app.ScopedIBCKeeper = scopedIBCKeeper | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for another time: this might be nice as a default behavior for mockVM (pin appends, unpin pops). That way we should also be able to more granularly check these