Skip to content

Commit

Permalink
fix(wasm): migrate wasm cache dir to the new path (#2115)
Browse files Browse the repository at this point in the history
* add --wasm-dir flag to start command

* use /Users/joaosousa env var

* docs

* programatically determine the default value for the wasm dir

* addendum

* addendum

* fix

* edit flag description

Co-authored-by: Milap Sheth <[email protected]>

* fix

* simplification

* fix(wasm): migrate wasm cache dir to the new path

* convert to abs path

* assume path is already expanded and move check earlier

* dep update

* go mod tidy

* use wasm path

---------

Co-authored-by: João Sousa <[email protected]>
Co-authored-by: jcs47 <[email protected]>
  • Loading branch information
3 people committed Mar 1, 2024
1 parent 03ed449 commit 486001d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
32 changes: 31 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import (
"github.com/axelarnetwork/axelar-core/x/vote"
voteKeeper "github.com/axelarnetwork/axelar-core/x/vote/keeper"
voteTypes "github.com/axelarnetwork/axelar-core/x/vote/types"
"github.com/axelarnetwork/utils/funcs"

// Override with generated statik docs
_ "github.com/axelarnetwork/axelar-core/client/docs/statik"
Expand Down Expand Up @@ -261,7 +262,17 @@ func NewAxelarApp(
wasmDir = filepath.Join(homePath, dbDir, "wasm")
}

SetKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, wasmDir))
wasmPath, err := filepath.Abs(wasmDir)
if err != nil {
panic(fmt.Sprintf("failed to resolve absolute path for new wasm dir %s: %v", wasmDir, err))
}

// Migrate wasm dir from old path to new path
// TODO: Remove this once nodes have migrated
oldWasmDir := filepath.Join(homePath, "wasm")
funcs.MustNoErr(migrateWasmDir(oldWasmDir, wasmPath))

SetKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, wasmPath))
SetKeeper(keepers, initWasmContractKeeper(keepers))

// set the contract keeper for the Ics20WasmHooks
Expand Down Expand Up @@ -457,6 +468,25 @@ func initMessageRouter(keepers *KeeperCache) nexusTypes.MessageRouter {
return messageRouter
}

func migrateWasmDir(oldWasmDir, newWasmDir string) error {
// If the new wasm dir exists, there's nothing to do
if _, err := os.Stat(newWasmDir); err == nil {
return nil
}

// If the old wasm dir doesn't exist, there's nothing to do
if _, err := os.Stat(oldWasmDir); err != nil && os.IsNotExist(err) {
return nil
}

// Move the wasm dir from old path to new path
if err := os.Rename(oldWasmDir, newWasmDir); err != nil {
return fmt.Errorf("failed to move wasm directory from %s to %s: %v", oldWasmDir, newWasmDir, err)
}

return nil
}

func (app *AxelarApp) registerWasmSnapshotExtension(keepers *KeeperCache) {
// Register wasm snapshot extension to enable state-sync compatibility for wasm.
// MUST be done before loading the version
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/matryer/moq v0.3.3
github.com/matryer/moq v0.3.4
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/mitchellh/mapstructure v1.5.0
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.5
Expand All @@ -35,12 +35,12 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tendermint/tendermint v0.34.27
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
golang.org/x/crypto v0.18.0
golang.org/x/crypto v0.19.0
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/mod v0.14.0
golang.org/x/mod v0.15.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.17.0
golang.org/x/tools v0.18.0
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529
google.golang.org/grpc v1.58.3
Expand Down Expand Up @@ -171,9 +171,9 @@ require (
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
28 changes: 14 additions & 14 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 486001d

Please sign in to comment.