Files
zeekay f70bac500d refactor: migrate to vm/rpc/chain, remove node dependency from production code
- Update import from vm/rpcchainvm to vm/rpc/chain
- Update vm dependency to v1.0.18
- node dependency now test-only (platformvm.NewClient for warp tests)
2026-01-11 21:38:33 -08:00

56 lines
2.1 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package validators
import (
"context"
validators "github.com/luxfi/consensus/validator"
"github.com/luxfi/constants"
"github.com/luxfi/ids"
)
var _ validators.State = (*State)(nil)
// State provides a special case used to handle Lux Warp Message verification for messages sent
// from the Primary Network. Chains have strictly fewer validators than the Primary Network, so we require
// signatures from a threshold of the RECEIVING chain validator set rather than the full Primary Network
// since the receiving chain already relies on a majority of its validators being correct.
type State struct {
validators.State
myChainID ids.ID
sourceChainID ids.ID
requirePrimaryNetworkSigners bool
}
// NewState returns a wrapper of [validators.State] which special cases the handling of the Primary Network.
//
// The wrapped state will return the [myChainID's] validator set instead of the Primary Network when
// the Primary Network ChainID is passed in.
func NewState(state validators.State, myChainID ids.ID, sourceChainID ids.ID, requirePrimaryNetworkSigners bool) *State {
return &State{
State: state,
myChainID: myChainID,
sourceChainID: sourceChainID,
requirePrimaryNetworkSigners: requirePrimaryNetworkSigners,
}
}
func (s *State) GetValidatorSet(
ctx context.Context,
height uint64,
chainID ids.ID,
) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
// If the chainID is anything other than the Primary Network, or Primary
// Network signers are required (except P-Chain), this is a direct passthrough.
usePrimary := s.requirePrimaryNetworkSigners && s.sourceChainID != constants.PlatformChainID
if usePrimary || chainID != constants.PrimaryNetworkID {
return s.State.GetValidatorSet(ctx, height, chainID)
}
// If the requested chain is the primary network, then we return the validator
// set for the Chain that is receiving the message instead.
return s.State.GetValidatorSet(ctx, height, s.myChainID)
}