Skip to content

Commit

Permalink
finality config
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 16, 2024
1 parent 70e1592 commit 433862f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions relay/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions relay/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ var ChainIDS = map[int64]string{
10: "OP",
42161: "Arbitrum",
}

const ConfirmationsNeeded = 12

0 comments on commit 433862f

Please sign in to comment.