Skip to content

Commit

Permalink
Merge branch 'main' into review/chain-providers
Browse files Browse the repository at this point in the history
  • Loading branch information
izyak authored Jul 25, 2023
2 parents d6e8985 + e2431d1 commit 0d3c7a1
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 58 deletions.
8 changes: 4 additions & 4 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
flagDstClientID = "dst-client-id"
flagSrcConnID = "src-connection-id"
flagDstConnID = "dst-connection-id"
flagIconStartHeight = "icon-start-height"
flagBtpBlockHeight = "btp-block-height"
)

const (
Expand All @@ -81,9 +81,9 @@ func heightFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
return cmd
}

func iconStartHeightFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Int64(flagIconStartHeight, 0, "Icon Start Height to register client")
if err := v.BindPFlag(flagIconStartHeight, cmd.Flags().Lookup(flagIconStartHeight)); err != nil {
func btpBlockHeightFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().Int64(flagBtpBlockHeight, 0, "Icon Start Height to register client")
if err := v.BindPFlag(flagBtpBlockHeight, cmd.Flags().Lookup(flagBtpBlockHeight)); err != nil {
panic(err)
}
return cmd
Expand Down
16 changes: 8 additions & 8 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func createClientsCmd(a *appState) *cobra.Command {
return err
}

iconStartHeight, err := cmd.Flags().GetInt64(flagIconStartHeight)
iconStartHeight, err := cmd.Flags().GetInt64(flagBtpBlockHeight)

Check warning on line 83 in cmd/tx.go

View check run for this annotation

Codecov / codecov/patch

cmd/tx.go#L83

Added line #L83 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func createClientsCmd(a *appState) *cobra.Command {
cmd = clientParameterFlags(a.viper, cmd)
cmd = overrideFlag(a.viper, cmd)
cmd = memoFlag(a.viper, cmd)
cmd = iconStartHeightFlag(a.viper, cmd)
cmd = btpBlockHeightFlag(a.viper, cmd)
return cmd
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func createClientCmd(a *appState) *cobra.Command {
return err
}

iconStartHeight, err := cmd.Flags().GetInt64(flagIconStartHeight)
iconStartHeight, err := cmd.Flags().GetInt64(flagBtpBlockHeight)

Check warning on line 203 in cmd/tx.go

View check run for this annotation

Codecov / codecov/patch

cmd/tx.go#L203

Added line #L203 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func createClientCmd(a *appState) *cobra.Command {
cmd = clientParameterFlags(a.viper, cmd)
cmd = overrideFlag(a.viper, cmd)
cmd = memoFlag(a.viper, cmd)
cmd = iconStartHeightFlag(a.viper, cmd)
cmd = btpBlockHeightFlag(a.viper, cmd)
return cmd
}

Expand Down Expand Up @@ -405,7 +405,7 @@ $ %s tx conn demo-path --timeout 5s`,
return err
}

iconStartHeight, err := cmd.Flags().GetInt64(flagIconStartHeight)
iconStartHeight, err := cmd.Flags().GetInt64(flagBtpBlockHeight)

Check warning on line 408 in cmd/tx.go

View check run for this annotation

Codecov / codecov/patch

cmd/tx.go#L408

Added line #L408 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -449,7 +449,7 @@ $ %s tx conn demo-path --timeout 5s`,
cmd = overrideFlag(a.viper, cmd)
cmd = memoFlag(a.viper, cmd)
cmd = initBlockFlag(a.viper, cmd)
cmd = iconStartHeightFlag(a.viper, cmd)
cmd = btpBlockHeightFlag(a.viper, cmd)
return cmd
}

Expand Down Expand Up @@ -690,7 +690,7 @@ $ %s tx connect demo-path --src-port mock --dst-port mock --order unordered --ve
return err
}

iconStartHeight, err := cmd.Flags().GetInt64(flagIconStartHeight)
iconStartHeight, err := cmd.Flags().GetInt64(flagBtpBlockHeight)

Check warning on line 693 in cmd/tx.go

View check run for this annotation

Codecov / codecov/patch

cmd/tx.go#L693

Added line #L693 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -728,7 +728,7 @@ $ %s tx connect demo-path --src-port mock --dst-port mock --order unordered --ve
cmd = overrideFlag(a.viper, cmd)
cmd = memoFlag(a.viper, cmd)
cmd = initBlockFlag(a.viper, cmd)
cmd = iconStartHeightFlag(a.viper, cmd)
cmd = btpBlockHeightFlag(a.viper, cmd)
return cmd
}

Expand Down
6 changes: 4 additions & 2 deletions examples/demo/configs/chains/ibc-icon.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"password":"gochain",
"btp-network-id":2,
"icon-network-id":3,
"start-btp-height":0,
"ibc-handler-address":"cxfffe383e4780084e48e477935099b03193d952fe"
"start-height":0,
"ibc-handler-address":"cxfffe383e4780084e48e477935099b03193d952fe",
"block-interval":1000,
"first-retry-block-after":8
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ replace (
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-20230619065023-ddc96101b9b1
github.com/icon-project/IBC-Integration => github.com/icon-project/ibc-integration v0.0.0-20230717083940-67949d73b622
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/icon-project/goloop v1.2.11/go.mod h1:P7mwPMmoAWFXdt0KmlrsQkRV9Qw1JswoCKqfTBpXYCw=
github.com/icon-project/goloop v1.3.4 h1:82x8x+zY2XLVPEuWKHvnTj4bkeC5EYlNaaiePDqdMjk=
github.com/icon-project/goloop v1.3.4/go.mod h1:9PoWRb5kowidc9jYy0RLuLpay1zT5FXgEKijx7rDQjE=
github.com/icon-project/ibc-integration v0.0.0-20230619065023-ddc96101b9b1 h1:AEfIOYcvh30JP7OopOYSvlvVbVdDk9oyKetZHK/h+2A=
github.com/icon-project/ibc-integration v0.0.0-20230619065023-ddc96101b9b1/go.mod h1:lYQTcVqXxpUhhdz/cU2xsX1rPGoIkeWalIAjiEt0K+0=
github.com/icon-project/ibc-integration v0.0.0-20230717083940-67949d73b622 h1:RHutSdyBRURe7MHx/838gVEw6Iu+tYMF/x2cx9hZSxY=
github.com/icon-project/ibc-integration v0.0.0-20230717083940-67949d73b622/go.mod h1:lYQTcVqXxpUhhdz/cU2xsX1rPGoIkeWalIAjiEt0K+0=
github.com/icon-project/icon-bridge v0.0.11 h1:1qUYq6YmzUQR+zCDJGnXQxXKs81NmkxATtOr8KEx4Wc=
github.com/icon-project/icon-bridge v0.0.11/go.mod h1:7GcN+biPaXdsYLvsiwC1Y/5ro6ENPinhUqm2MZL4tgQ=
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (icp *IconChainProcessor) monitoring(ctx context.Context, persistence *quer
}

var err error
processedheight := int64(icp.chainProvider.lastBTPBlockHeight)
processedheight := int64(icp.chainProvider.StartHeight)

Check warning on line 252 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L252

Added line #L252 was not covered by tests
if processedheight == 0 {
processedheight, err = icp.chainProvider.QueryLatestHeight(ctx)
if err != nil {
Expand All @@ -266,7 +266,7 @@ func (icp *IconChainProcessor) monitoring(ctx context.Context, persistence *quer
icp.firstTime = true

blockReq := &types.BlockRequest{
Height: types.NewHexInt(int64(icp.chainProvider.PCfg.BTPHeight)),
Height: types.NewHexInt(int64(icp.chainProvider.PCfg.StartHeight)),

Check warning on line 269 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L269

Added line #L269 was not covered by tests
EventFilters: GetMonitorEventFilters(icp.chainProvider.PCfg.IbcHandlerAddress),
}

Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/icon/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRestoreIconKeyStore(t *testing.T) {
Password: "gochain",
Timeout: "20s",
ChainName: "icon",
BTPHeight: 10,
StartHeight: 10,
IbcHandlerAddress: "aa",
}
p, err := pcfg.NewProvider(zap.NewNop(), "not_correct", false, "icon")
Expand Down
61 changes: 29 additions & 32 deletions relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type IconProviderConfig struct {
ICONNetworkID int64 `json:"icon-network-id" yaml:"icon-network-id" default:"3"`
BTPNetworkID int64 `json:"btp-network-id" yaml:"btp-network-id"`
BTPNetworkTypeID int64 `json:"btp-network-type-id" yaml:"btp-network-type-id"`
BTPHeight int64 `json:"start-btp-height" yaml:"start-btp-height"`
StartHeight int64 `json:"start-height" yaml:"start-height"`
IbcHandlerAddress string `json:"ibc-handler-address" yaml:"ibc-handler-address"`
FirstRetryBlockAfter uint64 `json:"first-retry-block-after" yaml:"first-retry-block-after"`
BlockInterval uint64 `json:"block-interval" yaml:"block-interval"`
}

func (pp *IconProviderConfig) Validate() error {
Expand Down Expand Up @@ -102,12 +103,12 @@ func (pp *IconProviderConfig) NewProvider(log *zap.Logger, homepath string, debu
codec := MakeCodec(ModuleBasics, []string{})

return &IconProvider{
log: log.With(zap.String("sys", "chain_client")),
client: NewClient(pp.getRPCAddr(), log),
PCfg: pp,
wallet: wallet,
lastBTPBlockHeight: uint64(pp.BTPHeight),
codec: codec,
log: log.With(zap.String("sys", "chain_client")),
client: NewClient(pp.getRPCAddr(), log),
PCfg: pp,
wallet: wallet,
StartHeight: uint64(pp.StartHeight),
codec: codec,
}, nil
}

Expand All @@ -124,15 +125,14 @@ func (pp IconProviderConfig) BroadcastMode() provider.BroadcastMode {
}

type IconProvider struct {
log *zap.Logger
PCfg *IconProviderConfig
txMu sync.Mutex
client *Client
wallet module.Wallet
metrics *processor.PrometheusMetrics
codec Codec
lastBTPBlockHeight uint64
lastBTPBlockHeightMu sync.Mutex
log *zap.Logger
PCfg *IconProviderConfig
txMu sync.Mutex
client *Client
wallet module.Wallet
metrics *processor.PrometheusMetrics
codec Codec
StartHeight uint64
}

type IconIBCHeader struct {
Expand Down Expand Up @@ -178,7 +178,8 @@ func (h IconIBCHeader) IsCompleteBlock() bool {
func (h IconIBCHeader) ConsensusState() ibcexported.ConsensusState {
if h.IsBTPBlock {
return &icon.ConsensusState{
MessageRoot: h.Header.MessageRoot,
MessageRoot: h.Header.MessageRoot,
NextProofContextHash: h.Header.NextProofContextHash,

Check warning on line 182 in relayer/chains/icon/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/provider.go#L181-L182

Added lines #L181 - L182 were not covered by tests
}
}
return &icon.ConsensusState{}
Expand Down Expand Up @@ -209,25 +210,21 @@ func (icp *IconProvider) NewClientState(
return nil, fmt.Errorf("Not complete block at height:%d", dstUpdateHeader.Height())
}

validatorSet, err := icp.GetProofContextByHeight(int64(dstUpdateHeader.Height()))
if err != nil {
return nil, err
if icp.PCfg.BlockInterval == 0 {
return nil, fmt.Errorf("Blockinterval cannot be empty in Icon config")

Check warning on line 214 in relayer/chains/icon/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/provider.go#L213-L214

Added lines #L213 - L214 were not covered by tests
}

iconHeader := dstUpdateHeader.(IconIBCHeader)

networkSectionhash := types.NewNetworkSection(iconHeader.Header).Hash()
trustingBlockPeriod := uint64(dstTrustingPeriod) / (icp.PCfg.BlockInterval * uint64(common.NanosecondRatio))

Check warning on line 217 in relayer/chains/icon/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/provider.go#L217

Added line #L217 was not covered by tests

return &icon.ClientState{
TrustingPeriod: uint64(dstTrustingPeriod),
FrozenHeight: 0,
MaxClockDrift: 3600,
LatestHeight: dstUpdateHeader.Height(),
NetworkSectionHash: networkSectionhash,
Validators: validatorSet,
SrcNetworkId: getSrcNetworkId(icp.PCfg.ICONNetworkID),
NetworkId: uint64(icp.PCfg.BTPNetworkID),
NetworkTypeId: uint64(icp.PCfg.BTPNetworkTypeID),
// In case of Icon: Trusting Period is block Difference // see: light.proto in ibc-integration
TrustingPeriod: trustingBlockPeriod,
FrozenHeight: 0,
MaxClockDrift: 3600,
LatestHeight: dstUpdateHeader.Height(),
SrcNetworkId: getSrcNetworkId(icp.PCfg.ICONNetworkID),
NetworkId: uint64(icp.PCfg.BTPNetworkID),
NetworkTypeId: uint64(icp.PCfg.BTPNetworkTypeID),

Check warning on line 227 in relayer/chains/icon/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/provider.go#L220-L227

Added lines #L220 - L227 were not covered by tests
}, nil

}
Expand Down
26 changes: 21 additions & 5 deletions relayer/chains/icon/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
)

func (icp *IconProvider) MsgCreateClient(clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (provider.RelayerMessage, error) {

Check warning on line 37 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L37

Added line #L37 was not covered by tests
clientStateBytes, err := proto.Marshal(clientState)
if err != nil {
return nil, err
Expand Down Expand Up @@ -499,13 +500,26 @@ func (icp *IconProvider) MsgUpdateClientHeader(latestHeader provider.IBCHeader,
return nil, err
}

var validatorList types.ValidatorList
info, err := icp.client.GetNetworkTypeInfo(int64(latestIconHeader.Header.MainHeight), icp.PCfg.BTPNetworkTypeID)
var currentValidatorList types.ValidatorList
// subtract 1 because it is a current validator not last validator
info, err := icp.client.GetNetworkTypeInfo(int64(latestIconHeader.Header.MainHeight-1), icp.PCfg.BTPNetworkTypeID)
if err != nil {
return nil, err
}

Check warning on line 508 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L503-L508

Added lines #L503 - L508 were not covered by tests

_, err = Base64ToData(string(info.NextProofContext), &currentValidatorList)

Check warning on line 510 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L510

Added line #L510 was not covered by tests
if err != nil {
return nil, err
}

var nextValidators types.ValidatorList
// subtract 1 because it is a current validator not last validator
next_info, err := icp.client.GetNetworkTypeInfo(int64(latestIconHeader.Header.MainHeight), icp.PCfg.BTPNetworkTypeID)
if err != nil {
return nil, err
}

Check warning on line 520 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L515-L520

Added lines #L515 - L520 were not covered by tests

_, err = Base64ToData(string(info.NextProofContext), &validatorList)
_, err = Base64ToData(string(next_info.NextProofContext), &nextValidators)

Check warning on line 522 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L522

Added line #L522 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -521,9 +535,11 @@ func (icp *IconProvider) MsgUpdateClientHeader(latestHeader provider.IBCHeader,
PrevNetworkSectionHash: latestIconHeader.Header.PrevNetworkSectionHash,
MessageCount: latestIconHeader.Header.MessageCount,
MessageRoot: latestIconHeader.Header.MessageRoot,
NextValidators: validatorList.Validators,
NextValidators: nextValidators.Validators,

Check warning on line 538 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L538

Added line #L538 was not covered by tests
},
Signatures: btp_proof,
Signatures: btp_proof,
TrustedHeight: trustedHeight.RevisionHeight,
CurrentValidators: currentValidatorList.Validators,

Check warning on line 542 in relayer/chains/icon/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/tx.go#L540-L542

Added lines #L540 - L542 were not covered by tests
}

return signedHeader, nil
Expand Down
2 changes: 2 additions & 0 deletions relayer/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ var (
ArchwayModule = "archway"
TendermintLightClient = "tendermint"
IconLightClient = "iconclient"

NanosecondRatio = 1000_000
)
1 change: 0 additions & 1 deletion relayer/processor/message_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (mp *messageProcessor) shouldUpdateClientNow(ctx context.Context, src, dst
return false, nil
}

Check warning on line 119 in relayer/processor/message_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/processor/message_processor.go#L113-L119

Added lines #L113 - L119 were not covered by tests
}

if header.ShouldUpdateWithZeroMessage() {
return true, nil
}
Expand Down

0 comments on commit 0d3c7a1

Please sign in to comment.