From 433862f35093815961a263ed7227adc72ea3fe56 Mon Sep 17 00:00:00 2001 From: marston Date: Mon, 16 Sep 2024 17:11:36 -0400 Subject: [PATCH] finality config --- config/config.go | 3 +++ relay/app.go | 8 ++++---- relay/types.go | 2 -- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index ea32152..4acad8f 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,7 @@ type NetworkConfig struct { RPC string `yaml:"rpc" mapstructure:"rpc"` Contract string `yaml:"contract" mapstructure:"contract"` ChainID int64 `yaml:"chain_id" mapstructure:"chain_id"` + Finality int64 `yaml:"finality" mapstructure:"finality"` } func DefaultConfig() Config { @@ -38,12 +39,14 @@ func DefaultConfig() Config { RPC: "wss://ethereum-sepolia-rpc.publicnode.com", Contract: "0x730fdF2ee985Ac0F7792f90cb9e1E5485d340208", ChainID: 11155111, + Finality: 2, }, { Name: "Base Sepolia", RPC: "wss://base-sepolia-rpc.publicnode.com", Contract: "0x20738B8eaB736f24c7881bA48263ee60Eb2a0A2a", ChainID: 84532, + Finality: 2, }, }, } diff --git a/relay/app.go b/relay/app.go index d2676ad..9476c9b 100644 --- a/relay/app.go +++ b/relay/app.go @@ -96,7 +96,7 @@ func (a *App) ListenToNetwork(network config.NetworkConfig, wg *sync.WaitGroup) go func() { // run async // Ensure transaction is confirmed - err := waitForReceipt(client, vLog.TxHash, func(receipt *types.Receipt) { + err := waitForReceipt(client, vLog.TxHash, network.Finality, func(receipt *types.Receipt) { for _, l := range receipt.Logs { if l.Address.Hex() == contractAddress.Hex() { handleLog(l, a.w, a.q, network.ChainID, jackalContract) @@ -243,7 +243,7 @@ func subscribeLogs(client *ethclient.Client, query ethereum.FilterQuery) (ethere } // waitForReceipt polls for the transaction receipt until it's available -func waitForReceipt(client *ethclient.Client, txHash common.Hash, callBack func(receipt *types.Receipt)) error { +func waitForReceipt(client *ethclient.Client, txHash common.Hash, finality int64, callBack func(receipt *types.Receipt)) error { var errCount int64 for { if errCount > 10 { @@ -268,11 +268,11 @@ func waitForReceipt(client *ethclient.Client, txHash common.Hash, callBack func( txBlock := receipt.BlockNumber.Int64() blockDiff := latest - txBlock - if blockDiff > ConfirmationsNeeded { + if blockDiff > finality { callBack(receipt) return nil } else { - log.Printf("Still waiting %d more blocks...", ConfirmationsNeeded-blockDiff) + log.Printf("Still waiting %d more blocks...", finality-blockDiff) } } } diff --git a/relay/types.go b/relay/types.go index c57c546..7ade802 100644 --- a/relay/types.go +++ b/relay/types.go @@ -19,5 +19,3 @@ var ChainIDS = map[int64]string{ 10: "OP", 42161: "Arbitrum", } - -const ConfirmationsNeeded = 12