badgeserver

package
v2.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 43 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Bade generator

The purpose of this service is to generate and provide a badge, of which consumers can use when communication with providers.

Configuration

The badge server uses a config file named badgeserver.yml that provides the projects data and some other basic configuration. An example for a configuration file:

projects-data:
	2:
		myWeb3Project:
			epochs-max-cu: 100000

default-geolocation: 2

countries-file-path: ""
ip-file-path: ""

projects-data - hold a map of maps of geolocation to project to project's data. In this example, there is only one project, under geolocation 2 , named myWeb3Project. epochs-max-cu - defines the max CU that can be used for this project per epoch. default-geolocation - the default geolocation to use, when one cannot be determined by the badge server. countries-file-path - path of the countries file ip-file-path - path of the IP file

Countries File

This is a CSV file with all countries and lava-geolocation link for example. It contains four columns: country-code, country-name, continent code and lava-geolocation. Example:

AD;Andorra;EU;2
AE;United Arab Emirates;AS;2
AF;Afghanistan;AS;2
AL;Albania;EU;2
AM;Armenia;AS;2
AO;Angola;AF;2
IP File

This is a TSV file with all IP ranges and country code that they belong to. Tt can be downloaded from this website, under ip2asn-v4.tsv. It contains 5 columns: range_start, range_end, AS_number, country_code and AS_description. Example:

1.0.0.0	1.0.0.255	13335	US	CLOUDFLARENET
1.0.1.0	1.0.3.255	0	None	Not routed
1.0.4.0	1.0.5.255	38803	AU	WPL-AS-AP Wirefreebroadband Pty Ltd
1.0.6.0	1.0.7.255	38803	AU	WPL-AS-AP Wirefreebroadband Pty Ltd
1.0.8.0	1.0.15.255	0	None	Not routed

Running the badgeserver

To run the badge server, run this command:

lavad badgeserver [config-path] --port=[port] --log_level=[log level] --chain-id=[chain id]

Where config-path is the directory which contains the badgeserver.yml file.

Generating a Badge

To generate a badge, use the RPC endpoint lavanet.lava.pairing.BadgeGenerator/GenerateBadge. The input for this endpoint is: badge_adress - the client wallet address that uses the badge. This address must match to the transactions signer address. project_id - the project ID to use. spec_id - the spec to generate the badge for.

The response of this request is: badge - and object, holding the following data:

  • cu_allocation
  • epoch
  • address
  • lava_chain_id
  • project_sig
  • virtual_epoch

get_pairing_response - the response from a pairing query, made automatically by the badge server on badge generation. badge_signer_address - the public address of the badge signer. spec - the full spec of the requested spec_id

Documentation

Index

Constants

View Source
const (
	PortFieldName               = "port"
	MetricsPortFieldName        = "metrics-port"
	ProjectDataFieldName        = "projects-data"
	LavaChainIDFieldName        = "chain-id"
	DefaultGeolocationFieldName = "default-geolocation"
	CountriesFilePathFieldName  = "countries-file-path"
	IpFilePathFieldName         = "ip-file-path"
)
View Source
const AddBlockDelayForEpochUpdaterBadgeServer = 2

adding 3 blocks delay, to update the epoch. the reason is for the sdk to wait until all providers are synced to the new epoch before SDK gets a new pairing list.

View Source
const DefaultProjectId = "default"
View Source
const RefererHeaderKey = "Referer"

Variables

View Source
var (
	// The name of our config file, without the file extension because viper supports many different config file languages.
	DefaultConfigFilename = "badgeserver.yml"
)

Functions

func CreateBadgeServerCobraCommand

func CreateBadgeServerCobraCommand() *cobra.Command

func RunBadgeServer

func RunBadgeServer(cmd *cobra.Command, v *viper.Viper)

Types

type BadgeStateTracker

type BadgeStateTracker struct {
	*statetracker.StateTracker
	statetracker.ConsumerEmergencyTrackerInf
	// contains filtered or unexported fields
}

func NewBadgeStateTracker

func NewBadgeStateTracker(ctx context.Context, clientCtx cosmosclient.Context, chainFetcher chaintracker.ChainFetcher, chainId string) (ret *BadgeStateTracker, err error)

func (*BadgeStateTracker) RegisterForDowntimeParamsUpdates

func (st *BadgeStateTracker) RegisterForDowntimeParamsUpdates(ctx context.Context, downtimeParamsUpdatable updaters.DowntimeParamsUpdatable) error

func (*BadgeStateTracker) RegisterForEpochUpdates

func (st *BadgeStateTracker) RegisterForEpochUpdates(ctx context.Context, epochUpdatable updaters.EpochUpdatable)

func (*BadgeStateTracker) RegisterForSpecUpdates

func (st *BadgeStateTracker) RegisterForSpecUpdates(ctx context.Context, specUpdatable updaters.SpecUpdatable, endpoint lavasession.RPCEndpoint) error

type GelocationToProjectsConfiguration

type GelocationToProjectsConfiguration map[string]map[string]*ProjectConfiguration

type HealthServer

type HealthServer struct {
	health.UnimplementedHealthServer
}

func (*HealthServer) Check

func (*HealthServer) Watch

type IpData

type IpData struct {
	FromIp      int64
	ToIP        int64
	CountryCode string
	Geolocation int
}

type IpService

type IpService struct {
	DefaultGeolocation int
	CountryCsvFilePath string
	IpTsvFilePath      string
	IpCountryData      *[]*IpData
}

func InitIpService

func InitIpService(defaultGeolocation int, countriesFilePath, ipFilePath string) (*IpService, error)

func (*IpService) ReadIpTsvFileData

func (service *IpService) ReadIpTsvFileData() error

func (*IpService) SearchForIp

func (service *IpService) SearchForIp(toSearchIp string) (*IpData, error)

type MetricsService

type MetricsService struct {
	TotalRequests      prometheus.Counter
	FailedRequests     prometheus.Counter
	SuccessfulRequests prometheus.Counter
}

func InitMetrics

func InitMetrics() *MetricsService

func (*MetricsService) AddRequest

func (service *MetricsService) AddRequest(isSuccessful bool)

type ProjectConfiguration

type ProjectConfiguration struct {
	EpochsMaxCu  int64                                     `yaml:"epochs-max-cu,omitempty" json:"epochs-max-cu,omitempty" mapstructure:"epochs-max-cu,omitempty"`
	UpdatedEpoch map[string]uint64                         `yaml:"update-epoch,omitempty" json:"update-epoch,omitempty" mapstructure:"update-epoch,omitempty"`
	PairingList  map[string]*types.QueryGetPairingResponse `yaml:"pairing-list,omitempty" json:"pairing-list,omitempty" mapstructure:"pairing-list,omitempty"`
}

type Server

type Server struct {
	pairingtypes.UnimplementedBadgeGeneratorServer
	ProjectsConfiguration GelocationToProjectsConfiguration // geolocation/project_id/project_data

	ChainId   string
	IpService *IpService
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ipService *IpService, chainId string, projectsData GelocationToProjectsConfiguration, chainFetcher *chainlib.LavaChainFetcher, clientCtx client.Context, projectPublicKey string, projectPrivateKey *btcSecp256k1.PrivateKey) (*Server, error)

func (*Server) Active

func (s *Server) Active() bool

func (*Server) GetEpoch

func (s *Server) GetEpoch() uint64

func (*Server) GetUniqueName

func (s *Server) GetUniqueName() string

func (*Server) InitializeStateTracker

func (s *Server) InitializeStateTracker(tracker *BadgeStateTracker)

func (*Server) SetSpec

func (s *Server) SetSpec(specUpdate spectypes.Spec)

func (*Server) UpdateEpoch

func (s *Server) UpdateEpoch(epoch uint64)

type UserBadgeItem

type UserBadgeItem struct {
	AllowedCu int64
	Epoch     uint64
	Signature string
	PublicKey string
	UserId    string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL