-
Notifications
You must be signed in to change notification settings - Fork 130
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
Tx lookup skip #400
Conversation
plugin/evm/config.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
eth/ethconfig/config.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
core/blockchain.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
core/blockchain.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
responded: #400 (comment)
This is very close. I think it is functionally correct right now (just has unnecessary checks). |
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 */} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
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 */} |
There was a problem hiding this comment.
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.
closing in favor of #399 |
It modifies type of
TxLookupLimit
flag fromuint64
type toint64
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