Skip to content

Commit

Permalink
Merge branch 'backfill_blocks_0' into backfill_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Nov 28, 2023
2 parents 33e8be8 + f8b3178 commit 2c6349d
Show file tree
Hide file tree
Showing 40 changed files with 1,686 additions and 1,886 deletions.
57 changes: 24 additions & 33 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,21 +883,17 @@ func (m *manager) createAvalancheChain(

// create bootstrap gear
bootstrapCfg := smbootstrap.Config{
Config: common.Config{
Ctx: ctx,
Beacons: vdrs,
SampleK: sampleK,
Alpha: bootstrapWeight/2 + 1, // must be > 50%
StartupTracker: startupTracker,
Sender: snowmanMessageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
SharedCfg: &common.SharedConfig{},
},
AllGetsServer: snowGetHandler,
Blocked: blockBlocker,
VM: vmWrappingProposerVM,
AllGetsServer: snowGetHandler,
Ctx: ctx,
Beacons: vdrs,
SampleK: sampleK,
StartupTracker: startupTracker,
Sender: snowmanMessageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
Blocked: blockBlocker,
VM: vmWrappingProposerVM,
}
var snowmanBootstrapper common.BootstrapableEngine
snowmanBootstrapper, err = smbootstrap.New(
Expand Down Expand Up @@ -1234,24 +1230,19 @@ func (m *manager) createSnowmanChain(
}

// create bootstrap gear
alpha := bootstrapWeight/2 + 1 // must be > 50%
bootstrapCfg := smbootstrap.Config{
Config: common.Config{
Ctx: ctx,
Beacons: beacons,
SampleK: sampleK,
StartupTracker: startupTracker,
Alpha: alpha,
Sender: messageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
SharedCfg: &common.SharedConfig{},
},
AllGetsServer: snowGetHandler,
Blocked: blocked,
VM: vm,
Bootstrapped: bootstrapFunc,
AllGetsServer: snowGetHandler,
Ctx: ctx,
Beacons: beacons,
SampleK: sampleK,
StartupTracker: startupTracker,
Sender: messageSender,
BootstrapTracker: sb,
Timer: h,
AncestorsMaxContainersReceived: m.BootstrapAncestorsMaxContainersReceived,
Blocked: blocked,
VM: vm,
Bootstrapped: bootstrapFunc,
}
var bootstrapper common.BootstrapableEngine
bootstrapper, err = smbootstrap.New(
Expand All @@ -1274,7 +1265,7 @@ func (m *manager) createSnowmanChain(
messageSender,
beacons,
sampleK,
alpha,
bootstrapWeight/2+1, // must be > 50%
m.StateSyncBeacons,
vm,
)
Expand Down
9 changes: 6 additions & 3 deletions genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
)

var (
Expand Down Expand Up @@ -58,9 +59,10 @@ func (a Allocation) Less(other Allocation) bool {
}

type Staker struct {
NodeID ids.NodeID `json:"nodeID"`
RewardAddress ids.ShortID `json:"rewardAddress"`
DelegationFee uint32 `json:"delegationFee"`
NodeID ids.NodeID `json:"nodeID"`
RewardAddress ids.ShortID `json:"rewardAddress"`
DelegationFee uint32 `json:"delegationFee"`
Signer *signer.ProofOfPossession `json:"signer,omitempty"`
}

func (s Staker) Unparse(networkID uint32) (UnparsedStaker, error) {
Expand All @@ -73,6 +75,7 @@ func (s Staker) Unparse(networkID uint32) (UnparsedStaker, error) {
NodeID: s.NodeID,
RewardAddress: avaxAddr,
DelegationFee: s.DelegationFee,
Signer: s.Signer,
}, err
}

Expand Down
1 change: 1 addition & 0 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
},
Staked: utxos,
ExactDelegationFee: &delegationFee,
Signer: staker.Signer,
},
)
}
Expand Down
9 changes: 6 additions & 3 deletions genesis/unparsed_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
)

var errInvalidETHAddress = errors.New("invalid eth address")
Expand Down Expand Up @@ -54,15 +55,17 @@ func (ua UnparsedAllocation) Parse() (Allocation, error) {
}

type UnparsedStaker struct {
NodeID ids.NodeID `json:"nodeID"`
RewardAddress string `json:"rewardAddress"`
DelegationFee uint32 `json:"delegationFee"`
NodeID ids.NodeID `json:"nodeID"`
RewardAddress string `json:"rewardAddress"`
DelegationFee uint32 `json:"delegationFee"`
Signer *signer.ProofOfPossession `json:"signer,omitempty"`
}

func (us UnparsedStaker) Parse() (Staker, error) {
s := Staker{
NodeID: us.NodeID,
DelegationFee: us.DelegationFee,
Signer: us.Signer,
}

_, _, avaxAddrBytes, err := address.Parse(us.RewardAddress)
Expand Down
5 changes: 1 addition & 4 deletions scripts/mocks.mockgen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ github.com/ava-labs/avalanchego/vms/components/avax=TransferableIn=vms/component
github.com/ava-labs/avalanchego/vms/components/verify=Verifiable=vms/components/verify/mock_verifiable.go
github.com/ava-labs/avalanchego/vms/platformvm/block/executor=Manager=vms/platformvm/block/executor/mock_manager.go
github.com/ava-labs/avalanchego/vms/platformvm/block=Block=vms/platformvm/block/mock_block.go
github.com/ava-labs/avalanchego/vms/platformvm/state=Chain=vms/platformvm/state/mock_chain.go
github.com/ava-labs/avalanchego/vms/platformvm/state=Diff=vms/platformvm/state/mock_diff.go
github.com/ava-labs/avalanchego/vms/platformvm/state=Chain,Diff,State,Versions=vms/platformvm/state/mock_state.go
github.com/ava-labs/avalanchego/vms/platformvm/state=StakerIterator=vms/platformvm/state/mock_staker_iterator.go
github.com/ava-labs/avalanchego/vms/platformvm/state=State=vms/platformvm/state/mock_state.go
github.com/ava-labs/avalanchego/vms/platformvm/state=Versions=vms/platformvm/state/mock_versions.go
github.com/ava-labs/avalanchego/vms/platformvm/txs/builder=Builder=vms/platformvm/txs/builder/mock_builder.go
github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool=Mempool=vms/platformvm/txs/mempool/mock_mempool.go
github.com/ava-labs/avalanchego/vms/platformvm/utxo=Verifier=vms/platformvm/utxo/mock_verifier.go
Expand Down
20 changes: 10 additions & 10 deletions snow/engine/avalanche/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const (
stripeWidth = 5
cacheSize = 100000

// statusUpdateFrequency is how many containers should be processed between
// logs
statusUpdateFrequency = 5000

// maxOutstandingGetAncestorsRequests is the maximum number of GetAncestors
// sent but not yet responded to/failed
maxOutstandingGetAncestorsRequests = 10
Expand Down Expand Up @@ -333,7 +337,7 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
return fmt.Errorf("failed to get linearization status: %w", err)
}
if linearized {
return b.ForceAccepted(ctx, nil)
return b.startSyncing(ctx, nil)
}

// If a stop vertex is well known, accept that.
Expand All @@ -342,7 +346,7 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
zap.Stringer("vtxID", b.Config.StopVertexID),
)

return b.ForceAccepted(ctx, []ids.ID{b.Config.StopVertexID})
return b.startSyncing(ctx, []ids.ID{b.Config.StopVertexID})
}

// If a stop vertex isn't well known, treat the current state as the final
Expand All @@ -364,7 +368,7 @@ func (b *bootstrapper) Start(ctx context.Context, startReqID uint32) error {
zap.Stringer("vtxID", stopVertexID),
)

return b.ForceAccepted(ctx, nil)
return b.startSyncing(ctx, nil)
}

func (b *bootstrapper) HealthCheck(ctx context.Context) (interface{}, error) {
Expand All @@ -379,10 +383,6 @@ func (b *bootstrapper) HealthCheck(ctx context.Context) (interface{}, error) {
return intf, vmErr
}

func (b *bootstrapper) GetVM() common.VM {
return b.VM
}

// Add the vertices in [vtxIDs] to the set of vertices that we need to fetch,
// and then fetch vertices (and their ancestors) until either there are no more
// to fetch or we are at the maximum number of outstanding requests.
Expand Down Expand Up @@ -494,7 +494,7 @@ func (b *bootstrapper) process(ctx context.Context, vtxs ...avalanche.Vertex) er
b.numFetchedVts.Inc()

verticesFetchedSoFar := b.VtxBlocked.Jobs.PendingJobs()
if verticesFetchedSoFar%common.StatusUpdateFrequency == 0 { // Periodically print progress
if verticesFetchedSoFar%statusUpdateFrequency == 0 { // Periodically print progress
b.Ctx.Log.Info("fetched vertices",
zap.Uint64("numVerticesFetched", verticesFetchedSoFar),
)
Expand Down Expand Up @@ -540,8 +540,8 @@ func (b *bootstrapper) process(ctx context.Context, vtxs ...avalanche.Vertex) er
return b.fetch(ctx)
}

// ForceAccepted starts bootstrapping. Process the vertices in [accepterContainerIDs].
func (b *bootstrapper) ForceAccepted(ctx context.Context, acceptedContainerIDs []ids.ID) error {
// startSyncing starts bootstrapping. Process the vertices in [accepterContainerIDs].
func (b *bootstrapper) startSyncing(ctx context.Context, acceptedContainerIDs []ids.ID) error {
pendingContainerIDs := b.VtxBlocked.MissingIDs()
// Append the list of accepted container IDs to pendingContainerIDs to ensure
// we iterate over every container that must be traversed.
Expand Down
4 changes: 0 additions & 4 deletions snow/engine/avalanche/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func (e *engine) Context() *snow.ConsensusContext {
return e.ctx
}

func (e *engine) GetVM() common.VM {
return e.vm
}

func (*engine) HealthCheck(context.Context) (interface{}, error) {
return nil, nil
}
14 changes: 1 addition & 13 deletions snow/engine/common/bootstrapable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@

package common

import (
"context"

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

type BootstrapableEngine interface {
Bootstrapable
Engine
}

// Bootstrapable defines the functionality required to support bootstrapping
type Bootstrapable interface {
// Force the provided containers to be accepted. Only returns fatal errors
// if they occur.
ForceAccepted(ctx context.Context, acceptedContainerIDs []ids.ID) error

// Clear removes all containers to be processed upon bootstrapping
Clear(ctx context.Context) error
Expand Down
Loading

0 comments on commit 2c6349d

Please sign in to comment.