Skip to content

fix: generalize archway module as wasm #112

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

Merged
merged 8 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dist/
.release-env

**/log*.txt
**/debug_archway_msg_data.json
**/debug_wasm_msg_data.json

# Don't commit the vendor directory if anyone runs 'go mod vendor'.
/vendor
8 changes: 4 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (
"time"

"github.com/cosmos/relayer/v2/relayer"
archway "github.com/cosmos/relayer/v2/relayer/chains/archway"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
"github.com/cosmos/relayer/v2/relayer/chains/icon"
"github.com/cosmos/relayer/v2/relayer/chains/penumbra"
wasm "github.com/cosmos/relayer/v2/relayer/chains/wasm"
"github.com/cosmos/relayer/v2/relayer/provider"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -378,7 +378,7 @@ func (pcw *ProviderConfigWrapper) UnmarshalJSON(data []byte) error {
customTypes := map[string]reflect.Type{
"cosmos": reflect.TypeOf(cosmos.CosmosProviderConfig{}),
"icon": reflect.TypeOf(icon.IconProviderConfig{}),
"archway": reflect.TypeOf(archway.ArchwayProviderConfig{}),
"wasm": reflect.TypeOf(wasm.WasmProviderConfig{}),
"penumbra": reflect.TypeOf(penumbra.PenumbraProviderConfig{}),
}
val, err := UnmarshalJSONProviderConfig(data, customTypes)
Expand Down Expand Up @@ -434,8 +434,8 @@ func (iw *ProviderConfigYAMLWrapper) UnmarshalYAML(n *yaml.Node) error {
iw.Value = new(cosmos.CosmosProviderConfig)
case "icon":
iw.Value = new(icon.IconProviderConfig)
case "archway":
iw.Value = new(archway.ArchwayProviderConfig)
case "wasm":
iw.Value = new(wasm.WasmProviderConfig)
case "penumbra":
iw.Value = new(penumbra.PenumbraProviderConfig)
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "archway",
"type": "wasm",
"value": {
"key": "default",
"chain-id": "constantine-2",
"chain-id": "test-1",
"rpc-addr": "https://rpc.constantine-2.archway.tech:443",
"key-directory":"/Users/viveksharmapoudel/.relayer/keys/archway",
"key-directory":"/Users/viveksharmapoudel/.relayer/keys/test-1",
"grpc-addr": "",
"account-prefix": "archway",
"account-prefix": "neutron",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.02uconst",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ require (
replace (
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d
github.com/CosmWasm/wasmd => github.com/cosmwasm/wasmd v0.40.0-rc.1.0.20230424144037-55647a1fd1f9
// github.com/CosmWasm/wasmd => github.com/archway-network/archway-wasmd v0.29.2-archway
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/icon-project/IBC-Integration => github.com/icon-project/ibc-integration v0.0.0-20230717083940-67949d73b622
)
1 change: 1 addition & 0 deletions relayer/chains/icon/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func GetLisbonIconProvider(network_id int, contractAddress string) *IconProvider
IbcHandlerAddress: contractAddress,
RPCAddr: "https://lisbon.net.solidwallet.io/api/v3",
Timeout: "20s",
BlockInterval: 2000,
}
log, _ := zap.NewProduction()
p, _ := pcfg.NewProvider(log, "", false, "icon")
Expand Down
1 change: 1 addition & 0 deletions relayer/chains/icon/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestRestoreIconKeyStore(t *testing.T) {
ChainName: "icon",
StartHeight: 10,
IbcHandlerAddress: "cxb6b5791be0b5ef67063b3c10b840fb81514db2fd",
BlockInterval: 2000,
}
p, err := pcfg.NewProvider(zap.NewNop(), "not_correct", false, "icon")
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion relayer/chains/icon/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func GetMockIconProvider(network_id int, contractAddress string) *IconProvider {
IbcHandlerAddress: contractAddress,
RPCAddr: "http://localhost:9082/api/v3",
// RPCAddr: "https://berlin.net.solidwallet.io/api/v3",
Timeout: "20s",
Timeout: "20s",
BlockInterval: 2000,
}
log, _ := zap.NewProduction()
p, _ := pcfg.NewProvider(log, "", false, "icon")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

import (
"context"
Expand All @@ -13,19 +13,19 @@ import (
"google.golang.org/grpc/metadata"
)

var _ client.AccountRetriever = &ArchwayProvider{}
var _ client.AccountRetriever = &WasmProvider{}

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

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

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

// GetAccountNumberSequence returns sequence and account number for the given address.
// It returns an error if the account couldn't be retrieved from the state.
func (cc *ArchwayProvider) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) {
func (cc *WasmProvider) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) {
acc, err := cc.GetAccount(clientCtx, addr)
if err != nil {
return 0, 0, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

import (
"bytes"
Expand All @@ -23,10 +23,10 @@ import (
"golang.org/x/sync/errgroup"
)

type ArchwayChainProcessor struct {
type WasmChainProcessor struct {
log *zap.Logger

chainProvider *ArchwayProvider
chainProvider *WasmProvider

pathProcessors processor.PathProcessors

Expand Down Expand Up @@ -64,8 +64,8 @@ type Verifier struct {
Header *types.LightBlock
}

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

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

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

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

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

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

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

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

ccp.log.Debug("Entering Archway main query loop")
ccp.log.Debug("Entering Wasm main query loop")

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

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

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

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

if err := ccp.Verify(ctx, lightBlock); err != nil {
ccp.log.Error("failed to Verify Archway Header", zap.Int64("Height", blockRes.Height))
ccp.log.Error("failed to Verify Wasm Header", zap.Int64("Height", blockRes.Height))
return err
}

Expand Down Expand Up @@ -496,7 +495,7 @@ func (ccp *ArchwayChainProcessor) queryCycle(ctx context.Context, persistence *q
return nil
}

func (ccp *ArchwayChainProcessor) SnapshotHeight(height int) {
func (ccp *WasmChainProcessor) SnapshotHeight(height int) {

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

func (ccp *ArchwayChainProcessor) CollectMetrics(ctx context.Context, persistence *queryCyclePersistence) {
func (ccp *WasmChainProcessor) CollectMetrics(ctx context.Context, persistence *queryCyclePersistence) {
ccp.CurrentBlockHeight(ctx, persistence)

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

func (ccp *ArchwayChainProcessor) CurrentBlockHeight(ctx context.Context, persistence *queryCyclePersistence) {
func (ccp *WasmChainProcessor) CurrentBlockHeight(ctx context.Context, persistence *queryCyclePersistence) {
ccp.metrics.SetLatestHeight(ccp.chainProvider.ChainId(), persistence.latestHeight)
}

func (ccp *ArchwayChainProcessor) Verify(ctx context.Context, untrusted *types.LightBlock) error {
func (ccp *WasmChainProcessor) Verify(ctx context.Context, untrusted *types.LightBlock) error {

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

// func (ccp *ArchwayChainProcessor) CurrentRelayerBalance(ctx context.Context) {
// func (ccp *WasmChainProcessor) CurrentRelayerBalance(ctx context.Context) {
// // memoize the current gas prices to only show metrics for "interesting" denoms
// if ccp.parsedGasPrices == nil {
// gp, err := sdk.ParseDecCoins(ccp.chainProvider.PCfg.GasPrices)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

import (
"sync"
Expand All @@ -13,10 +13,10 @@ import (
var sdkConfigMutex sync.Mutex

// Based on cosmos bech32_hack.go
// SetSDKContext sets the SDK config to the proper bech32 prefixes for archway.
// SetSDKContext sets the SDK config to the proper bech32 prefixes for wasm.
// Don't use this unless you know what you're doing.
// TODO: :dagger: :knife: :chainsaw: remove this function
func (ap *ArchwayProvider) SetSDKContext() {
func (ap *WasmProvider) SetSDKContext() {
sdkConfigMutex.Lock()
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(ap.PCfg.AccountPrefix, app.Bech32PrefixAccPub)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

import (
"github.com/CosmWasm/wasmd/x/wasm"
Expand All @@ -10,14 +10,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
archway_module "github.com/cosmos/relayer/v2/relayer/chains/archway/module"
icon_module "github.com/cosmos/relayer/v2/relayer/chains/icon/module"
wasm_module "github.com/cosmos/relayer/v2/relayer/chains/wasm/module"
)

var ModuleBasics = []module.AppModuleBasic{
auth.AppModuleBasic{},
ibc.AppModuleBasic{},
archway_module.AppModuleBasic{},
wasm_module.AppModuleBasic{},
wasm.AppModuleBasic{},
icon_module.AppModuleBasic{},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

const (
// External methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

import (
"encoding/base64"
Expand Down Expand Up @@ -36,7 +36,7 @@ type ibcMessageInfo interface {
MarshalLogObject(enc zapcore.ObjectEncoder) error
}

// func (ccp *ArchwayChainProcessor) ibcMessagesFromBlockEvents(
// func (ccp *WasmChainProcessor) ibcMessagesFromBlockEvents(
// beginBlockEvents, endBlockEvents []abci.Event,
// height uint64, base64Encoded bool,
// ) (res []ibcMessage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package archway
package wasm

import (
"testing"
Expand Down
Loading