Skip to content

Commit

Permalink
Log unexpected errors during GetValidatorSet (ava-labs#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexfusion authored Jun 9, 2023
1 parent 400dd66 commit 6dad1d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
18 changes: 16 additions & 2 deletions vms/platformvm/validators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (
"fmt"
"time"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/cache"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/utils/window"
Expand All @@ -32,7 +35,8 @@ const (
var (
_ validators.State = (*manager)(nil)

ErrMissingValidator = errors.New("missing validator")
ErrMissingValidator = errors.New("missing validator")
ErrMissingValidatorSet = errors.New("missing validator set")
)

// Manager adds the ability to introduce newly acceted blocks IDs to the State
Expand All @@ -46,12 +50,14 @@ type Manager interface {
}

func NewManager(
log logging.Logger,
cfg config.Config,
state state.State,
metrics metrics.Metrics,
clk *mockable.Clock,
) Manager {
return &manager{
log: log,
cfg: cfg,
state: state,
metrics: metrics,
Expand All @@ -68,6 +74,7 @@ func NewManager(
}

type manager struct {
log logging.Logger
cfg config.Config
state state.State
metrics metrics.Metrics
Expand Down Expand Up @@ -203,7 +210,10 @@ func (m *manager) makePrimaryNetworkValidatorSet(
currentValidators, ok := m.cfg.Validators.Get(constants.PrimaryNetworkID)
if !ok {
// This should never happen
return nil, ErrMissingValidator
m.log.Error(ErrMissingValidatorSet.Error(),
zap.Stringer("subnetID", constants.PrimaryNetworkID),
)
return nil, ErrMissingValidatorSet
}
currentValidatorList := currentValidators.List()

Expand Down Expand Up @@ -295,6 +305,10 @@ func (m *manager) makeSubnetValidatorSet(
primaryValidator, ok := primarySet[nodeID]
if !ok {
// This should never happen
m.log.Error(ErrMissingValidator.Error(),
zap.Stringer("nodeID", nodeID),
zap.Stringer("subnetID", subnetID),
)
return nil, ErrMissingValidator
}
subnetValidator.PublicKey = primaryValidator.PublicKey
Expand Down
5 changes: 3 additions & 2 deletions vms/platformvm/validators/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
Expand Down Expand Up @@ -386,7 +387,7 @@ func TestVM_GetValidatorSet(t *testing.T) {
r.NoError(err)

clk := &mockable.Clock{}
validatorssSet := NewManager(cfg, mockState, metrics, clk)
validatorSet := NewManager(logging.NoLog{}, cfg, mockState, metrics, clk)

// Mock the VM's validators
mockPrimaryVdrSet := validators.NewMockSet(ctrl)
Expand Down Expand Up @@ -426,7 +427,7 @@ func TestVM_GetValidatorSet(t *testing.T) {
mockState.EXPECT().GetStatelessBlock(mockTipID).Return(mockTip, choices.Accepted, nil)

// Compute validator set at previous height
gotVdrSet, err := validatorssSet.GetValidatorSet(context.Background(), tt.height, tt.subnetID)
gotVdrSet, err := validatorSet.GetValidatorSet(context.Background(), tt.height, tt.subnetID)
r.ErrorIs(err, tt.expectedErr)
if tt.expectedErr != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (vm *VM) Initialize(
return err
}

validatorManager := pvalidators.NewManager(vm.Config, vm.state, vm.metrics, &vm.clock)
validatorManager := pvalidators.NewManager(chainCtx.Log, vm.Config, vm.state, vm.metrics, &vm.clock)
vm.State = validatorManager
vm.atomicUtxosManager = avax.NewAtomicUTXOManager(chainCtx.SharedMemory, txs.Codec)
utxoHandler := utxo.NewHandler(vm.ctx, &vm.clock, vm.fx)
Expand Down

0 comments on commit 6dad1d4

Please sign in to comment.