Skip to content

Commit 0f004b0

Browse files
viveksharmapoudelizyak
authored and
izyak
committed
fix: generalize archway module as wasm (#112)
* fix: generalize archway module as wasm module * chore: gitignore rename * chore: add block interval to provider cfg * chore: add block interval * chore: block interval --------- Co-authored-by: izyak <test@test.com>
1 parent 9e0dd22 commit 0f004b0

30 files changed

+312
-329
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dist/
2020
.release-env
2121

2222
**/log*.txt
23-
**/debug_archway_msg_data.json
23+
**/debug_wasm_msg_data.json
2424

2525
# Don't commit the vendor directory if anyone runs 'go mod vendor'.
2626
/vendor

cmd/config.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import (
3131
"time"
3232

3333
"github.com/icon-project/ibc-relayer/relayer"
34-
archway "github.com/cosmos/relayer/v2/relayer/chains/archway"
3534
"github.com/icon-project/ibc-relayer/relayer/chains/cosmos"
3635
"github.com/icon-project/ibc-relayer/relayer/chains/icon"
3736
"github.com/icon-project/ibc-relayer/relayer/chains/penumbra"
37+
"github.com/icon-project/ibc-relayer/relayer/chains/wasm"
3838
"github.com/icon-project/ibc-relayer/relayer/provider"
3939
"github.com/spf13/cobra"
4040
"go.uber.org/zap"
@@ -379,8 +379,8 @@ func (pcw *ProviderConfigWrapper) UnmarshalJSON(data []byte) error {
379379
customTypes := map[string]reflect.Type{
380380
"icon": reflect.TypeOf(icon.IconProviderConfig{}),
381381
"cosmos": reflect.TypeOf(cosmos.CosmosProviderConfig{}),
382+
"wasm": reflect.TypeOf(wasm.WasmProviderConfig{}),
382383
"penumbra": reflect.TypeOf(penumbra.PenumbraProviderConfig{}),
383-
"archway": reflect.TypeOf(archway.ArchwayProviderConfig{}),
384384
}
385385
val, err := UnmarshalJSONProviderConfig(data, customTypes)
386386
if err != nil {
@@ -439,10 +439,8 @@ func (iw *ProviderConfigYAMLWrapper) UnmarshalYAML(n *yaml.Node) error {
439439
iw.Value = new(cosmos.CosmosProviderConfig)
440440
case "icon":
441441
iw.Value = new(icon.IconProviderConfig)
442-
case "penumbra":
443-
iw.Value = new(penumbra.PenumbraProviderConfig)
444-
case "archway":
445-
iw.Value = new(archway.ArchwayProviderConfig)
442+
case "wasm":
443+
iw.Value = new(wasm.WasmProviderConfig)
446444
case "penumbra":
447445
iw.Value = new(penumbra.PenumbraProviderConfig)
448446
default:

examples/demo/configs/chains/ibc-archway.json examples/demo/configs/chains/ibc-wasm.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"type": "archway",
2+
"type": "wasm",
33
"value": {
44
"key": "default",
5-
"chain-id": "constantine-2",
5+
"chain-id": "test-1",
66
"rpc-addr": "https://rpc.constantine-2.archway.tech:443",
7-
"key-directory":"/Users/viveksharmapoudel/.relayer/keys/archway",
7+
"key-directory":"/Users/viveksharmapoudel/.relayer/keys/test-1",
88
"grpc-addr": "",
9-
"account-prefix": "archway",
9+
"account-prefix": "neutron",
1010
"keyring-backend": "test",
1111
"gas-adjustment": 1.5,
1212
"gas-prices": "0.02uconst",

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ require (
208208
replace (
209209
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
210210
github.com/CosmWasm/wasmd => github.com/cosmwasm/wasmd v0.40.0-rc.1.0.20230424144037-55647a1fd1f9
211-
// github.com/CosmWasm/wasmd => github.com/archway-network/archway-wasmd v0.29.2-archway
212211
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
213212
github.com/icon-project/IBC-Integration => github.com/icon-project/ibc-integration v0.0.0-20230717083940-67949d73b622
214213
)

relayer/chains/icon/client_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func GetLisbonIconProvider(network_id int, contractAddress string) *IconProvider
3838
IbcHandlerAddress: contractAddress,
3939
RPCAddr: "https://lisbon.net.solidwallet.io/api/v3",
4040
Timeout: "20s",
41+
BlockInterval: 2000,
4142
}
4243
log, _ := zap.NewProduction()
4344
p, _ := pcfg.NewProvider(log, "", false, "icon")

relayer/chains/icon/keys_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestRestoreIconKeyStore(t *testing.T) {
4545
ChainName: "icon",
4646
StartHeight: 10,
4747
IbcHandlerAddress: "cxb6b5791be0b5ef67063b3c10b840fb81514db2fd",
48+
BlockInterval: 2000,
4849
}
4950
p, err := pcfg.NewProvider(zap.NewNop(), "not_correct", false, "icon")
5051
require.NoError(t, err)

relayer/chains/icon/provider_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ func GetMockIconProvider(network_id int, contractAddress string) *IconProvider {
5656
IbcHandlerAddress: contractAddress,
5757
RPCAddr: "http://localhost:9082/api/v3",
5858
// RPCAddr: "https://berlin.net.solidwallet.io/api/v3",
59-
Timeout: "20s",
59+
Timeout: "20s",
60+
BlockInterval: 2000,
6061
}
6162
log, _ := zap.NewProduction()
6263
p, _ := pcfg.NewProvider(log, "", false, "icon")

relayer/chains/archway/accounts.go relayer/chains/wasm/accounts.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archway
1+
package wasm
22

33
import (
44
"context"
@@ -13,19 +13,19 @@ import (
1313
"google.golang.org/grpc/metadata"
1414
)
1515

16-
var _ client.AccountRetriever = &ArchwayProvider{}
16+
var _ client.AccountRetriever = &WasmProvider{}
1717

1818
// GetAccount queries for an account given an address and a block height. An
1919
// error is returned if the query or decoding fails.
20-
func (cc *ArchwayProvider) GetAccount(clientCtx client.Context, addr sdk.AccAddress) (client.Account, error) {
20+
func (cc *WasmProvider) GetAccount(clientCtx client.Context, addr sdk.AccAddress) (client.Account, error) {
2121
account, _, err := cc.GetAccountWithHeight(clientCtx, addr)
2222
return account, err
2323
}
2424

2525
// GetAccountWithHeight queries for an account given an address. Returns the
2626
// height of the query with the account. An error is returned if the query
2727
// or decoding fails.
28-
func (cc *ArchwayProvider) GetAccountWithHeight(clientCtx client.Context, addr sdk.AccAddress) (client.Account, int64, error) {
28+
func (cc *WasmProvider) GetAccountWithHeight(clientCtx client.Context, addr sdk.AccAddress) (client.Account, int64, error) {
2929
var header metadata.MD
3030
address, err := cc.EncodeBech32AccAddr(addr)
3131
if err != nil {
@@ -57,7 +57,7 @@ func (cc *ArchwayProvider) GetAccountWithHeight(clientCtx client.Context, addr s
5757
}
5858

5959
// EnsureExists returns an error if no account exists for the given address else nil.
60-
func (cc *ArchwayProvider) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error {
60+
func (cc *WasmProvider) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error {
6161
if _, err := cc.GetAccount(clientCtx, addr); err != nil {
6262
return err
6363
}
@@ -66,7 +66,7 @@ func (cc *ArchwayProvider) EnsureExists(clientCtx client.Context, addr sdk.AccAd
6666

6767
// GetAccountNumberSequence returns sequence and account number for the given address.
6868
// It returns an error if the account couldn't be retrieved from the state.
69-
func (cc *ArchwayProvider) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) {
69+
func (cc *WasmProvider) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) {
7070
acc, err := cc.GetAccount(clientCtx, addr)
7171
if err != nil {
7272
return 0, 0, err

relayer/chains/archway/archway_chain_processor.go relayer/chains/wasm/archway_chain_processor.go

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archway
1+
package wasm
22

33
import (
44
"bytes"
@@ -23,10 +23,10 @@ import (
2323
"golang.org/x/sync/errgroup"
2424
)
2525

26-
type ArchwayChainProcessor struct {
26+
type WasmChainProcessor struct {
2727
log *zap.Logger
2828

29-
chainProvider *ArchwayProvider
29+
chainProvider *WasmProvider
3030

3131
pathProcessors processor.PathProcessors
3232

@@ -64,8 +64,8 @@ type Verifier struct {
6464
Header *types.LightBlock
6565
}
6666

67-
func NewArchwayChainProcessor(log *zap.Logger, provider *ArchwayProvider, metrics *processor.PrometheusMetrics) *ArchwayChainProcessor {
68-
return &ArchwayChainProcessor{
67+
func NewWasmChainProcessor(log *zap.Logger, provider *WasmProvider, metrics *processor.PrometheusMetrics) *WasmChainProcessor {
68+
return &WasmChainProcessor{
6969
log: log.With(zap.String("chain_name", provider.ChainName()), zap.String("chain_id", provider.ChainId())),
7070
chainProvider: provider,
7171
latestClientState: make(latestClientState),
@@ -92,7 +92,7 @@ const (
9292
// latestClientState is a map of clientID to the latest clientInfo for that client.
9393
type latestClientState map[string]provider.ClientState
9494

95-
func (l latestClientState) update(ctx context.Context, clientInfo clientInfo, ccp *ArchwayChainProcessor) {
95+
func (l latestClientState) update(ctx context.Context, clientInfo clientInfo, ccp *WasmChainProcessor) {
9696
existingClientInfo, ok := l[clientInfo.clientID]
9797
var trustingPeriod time.Duration
9898
if ok {
@@ -122,19 +122,19 @@ func (l latestClientState) update(ctx context.Context, clientInfo clientInfo, cc
122122
}
123123

124124
// Provider returns the ChainProvider, which provides the methods for querying, assembling IBC messages, and sending transactions.
125-
func (ccp *ArchwayChainProcessor) Provider() provider.ChainProvider {
125+
func (ccp *WasmChainProcessor) Provider() provider.ChainProvider {
126126
return ccp.chainProvider
127127
}
128128

129129
// Set the PathProcessors that this ChainProcessor should publish relevant IBC events to.
130130
// ChainProcessors need reference to their PathProcessors and vice-versa, handled by EventProcessorBuilder.Build().
131-
func (ccp *ArchwayChainProcessor) SetPathProcessors(pathProcessors processor.PathProcessors) {
131+
func (ccp *WasmChainProcessor) SetPathProcessors(pathProcessors processor.PathProcessors) {
132132
ccp.pathProcessors = pathProcessors
133133
}
134134

135135
// latestHeightWithRetry will query for the latest height, retrying in case of failure.
136136
// It will delay by latestHeightQueryRetryDelay between attempts, up to latestHeightQueryRetries.
137-
func (ccp *ArchwayChainProcessor) latestHeightWithRetry(ctx context.Context) (latestHeight int64, err error) {
137+
func (ccp *WasmChainProcessor) latestHeightWithRetry(ctx context.Context) (latestHeight int64, err error) {
138138
return latestHeight, retry.Do(func() error {
139139
latestHeightQueryCtx, cancelLatestHeightQueryCtx := context.WithTimeout(ctx, queryTimeout)
140140
defer cancelLatestHeightQueryCtx()
@@ -153,7 +153,7 @@ func (ccp *ArchwayChainProcessor) latestHeightWithRetry(ctx context.Context) (la
153153

154154
// nodeStatusWithRetry will query for the latest node status, retrying in case of failure.
155155
// It will delay by latestHeightQueryRetryDelay between attempts, up to latestHeightQueryRetries.
156-
func (ccp *ArchwayChainProcessor) nodeStatusWithRetry(ctx context.Context) (status *ctypes.ResultStatus, err error) {
156+
func (ccp *WasmChainProcessor) nodeStatusWithRetry(ctx context.Context) (status *ctypes.ResultStatus, err error) {
157157
return status, retry.Do(func() error {
158158
latestHeightQueryCtx, cancelLatestHeightQueryCtx := context.WithTimeout(ctx, queryTimeout)
159159
defer cancelLatestHeightQueryCtx()
@@ -172,7 +172,7 @@ func (ccp *ArchwayChainProcessor) nodeStatusWithRetry(ctx context.Context) (stat
172172

173173
// clientState will return the most recent client state if client messages
174174
// have already been observed for the clientID, otherwise it will query for it.
175-
func (ccp *ArchwayChainProcessor) clientState(ctx context.Context, clientID string) (provider.ClientState, error) {
175+
func (ccp *WasmChainProcessor) clientState(ctx context.Context, clientID string) (provider.ClientState, error) {
176176
if state, ok := ccp.latestClientState[clientID]; ok && state.TrustingPeriod > 0 {
177177
return state, nil
178178
}
@@ -198,8 +198,8 @@ type queryCyclePersistence struct {
198198
balanceUpdateWaitDuration time.Duration
199199
}
200200

201-
func (ccp *ArchwayChainProcessor) StartFromHeight(ctx context.Context) int {
202-
cfg := ccp.Provider().ProviderConfig().(*ArchwayProviderConfig)
201+
func (ccp *WasmChainProcessor) StartFromHeight(ctx context.Context) int {
202+
cfg := ccp.Provider().ProviderConfig().(*WasmProviderConfig)
203203
if cfg.StartHeight != 0 {
204204
return int(cfg.StartHeight)
205205
}
@@ -215,7 +215,7 @@ func (ccp *ArchwayChainProcessor) StartFromHeight(ctx context.Context) int {
215215
// Run starts the query loop for the chain which will gather applicable ibc messages and push events out to the relevant PathProcessors.
216216
// The initialBlockHistory parameter determines how many historical blocks should be fetched and processed before continuing with current blocks.
217217
// ChainProcessors should obey the context and return upon context cancellation.
218-
func (ccp *ArchwayChainProcessor) Run(ctx context.Context, initialBlockHistory uint64) error {
218+
func (ccp *WasmChainProcessor) Run(ctx context.Context, initialBlockHistory uint64) error {
219219
// this will be used for persistence across query cycle loop executions
220220
persistence := queryCyclePersistence{
221221
minQueryLoopDuration: defaultMinQueryLoopDuration,
@@ -278,7 +278,7 @@ func (ccp *ArchwayChainProcessor) Run(ctx context.Context, initialBlockHistory u
278278
return err
279279
}
280280

281-
ccp.log.Debug("Entering Archway main query loop")
281+
ccp.log.Debug("Entering Wasm main query loop")
282282

283283
ticker := time.NewTicker(persistence.minQueryLoopDuration)
284284
defer ticker.Stop()
@@ -297,7 +297,7 @@ func (ccp *ArchwayChainProcessor) Run(ctx context.Context, initialBlockHistory u
297297
}
298298

299299
// initializeConnectionState will bootstrap the connectionStateCache with the open connection state.
300-
func (ccp *ArchwayChainProcessor) initializeConnectionState(ctx context.Context) error {
300+
func (ccp *WasmChainProcessor) initializeConnectionState(ctx context.Context) error {
301301
ctx, cancel := context.WithTimeout(ctx, queryTimeout)
302302
defer cancel()
303303
connections, err := ccp.chainProvider.QueryConnections(ctx)
@@ -317,7 +317,7 @@ func (ccp *ArchwayChainProcessor) initializeConnectionState(ctx context.Context)
317317
}
318318

319319
// initializeChannelState will bootstrap the channelStateCache with the open channel state.
320-
func (ccp *ArchwayChainProcessor) initializeChannelState(ctx context.Context) error {
320+
func (ccp *WasmChainProcessor) initializeChannelState(ctx context.Context) error {
321321
ctx, cancel := context.WithTimeout(ctx, queryTimeout)
322322
defer cancel()
323323
channels, err := ccp.chainProvider.QueryChannels(ctx)
@@ -344,11 +344,10 @@ func (ccp *ArchwayChainProcessor) initializeChannelState(ctx context.Context) er
344344
return nil
345345
}
346346

347-
func (ccp *ArchwayChainProcessor) queryCycle(ctx context.Context, persistence *queryCyclePersistence) error {
348-
// TODO : review if redundent remove
347+
func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *queryCyclePersistence) error {
349348
status, err := ccp.nodeStatusWithRetry(ctx)
350349
if err != nil {
351-
// don't want to cause ArchwayChainProcessor to quit here, can retry again next cycle.
350+
// don't want to cause WasmChainProcessor to quit here, can retry again next cycle.
352351
ccp.log.Error(
353352
"Failed to query node status after max attempts",
354353
zap.Uint("attempts", latestHeightQueryRetries),
@@ -420,7 +419,7 @@ func (ccp *ArchwayChainProcessor) queryCycle(ctx context.Context, persistence *q
420419
}
421420

422421
if err := ccp.Verify(ctx, lightBlock); err != nil {
423-
ccp.log.Error("failed to Verify Archway Header", zap.Int64("Height", blockRes.Height))
422+
ccp.log.Error("failed to Verify Wasm Header", zap.Int64("Height", blockRes.Height))
424423
return err
425424
}
426425

@@ -496,7 +495,7 @@ func (ccp *ArchwayChainProcessor) queryCycle(ctx context.Context, persistence *q
496495
return nil
497496
}
498497

499-
func (ccp *ArchwayChainProcessor) SnapshotHeight(height int) {
498+
func (ccp *WasmChainProcessor) SnapshotHeight(height int) {
500499

501500
blockInterval := ccp.Provider().ProviderConfig().GetBlockInterval()
502501
snapshotThreshold := common.ONE_HOUR / int(blockInterval)
@@ -512,7 +511,7 @@ func (ccp *ArchwayChainProcessor) SnapshotHeight(height int) {
512511
}
513512
}
514513

515-
func (ccp *ArchwayChainProcessor) CollectMetrics(ctx context.Context, persistence *queryCyclePersistence) {
514+
func (ccp *WasmChainProcessor) CollectMetrics(ctx context.Context, persistence *queryCyclePersistence) {
516515
ccp.CurrentBlockHeight(ctx, persistence)
517516

518517
// Wait a while before updating the balance
@@ -522,11 +521,11 @@ func (ccp *ArchwayChainProcessor) CollectMetrics(ctx context.Context, persistenc
522521
}
523522
}
524523

525-
func (ccp *ArchwayChainProcessor) CurrentBlockHeight(ctx context.Context, persistence *queryCyclePersistence) {
524+
func (ccp *WasmChainProcessor) CurrentBlockHeight(ctx context.Context, persistence *queryCyclePersistence) {
526525
ccp.metrics.SetLatestHeight(ccp.chainProvider.ChainId(), persistence.latestHeight)
527526
}
528527

529-
func (ccp *ArchwayChainProcessor) Verify(ctx context.Context, untrusted *types.LightBlock) error {
528+
func (ccp *WasmChainProcessor) Verify(ctx context.Context, untrusted *types.LightBlock) error {
530529

531530
if untrusted.Height != ccp.verifier.Header.Height+1 {
532531
return errors.New("headers must be adjacent in height")
@@ -607,7 +606,7 @@ func verifyNewHeaderAndVals(
607606
return nil
608607
}
609608

610-
// func (ccp *ArchwayChainProcessor) CurrentRelayerBalance(ctx context.Context) {
609+
// func (ccp *WasmChainProcessor) CurrentRelayerBalance(ctx context.Context) {
611610
// // memoize the current gas prices to only show metrics for "interesting" denoms
612611
// if ccp.parsedGasPrices == nil {
613612
// gp, err := sdk.ParseDecCoins(ccp.chainProvider.PCfg.GasPrices)

relayer/chains/archway/archway_prefix.go relayer/chains/wasm/archway_prefix.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archway
1+
package wasm
22

33
import (
44
"sync"
@@ -13,10 +13,10 @@ import (
1313
var sdkConfigMutex sync.Mutex
1414

1515
// Based on cosmos bech32_hack.go
16-
// SetSDKContext sets the SDK config to the proper bech32 prefixes for archway.
16+
// SetSDKContext sets the SDK config to the proper bech32 prefixes for wasm.
1717
// Don't use this unless you know what you're doing.
1818
// TODO: :dagger: :knife: :chainsaw: remove this function
19-
func (ap *ArchwayProvider) SetSDKContext() {
19+
func (ap *WasmProvider) SetSDKContext() {
2020
sdkConfigMutex.Lock()
2121
cfg := sdk.GetConfig()
2222
cfg.SetBech32PrefixForAccount(ap.PCfg.AccountPrefix, app.Bech32PrefixAccPub)

relayer/chains/archway/codec.go relayer/chains/wasm/codec.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archway
1+
package wasm
22

33
import (
44
"github.com/CosmWasm/wasmd/x/wasm"
@@ -10,14 +10,14 @@ import (
1010
"github.com/cosmos/cosmos-sdk/x/auth"
1111
"github.com/cosmos/cosmos-sdk/x/auth/tx"
1212
ibc "github.com/cosmos/ibc-go/v7/modules/core"
13-
archway_module "github.com/cosmos/relayer/v2/relayer/chains/archway/module"
1413
icon_module "github.com/cosmos/relayer/v2/relayer/chains/icon/module"
14+
wasm_module "github.com/cosmos/relayer/v2/relayer/chains/wasm/module"
1515
)
1616

1717
var ModuleBasics = []module.AppModuleBasic{
1818
auth.AppModuleBasic{},
1919
ibc.AppModuleBasic{},
20-
archway_module.AppModuleBasic{},
20+
wasm_module.AppModuleBasic{},
2121
wasm.AppModuleBasic{},
2222
icon_module.AppModuleBasic{},
2323
}

relayer/chains/archway/consts.go relayer/chains/wasm/consts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archway
1+
package wasm
22

33
const (
44
// External methods

relayer/chains/archway/event_parser.go relayer/chains/wasm/event_parser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package archway
1+
package wasm
22

33
import (
44
"encoding/base64"
@@ -36,7 +36,7 @@ type ibcMessageInfo interface {
3636
MarshalLogObject(enc zapcore.ObjectEncoder) error
3737
}
3838

39-
// func (ccp *ArchwayChainProcessor) ibcMessagesFromBlockEvents(
39+
// func (ccp *WasmChainProcessor) ibcMessagesFromBlockEvents(
4040
// beginBlockEvents, endBlockEvents []abci.Event,
4141
// height uint64, base64Encoded bool,
4242
// ) (res []ibcMessage) {

0 commit comments

Comments
 (0)