github.com/vipernet-xyz/tm@v0.34.24/light/trust_options.go (about)

     1  package light
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/vipernet-xyz/tm/crypto/tmhash"
     9  )
    10  
    11  // TrustOptions are the trust parameters needed when a new light client
    12  // connects to the network or when an existing light client that has been
    13  // offline for longer than the trusting period connects to the network.
    14  //
    15  // The expectation is the user will get this information from a trusted source
    16  // like a validator, a friend, or a secure website. A more user friendly
    17  // solution with trust tradeoffs is that we establish an https based protocol
    18  // with a default end point that populates this information. Also an on-chain
    19  // registry of roots-of-trust (e.g. on the Cosmos Hub) seems likely in the
    20  // future.
    21  type TrustOptions struct {
    22  	// tp: trusting period.
    23  	//
    24  	// Should be significantly less than the unbonding period (e.g. unbonding
    25  	// period = 3 weeks, trusting period = 2 weeks).
    26  	//
    27  	// More specifically, trusting period + time needed to check headers + time
    28  	// needed to report and punish misbehavior should be less than the unbonding
    29  	// period.
    30  	Period time.Duration
    31  
    32  	// Header's Height and Hash must both be provided to force the trusting of a
    33  	// particular header.
    34  	Height int64
    35  	Hash   []byte
    36  }
    37  
    38  // ValidateBasic performs basic validation.
    39  func (opts TrustOptions) ValidateBasic() error {
    40  	if opts.Period <= 0 {
    41  		return errors.New("negative or zero period")
    42  	}
    43  	if opts.Height <= 0 {
    44  		return errors.New("negative or zero height")
    45  	}
    46  	if len(opts.Hash) != tmhash.Size {
    47  		return fmt.Errorf("expected hash size to be %d bytes, got %d bytes",
    48  			tmhash.Size,
    49  			len(opts.Hash),
    50  		)
    51  	}
    52  	return nil
    53  }