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

Tx lookup skip #400

Closed
wants to merge 13 commits into from
Closed

Tx lookup skip #400

wants to merge 13 commits into from

Conversation

ceyonur
Copy link
Collaborator

@ceyonur ceyonur commented Nov 21, 2023

It modifies type of TxLookupLimit flag from uint64 type to int64 with support for negative numbers which indicates to skip tx indexing.

Using negative number also means stop the tx unindexer from removing old indices. This is because unindexer still writes tail to DB and tries to keep up with the latest tip (even though the actual tx indexing is not performed on DB). Stopping (

Closes: #397

@ceyonur ceyonur added the enhancement New feature or request label Nov 21, 2023
@ceyonur ceyonur self-assigned this Nov 21, 2023
@ceyonur ceyonur mentioned this pull request Nov 21, 2023
@ceyonur ceyonur marked this pull request as ready for review November 21, 2023 00:20
@@ -193,9 +196,10 @@ type Config struct {

// TxLookupLimit is the maximum number of blocks from head whose tx indices
// are reserved:
// * -1: means skip tx indexing
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also clarify that no txs will be cleaned up in this mode here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

same nit here to align the formatting of -1 with the values below

@@ -153,7 +153,8 @@ type Config struct {

// TxLookupLimit is the maximum number of blocks from head whose tx indices
// are reserved:
// * -1: means skip tx indexing
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: align formatting with the values below

aaronbuchwald
aaronbuchwald previously approved these changes Nov 21, 2023
@@ -413,7 +413,10 @@ func NewBlockChain(
// unindexBlocks unindexes transactions depending on user configuration
func (bc *BlockChain) unindexBlocks(tail uint64, head uint64, done chan struct{}) {
start := time.Now()
txLookupLimit := bc.cacheConfig.TxLookupLimit
if bc.cacheConfig.TxLookupLimit < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because unindexBlocks is spawned by dispatchTxUnindexer, do we need to worry about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup correct. I put it to be extra safe (in case this is directly called by tests), but I guess it's fine to just add it as a comment.

@@ -431,7 +434,10 @@ func (bc *BlockChain) unindexBlocks(tail uint64, head uint64, done chan struct{}
// Meaning that this function should never be called.
func (bc *BlockChain) dispatchTxUnindexer() {
defer bc.wg.Done()
txLookupLimit := bc.cacheConfig.TxLookupLimit
if bc.cacheConfig.TxLookupLimit < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because we check TxLookupLimit before spawning dispatchTxUnindexer, do we need to worry about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

responded: #400 (comment)

@patrick-ogrady
Copy link
Contributor

This is very close. I think it is functionally correct right now (just has unnecessary checks).

Comment on lines +738 to +741
limit := []int64{130 /* 129 + 1 reserve all */, 64 /* drop stale */, 32 /* shorten history */, -1 /* skip indexing */, -1 /* skip indexing */}
tails := []uint64{0 /* reserve all */, 67 /* 130 - 64 + 1 */, 100 /* 131 - 32 + 1 */, 100 /* skip indexing */, 100 /* skip indexing */}
// lastIndexed should stop with limit=-1 otherwise it should be the current block number
lastIndexed := []uint64{129 /* current block number */, 130 /* current block number */, 131 /* current block number */, 131 /* skip indexing */, 131 /* skip indexing */}
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should convert this to a struct in the future. It was a bit hard to follow before and going from 2 to 3 values makes it a bit harder to follow.

Copy link
Collaborator

Choose a reason for hiding this comment

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

might be nice to do this as part of this PR (or immediate follow-up), doesn't seem like a big change.

@@ -160,7 +160,7 @@ type CacheConfig struct {
SnapshotVerify bool // Verify generated snapshots
Preimages bool // Whether to store preimage of trie key to the disk
AcceptedCacheSize int // Depth of accepted headers cache and accepted logs cache at the accepted tip
TxLookupLimit uint64 // Number of recent blocks for which to maintain transaction lookup indices
TxLookupLimit int64 // Number of recent blocks for which to maintain transaction lookup indices
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add a new parameter liketx-indexing-disabled instead of adding -1?
Seems this would simplify validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In that case we should validate it against TxLookupLimit and it might be confusing to use both of them at the same time.

bc.wg.Add(1)
go bc.dispatchTxUnindexer()
}
return bc, nil
}

// unindexBlocks unindexes transactions depending on user configuration
// Invariant: This should not be called if TxLookupLimit is negative.
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be clearer to take a uint param here & to dispatchTxUnindexer?

@@ -485,7 +487,10 @@ func (bc *BlockChain) dispatchTxUnindexer() {
// - updating the acceptor tip index
func (bc *BlockChain) writeBlockAcceptedIndices(b *types.Block) error {
batch := bc.db.NewBatch()
rawdb.WriteTxLookupEntriesByBlock(batch, b)
// -1 means skip writing tx lookup entries
if bc.cacheConfig.TxLookupLimit != -1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's be consistent with using < 0 here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I specifically kept it -1 to make it consistent with docs/comments.

@@ -749,7 +775,7 @@ func TestTransactionIndices(t *testing.T) {
// TestCanonicalHashMarker tests all the canonical hash markers are updated/deleted
// correctly in case reorg is called.
func TestCanonicalHashMarker(t *testing.T) {
var cases = []struct {
cases := []struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we revert the unnecessary changes?

Comment on lines +738 to +741
limit := []int64{130 /* 129 + 1 reserve all */, 64 /* drop stale */, 32 /* shorten history */, -1 /* skip indexing */, -1 /* skip indexing */}
tails := []uint64{0 /* reserve all */, 67 /* 130 - 64 + 1 */, 100 /* 131 - 32 + 1 */, 100 /* skip indexing */, 100 /* skip indexing */}
// lastIndexed should stop with limit=-1 otherwise it should be the current block number
lastIndexed := []uint64{129 /* current block number */, 130 /* current block number */, 131 /* current block number */, 131 /* skip indexing */, 131 /* skip indexing */}
Copy link
Collaborator

Choose a reason for hiding this comment

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

might be nice to do this as part of this PR (or immediate follow-up), doesn't seem like a big change.

@ceyonur
Copy link
Collaborator Author

ceyonur commented Nov 21, 2023

closing in favor of #399

@ceyonur ceyonur closed this Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support omitting writing tx indices
4 participants