Skip to content

Commit

Permalink
chore: refactor get retry block after to provider config interface
Browse files Browse the repository at this point in the history
  • Loading branch information
izyak committed Jul 25, 2023
1 parent 8256d0c commit 0b6e184
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 36 deletions.
7 changes: 3 additions & 4 deletions relayer/chains/archway/archway_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (ccp *ArchwayChainProcessor) queryCycle(ctx context.Context, persistence *q
var latestHeader provider.IBCHeader

ccp.SnapshotHeight(int(persistence.latestHeight))

for i := persistence.latestQueriedBlock + 1; i <= persistence.latestHeight; i++ {
var eg errgroup.Group
var blockRes *ctypes.ResultBlockResults
Expand Down Expand Up @@ -498,10 +498,10 @@ func (ccp *ArchwayChainProcessor) queryCycle(ctx context.Context, persistence *q

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

blockInterval := ccp.Provider().ProviderConfig().BlockInterval()
blockInterval := ccp.Provider().ProviderConfig().GetBlockInterval()
snapshotThreshold := common.ONE_HOUR / int(blockInterval)

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

if snapshotHeight%snapshotThreshold == 0 {
Expand All @@ -511,7 +511,6 @@ func (ccp *ArchwayChainProcessor) SnapshotHeight(height int) {
}
}
}
// TODO: review add verifier

func (ccp *ArchwayChainProcessor) CollectMetrics(ctx context.Context, persistence *queryCyclePersistence) {
ccp.CurrentBlockHeight(ctx, persistence)
Expand Down
22 changes: 11 additions & 11 deletions relayer/chains/archway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ func (pp *ArchwayProviderConfig) Validate() error {
return nil
}

func (pc *ArchwayProviderConfig) BlockInterval() uint64 {
return pc.ChainBlockInterval
}

func (pp *ArchwayProviderConfig) getRPCAddr() string {
return pp.RPCAddr
}
Expand All @@ -213,6 +209,17 @@ func (pp *ArchwayProviderConfig) BroadcastMode() provider.BroadcastMode {
return pp.Broadcast
}

func (pp *ArchwayProviderConfig) GetBlockInterval() uint64 {
return pp.ChainBlockInterval
}

func (pp *ArchwayProviderConfig) GetFirstRetryBlockAfter() uint64 {
if pp.FirstRetryBlockAfter != 0 {
return pp.FirstRetryBlockAfter
}
return 3
}

func (pc *ArchwayProviderConfig) NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error) {
if err := pc.Validate(); err != nil {
return nil, err
Expand Down Expand Up @@ -467,13 +474,6 @@ func (app *ArchwayProvider) MsgRegisterCounterpartyPayee(portID, channelID, rela
return nil, fmt.Errorf("Not implemented for Icon")
}

func (cc *ArchwayProvider) FirstRetryBlockAfter() uint64 {
if cc.PCfg.FirstRetryBlockAfter != 0 {
return cc.PCfg.FirstRetryBlockAfter
}
return 3
}

// keysDir returns a string representing the path on the local filesystem where the keystore will be initialized.
func keysDir(home, chainID string) string {
return path.Join(home, "keys", chainID)
Expand Down
10 changes: 5 additions & 5 deletions relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ func (pc CosmosProviderConfig) BroadcastMode() provider.BroadcastMode {
return pc.Broadcast
}

func (pc CosmosProviderConfig) BlockInterval() uint64 {
func (pc CosmosProviderConfig) GetBlockInterval() uint64 {
panic("Not implemented for Cosmos")
}

func (pc CosmosProviderConfig) GetFirstRetryBlockAfter() uint64 {
return 1
}

// NewProvider validates the CosmosProviderConfig, instantiates a ChainClient and then instantiates a CosmosProvider
func (pc CosmosProviderConfig) NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error) {
if err := pc.Validate(); err != nil {
Expand Down Expand Up @@ -314,10 +318,6 @@ func (cc *CosmosProvider) legacyEncodedEvents(log *zap.Logger, version string) b
return semver.Compare("v"+version, cometEncodingThreshold) < 0
}

func (cc *CosmosProvider) FirstRetryBlockAfter() uint64 {
return 1
}

// keysDir returns a string representing the path on the local filesystem where the keystore will be initialized.
func keysDir(home, chainID string) string {
return path.Join(home, "keys", chainID)
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 @@ -464,10 +464,10 @@ loop:

func (icp *IconChainProcessor) SnapshotHeight(height int) {

blockInterval := icp.Provider().ProviderConfig().BlockInterval()
blockInterval := icp.Provider().ProviderConfig().GetBlockInterval()
snapshotThreshold := rlycommon.ONE_HOUR / int(blockInterval)

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

if snapshotHeight%snapshotThreshold == 0 {
Expand Down
16 changes: 8 additions & 8 deletions relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ func (pp *IconProviderConfig) Validate() error {
return nil
}

func (pp *IconProviderConfig) BlockInterval() uint64 {
func (pp *IconProviderConfig) GetBlockInterval() uint64 {
return pp.ChainBlockInterval
}

func (pp *IconProviderConfig) GetFirstRetryBlockAfter() uint64 {
if pp.FirstRetryBlockAfter != 0 {
return pp.FirstRetryBlockAfter
}
return 8
}

// NewProvider should provide a new Icon provider
// NewProvider should provide a new Icon provider
func (pp *IconProviderConfig) NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (provider.ChainProvider, error) {
Expand Down Expand Up @@ -578,10 +585,3 @@ func (icp *IconProvider) GetCurrentBtpNetworkStartHeight() (int64, error) {
func (icp *IconProvider) MsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) (provider.RelayerMessage, error) {
return nil, fmt.Errorf("Not implemented for Icon")
}

func (icp *IconProvider) FirstRetryBlockAfter() uint64 {
if icp.PCfg.FirstRetryBlockAfter != 0 {
return icp.PCfg.FirstRetryBlockAfter
}
return 8
}
6 changes: 5 additions & 1 deletion relayer/chains/penumbra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ func (pc PenumbraProviderConfig) Validate() error {
return nil
}

func (pc PenumbraProviderConfig) BlockInterval() uint64 {
func (pc PenumbraProviderConfig) GetBlockInterval() uint64 {
panic("Not implemented for Penumbra")
}

func (pc PenumbraProviderConfig) GetFirstRetryBlockAfter() uint64 {
return 1
}

func (pc PenumbraProviderConfig) BroadcastMode() provider.BroadcastMode {
return pc.Broadcast
}
Expand Down
6 changes: 3 additions & 3 deletions relayer/processor/path_end_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (pathEnd *pathEndRuntime) shouldSendPacketMessage(message packetIBCMessage,
// this message was sent less than blocksToRetrySendAfter ago, do not attempt to send again yet.
return false
}
if inProgress.retryCount <= 1 && blocksSinceLastProcessed < pathEnd.chainProvider.FirstRetryBlockAfter() {
if inProgress.retryCount <= 1 && blocksSinceLastProcessed < pathEnd.chainProvider.ProviderConfig().GetFirstRetryBlockAfter() {
return false
}
} else {
Expand Down Expand Up @@ -580,7 +580,7 @@ func (pathEnd *pathEndRuntime) shouldSendConnectionMessage(message connectionIBC
// this message was sent less than blocksToRetrySendAfter ago, do not attempt to send again yet.
return false
}
if inProgress.retryCount <= 1 && blocksSinceLastProcessed < pathEnd.chainProvider.FirstRetryBlockAfter() {
if inProgress.retryCount <= 1 && blocksSinceLastProcessed < pathEnd.chainProvider.ProviderConfig().GetFirstRetryBlockAfter() {
return false
}
} else {
Expand Down Expand Up @@ -660,7 +660,7 @@ func (pathEnd *pathEndRuntime) shouldSendChannelMessage(message channelIBCMessag
// this message was sent less than blocksToRetrySendAfter ago, do not attempt to send again yet.
return false
}
if inProgress.retryCount <= 1 && blocksSinceLastProcessed < pathEnd.chainProvider.FirstRetryBlockAfter() {
if inProgress.retryCount <= 1 && blocksSinceLastProcessed < pathEnd.chainProvider.ProviderConfig().GetFirstRetryBlockAfter() {
return false
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type ProviderConfig interface {
NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (ChainProvider, error)
Validate() error
BroadcastMode() BroadcastMode
BlockInterval() uint64
GetBlockInterval() uint64
GetFirstRetryBlockAfter() uint64
}

type RelayerMessage interface {
Expand Down Expand Up @@ -424,7 +425,6 @@ type QueryProvider interface {
QueryTx(ctx context.Context, hashHex string) (*RelayerTxResponse, error)
QueryTxs(ctx context.Context, page, limit int, events []string) ([]*RelayerTxResponse, error)
QueryLatestHeight(ctx context.Context) (int64, error)
FirstRetryBlockAfter() uint64

// QueryIBCHeader returns the IBC compatible block header at a specific height.
QueryIBCHeader(ctx context.Context, h int64) (IBCHeader, error)
Expand Down

0 comments on commit 0b6e184

Please sign in to comment.