les: historical data garbage collection (#19570)
This change introduces garbage collection for the light client. Historical chain data is deleted periodically. If you want to disable the GC, use the --light.nopruning flag.
This commit is contained in:
@ -23,6 +23,7 @@ import (
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@ -424,3 +425,35 @@ func TestAncientStorage(t *testing.T) {
|
||||
t.Fatalf("invalid td returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalHashIteration(t *testing.T) {
|
||||
var cases = []struct {
|
||||
from, to uint64
|
||||
limit int
|
||||
expect []uint64
|
||||
}{
|
||||
{1, 8, 0, nil},
|
||||
{1, 8, 1, []uint64{1}},
|
||||
{1, 8, 10, []uint64{1, 2, 3, 4, 5, 6, 7}},
|
||||
{1, 9, 10, []uint64{1, 2, 3, 4, 5, 6, 7, 8}},
|
||||
{2, 9, 10, []uint64{2, 3, 4, 5, 6, 7, 8}},
|
||||
{9, 10, 10, nil},
|
||||
}
|
||||
// Test empty db iteration
|
||||
db := NewMemoryDatabase()
|
||||
numbers, _ := ReadAllCanonicalHashes(db, 0, 10, 10)
|
||||
if len(numbers) != 0 {
|
||||
t.Fatalf("No entry should be returned to iterate an empty db")
|
||||
}
|
||||
// Fill database with testing data.
|
||||
for i := uint64(1); i <= 8; i++ {
|
||||
WriteCanonicalHash(db, common.Hash{}, i)
|
||||
WriteTd(db, common.Hash{}, i, big.NewInt(10)) // Write some interferential data
|
||||
}
|
||||
for i, c := range cases {
|
||||
numbers, _ := ReadAllCanonicalHashes(db, c.from, c.to, c.limit)
|
||||
if !reflect.DeepEqual(numbers, c.expect) {
|
||||
t.Fatalf("Case %d failed, want %v, got %v", i, c.expect, numbers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user