Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks backfilling option - 0 Empty implementations #2343

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6108e6a
block backfilling basics: interface, metervm tracevm, rpcchainvm
abi87 Nov 20, 2023
76dbcc4
temporarily cut coreth dependency
abi87 Oct 30, 2023
586dcbc
bumped coreth version
abi87 Nov 20, 2023
a4bfddd
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 21, 2023
16b8cef
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 22, 2023
f67ba0a
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 23, 2023
b34e974
temporarily cut coreth dependency
abi87 Oct 30, 2023
e8fe105
bumped coreth version
abi87 Nov 23, 2023
33e0829
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 27, 2023
f8b3178
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 28, 2023
4b38a58
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 29, 2023
f6c3bb0
Merge branch 'dev' into backfill_blocks_0
abi87 Nov 30, 2023
518f88b
Merge branch 'dev' into backfill_blocks_0
abi87 Dec 3, 2023
143934e
temporarily cut coreth dependency
abi87 Oct 30, 2023
78cc14b
bumped coreth version
abi87 Dec 3, 2023
76ce1e1
Merge branch 'dev' into backfill_blocks_0
abi87 Dec 3, 2023
69199fc
Merge branch 'dev' into backfill_blocks_0
abi87 Dec 9, 2023
fa7f02d
bumped coreth version
abi87 Dec 9, 2023
0c9b208
Merge branch 'dev' into backfill_blocks_0
abi87 Dec 11, 2023
d6f49fc
Merge branch 'dev' into backfill_blocks_0
abi87 Dec 27, 2023
5b058f7
temporarily cut coreth dependency
abi87 Oct 30, 2023
bf308c8
bumped coreth version
abi87 Dec 27, 2023
0720496
Merge branch 'dev' into backfill_blocks_0
abi87 Dec 27, 2023
3e70e97
Merge branch 'dev' into backfill_blocks_0
abi87 Jan 2, 2024
6c1a40a
cut coreth dependency
abi87 Oct 30, 2023
fa12327
bumped coreth version
abi87 Jan 2, 2024
ca3c6e9
regenerated mock
abi87 Jan 2, 2024
004c787
Merge branch 'dev' into backfill_blocks_0
abi87 Jan 4, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/DataDog/zstd v1.5.2
github.com/Microsoft/go-winio v0.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/ava-labs/coreth v0.12.9-rc.0
github.com/ava-labs/coreth v0.12.9-rc.0.0.20231120093327-25efed25b396
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.12.9-rc.0 h1:Xvk/iJTY2MSBkkiOs9Eo92nxd67VXzRjaC/WmQXRIb0=
github.com/ava-labs/coreth v0.12.9-rc.0/go.mod h1:rECKQfGFDeodrwGPlJSvFUJDbVr30jSMIVjQLi6pNX4=
github.com/ava-labs/coreth v0.12.9-rc.0.0.20231120093327-25efed25b396 h1:q8wdwg2osP5xs+hj681FU8IDsE/ZrE58tFKXl5NbXJc=
github.com/ava-labs/coreth v0.12.9-rc.0.0.20231120093327-25efed25b396/go.mod h1:lAjiEbIj6wQSELIday+toGa2bMkA0birr3h6O2C4mY8=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 h1:mg9Uw6oZFJKytJxgxnl3uxZOs/SB8CVHg6Io4Tf99Zc=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
832 changes: 544 additions & 288 deletions proto/pb/vm/vm.pb.go

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions proto/pb/vm/vm_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions proto/vm/vm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ service VM {
// [summaryHeight].
rpc GetStateSummary(GetStateSummaryRequest) returns (GetStateSummaryResponse);

// BackfillBlocksEnabled indicates whether the block backfilling is enabled for this VM.
rpc BackfillBlocksEnabled(google.protobuf.Empty) returns (BackfillBlocksEnabledResponse);
// BackfillBlocks pushes to the VM downloaded blocks to be backfilled.
rpc BackfillBlocks(BackfillBlocksRequest) returns (BackfillBlocksResponse);

// Block
rpc BlockVerify(BlockVerifyRequest) returns (BlockVerifyResponse);
rpc BlockAccept(BlockAcceptRequest) returns (google.protobuf.Empty);
Expand Down Expand Up @@ -110,6 +115,8 @@ enum Error {
ERROR_NOT_FOUND = 2;
ERROR_HEIGHT_INDEX_INCOMPLETE = 3;
ERROR_STATE_SYNC_NOT_IMPLEMENTED = 4;
ERROR_STATE_SYNC_BLOCK_BACKFILLING_NOT_ENABLED = 5;
ERROR_STATE_SYNC_STOP_BLOCK_BACKFILLING = 6;
}

message InitializeRequest {
Expand Down Expand Up @@ -388,6 +395,22 @@ message GetStateSummaryResponse {
Error err = 3;
}

message BackfillBlocksEnabledResponse {
bytes id = 1;
uint64 height = 2;
Error err = 3;
}

message BackfillBlocksRequest {
repeated bytes blks_bytes = 1;
}

message BackfillBlocksResponse {
bytes id = 1;
uint64 height = 2;
Error err = 3;
}

message StateSummaryAcceptRequest {
bytes bytes = 1;
}
Expand Down
33 changes: 33 additions & 0 deletions snow/engine/snowman/block/mocks/state_syncable_vm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion snow/engine/snowman/block/state_syncable_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ package block
import (
"context"
"errors"

"github.com/ava-labs/avalanchego/ids"
)

var ErrStateSyncableVMNotImplemented = errors.New("vm does not implement StateSyncableVM interface")
var (
ErrStateSyncableVMNotImplemented = errors.New("vm does not implement StateSyncableVM interface")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change of this PR, where the new interface is introduced and its usage described

ErrBlockBackfillingNotEnabled = errors.New("vm does not require block backfilling")
ErrStopBlockBackfilling = errors.New("vm required stopping block backfilling")
ErrInternalBlockBackfilling = errors.New("block backfilling internal error")
)

// StateSyncableVM contains the functionality to allow VMs to sync to a given
// state, rather then boostrapping from genesis.
Expand Down Expand Up @@ -42,4 +49,22 @@ type StateSyncableVM interface {
// Returns database.ErrNotFound if no summary is available at
// [summaryHeight].
GetStateSummary(ctx context.Context, summaryHeight uint64) (StateSummary, error)

// BackfillBlocksEnabled checks if VM wants to download all blocks from state summary one
// down to genesis.
//
// Returns the ID and height of the block it wants to start backfilling from.
// Returns ErrBlockBackfillingNotEnabled if block backfilling is not enabled.
// BackfillBlocksEnabled can be called multiple times by the engine
BackfillBlocksEnabled(ctx context.Context) (ids.ID, uint64, error)

// BackfillBlocks passes blocks bytes retrieved via GetAncestors calls to the VM
// It's left to the VM the to parse, validate and index the blocks.
// BackfillBlocks returns the next block ID to be requested and an error
// Returns the ID and height of the block it wants to start backfilling from.
// Returns [ErrStopBlockBackfilling] if VM has done backfilling; engine will stop requesting blocks.
// Returns [ErrInternalBlockBackfilling] if VM has erred in a way that should make block backfilling fail.
// If BackfillBlocks returns any other error, engine will issue a GetAncestor call to a different peer
// with the previously requested block ID
BackfillBlocks(ctx context.Context, blocks [][]byte) (ids.ID, uint64, error)
}
27 changes: 27 additions & 0 deletions snow/engine/snowman/block/test_state_syncable_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
)

var (
Expand All @@ -19,6 +21,8 @@ var (
errGetLastStateSummary = errors.New("unexpectedly called GetLastStateSummary")
errParseStateSummary = errors.New("unexpectedly called ParseStateSummary")
errGetStateSummary = errors.New("unexpectedly called GetStateSummary")
errBackfillBlocksEnabled = errors.New("unexpectedly called BackfillBlocksEnabled")
errBackfillBlock = errors.New("unexpectedly called BackfillBlock")
)

type TestStateSyncableVM struct {
Expand All @@ -35,6 +39,9 @@ type TestStateSyncableVM struct {
GetLastStateSummaryF func(context.Context) (StateSummary, error)
ParseStateSummaryF func(ctx context.Context, summaryBytes []byte) (StateSummary, error)
GetStateSummaryF func(ctx context.Context, summaryHeight uint64) (StateSummary, error)

BackfillBlocksEnabledF func(context.Context) (ids.ID, uint64, error)
BackfillBlocksF func(context.Context, [][]byte) (ids.ID, uint64, error)
}

func (vm *TestStateSyncableVM) StateSyncEnabled(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -86,3 +93,23 @@ func (vm *TestStateSyncableVM) GetStateSummary(ctx context.Context, summaryHeigh
}
return nil, errGetStateSummary
}

func (vm *TestStateSyncableVM) BackfillBlocksEnabled(ctx context.Context) (ids.ID, uint64, error) {
if vm.BackfillBlocksEnabledF != nil {
return vm.BackfillBlocksEnabledF(ctx)
}
if vm.CantGetStateSummary && vm.T != nil {
require.FailNow(vm.T, errGetStateSummary.Error())
}
return ids.Empty, 0, errBackfillBlocksEnabled
}

func (vm *TestStateSyncableVM) BackfillBlocks(ctx context.Context, blocks [][]byte) (ids.ID, uint64, error) {
if vm.BackfillBlocksF != nil {
return vm.BackfillBlocksF(ctx, blocks)
}
if vm.CantGetStateSummary && vm.T != nil {
require.FailNow(vm.T, errGetStateSummary.Error())
}
return ids.Empty, 0, errBackfillBlock
}
6 changes: 5 additions & 1 deletion vms/metervm/block_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ type blockMetrics struct {
parseStateSummary,
parseStateSummaryErr,
getStateSummary,
getStateSummaryErr metric.Averager
getStateSummaryErr,
backfillBlocksEnabled,
backfillBlocks metric.Averager
}

func (m *blockMetrics) Initialize(
Expand Down Expand Up @@ -88,6 +90,8 @@ func (m *blockMetrics) Initialize(
m.parseStateSummaryErr = newAverager(namespace, "parse_state_summary_err", reg, &errs)
m.getStateSummary = newAverager(namespace, "get_state_summary", reg, &errs)
m.getStateSummaryErr = newAverager(namespace, "get_state_summary_err", reg, &errs)
m.backfillBlocksEnabled = newAverager(namespace, "backfill_blocks_enabled", reg, &errs)
m.backfillBlocks = newAverager(namespace, "backfill_blocks", reg, &errs)
}
return errs.Err
}
35 changes: 35 additions & 0 deletions vms/metervm/state_syncable_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package metervm
import (
"context"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
)

Expand Down Expand Up @@ -78,3 +79,37 @@ func (vm *blockVM) GetStateSummary(ctx context.Context, height uint64) (block.St
vm.blockMetrics.getStateSummary.Observe(duration)
return summary, nil
}

func (vm *blockVM) BackfillBlocksEnabled(ctx context.Context) (ids.ID, uint64, error) {
if vm.ssVM == nil {
return ids.Empty, 0, block.ErrStateSyncableVMNotImplemented
}

start := vm.clock.Time()
blkID, blkHeight, err := vm.ssVM.BackfillBlocksEnabled(ctx)
end := vm.clock.Time()
duration := float64(end.Sub(start))
if err != nil {
vm.blockMetrics.backfillBlocksEnabled.Observe(duration)
return ids.Empty, blkHeight, err
}
vm.blockMetrics.backfillBlocksEnabled.Observe(duration)
return blkID, blkHeight, nil
}

func (vm *blockVM) BackfillBlocks(ctx context.Context, blocks [][]byte) (ids.ID, uint64, error) {
if vm.ssVM == nil {
return ids.Empty, 0, block.ErrStateSyncableVMNotImplemented
}

start := vm.clock.Time()
nextWantedBlkID, nextWantedBlkHeight, err := vm.ssVM.BackfillBlocks(ctx, blocks)
end := vm.clock.Time()
duration := float64(end.Sub(start))
if err != nil {
vm.blockMetrics.backfillBlocks.Observe(duration)
return nextWantedBlkID, nextWantedBlkHeight, err
}
vm.blockMetrics.backfillBlocks.Observe(duration)
return nextWantedBlkID, nextWantedBlkHeight, nil
}
Comment on lines +83 to +115
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is all we need to extende the interface in the metervm, so I figured I coded it in this first PR to reduce diffs down the line

Loading
Loading