Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e096dc1
refactor: block export
RodrigoVillar Dec 2, 2025
fa99ce5
chore: nits
RodrigoVillar Dec 3, 2025
a433a81
chore(reexecute/c): remove go bench from benchmark
RodrigoVillar Dec 2, 2025
c1203b1
chore: remove go bench in workflow
RodrigoVillar Dec 2, 2025
1935adf
chore: reduce diff
RodrigoVillar Dec 2, 2025
b508826
chore: use test context logger
RodrigoVillar Dec 4, 2025
953a76e
chore: clean up benchmarkTool
RodrigoVillar Dec 4, 2025
e6481ab
docs: benchmarking types
RodrigoVillar Dec 4, 2025
89abbde
refactor: use tc wherever convenient
RodrigoVillar Dec 4, 2025
5f55711
refactor: clean up result logging
RodrigoVillar Dec 4, 2025
afac7bc
fix: append unit to base name
RodrigoVillar Dec 4, 2025
a817e73
chore: remove unnecessary log
RodrigoVillar Dec 4, 2025
d0b95de
Merge branch 'master' into rodrigo/custom-benchmarks
RodrigoVillar Dec 9, 2025
828abe3
chore: nit
RodrigoVillar Dec 9, 2025
01f0663
chore: add back require
RodrigoVillar Dec 9, 2025
18b884d
chore: txt => json
RodrigoVillar Dec 9, 2025
d4639ff
docs: remove stale ref
RodrigoVillar Dec 9, 2025
718bc52
docs: nit
RodrigoVillar Dec 9, 2025
b26e8c4
chore: improve logResults()
RodrigoVillar Dec 9, 2025
3588978
chore: address PR review
RodrigoVillar Dec 9, 2025
9e7f54f
Merge branch 'master' into rodrigo/custom-benchmarks
RodrigoVillar Dec 10, 2025
bc78644
chore(reexecute/c): add back scraping of multiple metrics
RodrigoVillar Dec 10, 2025
29da042
Merge branch 'master' into rodrigo/add-back-multiple-metrics
RodrigoVillar Dec 16, 2025
7250778
chore: nit
RodrigoVillar Dec 16, 2025
43f9633
chore: nsPerMs => nanosecondsPerMillisecond
RodrigoVillar Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor: block export
  • Loading branch information
RodrigoVillar committed Dec 3, 2025
commit e096dc14192ae4f430cdb0887ca53fc653853571
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ tasks:
START_BLOCK: '{{.START_BLOCK}}'
END_BLOCK: '{{.END_BLOCK}}'
cmds:
- cmd: go test -timeout=0 -run=TestExportBlockRange github.com/ava-labs/avalanchego/tests/reexecute/c --block-dir-src={{.BLOCK_DIR_SRC}} --block-dir-dst={{.BLOCK_DIR_DST}} --start-block={{.START_BLOCK}} --end-block={{.END_BLOCK}}
- cmd: go run github.com/ava-labs/avalanchego/tests/reexecute/blockexport --block-dir-src={{.BLOCK_DIR_SRC}} --block-dir-dst={{.BLOCK_DIR_DST}} --start-block={{.START_BLOCK}} --end-block={{.END_BLOCK}}

export-dir-to-s3:
desc: Copies a directory to s3
Expand Down
62 changes: 62 additions & 0 deletions tests/reexecute/blockexport/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package main

import (
"flag"

"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/database/leveldb"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/reexecute"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/units"
)

var (
blockDirSrcArg string
blockDirDstArg string
startBlockArg uint64
endBlockArg uint64
chanSizeArg int
)

func init() {
flag.StringVar(&blockDirSrcArg, "block-dir-src", blockDirSrcArg, "Source block directory to copy from when running TestExportBlockRange.")
flag.StringVar(&blockDirDstArg, "block-dir-dst", blockDirDstArg, "Destination block directory to write blocks into when executing TestExportBlockRange.")
flag.Uint64Var(&startBlockArg, "start-block", 101, "Start block to begin execution (exclusive).")
flag.Uint64Var(&endBlockArg, "end-block", 200, "End block to end execution (inclusive).")
flag.IntVar(&chanSizeArg, "chan-size", 100, "Size of the channel to use for block processing.")

flag.Parse()
}

func main() {
tc := tests.NewTestContext(tests.NewDefaultLogger(""))
defer tc.RecoverAndExit()

r := require.New(tc)
blockChan, err := reexecute.CreateBlockChanFromLevelDB(blockDirSrcArg, startBlockArg, endBlockArg, chanSizeArg, tc.DeferCleanup)
r.NoError(err)

db, err := leveldb.New(blockDirDstArg, nil, logging.NoLog{}, prometheus.NewRegistry())
r.NoError(err)
tc.DeferCleanup(func() {
r.NoError(db.Close())
})

batch := db.NewBatch()
for blkResult := range blockChan {
r.NoError(batch.Put(reexecute.BlockKey(blkResult.Height), blkResult.BlockBytes))

if batch.Size() > 10*units.MiB {
r.NoError(batch.Write())
batch = db.NewBatch()
}
}

r.NoError(batch.Write())
}
37 changes: 1 addition & 36 deletions tests/reexecute/c/vm_reexecute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/metervm"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
)
Expand All @@ -55,8 +54,6 @@ var (

var (
blockDirArg string
blockDirSrcArg string
blockDirDstArg string
currentStateDirArg string
startBlockArg uint64
endBlockArg uint64
Expand Down Expand Up @@ -122,10 +119,6 @@ func TestMain(m *testing.M) {
flag.StringVar(&configNameArg, configKey, defaultConfigKey, fmt.Sprintf("Specifies the predefined config to use for the VM. Options include %s.", predefinedConfigOptionsStr))
flag.StringVar(&runnerNameArg, "runner", "dev", "Name of the runner executing this test. Added as a metric label and to the sub-benchmark's name to differentiate results on the runner key.")

// Flags specific to TestExportBlockRange.
flag.StringVar(&blockDirSrcArg, "block-dir-src", blockDirSrcArg, "Source block directory to copy from when running TestExportBlockRange.")
flag.StringVar(&blockDirDstArg, "block-dir-dst", blockDirDstArg, "Destination block directory to write blocks into when executing TestExportBlockRange.")

flag.Parse()

if metricsCollectorEnabledArg {
Expand Down Expand Up @@ -232,7 +225,7 @@ func benchmarkReexecuteRange(
zap.Int("chan-size", chanSize),
)

blockChan, err := reexecute.CreateBlockChanFromLevelDB(b, blockDir, startBlock, endBlock, chanSize)
blockChan, err := reexecute.CreateBlockChanFromLevelDB(blockDir, startBlock, endBlock, chanSize, b.Cleanup)
r.NoError(err)

dbLogger := tests.NewDefaultLogger("db")
Expand Down Expand Up @@ -477,34 +470,6 @@ func (e *vmExecutor) executeSequence(ctx context.Context, blkChan <-chan reexecu
return nil
}

func TestExportBlockRange(t *testing.T) {
exportBlockRange(t, blockDirSrcArg, blockDirDstArg, startBlockArg, endBlockArg, chanSizeArg)
}

func exportBlockRange(tb testing.TB, blockDirSrc string, blockDirDst string, startBlock, endBlock uint64, chanSize int) {
r := require.New(tb)
blockChan, err := reexecute.CreateBlockChanFromLevelDB(tb, blockDirSrc, startBlock, endBlock, chanSize)
r.NoError(err)

db, err := leveldb.New(blockDirDst, nil, logging.NoLog{}, prometheus.NewRegistry())
r.NoError(err)
tb.Cleanup(func() {
r.NoError(db.Close())
})

batch := db.NewBatch()
for blkResult := range blockChan {
r.NoError(batch.Put(reexecute.BlockKey(blkResult.Height), blkResult.BlockBytes))

if batch.Size() > 10*units.MiB {
r.NoError(batch.Write())
batch = db.NewBatch()
}
}

r.NoError(batch.Write())
}

type consensusMetrics struct {
lastAcceptedHeight prometheus.Gauge
}
Expand Down
9 changes: 3 additions & 6 deletions tests/reexecute/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ package reexecute
import (
"encoding/binary"
"fmt"
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/leveldb"
Expand All @@ -29,16 +27,15 @@ type BlockResult struct {
// Blocks are read sequentially and sent to the returned channel as BlockResult values.
//
// Any validation errors or iteration errors are sent as BlockResult with Err set, then the channel is closed.
func CreateBlockChanFromLevelDB(tb testing.TB, sourceDir string, startBlock, endBlock uint64, chanSize int) (<-chan BlockResult, error) {
r := require.New(tb)
func CreateBlockChanFromLevelDB(sourceDir string, startBlock, endBlock uint64, chanSize int, cleanup func(func())) (<-chan BlockResult, error) {
ch := make(chan BlockResult, chanSize)

db, err := leveldb.New(sourceDir, nil, logging.NoLog{}, prometheus.NewRegistry())
if err != nil {
return nil, fmt.Errorf("failed to create leveldb database from %q: %w", sourceDir, err)
}
tb.Cleanup(func() {
r.NoError(db.Close())
cleanup(func() {
db.Close()
})

go func() {
Expand Down
Loading