Skip to content

Commit

Permalink
P-chain: Improve GetValidatorsSet error expressivity (#2808)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Buttolph <[email protected]>
  • Loading branch information
abi87 and StephenButtolph authored Mar 11, 2024
1 parent f3abe3c commit ddf66ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions vms/platformvm/validators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package validators

import (
"context"
"errors"
"fmt"
"time"

"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"
Expand All @@ -30,7 +30,11 @@ const (
recentlyAcceptedWindowTTL = 2 * time.Minute
)

var _ validators.State = (*manager)(nil)
var (
_ validators.State = (*manager)(nil)

errUnfinalizedHeight = errors.New("failed to fetch validator set at unfinalized height")
)

// Manager adds the ability to introduce newly accepted blocks IDs to the State
// interface.
Expand Down Expand Up @@ -247,7 +251,12 @@ func (m *manager) makePrimaryNetworkValidatorSet(
return nil, 0, err
}
if currentHeight < targetHeight {
return nil, 0, database.ErrNotFound
return nil, 0, fmt.Errorf("%w with SubnetID = %s: current P-chain height (%d) < requested P-Chain height (%d)",
errUnfinalizedHeight,
constants.PrimaryNetworkID,
currentHeight,
targetHeight,
)
}

// Rebuild primary network validators at [targetHeight]
Expand Down Expand Up @@ -295,7 +304,12 @@ func (m *manager) makeSubnetValidatorSet(
return nil, 0, err
}
if currentHeight < targetHeight {
return nil, 0, database.ErrNotFound
return nil, 0, fmt.Errorf("%w with SubnetID = %s: current P-chain height (%d) < requested P-Chain height (%d)",
errUnfinalizedHeight,
subnetID,
currentHeight,
targetHeight,
)
}

// Rebuild subnet validators at [targetHeight]
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/warp/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func GetCanonicalValidatorSet(
// Get the validator set at the given height.
vdrSet, err := pChainState.GetValidatorSet(ctx, pChainHeight, subnetID)
if err != nil {
return nil, 0, fmt.Errorf("failed to fetch validator set (P-Chain Height: %d, SubnetID: %s): %w", pChainHeight, subnetID, err)
return nil, 0, err
}

var (
Expand Down

0 comments on commit ddf66ea

Please sign in to comment.