mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
fix transaction history flag (#1169)
Co-authored-by: Darioush Jalali <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
Darioush Jalali
parent
03aea9d701
commit
7703c87569
+7
-7
@@ -183,7 +183,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
|
||||
TransactionHistory uint64 // Number of recent blocks for which to maintain transaction lookup indices
|
||||
SkipTxIndexing bool // Whether to skip transaction indexing
|
||||
StateHistory uint64 // Number of blocks from head whose state histories are reserved.
|
||||
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
|
||||
@@ -448,7 +448,7 @@ func NewBlockChain(
|
||||
bc.warmAcceptedCaches()
|
||||
|
||||
// if txlookup limit is 0 (uindexing disabled), we don't need to repair the tx index tail.
|
||||
if bc.cacheConfig.TxLookupLimit != 0 {
|
||||
if bc.cacheConfig.TransactionHistory != 0 {
|
||||
latestStateSynced := rawdb.GetLatestSyncPerformed(bc.db)
|
||||
bc.setTxIndexTail(latestStateSynced)
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func NewBlockChain(
|
||||
go bc.startAcceptor()
|
||||
|
||||
// Start tx indexer/unindexer if required.
|
||||
if bc.cacheConfig.TxLookupLimit != 0 {
|
||||
if bc.cacheConfig.TransactionHistory != 0 {
|
||||
bc.wg.Add(1)
|
||||
var (
|
||||
headCh = make(chan ChainEvent, 1) // Buffered to avoid locking up the event feed
|
||||
@@ -480,7 +480,7 @@ 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
|
||||
txLookupLimit := bc.cacheConfig.TransactionHistory
|
||||
bc.txIndexTailLock.Lock()
|
||||
defer func() {
|
||||
txUnindexTimer.Inc(time.Since(start).Milliseconds())
|
||||
@@ -506,7 +506,7 @@ func (bc *BlockChain) unindexBlocks(tail uint64, head uint64, done chan struct{}
|
||||
// Invariant: If TxLookupLimit is 0, it means all tx indices will be preserved.
|
||||
// Meaning that this function should never be called.
|
||||
func (bc *BlockChain) maintainTxIndex(headCh <-chan ChainEvent) {
|
||||
txLookupLimit := bc.cacheConfig.TxLookupLimit
|
||||
txLookupLimit := bc.cacheConfig.TransactionHistory
|
||||
|
||||
// If the user just upgraded to a new version which supports transaction
|
||||
// index pruning, write the new tail and remove anything older.
|
||||
@@ -952,7 +952,7 @@ func (bc *BlockChain) ValidateCanonicalChain() error {
|
||||
// that the transactions have been indexed, if we are checking below the last accepted
|
||||
// block.
|
||||
shouldIndexTxs := !bc.cacheConfig.SkipTxIndexing &&
|
||||
(bc.cacheConfig.TxLookupLimit == 0 || bc.lastAccepted.NumberU64() < current.Number.Uint64()+bc.cacheConfig.TxLookupLimit)
|
||||
(bc.cacheConfig.TransactionHistory == 0 || bc.lastAccepted.NumberU64() < current.Number.Uint64()+bc.cacheConfig.TransactionHistory)
|
||||
if current.Number.Uint64() <= bc.lastAccepted.NumberU64() && shouldIndexTxs {
|
||||
// Ensure that all of the transactions have been stored correctly in the canonical
|
||||
// chain
|
||||
@@ -2217,7 +2217,7 @@ func (bc *BlockChain) ResetToStateSyncedBlock(block *types.Block) error {
|
||||
}
|
||||
|
||||
// if txlookup limit is 0 (uindexing disabled), we don't need to repair the tx index tail.
|
||||
if bc.cacheConfig.TxLookupLimit != 0 {
|
||||
if bc.cacheConfig.TransactionHistory != 0 {
|
||||
bc.setTxIndexTail(block.NumberU64())
|
||||
}
|
||||
|
||||
|
||||
@@ -609,7 +609,7 @@ func TestTransactionIndices(t *testing.T) {
|
||||
}
|
||||
for i, l := range limits {
|
||||
t.Run(fmt.Sprintf("test-%d, limit: %d", i+1, l), func(t *testing.T) {
|
||||
conf.TxLookupLimit = l
|
||||
conf.TransactionHistory = l
|
||||
|
||||
chain, err := createBlockChain(chainDB, conf, gspec, lastAcceptedBlock.Hash())
|
||||
require.NoError(err)
|
||||
@@ -701,19 +701,19 @@ func TestTransactionSkipIndexing(t *testing.T) {
|
||||
chain.Stop()
|
||||
|
||||
// test2: specify lookuplimit with tx index skipping enabled. Blocks should not be indexed but tail should be updated.
|
||||
conf.TxLookupLimit = 2
|
||||
conf.TransactionHistory = 2
|
||||
chainDB = rawdb.NewMemoryDatabase()
|
||||
chain, err = createAndInsertChain(chainDB, conf, gspec, blocks, common.Hash{},
|
||||
func(b *types.Block) {
|
||||
bNumber := b.NumberU64()
|
||||
tail := bNumber - conf.TxLookupLimit + 1
|
||||
tail := bNumber - conf.TransactionHistory + 1
|
||||
checkTxIndicesHelper(t, &tail, bNumber+1, bNumber+1, bNumber, chainDB, false) // check all indices has been skipped
|
||||
})
|
||||
require.NoError(err)
|
||||
chain.Stop()
|
||||
|
||||
// test3: tx index skipping and unindexer disabled. Blocks should be indexed and tail should be updated.
|
||||
conf.TxLookupLimit = 0
|
||||
conf.TransactionHistory = 0
|
||||
conf.SkipTxIndexing = false
|
||||
chainDB = rawdb.NewMemoryDatabase()
|
||||
chain, err = createAndInsertChain(chainDB, conf, gspec, blocks, common.Hash{},
|
||||
@@ -726,12 +726,12 @@ func TestTransactionSkipIndexing(t *testing.T) {
|
||||
|
||||
// now change tx index skipping to true and check that the indices are skipped for the last block
|
||||
// and old indices are removed up to the tail, but [tail, current) indices are still there.
|
||||
conf.TxLookupLimit = 2
|
||||
conf.TransactionHistory = 2
|
||||
conf.SkipTxIndexing = true
|
||||
chain, err = createAndInsertChain(chainDB, conf, gspec, blocks2[0:1], chain.CurrentHeader().Hash(),
|
||||
func(b *types.Block) {
|
||||
bNumber := b.NumberU64()
|
||||
tail := bNumber - conf.TxLookupLimit + 1
|
||||
tail := bNumber - conf.TransactionHistory + 1
|
||||
checkTxIndicesHelper(t, &tail, tail, bNumber-1, bNumber, chainDB, false)
|
||||
})
|
||||
require.NoError(err)
|
||||
@@ -865,7 +865,7 @@ func TestTxLookupBlockChain(t *testing.T) {
|
||||
SnapshotLimit: 256,
|
||||
SnapshotNoBuild: true, // Ensure the test errors if snapshot initialization fails
|
||||
AcceptorQueueLimit: 64, // ensure channel doesn't block
|
||||
TxLookupLimit: 5,
|
||||
TransactionHistory: 5,
|
||||
}
|
||||
createTxLookupBlockChain := func(db ethdb.Database, gspec *Genesis, lastAcceptedHash common.Hash) (*BlockChain, error) {
|
||||
return createBlockChain(db, cacheConf, gspec, lastAcceptedHash)
|
||||
@@ -888,7 +888,7 @@ func TestTxLookupSkipIndexingBlockChain(t *testing.T) {
|
||||
SnapshotLimit: 256,
|
||||
SnapshotNoBuild: true, // Ensure the test errors if snapshot initialization fails
|
||||
AcceptorQueueLimit: 64, // ensure channel doesn't block
|
||||
TxLookupLimit: 5,
|
||||
TransactionHistory: 5,
|
||||
SkipTxIndexing: true,
|
||||
}
|
||||
createTxLookupBlockChain := func(db ethdb.Database, gspec *Genesis, lastAcceptedHash common.Hash) (*BlockChain, error) {
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@ func New(
|
||||
SnapshotNoBuild: config.SkipSnapshotRebuild,
|
||||
Preimages: config.Preimages,
|
||||
AcceptedCacheSize: config.AcceptedCacheSize,
|
||||
TxLookupLimit: config.TxLookupLimit,
|
||||
TransactionHistory: config.TransactionHistory,
|
||||
SkipTxIndexing: config.SkipTxIndexing,
|
||||
StateHistory: config.StateHistory,
|
||||
StateScheme: config.StateScheme,
|
||||
|
||||
@@ -158,12 +158,10 @@ type Config struct {
|
||||
// identical state with the pre-upgrade ruleset.
|
||||
SkipUpgradeCheck bool
|
||||
|
||||
// TxLookupLimit is the maximum number of blocks from head whose tx indices
|
||||
// TransactionHistory is the maximum number of blocks from head whose tx indices
|
||||
// are reserved:
|
||||
// * 0: means no limit
|
||||
// * N: means N block limit [HEAD-N+1, HEAD] and delete extra indexes
|
||||
// Deprecated, use 'TransactionHistory' instead.
|
||||
TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
|
||||
TransactionHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
|
||||
StateHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose state histories are reserved.
|
||||
StateScheme string `toml:",omitempty"` // State scheme used to store ethereum state and merkle trie nodes on top
|
||||
|
||||
@@ -456,7 +456,7 @@ func testSyncerVM(t *testing.T, vmSetup *syncVMSetup, test syncTest) {
|
||||
}
|
||||
|
||||
// tail should be the last block synced
|
||||
if syncerVM.ethConfig.TxLookupLimit != 0 {
|
||||
if syncerVM.ethConfig.TransactionHistory != 0 {
|
||||
tail := lastSyncedBlock.NumberU64()
|
||||
|
||||
core.CheckTxIndices(t, &tail, tail, syncerVM.chaindb, true)
|
||||
@@ -484,8 +484,8 @@ func testSyncerVM(t *testing.T, vmSetup *syncVMSetup, test syncTest) {
|
||||
}
|
||||
},
|
||||
func(block *types.Block) {
|
||||
if syncerVM.ethConfig.TxLookupLimit != 0 {
|
||||
tail := block.NumberU64() - syncerVM.ethConfig.TxLookupLimit + 1
|
||||
if syncerVM.ethConfig.TransactionHistory != 0 {
|
||||
tail := block.NumberU64() - syncerVM.ethConfig.TransactionHistory + 1
|
||||
// tail should be the minimum last synced block, since we skipped it to the last block
|
||||
if tail < lastSyncedBlock.NumberU64() {
|
||||
tail = lastSyncedBlock.NumberU64()
|
||||
@@ -517,8 +517,8 @@ func testSyncerVM(t *testing.T, vmSetup *syncVMSetup, test syncTest) {
|
||||
}
|
||||
},
|
||||
func(block *types.Block) {
|
||||
if syncerVM.ethConfig.TxLookupLimit != 0 {
|
||||
tail := block.NumberU64() - syncerVM.ethConfig.TxLookupLimit + 1
|
||||
if syncerVM.ethConfig.TransactionHistory != 0 {
|
||||
tail := block.NumberU64() - syncerVM.ethConfig.TransactionHistory + 1
|
||||
// tail should be the minimum last synced block, since we skipped it to the last block
|
||||
if tail < lastSyncedBlock.NumberU64() {
|
||||
tail = lastSyncedBlock.NumberU64()
|
||||
|
||||
+1
-1
@@ -433,7 +433,7 @@ func (vm *VM) Initialize(
|
||||
vm.ethConfig.CommitInterval = vm.config.CommitInterval
|
||||
vm.ethConfig.SkipUpgradeCheck = vm.config.SkipUpgradeCheck
|
||||
vm.ethConfig.AcceptedCacheSize = vm.config.AcceptedCacheSize
|
||||
vm.ethConfig.TxLookupLimit = vm.config.TxLookupLimit
|
||||
vm.ethConfig.TransactionHistory = vm.config.TransactionHistory
|
||||
vm.ethConfig.SkipTxIndexing = vm.config.SkipTxIndexing
|
||||
|
||||
// Create directory for offline pruning
|
||||
|
||||
Reference in New Issue
Block a user