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

Refactor indexing #1302

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Refactor indexing #1302

merged 1 commit into from
Feb 7, 2025

Conversation

Tangui-Bitfly
Copy link
Contributor

@Tangui-Bitfly Tangui-Bitfly commented Jan 29, 2025

The main goal of this PR is to remove functionalities from db package and put them into there own object "easily" testable. Those changes aim at removing the basic indexing flow.
⚠️ Please do not focus on the code quality, I tried to change as little as possible to reduce risk of breaking something. The goal here is not to refactor everything but to separate things, remove coupling, introduce dependancies injections and a tests.

Overview of the new architecture

pkg
    commons
        db2
            database            // wrappers around database interractions
                databasetest    // test utility that provide an in mem database that database wrappers can use
            data                // handles all the interactions with the store `data` (indexing resulted objects)
            metadaupdates       // handles all the interactions with the store `metadaupdates` (balances, contracts, ...)
    executionlayer              // contains the indexer and the transformers      

Those are the main package to focus your review on.
Lot of the changed lines come from generated code around contract bindings. You can find those in internal/contracts, and I would suggest to not spend too much time on those beside maybe having a look at the readme here internal/contracts/README.md.

@Tangui-Bitfly Tangui-Bitfly force-pushed the refactor-indexing branch 3 times, most recently from 31274d8 to b06f30c Compare January 30, 2025 14:47
@Tangui-Bitfly Tangui-Bitfly marked this pull request as ready for review January 30, 2025 14:51
@Tangui-Bitfly Tangui-Bitfly force-pushed the refactor-indexing branch 6 times, most recently from 0e7877e to 1a39ae4 Compare February 5, 2025 13:12
Copy link

@mccreedy-bitfly mccreedy-bitfly left a comment

Choose a reason for hiding this comment

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

Generally looks OK. I would like to note that this CR is enormous, and so couldn't review it for functional changes. Since this review concentrates mostly on testing, I focused my efforts there, specifically on the structure and ensuring we were creating a good model that others could use moving forward.

Your suggestion to use table-based tests is a good one, and raises the quality and our confidence of the code as a whole. I have concerns however about the flexibility of the testing code if we were to for example change the underlying database model, and how much of these tests we would have to re-write. However, as we had 0 tests prior to this CR and because this is clearly already a measurable improvement, I believe that is out of scope and we can tackle that problem later.

Please avoid having "TODOs" in the code, as it is very unlikely we will go back and revisit them. Consider any TODOs as essentially final. Also, next time it would make sense to split such a large CR up in to smaller pieces, so that they are reviewable and can be iterated on more quickly. This saves time for both the author of the changes and the reviewers.

Comment on lines +317 to +319
},
// TODO add transfer bulk when bug fixed
}

Choose a reason for hiding this comment

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

Whats this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's related to a bug I found but did not fix.
https://github.com/gobitfly/beaconchain/blob/refactor-indexing/backend/pkg/executionlayer/transformer.go#L398
To sum up, erc1155 can be transferred in batch, in that case we only save the last batched transfer because we overwrite our indexed log for each batch elem.
There is no easy fix to that because we store those indexed log with key <tx_index>:<log_index> but in this case all the batched transfer have the same log index. So even if we fix our indexing, it will be overwritten in the db.

Comment on lines +49 to +58
/*
list of filter
data.ByMethod(method)
data.ByAsset(asset)
data.OnlyReceived()
data.OnlySent()
data.IgnoreTransactions()
data.IgnoreTransfers()
data.WithTimeRange(from, to)
*/

Choose a reason for hiding this comment

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

Why commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was more a test to showcase how to interact with the data.Store, I can remove it bring confusion.

Comment on lines +170 to +171
// BaseFeeChange: new(big.Int).Sub(new(big.Int).SetBytes(block.GetBaseFee()), new(big.Int).SetBytes(previous.GetBaseFee())).Bytes(),
// BlockUtilizationChange: new(big.Int).Sub(new(big.Int).Div(big.NewInt(int64(block.GetGasUsed())), big.NewInt(int64(block.GetGasLimit()))), new(big.Int).Div(big.NewInt(int64(previous.GetGasUsed())), big.NewInt(int64(previous.GetGasLimit())))).Bytes(),

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy pasted previous code

GasUsed: block.GetGasUsed(),
Time: block.GetTime(),
BaseFee: block.GetBaseFee(),
// Duration: uint64(block.GetTime().AsTime().Unix() - previous.GetTime().AsTime().Unix()),

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy pasted previous code

@Tangui-Bitfly Tangui-Bitfly merged commit 08050b7 into staging Feb 7, 2025
3 checks passed
@Tangui-Bitfly Tangui-Bitfly deleted the refactor-indexing branch February 7, 2025 10:09
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

Successfully merging this pull request may close these issues.

3 participants