Skip to content

Commit

Permalink
Merge branch 'master' into testing-bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored Sep 23, 2024
2 parents 43d76ad + c4912bc commit f687e6c
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 141 deletions.
1 change: 1 addition & 0 deletions database/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (b *BatchOps) Size() int {
}

func (b *BatchOps) Reset() {
clear(b.Ops)
b.Ops = b.Ops[:0]
b.size = 0
}
Expand Down
1 change: 1 addition & 0 deletions database/encdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func (b *batch) Reset() {
if cap(b.ops) > len(b.ops)*database.MaxExcessCapacityFactor {
b.ops = make([]database.BatchOp, 0, cap(b.ops)/database.CapacityReductionFactor)
} else {
clear(b.ops)
b.ops = b.ops[:0]
}
b.Batch.Reset()
Expand Down
1 change: 1 addition & 0 deletions database/prefixdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func (b *batch) Reset() {
if cap(b.ops) > len(b.ops)*database.MaxExcessCapacityFactor {
b.ops = make([]batchOp, 0, cap(b.ops)/database.CapacityReductionFactor)
} else {
clear(b.ops)
b.ops = b.ops[:0]
}
b.Batch.Reset()
Expand Down
4 changes: 1 addition & 3 deletions utils/set/sampleable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func (s *SampleableSet[T]) Remove(elements ...T) {
// Clear empties this set
func (s *SampleableSet[T]) Clear() {
clear(s.indices)
for i := range s.elements {
s.elements[i] = utils.Zero[T]()
}
clear(s.elements)
s.elements = s.elements[:0]
}

Expand Down
14 changes: 2 additions & 12 deletions utils/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
package utils

// Returns a new instance of a T.
func Zero[T any]() T {
return *new(T)
}

// ZeroSlice sets all values of the provided slice to the type's zero value.
//
// This can be useful to ensure that the garbage collector doesn't hold
// references to values that are no longer desired.
func ZeroSlice[T any](s []T) {
for i := range s {
s[i] = *new(T)
}
func Zero[T any]() (_ T) {
return
}
4 changes: 2 additions & 2 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest"
"github.com/ava-labs/avalanchego/vms/platformvm/utxo"
"github.com/ava-labs/avalanchego/vms/platformvm/validators/validatorstest"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/chain/p/wallet"

blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor"
txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators"
)

const (
Expand Down Expand Up @@ -153,7 +153,7 @@ func newEnvironment(t *testing.T, f upgradetest.Fork) *environment { //nolint:un
metrics,
res.state,
&res.backend,
pvalidators.TestManager,
validatorstest.Manager,
)

txVerifier := network.NewLockedTxVerifier(&res.ctx.Lock, res.blkManager)
Expand Down
12 changes: 6 additions & 6 deletions vms/platformvm/block/executor/acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/validators"
"github.com/ava-labs/avalanchego/vms/platformvm/validators/validatorstest"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func TestAcceptorVisitProposalBlock(t *testing.T) {
state: s,
},
metrics: metrics.Noop,
validators: validators.TestManager,
validators: validatorstest.Manager,
}

require.NoError(acceptor.ApricotProposalBlock(blk))
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) {
},
},
metrics: metrics.Noop,
validators: validators.TestManager,
validators: validatorstest.Manager,
}

blk, err := block.NewApricotAtomicBlock(
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestAcceptorVisitStandardBlock(t *testing.T) {
},
},
metrics: metrics.Noop,
validators: validators.TestManager,
validators: validatorstest.Manager,
}

blk, err := block.NewBanffStandardBlock(
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
},
},
metrics: metrics.Noop,
validators: validators.TestManager,
validators: validatorstest.Manager,
bootstrapped: &utils.Atomic[bool]{},
}

Expand Down Expand Up @@ -376,7 +376,7 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
},
},
metrics: metrics.Noop,
validators: validators.TestManager,
validators: validatorstest.Manager,
bootstrapped: &utils.Atomic[bool]{},
}

Expand Down
7 changes: 3 additions & 4 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest"
"github.com/ava-labs/avalanchego/vms/platformvm/utxo"
"github.com/ava-labs/avalanchego/vms/platformvm/validators/validatorstest"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/chain/p/wallet"

pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators"
)

const (
Expand Down Expand Up @@ -166,7 +165,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) *
metrics,
res.state,
res.backend,
pvalidators.TestManager,
validatorstest.Manager,
)
addSubnet(t, res)
} else {
Expand All @@ -175,7 +174,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f upgradetest.Fork) *
metrics,
res.mockedState,
res.backend,
pvalidators.TestManager,
validatorstest.Manager,
)
// we do not add any subnet to state, since we can mock
// whatever we need
Expand Down
33 changes: 0 additions & 33 deletions vms/platformvm/validators/test_manager.go

This file was deleted.

35 changes: 35 additions & 0 deletions vms/platformvm/validators/validatorstest/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package validatorstest

import (
"context"

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

snowvalidators "github.com/ava-labs/avalanchego/snow/validators"
vmvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators"
)

var Manager vmvalidators.Manager = manager{}

type manager struct{}

func (manager) GetMinimumHeight(context.Context) (uint64, error) {
return 0, nil
}

func (manager) GetCurrentHeight(context.Context) (uint64, error) {
return 0, nil
}

func (manager) GetSubnetID(context.Context, ids.ID) (ids.ID, error) {
return ids.Empty, nil
}

func (manager) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*snowvalidators.GetValidatorOutput, error) {
return nil, nil
}

func (manager) OnAcceptedBlockID(ids.ID) {}
Loading

0 comments on commit f687e6c

Please sign in to comment.