Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant ChainID Calls #2959

Open
trajan0x opened this issue Jul 30, 2024 · 1 comment
Open

Redundant ChainID Calls #2959

trajan0x opened this issue Jul 30, 2024 · 1 comment
Assignees

Comments

@trajan0x
Copy link
Contributor

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:

  • On startup, crashes node if this errors
  • New Chain is called in chainIDToChain and therefore ends up getting called twice on every singel request (although only once when forwarding is in use):
image
Copy link

greptile-apps bot commented Jul 30, 2024

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
}
  1. 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)
}
  1. 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 · Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants