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 - 1 Engine #2144

Closed
wants to merge 65 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e911af9
backfilling scaffolding
abi87 Oct 5, 2023
6fbe978
bumped coreth version
abi87 Oct 5, 2023
b9d821b
Merge branch 'dev' into backfill_blocks
abi87 Oct 11, 2023
3dd344f
Merge branch 'dev' into backfill_blocks. Broken due to coreth dependency
abi87 Oct 26, 2023
5025fcf
temporarily cut coreth dependency
abi87 Oct 26, 2023
b638c44
bumped coreth version
abi87 Oct 26, 2023
54ff252
proposervm backfilling scaffolding
abi87 Oct 26, 2023
3ba03dc
rpcchainvm backfilling scaffolding
abi87 Oct 26, 2023
58647b4
wip: block backfilling scaffolding
abi87 Oct 30, 2023
397ce7d
wip: block backfilling scaffolding
abi87 Oct 30, 2023
1b7015e
improved StateSyncableVM interface
abi87 Oct 30, 2023
36905ac
temporarily cut coreth dependency
abi87 Oct 30, 2023
c8ec0f2
bumped coreth version
abi87 Oct 30, 2023
8c125ff
wip: block backfilling UTs
abi87 Oct 30, 2023
3e1838a
wip: block backfilling UTs
abi87 Oct 30, 2023
25f3e8d
wip: block backfilling UTs
abi87 Oct 30, 2023
4664e26
wip: block backfilling UTs
abi87 Oct 30, 2023
f6c5546
fixed blocks backfilling restart
abi87 Oct 30, 2023
46481ab
fixed blocks backfilling UTs flakiness
abi87 Oct 30, 2023
4eb0ccb
repackaged block backfilling into ad-hoc struct
abi87 Oct 30, 2023
bdaa39d
fixed state sync termination
abi87 Oct 30, 2023
28b3846
Merge branch 'dev' into backfill_blocks
abi87 Oct 30, 2023
61ebecd
temporarily cut coreth dependencies
abi87 Oct 30, 2023
cde6ae3
bumped coreth version
abi87 Oct 30, 2023
d89f1e1
bumped coreth version
abi87 Oct 30, 2023
8a7867a
moved up proposerVM block backfilling
abi87 Oct 30, 2023
ae98ede
changing block backfilling interface
abi87 Nov 1, 2023
50a01e6
temporarily cut coreth dependencies
abi87 Nov 1, 2023
171a704
bumped coreth version
abi87 Nov 1, 2023
e7b68cd
Merge branch 'dev' into backfill_blocks
abi87 Nov 2, 2023
0c70a78
temporarily cut coreth dependencies
abi87 Nov 2, 2023
36f700a
bumped coreth version
abi87 Nov 2, 2023
fde68a7
Merge branch 'dev' into backfill_blocks
abi87 Nov 3, 2023
682939f
Merge branch 'dev' into backfill_blocks
abi87 Nov 3, 2023
8489a0b
Merge branch 'dev' into backfill_blocks
abi87 Nov 4, 2023
834f99d
introduced backfilling internal error
abi87 Nov 4, 2023
5269013
improved error checking
abi87 Nov 5, 2023
d316f28
Merge branch 'dev' into backfill_blocks
abi87 Nov 5, 2023
db00453
Merge branch 'dev' into backfill_blocks
abi87 Nov 8, 2023
a2464eb
temporarily cut coreth dependencies
abi87 Nov 2, 2023
55e3adf
bumped coreth version
abi87 Nov 8, 2023
ac46316
Merge branch 'dev' into backfill_blocks
abi87 Nov 9, 2023
3fd6a17
Merge branch 'dev' into backfill_blocks
abi87 Nov 9, 2023
0bc7200
Merge branch 'dev' into backfill_blocks
abi87 Nov 13, 2023
38bf0d4
Merge branch 'dev' into backfill_blocks
abi87 Nov 14, 2023
f723063
Merge branch 'dev' into backfill_blocks
abi87 Nov 15, 2023
a4dcf13
Merge branch 'dev' into backfill_blocks
abi87 Nov 19, 2023
98d01e8
temporarily cut coreth dependencies
abi87 Nov 2, 2023
40215d1
bumped coreth version
abi87 Nov 19, 2023
e31c755
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 20, 2023
549c242
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 21, 2023
c8c28d8
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 22, 2023
28ba314
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 23, 2023
33e8be8
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 27, 2023
5cb606a
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 28, 2023
577bd7c
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Nov 29, 2023
b59fe3f
fixed mere
abi87 Nov 29, 2023
ed8ad5a
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Dec 3, 2023
85fa97b
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Dec 9, 2023
dde0bfa
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Dec 11, 2023
fb028ba
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Dec 27, 2023
4ae3a08
fixed merge
abi87 Dec 27, 2023
3acc18b
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Dec 27, 2023
6532f3e
Merge branch 'backfill_blocks_0' into backfill_blocks
abi87 Jan 2, 2024
ff4aa67
Merge branch 'backfill_blocks_0' into backfill_blocks
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
Prev Previous commit
Next Next commit
wip: block backfilling scaffolding
abi87 committed Oct 30, 2023
commit 58647b416af4c6e7087c8cc2d1f4b614ae6243d2
3 changes: 3 additions & 0 deletions chains/manager.go
Original file line number Diff line number Diff line change
@@ -878,6 +878,8 @@ func (m *manager) createAvalancheChain(
Validators: vdrs,
Params: consensusParams,
Consensus: snowmanConsensus,

Peers: connectedBeacons,
}
snowmanEngine, err := smeng.New(snowmanEngineConfig)
if err != nil {
@@ -1231,6 +1233,7 @@ func (m *manager) createSnowmanChain(
Params: consensusParams,
Consensus: consensus,
PartialSync: m.PartialSyncPrimaryNetwork && commonCfg.Ctx.ChainID == constants.PlatformChainID,
Peers: connectedBeacons,
}
engine, err := smeng.New(engineConfig)
if err != nil {
1 change: 1 addition & 0 deletions snow/engine/snowman/block/state_syncable_vm.go
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ type StateSyncableVM interface {
// down to genesis.
//
// Returns ids.EmptyID if block backfilling is not enabled.
// TODO ABENEGIA: Use error instead of the EmptyID
BackfillBlocksEnabled(ctx context.Context) (ids.ID, error)

BackfillBlocks(ctx context.Context, blocks [][]byte) error
4 changes: 4 additions & 0 deletions snow/engine/snowman/config.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/common/tracker"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/validators"
)
@@ -23,4 +24,7 @@ type Config struct {
Params snowball.Parameters
Consensus snowman.Consensus
PartialSync bool

// used for block-backfilling
Peers tracker.Peers
}
2 changes: 2 additions & 0 deletions snow/engine/snowman/config_test.go
Original file line number Diff line number Diff line change
@@ -30,5 +30,7 @@ func DefaultConfigs() Config {
MaxItemProcessingTime: 1,
},
Consensus: &snowman.Topological{},

Peers: commonCfg.StartupTracker,
}
}
67 changes: 66 additions & 1 deletion snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/common/tracker"
"github.com/ava-labs/avalanchego/snow/engine/snowman/ancestor"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/event"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/bag"
@@ -29,6 +30,7 @@ import (
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/version"
)

const nonVerifiedCacheSize = 64 * units.MiB
@@ -92,6 +94,12 @@ type Transitive struct {

// errs tracks if an error has occurred in a callback
errs wrappers.Errs

// START OF BLOCK BACKFILLING STUFF
fetchFrom set.Set[ids.NodeID] // picked from bootstrapper
peers tracker.Peers

// END OF BLOCK BACKFILLING STUFF
}

func newTransitive(config Config) (*Transitive, error) {
@@ -135,6 +143,10 @@ func newTransitive(config Config) (*Transitive, error) {
"",
config.Ctx.Registerer,
),

// block-backfilling stuff
fetchFrom: set.Of[ids.NodeID](config.Validators.GetValidatorIDs(config.Ctx.SubnetID)...),
peers: config.Peers,
}

return t, t.metrics.Initialize("", config.Ctx.Registerer)
@@ -454,7 +466,10 @@ func (t *Transitive) Start(ctx context.Context, startReqID uint32) error {
err)
}

return nil
// Start Block backfilling if needed
// TODO: for now we extend transitive engine with backfilling features
// Later on we'll repackage them into a separate struct to be moved in syncer package.
return t.startBlockBackfilling(ctx)
}

func (t *Transitive) HealthCheck(ctx context.Context) (interface{}, error) {
@@ -992,3 +1007,53 @@ func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snow
tree: t.nonVerifieds,
})
}

// BLOCK BACKFILLING STUFF
func (t *Transitive) startBlockBackfilling(ctx context.Context) error {
ssVM, ok := t.VM.(block.StateSyncableVM)
if !ok {
return nil // nothing to do
}

switch blkID, err := ssVM.BackfillBlocksEnabled(ctx); {
case err != nil:
return fmt.Errorf("failed checking if state sync block backfilling is enabled: %w", err)
case blkID == ids.Empty:
t.Ctx.Log.Info("block backfilling not enabled")
return nil
default:
validatorID, ok := t.fetchFrom.Peek()
if !ok {
return fmt.Errorf("dropping request for %s as there are no nodes to request blkID from", blkID)
}

// We only allow one outbound request at a time from a node
t.markUnavailable(validatorID)
t.RequestID++
t.Sender.SendGetAncestors(ctx, validatorID, t.RequestID, blkID)
return nil
}
}

func (t *Transitive) markUnavailable(nodeID ids.NodeID) {
t.fetchFrom.Remove(nodeID)

// if [fetchFrom] has become empty, reset it to the currently preferred
// peers
if t.fetchFrom.Len() == 0 {
t.fetchFrom = t.peers.PreferredPeers()
}
}

func (t *Transitive) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error {
// Ensure fetchFrom reflects proper validator list
if _, ok := t.Validators.GetValidator(t.Ctx.SubnetID, nodeID); ok {
t.fetchFrom.Add(nodeID)
}
return t.Connector.Connected(ctx, nodeID, nodeVersion)
}

func (t *Transitive) Disconnected(ctx context.Context, nodeID ids.NodeID) error {
t.markUnavailable(nodeID)
return t.Connector.Disconnected(ctx, nodeID)
}