Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
53 changes: 38 additions & 15 deletions relayer/chains/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ type Client interface {

// Client is the struct that handles interactions with the EVM chain.
type client struct {
ChainName string
Endpoints []string
QueryTimeout time.Duration
ExecuteTimeout time.Duration
ChainName string
Endpoints []string
QueryTimeout time.Duration
ExecuteTimeout time.Duration
BlockConfirmation uint64

Log logger.Logger

Expand Down Expand Up @@ -90,13 +91,14 @@ func dialEVMEndpoint(ctx context.Context, endpoint string) (*ethclient.Client, e
// NewClient creates a new EVM client from config file and load keys.
func NewClient(chainName string, cfg *EVMChainProviderConfig, log logger.Logger, alert alert.Alert) *client {
return &client{
ChainName: chainName,
Endpoints: cfg.Endpoints,
QueryTimeout: cfg.QueryTimeout,
ExecuteTimeout: cfg.ExecuteTimeout,
Log: log.With("chain_name", chainName),
alert: alert,
clients: NewEVMClients(),
ChainName: chainName,
Endpoints: cfg.Endpoints,
QueryTimeout: cfg.QueryTimeout,
ExecuteTimeout: cfg.ExecuteTimeout,
BlockConfirmation: cfg.BlockConfirmation,
Log: log.With("chain_name", chainName),
alert: alert,
clients: NewEVMClients(),
}
}

Expand Down Expand Up @@ -504,7 +506,10 @@ func (c *client) BroadcastTx(ctx context.Context, tx *gethtypes.Transaction) (st
return tx.Hash().Hex(), nil
}

// getClientWithMaxHeight connects to the endpoint that has the highest block height.
// getClientWithMaxHeight selects an endpoint using first-come-first-serve within
// the confirmed block range. It collects block heights from all endpoints, then
// picks the first one (by arrival order) whose block height is within
// [maxHeight - BlockConfirmation, maxHeight].
Comment thread
RogerKSI marked this conversation as resolved.
Outdated
func (c *client) getClientWithMaxHeight(ctx context.Context) (ClientConnectionResult, error) {
ch := make(chan ClientConnectionResult, len(c.Endpoints))
Comment thread
RogerKSI marked this conversation as resolved.
Outdated

Expand Down Expand Up @@ -554,16 +559,34 @@ func (c *client) getClientWithMaxHeight(ctx context.Context) (ClientConnectionRe
}(endpoint)
}

var result ClientConnectionResult
// Collect all results in arrival order and track the maximum block height.
results := make([]ClientConnectionResult, 0, len(c.Endpoints))
var maxHeight uint64
for i := 0; i < len(c.Endpoints); i++ {
r := <-ch
if r.Client != nil {
if r.BlockHeight > result.BlockHeight || (r.Endpoint == c.clients.GetSelectedEndpoint() && r.BlockHeight == result.BlockHeight) {
result = r
results = append(results, r)
if r.BlockHeight > maxHeight {
maxHeight = r.BlockHeight
}
}
}

// Determine the minimum acceptable block height based on BlockConfirmation.
var minHeight uint64
if maxHeight >= c.BlockConfirmation {
minHeight = maxHeight - c.BlockConfirmation
}

// First-come-first-serve: pick the first arrived endpoint within the confirmed range.
var result ClientConnectionResult
for _, r := range results {
if r.BlockHeight >= minHeight {
result = r
break
}
}

if result.Client == nil {
Comment thread
RogerKSI marked this conversation as resolved.
Outdated
alert.HandleAlert(
c.alert,
Expand Down
54 changes: 38 additions & 16 deletions relayer/chains/flow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ var _ Client = (*client)(nil)

// client is the concrete implementation that handles Flow HTTP interactions.
type client struct {
ChainName string
Endpoints []string
QueryTimeout time.Duration
ExecuteTimeout time.Duration
ChainName string
Endpoints []string
QueryTimeout time.Duration
ExecuteTimeout time.Duration
BlockConfirmation uint64

Log logger.Logger
alert alert.Alert
Expand All @@ -61,13 +62,14 @@ type client struct {
// NewClient creates a new Flow client from config.
func NewClient(chainName string, cfg *FlowChainProviderConfig, log logger.Logger, a alert.Alert) Client {
return &client{
ChainName: chainName,
Endpoints: cfg.Endpoints,
QueryTimeout: cfg.QueryTimeout,
ExecuteTimeout: cfg.ExecuteTimeout,
Log: log.With("chain_name", chainName),
alert: a,
clients: NewFlowClients(),
ChainName: chainName,
Endpoints: cfg.Endpoints,
QueryTimeout: cfg.QueryTimeout,
ExecuteTimeout: cfg.ExecuteTimeout,
BlockConfirmation: 5,
Log: log.With("chain_name", chainName),
alert: a,
clients: NewFlowClients(),
Comment thread
RogerKSI marked this conversation as resolved.
}
Comment thread
RogerKSI marked this conversation as resolved.
}

Expand Down Expand Up @@ -123,7 +125,10 @@ func (c *client) Connect(_ context.Context) error {
return nil
}

// getClientWithMaxHeight selects the endpoint with the highest sealed block height.
// getClientWithMaxHeight selects an endpoint using first-come-first-serve within
// the confirmed block range. It collects block heights from all endpoints, then
// picks the first one (by arrival order) whose block height is within
Comment thread
RogerKSI marked this conversation as resolved.
Outdated
// [maxHeight - BlockConfirmation, maxHeight].
func (c *client) getClientWithMaxHeight() (ClientConnectionResult, error) {
ch := make(chan ClientConnectionResult, len(c.Endpoints))

Expand Down Expand Up @@ -163,17 +168,34 @@ func (c *client) getClientWithMaxHeight() (ClientConnectionResult, error) {
}(endpoint)
}

var result ClientConnectionResult
// Collect all results in arrival order and track the maximum block height.
results := make([]ClientConnectionResult, 0, len(c.Endpoints))
var maxHeight uint64
for range c.Endpoints {
r := <-ch
if r.Client != nil {
if r.BlockHeight > result.BlockHeight ||
(r.Endpoint == c.clients.GetSelectedEndpoint() && r.BlockHeight == result.BlockHeight) {
result = r
results = append(results, r)
if r.BlockHeight > maxHeight {
maxHeight = r.BlockHeight
}
}
}

// Determine the minimum acceptable block height based on BlockConfirmation.
var minHeight uint64
if maxHeight >= c.BlockConfirmation {
minHeight = maxHeight - c.BlockConfirmation
}

// First-come-first-serve: pick the first arrived endpoint within the confirmed range.
var result ClientConnectionResult
for _, r := range results {
if r.BlockHeight >= minHeight {
result = r
break
}
}

if result.Client == nil {
alert.HandleAlert(
c.alert,
Expand Down
42 changes: 31 additions & 11 deletions relayer/chains/icon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ type Client interface {

// Client is the struct that handles interactions with the Icon chain.
type client struct {
ChainName string
Endpoints []string
ChainName string
Endpoints []string
BlockConfirmation uint64

Log logger.Logger

Expand All @@ -50,11 +51,12 @@ type client struct {
// NewClient creates a new Icon client from config file and load keys.
func NewClient(chainName string, cfg *IconChainProviderConfig, log logger.Logger, alert alert.Alert) *client {
return &client{
ChainName: chainName,
Endpoints: cfg.Endpoints,
Log: log.With("chain_name", chainName),
alert: alert,
clients: NewIconClients(),
ChainName: chainName,
Endpoints: cfg.Endpoints,
BlockConfirmation: 5,
Log: log.With("chain_name", chainName),
alert: alert,
clients: NewIconClients(),
}
Comment thread
RogerKSI marked this conversation as resolved.
Comment thread
RogerKSI marked this conversation as resolved.
}

Expand Down Expand Up @@ -112,6 +114,7 @@ func (c *client) StartLivelinessCheck(ctx context.Context, interval time.Duratio
}

// getClientWithMaxHeight connects to the endpoint that has the highest block height.
// It uses first-come-first-serve selection within [maxHeight - BlockConfirmation, maxHeight].
Comment thread
RogerKSI marked this conversation as resolved.
Outdated
func (c *client) getClientWithMaxHeight() (ClientConnectionResult, error) {
ch := make(chan ClientConnectionResult, len(c.Endpoints))

Expand Down Expand Up @@ -158,17 +161,34 @@ func (c *client) getClientWithMaxHeight() (ClientConnectionResult, error) {
}(endpoint)
}

var result ClientConnectionResult
// Collect all results in arrival order and track the maximum block height.
results := make([]ClientConnectionResult, 0, len(c.Endpoints))
var maxHeight uint64
for i := 0; i < len(c.Endpoints); i++ {
r := <-ch
if r.Client != nil {
if r.BlockHeight > result.BlockHeight ||
(r.Endpoint == c.clients.GetSelectedEndpoint() && r.BlockHeight == result.BlockHeight) {
result = r
results = append(results, r)
if r.BlockHeight > maxHeight {
maxHeight = r.BlockHeight
}
}
}

// Determine the minimum acceptable block height based on BlockConfirmation.
var minHeight uint64
if maxHeight >= c.BlockConfirmation {
minHeight = maxHeight - c.BlockConfirmation
}

// First-come-first-serve: pick the first arrived endpoint within the confirmed range.
var result ClientConnectionResult
for _, r := range results {
if r.BlockHeight >= minHeight {
result = r
break
}
}

if result.Client == nil {
alert.HandleAlert(
c.alert,
Expand Down
45 changes: 33 additions & 12 deletions relayer/chains/secret/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ type typesBlockResult struct {
var _ Client = (*client)(nil)

type client struct {
chainName string
endpoints []string
denom string
chainName string
endpoints []string
denom string
blockConfirmation int64

log logger.Logger
alert alert.Alert
Expand All @@ -69,12 +70,13 @@ type client struct {

func NewClient(chainName string, cpc *SecretChainProviderConfig, log logger.Logger, alert alert.Alert) *client {
return &client{
chainName: chainName,
endpoints: cpc.Endpoints,
denom: cpc.Denom,
log: log.With("chain_name", chainName),
alert: alert,
clients: chains.NewClientPool[sdkclient.Context](),
chainName: chainName,
endpoints: cpc.Endpoints,
denom: cpc.Denom,
blockConfirmation: 5,
log: log.With("chain_name", chainName),
alert: alert,
clients: chains.NewClientPool[sdkclient.Context](),
}
Comment thread
RogerKSI marked this conversation as resolved.
Comment thread
RogerKSI marked this conversation as resolved.
}

Expand Down Expand Up @@ -338,6 +340,7 @@ func (c *client) GetBlockByHeight(ctx context.Context, height *big.Int) (*typesB
}

// getClientWithMaxHeight connects to the endpoint that has the highest block height.
// It uses first-come-first-serve selection within [maxHeight - blockConfirmation, maxHeight].
Comment thread
RogerKSI marked this conversation as resolved.
Outdated
func (c *client) getClientWithMaxHeight(ctx context.Context) (ClientConnectionResult, error) {
ch := make(chan ClientConnectionResult, len(c.endpoints))

Expand Down Expand Up @@ -402,16 +405,34 @@ func (c *client) getClientWithMaxHeight(ctx context.Context) (ClientConnectionRe
}(endpoint)
}

var result ClientConnectionResult
// Collect all results in arrival order and track the maximum block height.
results := make([]ClientConnectionResult, 0, len(c.endpoints))
var maxHeight int64
for i := 0; i < len(c.endpoints); i++ {
r := <-ch
if r.Client != nil {
if r.BlockHeight > result.BlockHeight || (r.Endpoint == c.clients.GetSelectedEndpoint() && r.BlockHeight == result.BlockHeight) {
result = r
results = append(results, r)
if r.BlockHeight > maxHeight {
maxHeight = r.BlockHeight
}
}
}

// Determine the minimum acceptable block height based on blockConfirmation.
var minHeight int64
if maxHeight >= c.blockConfirmation {
minHeight = maxHeight - c.blockConfirmation
}

// First-come-first-serve: pick the first arrived endpoint within the confirmed range.
var result ClientConnectionResult
for _, r := range results {
if r.BlockHeight >= minHeight {
result = r
break
}
}

if result.Client == nil {
alert.HandleAlert(
c.alert,
Expand Down
Loading
Loading