mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/blockchain: address review concerns
This commit is contained in:
parent
4ed4b9ac32
commit
5a4a65f959
1 changed files with 6 additions and 5 deletions
|
|
@ -2242,12 +2242,15 @@ func BenchmarkBlockChain_1x1000Executions(b *testing.B) {
|
||||||
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn, dataFn)
|
benchmarkLargeNumberOfValueToNonexisting(b, numTxs, numBlocks, recipientFn, dataFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that importing a some old blocks, where the first one is before the
|
// Tests that importing a some old blocks, where all blocks are before the
|
||||||
// pruning point.
|
// pruning point.
|
||||||
// This internally leads to a sidechain import, since the blocks trigger an
|
// This internally leads to a sidechain import, since the blocks trigger an
|
||||||
// ErrPrunedAncestor error.
|
// ErrPrunedAncestor error.
|
||||||
|
// This may e.g. happen if
|
||||||
|
// 1. Downloader rollbacks a batch of inserted blocks and exits
|
||||||
|
// 2. Downloader starts to sync again
|
||||||
|
// 3. The blocks fetched are all known and canonical blocks
|
||||||
func TestSideImportPrunedBlocks(t *testing.T) {
|
func TestSideImportPrunedBlocks(t *testing.T) {
|
||||||
|
|
||||||
// Generate a canonical chain to act as the main dataset
|
// Generate a canonical chain to act as the main dataset
|
||||||
engine := ethash.NewFaker()
|
engine := ethash.NewFaker()
|
||||||
db := rawdb.NewMemoryDatabase()
|
db := rawdb.NewMemoryDatabase()
|
||||||
|
|
@ -2272,15 +2275,13 @@ func TestSideImportPrunedBlocks(t *testing.T) {
|
||||||
if chain.HasBlockAndState(lastPrunedBlock.Hash(), lastPrunedBlock.NumberU64()) {
|
if chain.HasBlockAndState(lastPrunedBlock.Hash(), lastPrunedBlock.NumberU64()) {
|
||||||
t.Errorf("Block %d not pruned", lastPrunedBlock.NumberU64())
|
t.Errorf("Block %d not pruned", lastPrunedBlock.NumberU64())
|
||||||
}
|
}
|
||||||
|
|
||||||
firstNonPrunedBlock := blocks[len(blocks)-TriesInMemory]
|
firstNonPrunedBlock := blocks[len(blocks)-TriesInMemory]
|
||||||
// Verify firstNonPrunedBlock is not pruned
|
// Verify firstNonPrunedBlock is not pruned
|
||||||
if !chain.HasBlockAndState(firstNonPrunedBlock.Hash(), firstNonPrunedBlock.NumberU64()) {
|
if !chain.HasBlockAndState(firstNonPrunedBlock.Hash(), firstNonPrunedBlock.NumberU64()) {
|
||||||
t.Errorf("Block %d pruned", firstNonPrunedBlock.NumberU64())
|
t.Errorf("Block %d pruned", firstNonPrunedBlock.NumberU64())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now re-import some old blocks
|
// Now re-import some old blocks
|
||||||
blockToReimport := blocks[5 : len(blocks)-TriesInMemory]
|
blockToReimport := blocks[5 : 8]
|
||||||
_, err = chain.InsertChain(blockToReimport)
|
_, err = chain.InsertChain(blockToReimport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error, %v", err)
|
t.Errorf("Got error, %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue