Skip to content
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

fix: generalize archway module as wasm #112

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 @@
"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 @@
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 @@
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)

Check warning on line 438 in cmd/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/config.go#L437-L438

Added lines #L437 - L438 were not covered by tests
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 @@
"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) {

Check warning on line 20 in relayer/chains/wasm/accounts.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/accounts.go#L20

Added line #L20 was not covered by tests
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) {

Check warning on line 28 in relayer/chains/wasm/accounts.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/accounts.go#L28

Added line #L28 was not covered by tests
var header metadata.MD
address, err := cc.EncodeBech32AccAddr(addr)
if err != nil {
Expand Down Expand Up @@ -57,7 +57,7 @@
}

// 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 {

Check warning on line 60 in relayer/chains/wasm/accounts.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/accounts.go#L60

Added line #L60 was not covered by tests
if _, err := cc.GetAccount(clientCtx, addr); err != nil {
return err
}
Expand All @@ -66,7 +66,7 @@

// 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) {

Check warning on line 69 in relayer/chains/wasm/accounts.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/accounts.go#L69

Added line #L69 was not covered by tests
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 @@
"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 @@
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{

Check warning on line 68 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L67-L68

Added lines #L67 - L68 were not covered by tests
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 @@
// 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) {

Check warning on line 95 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L95

Added line #L95 was not covered by tests
existingClientInfo, ok := l[clientInfo.clientID]
var trustingPeriod time.Duration
if ok {
Expand Down Expand Up @@ -122,19 +122,19 @@
}

// 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 {

Check warning on line 125 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L125

Added line #L125 was not covered by tests
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) {

Check warning on line 131 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L131

Added line #L131 was not covered by tests
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) {

Check warning on line 137 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L137

Added line #L137 was not covered by tests
return latestHeight, retry.Do(func() error {
latestHeightQueryCtx, cancelLatestHeightQueryCtx := context.WithTimeout(ctx, queryTimeout)
defer cancelLatestHeightQueryCtx()
Expand All @@ -153,7 +153,7 @@

// 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) {

Check warning on line 156 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L156

Added line #L156 was not covered by tests
return status, retry.Do(func() error {
latestHeightQueryCtx, cancelLatestHeightQueryCtx := context.WithTimeout(ctx, queryTimeout)
defer cancelLatestHeightQueryCtx()
Expand All @@ -172,7 +172,7 @@

// 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) {

Check warning on line 175 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L175

Added line #L175 was not covered by tests
if state, ok := ccp.latestClientState[clientID]; ok && state.TrustingPeriod > 0 {
return state, nil
}
Expand All @@ -198,24 +198,24 @@
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)
}
snapshotHeight, err := common.LoadSnapshotHeight(ccp.Provider().ChainId())
if err != nil {
ccp.log.Warn("Failed to load height from snapshot", zap.Error(err))
} else {
ccp.log.Info("Obtained start height from config", zap.Int("height", snapshotHeight))
}
return snapshotHeight

Check warning on line 212 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L201-L212

Added lines #L201 - L212 were not covered by tests
}

// 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 {

Check warning on line 218 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L218

Added line #L218 was not covered by tests
// this will be used for persistence across query cycle loop executions
persistence := queryCyclePersistence{
minQueryLoopDuration: defaultMinQueryLoopDuration,
Expand All @@ -242,30 +242,30 @@
}

// this will make initial QueryLoop iteration look back initialBlockHistory blocks in history
latestQueriedBlock := ccp.StartFromHeight(ctx)

Check warning on line 245 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L245

Added line #L245 was not covered by tests
if latestQueriedBlock < 0 {
latestQueriedBlock = int(persistence.latestHeight - int64(initialBlockHistory))
if latestQueriedBlock < 0 {
latestQueriedBlock = 0
}

Check warning on line 250 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L247-L250

Added lines #L247 - L250 were not covered by tests
}

persistence.latestQueriedBlock = int64(latestQueriedBlock)

ccp.log.Info("Start to query from height ", zap.Int("height", latestQueriedBlock))

_, lightBlock, err := ccp.chainProvider.QueryLightBlock(ctx, persistence.latestQueriedBlock)
if err != nil {
ccp.log.Error("Failed to get ibcHeader",
zap.Int64("height", persistence.latestQueriedBlock),
zap.Any("error", err),
)
return err

Check warning on line 263 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L253-L263

Added lines #L253 - L263 were not covered by tests
}

ccp.verifier = &Verifier{
Header: lightBlock,
}

Check warning on line 268 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L266-L268

Added lines #L266 - L268 were not covered by tests

var eg errgroup.Group
eg.Go(func() error {
Expand All @@ -278,7 +278,7 @@
return err
}

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

Check warning on line 281 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L281

Added line #L281 was not covered by tests

ticker := time.NewTicker(persistence.minQueryLoopDuration)
defer ticker.Stop()
Expand All @@ -297,7 +297,7 @@
}

// 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 {

Check warning on line 300 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L300

Added line #L300 was not covered by tests
ctx, cancel := context.WithTimeout(ctx, queryTimeout)
defer cancel()
connections, err := ccp.chainProvider.QueryConnections(ctx)
Expand All @@ -317,7 +317,7 @@
}

// 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 {

Check warning on line 320 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L320

Added line #L320 was not covered by tests
ctx, cancel := context.WithTimeout(ctx, queryTimeout)
defer cancel()
channels, err := ccp.chainProvider.QueryChannels(ctx)
Expand All @@ -344,11 +344,10 @@
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 {

Check warning on line 347 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L347

Added line #L347 was not covered by tests
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.

Check warning on line 350 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L350

Added line #L350 was not covered by tests
ccp.log.Error(
"Failed to query node status after max attempts",
zap.Uint("attempts", latestHeightQueryRetries),
Expand All @@ -360,7 +359,7 @@
persistence.latestHeight = status.SyncInfo.LatestBlockHeight
// ccp.chainProvider.setCometVersion(ccp.log, status.NodeInfo.Version)

ccp.log.Info("Queried latest height",

Check warning on line 362 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L362

Added line #L362 was not covered by tests
zap.Int64("latest_height", persistence.latestHeight),
)

Expand Down Expand Up @@ -391,14 +390,14 @@

newLatestQueriedBlock := persistence.latestQueriedBlock
chainID := ccp.chainProvider.ChainId()
var latestHeader provider.IBCHeader

ccp.SnapshotHeight(int(persistence.latestHeight))

Check warning on line 395 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L393-L395

Added lines #L393 - L395 were not covered by tests

for i := persistence.latestQueriedBlock + 1; i <= persistence.latestHeight; i++ {
var eg errgroup.Group
var blockRes *ctypes.ResultBlockResults
var lightBlock *types.LightBlock

Check warning on line 400 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L400

Added line #L400 was not covered by tests
i := i
eg.Go(func() (err error) {
queryCtx, cancelQueryCtx := context.WithTimeout(ctx, blockResultsQueryTimeout)
Expand All @@ -410,7 +409,7 @@
eg.Go(func() (err error) {
queryCtx, cancelQueryCtx := context.WithTimeout(ctx, queryTimeout)
defer cancelQueryCtx()
latestHeader, lightBlock, err = ccp.chainProvider.QueryLightBlock(queryCtx, i)

Check warning on line 412 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L412

Added line #L412 was not covered by tests
return err
})

Expand All @@ -419,13 +418,13 @@
break
}

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
}

Check warning on line 424 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L421-L424

Added lines #L421 - L424 were not covered by tests

ccp.log.Debug("Verified block ",
zap.Int64("height", lightBlock.Header.Height))

Check warning on line 427 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L426-L427

Added lines #L426 - L427 were not covered by tests

heightUint64 := uint64(i)

Expand Down Expand Up @@ -496,23 +495,23 @@
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)

retryAfter := ccp.Provider().ProviderConfig().GetFirstRetryBlockAfter()
snapshotHeight := height - int(retryAfter)

if snapshotHeight%snapshotThreshold == 0 {
err := common.SnapshotHeight(ccp.Provider().ChainId(), height)
if err != nil {
ccp.log.Warn("Failed saving height snapshot for height", zap.Int("height", height))
}

Check warning on line 510 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L498-L510

Added lines #L498 - L510 were not covered by tests
}
}

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

Check warning on line 514 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L514

Added line #L514 was not covered by tests
ccp.CurrentBlockHeight(ctx, persistence)

// Wait a while before updating the balance
Expand All @@ -522,47 +521,47 @@
}
}

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

Check warning on line 524 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L524

Added line #L524 was not covered by tests
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")
}

Check warning on line 532 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L528-L532

Added lines #L528 - L532 were not covered by tests

if err := verifyNewHeaderAndVals(untrusted.SignedHeader,
untrusted.ValidatorSet,
ccp.verifier.Header.SignedHeader,
time.Now(), 0); err != nil {
return fmt.Errorf("Failed to verify Header: %v", err)
}

Check warning on line 539 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L534-L539

Added lines #L534 - L539 were not covered by tests

if !bytes.Equal(untrusted.Header.ValidatorsHash, ccp.verifier.Header.NextValidatorsHash) {
err := fmt.Errorf("expected old header next validators (%X) to match those from new header (%X)",
ccp.verifier.Header.NextValidatorsHash,
untrusted.Header.ValidatorsHash,
)
return err
}

Check warning on line 547 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L541-L547

Added lines #L541 - L547 were not covered by tests

if !bytes.Equal(untrusted.Header.LastBlockID.Hash.Bytes(), ccp.verifier.Header.Commit.BlockID.Hash.Bytes()) {
err := fmt.Errorf("expected LastBlockId Hash (%X) of current header to match those from trusted Header BlockID hash (%X)",
ccp.verifier.Header.NextValidatorsHash,
untrusted.Header.ValidatorsHash,
)
return err
}

Check warning on line 555 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L549-L555

Added lines #L549 - L555 were not covered by tests

// Ensure that +2/3 of new validators signed correctly.
if err := untrusted.ValidatorSet.VerifyCommitLight(ccp.verifier.Header.ChainID, untrusted.Commit.BlockID,
untrusted.Header.Height, untrusted.Commit); err != nil {
return fmt.Errorf("invalid header: %v", err)
}

Check warning on line 561 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L558-L561

Added lines #L558 - L561 were not covered by tests

ccp.verifier.Header = untrusted
return nil

Check warning on line 564 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L563-L564

Added lines #L563 - L564 were not covered by tests

}

Expand All @@ -571,43 +570,43 @@
untrustedVals *types.ValidatorSet,
trustedHeader *types.SignedHeader,
now time.Time,
maxClockDrift time.Duration) error {

if err := untrustedHeader.ValidateBasic(trustedHeader.ChainID); err != nil {
return fmt.Errorf("untrustedHeader.ValidateBasic failed: %w", err)
}

Check warning on line 577 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L573-L577

Added lines #L573 - L577 were not covered by tests

if untrustedHeader.Height <= trustedHeader.Height {
return fmt.Errorf("expected new header height %d to be greater than one of old header %d",
untrustedHeader.Height,
trustedHeader.Height)
}

Check warning on line 583 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L579-L583

Added lines #L579 - L583 were not covered by tests

if !untrustedHeader.Time.After(trustedHeader.Time) {
return fmt.Errorf("expected new header time %v to be after old header time %v",
untrustedHeader.Time,
trustedHeader.Time)
}

Check warning on line 589 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L585-L589

Added lines #L585 - L589 were not covered by tests

if !untrustedHeader.Time.Before(now.Add(maxClockDrift)) {
return fmt.Errorf("new header has a time from the future %v (now: %v; max clock drift: %v)",
untrustedHeader.Time,
now,
maxClockDrift)
}

Check warning on line 596 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L591-L596

Added lines #L591 - L596 were not covered by tests

if !bytes.Equal(untrustedHeader.ValidatorsHash, untrustedVals.Hash()) {
return fmt.Errorf("expected new header validators (%X) to match those that were supplied (%X) at height %d",
untrustedHeader.ValidatorsHash,
untrustedVals.Hash(),
untrustedHeader.Height,
)
}

Check warning on line 604 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L598-L604

Added lines #L598 - L604 were not covered by tests

return nil

Check warning on line 606 in relayer/chains/wasm/archway_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/archway_chain_processor.go#L606

Added line #L606 was not covered by tests
}

// 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
Loading