synapsecns / sanguine

Synapse Monorepo
MIT License
37 stars 30 forks source link

Redundant ChainID Calls #2959

Open trajan0x opened 3 months ago

trajan0x commented 3 months ago

I was drilling down into the performance of handleBridgeRequestedLog and noticed we could probably shave almost half a second off by removing some redundant calls:

image

chain.NewChain does not know it's own chainID and must do an RPC call to get it. By passing this in, we could get rid of these calls.

This calls presence has two deleterious effects:

image
greptile-apps[bot] commented 3 months ago

To address the redundant ChainID calls in handleBridgeRequestedLog, follow these steps:

  1. Modify NewChain to accept a ChainID parameter:

    func NewChain(client *ethclient.Client, chainID *big.Int) (*Chain, error) {
    // existing code
    }
  2. Update the call to NewChain in chainIDToChain to pass the ChainID:

    func chainIDToChain(chainID *big.Int) (*Chain, error) {
    client, err := ethclient.Dial(url)
    if err != nil {
        return nil, err
    }
    return NewChain(client, chainID)
    }
  3. Ensure handleBridgeRequestedLog retrieves and passes the ChainID:

    func handleBridgeRequestedLog(log types.Log) error {
    chainID := getChainIDFromLog(log) // Implement this function to extract ChainID from log
    chain, err := chainIDToChain(chainID)
    if err != nil {
        return err
    }
    // existing code
    }

These changes will eliminate the redundant ChainID RPC calls.

References

/services/scribe/config/chain.go /packages/sdk-router/src/sdk.test.ts /agents/contracts/test/attestationharness/generate.go /services/rfq/tools/rfqdecoder /services/scribe/config/config.go /packages/contracts-rfq/deployments/base_sepolia /packages/contracts-rfq/deployments/op_sepolia /services/rfq /services/omnirpc/chainmanager/mocks /ethergo/chain/logger.go /services/rfq/tools/rfqdecoder/main.go /agents/contracts/test/snapshotharness/generate.go /packages/contracts-rfq/deployments/eth_sepolia /services/rfq/api/model/response.go /contrib/screener-api/chainalysis/doc.go /services/explorer/backfill /services/rfq/relayer/service/statushandler.go /services/rfq/tools /packages/contracts-rfq/deployments/base /services/scribe/service/chain.go /services/rfq/guard/service/handlers.go /services/rfq/relayer/chain /packages/contracts-rfq/deployments/optimism /ethergo/chaindata/chaindata.go /ethergo/chain/chain.go

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/synapsecns/sanguine/master) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)