mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
79ed8cad35
This change introduces additional processes to manage snapshot uploading for E2 snapshots: ## erigon snapshots upload The `snapshots uploader` command starts a version of erigon customized for uploading snapshot files to a remote location. It breaks the stage execution process after the senders stage and then uses the snapshot stage to send uploaded headers, bodies and (in the case of polygon) bor spans and events to snapshot files. Because this process avoids execution in run signifigantly faster than a standard erigon configuration. The uploader uses rclone to send seedable (100K or 500K blocks) to a remote storage location specified in the rclone config file. The **uploader** is configured to minimize disk usage by doing the following: * It removes snapshots once they are loaded * It aggressively prunes the database once entities are transferred to snapshots in addition to this it has the following performance related features: * maximizes the workers allocated to snapshot processing to improve throughput * Can be started from scratch by downloading the latest snapshots from the remote location to seed processing ## snapshots command Is a stand alone command for managing remote snapshots it has the following sub commands * **cmp** - compare snapshots * **copy** - copy snapshots * **verify** - verify snapshots * **manifest** - manage the manifest file in the root of remote snapshot locations * **torrent** - manage snapshot torrent files
227 lines
8.9 KiB
Go
227 lines
8.9 KiB
Go
package freezeblocks
|
|
|
|
import (
|
|
"context"
|
|
"encoding/binary"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common/length"
|
|
"github.com/ledgerwatch/erigon-lib/compress"
|
|
"github.com/ledgerwatch/erigon-lib/downloader/snaptype"
|
|
"github.com/ledgerwatch/erigon-lib/recsplit"
|
|
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
|
"github.com/ledgerwatch/erigon/turbo/testlog"
|
|
)
|
|
|
|
func TestBlockReaderLastFrozenSpanIDWhenSegmentFilesArePresent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger)
|
|
createTestSegmentFile(t, 0, 500_000, snaptype.BorSpans, dir, 1, logger)
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err := borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(78), blockReader.LastFrozenSpanID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenSpanIDWhenSegmentFilesAreNotPresent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err := borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(0), blockReader.LastFrozenSpanID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenSpanIDReturnsLastSegWithIdx(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger)
|
|
createTestBorEventSegmentFile(t, 500_000, 1_000_000, 264, dir, logger)
|
|
createTestBorEventSegmentFile(t, 1_000_000, 1_500_000, 528, dir, logger)
|
|
createTestSegmentFile(t, 0, 500_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 500_000, 1_000_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 1_000_000, 1_500_000, snaptype.BorSpans, dir, 1, logger)
|
|
// delete idx file for last bor span segment to simulate segment with missing idx file
|
|
idxFileToDelete := filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, snaptype.BorSpans.String()))
|
|
err := os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err = borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(156), blockReader.LastFrozenSpanID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenSpanIDReturnsZeroWhenAllSegmentsDoNotHaveIdx(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger)
|
|
createTestBorEventSegmentFile(t, 500_000, 1_000_000, 264, dir, logger)
|
|
createTestBorEventSegmentFile(t, 1_000_000, 1_500_000, 528, dir, logger)
|
|
createTestSegmentFile(t, 0, 500_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 500_000, 1_000_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 1_000_000, 1_500_000, snaptype.BorSpans, dir, 1, logger)
|
|
// delete idx file for all bor span segments to simulate segments with missing idx files
|
|
idxFileToDelete := filepath.Join(dir, snaptype.IdxFileName(1, 1, 500_000, snaptype.BorSpans.String()))
|
|
err := os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
idxFileToDelete = filepath.Join(dir, snaptype.IdxFileName(1, 500_000, 1_000_000, snaptype.BorSpans.String()))
|
|
err = os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
idxFileToDelete = filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, snaptype.BorSpans.String()))
|
|
err = os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err = borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(0), blockReader.LastFrozenSpanID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenEventIDWhenSegmentFilesArePresent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger)
|
|
createTestSegmentFile(t, 0, 500_000, snaptype.BorSpans, dir, 1, logger)
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err := borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(132), blockReader.LastFrozenEventID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenEventIDWhenSegmentFilesAreNotPresent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err := borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(0), blockReader.LastFrozenEventID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenEventIDReturnsLastSegWithIdx(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger)
|
|
createTestBorEventSegmentFile(t, 500_000, 1_000_000, 264, dir, logger)
|
|
createTestBorEventSegmentFile(t, 1_000_000, 1_500_000, 528, dir, logger)
|
|
createTestSegmentFile(t, 0, 500_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 500_000, 1_000_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 1_000_000, 1_500_000, snaptype.BorSpans, dir, 1, logger)
|
|
// delete idx file for last bor events segment to simulate segment with missing idx file
|
|
idxFileToDelete := filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, snaptype.BorEvents.String()))
|
|
err := os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err = borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(264), blockReader.LastFrozenEventID())
|
|
}
|
|
|
|
func TestBlockReaderLastFrozenEventIDReturnsZeroWhenAllSegmentsDoNotHaveIdx(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testlog.Logger(t, log.LvlInfo)
|
|
dir := t.TempDir()
|
|
createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger)
|
|
createTestBorEventSegmentFile(t, 500_000, 1_000_000, 264, dir, logger)
|
|
createTestBorEventSegmentFile(t, 1_000_000, 1_500_000, 528, dir, logger)
|
|
createTestSegmentFile(t, 0, 500_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 500_000, 1_000_000, snaptype.BorSpans, dir, 1, logger)
|
|
createTestSegmentFile(t, 1_000_000, 1_500_000, snaptype.BorSpans, dir, 1, logger)
|
|
// delete idx files for all bor events segment to simulate segment files with missing idx files
|
|
idxFileToDelete := filepath.Join(dir, snaptype.IdxFileName(1, 0, 500_000, snaptype.BorEvents.String()))
|
|
err := os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
idxFileToDelete = filepath.Join(dir, snaptype.IdxFileName(1, 500_000, 1_000_000, snaptype.BorEvents.String()))
|
|
err = os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
idxFileToDelete = filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, snaptype.BorEvents.String()))
|
|
err = os.Remove(idxFileToDelete)
|
|
require.NoError(t, err)
|
|
borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, 1, logger)
|
|
defer borRoSnapshots.Close()
|
|
err = borRoSnapshots.ReopenFolder()
|
|
require.NoError(t, err)
|
|
|
|
blockReader := &BlockReader{borSn: borRoSnapshots}
|
|
require.Equal(t, uint64(0), blockReader.LastFrozenEventID())
|
|
}
|
|
|
|
func createTestBorEventSegmentFile(t *testing.T, from, to, eventId uint64, dir string, logger log.Logger) {
|
|
compressor, err := compress.NewCompressor(
|
|
context.Background(),
|
|
"test",
|
|
filepath.Join(dir, snaptype.SegmentFileName(1, from, to, snaptype.BorEvents)),
|
|
dir,
|
|
100,
|
|
1,
|
|
log.LvlDebug,
|
|
logger,
|
|
)
|
|
require.NoError(t, err)
|
|
defer compressor.Close()
|
|
compressor.DisableFsync()
|
|
data := make([]byte, length.Hash+length.BlockNum+8)
|
|
binary.BigEndian.PutUint64(data[length.Hash+length.BlockNum:length.Hash+length.BlockNum+8], eventId)
|
|
err = compressor.AddWord(data)
|
|
require.NoError(t, err)
|
|
err = compressor.Compress()
|
|
require.NoError(t, err)
|
|
idx, err := recsplit.NewRecSplit(
|
|
recsplit.RecSplitArgs{
|
|
KeyCount: 1,
|
|
BucketSize: 10,
|
|
TmpDir: dir,
|
|
IndexFile: filepath.Join(dir, snaptype.IdxFileName(1, from, to, snaptype.BorEvents.String())),
|
|
LeafSize: 8,
|
|
},
|
|
logger,
|
|
)
|
|
require.NoError(t, err)
|
|
defer idx.Close()
|
|
idx.DisableFsync()
|
|
err = idx.AddKey([]byte{1}, 0)
|
|
require.NoError(t, err)
|
|
err = idx.Build(context.Background())
|
|
require.NoError(t, err)
|
|
}
|