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

feat: Add Bitcoin indexing #215

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

feat: Add Bitcoin indexing #215

wants to merge 18 commits into from

Conversation

mj52951
Copy link
Contributor

@mj52951 mj52951 commented Sep 9, 2024

Added Bitcoin indexing functionality.

closes #201
closes #202
closes #203

src/indexer/config/index.ts Outdated Show resolved Hide resolved
src/indexer/index.ts Outdated Show resolved Hide resolved
src/indexer/index.ts Outdated Show resolved Hide resolved
src/indexer/services/bitcoinIndexer/bitcoinIndexer.ts Outdated Show resolved Hide resolved
import { Block } from "./bitcoinTypes"

const BLOCK_TIME = Number(process.env.BLOCK_TIME) || 12000
const BLOCK_DELAY = Number(process.env.BLOCK_DELAY) || 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if these are config options that can be passed to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem with this whole approach to that being one env variable is that evm, substrate and btc all have different BLOCK_TIME and BLOCK_DELAY default options. And e.g. setting one value as block delay for all three network types doesn't look correct from my perspective. So what do you think of adding 4 more different env variables as BLOCK_DELAY_EVM, BLOCK_DELAY_SUBSTRATE and similar?

Copy link
Contributor

@mpetrun5 mpetrun5 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different networks have different params in this case also.
One EVM network won't have the same params as another.
Setting it by domainID_variableName would fix that.

}
}

function decodeDepositEvent(tx: Transaction, domain: Domain): DecodedDeposit | undefined {
Copy link
Contributor

@mpetrun5 mpetrun5 Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more intuitive to throw errors for unexpected behaviours instead of returning undefined and then we don't what happened. Also, would remove the need to have decoding and then undefined checks in saveEvents
Probably decoding errors will need to be caught and handled appropriately in saveEvents and logged as warn as we most likely don't want to try decoding that again, but at least we will know what happened.

Copy link
Contributor Author

@mj52951 mj52951 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I might've made a bad approach for the whole workflow then. But what this is essentially doing is checking if the output address is the relayer address (resourceFound) and if it is, it parses and returns the data so it can be stored in the database. If it isn't, it returns undefined. So it'll return undefined for every transaction that isn't actually a Sygma deposit.

try {
amountInUSD = await coinMakerCapService.getValueInUSD(decodedDeposit.amount.toString(), decodedDeposit.resource.symbol)
} catch (error) {
logger.error((error as Error).message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some description of where and why it happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coinmarketcap service functions already log the whole URL that was unsuccessfully fetched and additionally throw the message Error getting value from CoinMarketCap which is shown to be caught and logged here so not sure should I provide any more context?

}
}

async function saveDeposit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we have this logic somewhere else as well.
See if it can be reused instead of copied.

Copy link
Contributor Author

@mj52951 mj52951 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, something like getUpdatedTransfer function was in the squid-indexer repo. Just, that would require a partial refactor of evm and substrate parts also, so not sure should I do it in this PR ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is a big refactor I would avoid it/do it separetly for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to do it in a separate PR. Along with refactoring saveProposalExecution functions.

src/indexer/utils/bitcoin/index.ts Show resolved Hide resolved
return executionData
}

async function saveProposalExecution(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this save functions have basically the same logic as other networks.
Would be prudent to check if it can be unified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to do it in a separate PR. Along with refactoring saveDeposit functions.

@mj52951 mj52951 marked this pull request as ready for review September 19, 2024 07:23
@mj52951 mj52951 marked this pull request as draft September 19, 2024 07:54
@mj52951 mj52951 marked this pull request as ready for review September 19, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants