Skip to content

Commit

Permalink
Merge branch 'main' into CNS-784-project-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Dec 31, 2023
2 parents 1dfbec7 + 240ec56 commit c41d5cb
Show file tree
Hide file tree
Showing 54 changed files with 2,531 additions and 460 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ LAVA_BINARY=lavad make install

Or check out the latest [release](https://github.com/lavanet/lava/releases).

### Add `lavad` autocomplete
### Add `lavad`/`lavap` autocomplete

You can add a useful autocomplete feature to `lavad` with a simple bash [script](https://github.com/lavanet/lava/blob/update-readme-autocomplete/scripts/lavad_auto_completion_install.sh).
You can add a useful autocomplete feature to `lavad` & `lavap` with a simple bash [script](https://github.com/lavanet/lava/blob/main/scripts/lavad_auto_completion_install.sh).

### Quick Start

Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var Upgrades = []upgrades.Upgrade{
upgrades.Upgrade_0_31_0,
upgrades.Upgrade_0_31_1,
upgrades.Upgrade_0_32_0,
upgrades.Upgrade_0_32_3,
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -241,6 +242,7 @@ var (
string(rewardsmoduletypes.ValidatorsRewardsDistributionPoolName): {authtypes.Burner, authtypes.Staking},
string(rewardsmoduletypes.ProviderRewardsDistributionPool): {authtypes.Burner, authtypes.Staking},
string(rewardsmoduletypes.ProvidersRewardsAllocationPool): {authtypes.Minter, authtypes.Staking},
dualstakingmoduletypes.ModuleName: {authtypes.Burner, authtypes.Staking},
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,9 @@ var Upgrade_0_32_0 = Upgrade{
Deleted: []string{minttypes.StoreKey},
},
}

var Upgrade_0_32_3 = Upgrade{
UpgradeName: "v0.32.3",
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
47 changes: 43 additions & 4 deletions cmd/lavad/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
)

const (
flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time"
flagVestingAmt = "vesting-amount"
flagModuleAccount = "module-account"
flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time"
flagVestingAmt = "vesting-amount"
flagModuleAccount = "module-account"
flagPeriodicLength = "periodic-length"
flagPeriodicNumber = "periodic-Number"
)

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
Expand Down Expand Up @@ -102,6 +104,16 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
return fmt.Errorf("failed to parse vesting amount: %w", err)
}

periodicLength, err := cmd.Flags().GetInt64(flagPeriodicLength)
if err != nil {
return err
}

periodicNumber, err := cmd.Flags().GetInt64(flagPeriodicNumber)
if err != nil {
return err
}

// create concrete account type based on input parameters
var genAccount authtypes.GenesisAccount

Expand All @@ -121,6 +133,30 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
}

switch {
case periodicLength != 0 || periodicNumber != 0:
if periodicLength <= 0 {
return errors.New("periodic account must set periodicLength flag")
}

if periodicNumber <= 0 {
return errors.New("periodic account must set periodicNumber flag")
}

if vestingStart <= 0 {
return errors.New("periodic account must have vesting start flag")
}

if !vestingAmt.QuoInt(sdk.NewInt(periodicNumber)).MulInt(sdk.NewInt(periodicNumber)).IsEqual(vestingAmt) {
return errors.New("periodic vesting amount must be divisble by the periodicNumber")
}

var periods []authvesting.Period
for i := int64(0); i < periodicNumber; i++ {
period := authvesting.Period{Length: periodicLength, Amount: vestingAmt.QuoInt(sdk.NewInt(periodicNumber))}
periods = append(periods, period)
}

genAccount = authvesting.NewPeriodicVestingAccount(baseAccount, vestingAmt, vestingStart, periods)
case vestingStart != 0 && vestingEnd != 0:
genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)

Expand Down Expand Up @@ -200,6 +236,9 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
cmd.Flags().Bool(flagModuleAccount, false, "create a module account")
cmd.Flags().Int64(flagPeriodicLength, 0, "length of the each period")
cmd.Flags().Int64(flagPeriodicNumber, 0, "number of periods")

flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand Down
17 changes: 8 additions & 9 deletions config/rpcconsumer_test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
endpoints:
- chain-id: EVMOS
- chain-id: LAV1
api-interface: tendermintrpc
network-address: 127.0.0.1:3333
- chain-id: EVMOS
network-address: 127.0.0.1:3360
- chain-id: LAV1
api-interface: rest
network-address: 127.0.0.1:3334
- chain-id: EVMOS
network-address: 127.0.0.1:3361
- chain-id: LAV1
api-interface: grpc
network-address: 127.0.0.1:3335
- chain-id: EVMOS
api-interface: jsonrpc
network-address: 127.0.0.1:3336
network-address: 127.0.0.1:3362
tls-enabled: true
health-check-path: "/"
metrics-listen-address: ":7779"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.2.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/gogoproto v1.4.10
github.com/dgraph-io/badger/v4 v4.1.0
github.com/fullstorydev/grpcurl v1.8.5
Expand Down Expand Up @@ -68,7 +69,6 @@ require (
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
Expand Down
8 changes: 5 additions & 3 deletions proto/lavanet/lava/subscription/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ service Query {
option (google.api.http).get = "/lavanet/lava/subscription/current/{consumer}";
}

// Queries a list of ListProjects items.
// Queries a list of ListProjects items.
rpc ListProjects(QueryListProjectsRequest) returns (QueryListProjectsResponse) {
option (google.api.http).get = "/lavanet/lava/subscription/list_projects/{subscription}";
}

// Queries a list of List items.
// Queries a list of List items.
rpc List(QueryListRequest) returns (QueryListResponse) {
option (google.api.http).get = "/lavanet/lava/subscription/list";
}
Expand Down Expand Up @@ -80,7 +80,9 @@ message ListInfoStruct {
uint64 month_cu_left = 7; // remaining CU allowance this month
string cluster = 8;
uint64 duration_total = 9;
bool auto_renewal = 10;
reserved 10;
string auto_renewal_next_plan = 11;
FutureSubscription future_subscription = 12;
}

message QueryNextToMonthExpiryRequest {
Expand Down
3 changes: 2 additions & 1 deletion proto/lavanet/lava/subscription/subscription.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ message Subscription {
reserved 12;
string cluster = 13; // cluster key
uint64 duration_total = 14; // continous subscription usage
bool auto_renewal = 15; // automatic renewal when the subscription expires
reserved 15; // automatic renewal when the subscription expires
FutureSubscription future_subscription = 16; // future subscription made with buy --advance-purchase
string auto_renewal_next_plan = 17; // the next plan to subscribe to. If none is set, then auto renewal is disabled
}

message FutureSubscription {
Expand Down
2 changes: 2 additions & 0 deletions proto/lavanet/lava/subscription/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ message MsgDelProjectResponse {
message MsgAutoRenewal {
string creator = 1;
bool enable = 2;
string consumer = 3;
string index = 4;
}

message MsgAutoRenewalResponse {
Expand Down
18 changes: 16 additions & 2 deletions protocol/chainlib/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (apil *GrpcChainListener) Serve(ctx context.Context) {
return relayReply.Data, convertRelayMetaDataToMDMetaData(metadataToReply), nil
}

_, httpServer, err := grpcproxy.NewGRPCProxy(sendRelayCallback)
_, httpServer, err := grpcproxy.NewGRPCProxy(sendRelayCallback, apil.endpoint.HealthCheckPath)
if err != nil {
utils.LavaFormatFatal("provider failure RegisterServer", err, utils.Attribute{Key: "listenAddr", Value: apil.endpoint.NetworkAddress})
}
Expand All @@ -327,7 +327,21 @@ func (apil *GrpcChainListener) Serve(ctx context.Context) {

utils.LavaFormatInfo("Server listening", utils.Attribute{Key: "Address", Value: lis.Addr()})

if err := httpServer.Serve(lis); !errors.Is(err, http.ErrServerClosed) {
var serveExecutor func() error
if apil.endpoint.TLSEnabled {
utils.LavaFormatInfo("Running with self signed TLS certificate")
var certificateErr error
httpServer.TLSConfig, certificateErr = lavasession.GetSelfSignedConfig()
if certificateErr != nil {
utils.LavaFormatFatal("failed getting a self signed certificate", certificateErr)
}
serveExecutor = func() error { return httpServer.ServeTLS(lis, "", "") }
} else {
utils.LavaFormatInfo("Running with disabled TLS configuration")
serveExecutor = func() error { return httpServer.Serve(lis) }
}

if err := serveExecutor(); !errors.Is(err, http.ErrServerClosed) {
utils.LavaFormatFatal("Portal failed to serve", err, utils.Attribute{Key: "Address", Value: lis.Addr()}, utils.Attribute{Key: "ChainID", Value: apil.endpoint.ChainID})
}
}
Expand Down
9 changes: 7 additions & 2 deletions protocol/chainlib/grpcproxy/grpcproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ import (

type ProxyCallBack = func(ctx context.Context, method string, reqBody []byte) ([]byte, metadata.MD, error)

func NewGRPCProxy(cb ProxyCallBack) (*grpc.Server, *http.Server, error) {
func NewGRPCProxy(cb ProxyCallBack, healthCheckPath string) (*grpc.Server, *http.Server, error) {
s := grpc.NewServer(grpc.UnknownServiceHandler(makeProxyFunc(cb)), grpc.ForceServerCodec(RawBytesCodec{}))
wrappedServer := grpcweb.WrapServer(s)
handler := func(resp http.ResponseWriter, req *http.Request) {
// Set CORS headers
resp.Header().Set("Access-Control-Allow-Origin", "*")
resp.Header().Set("Access-Control-Allow-Headers", "Content-Type,x-grpc-web")

if req.URL.Path == healthCheckPath && req.Method == http.MethodGet {
resp.WriteHeader(200)
_, _ = resp.Write(make([]byte, 0))
return
}
wrappedServer.ServeHTTP(resp, req)
}

httpServer := &http.Server{
Handler: h2c.NewHandler(http.HandlerFunc(handler), &http2.Server{}),
}

return s, httpServer, nil
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/grpcproxy/grpcproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestGRPCProxy(t *testing.T) {
responseHeaders := make(metadata.MD)
responseHeaders["test-headers"] = append(responseHeaders["test-headers"], "55")
return respBytes, responseHeaders, nil
})
}, "")
require.NoError(t, err)

client := testproto.NewTestClient(testproto.InMemoryClientConn(t, proxyGRPCSrv))
Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ func (apil *JsonRPCChainListener) Serve(ctx context.Context) {
return addHeadersAndSendString(fiberCtx, reply.GetMetadata(), response)
})

app.Get(apil.endpoint.HealthCheckPath, func(fiberCtx *fiber.Ctx) error {
fiberCtx.Status(http.StatusOK)
return fiberCtx.SendString("Health status OK")
})
// Go
ListenWithRetry(app, apil.endpoint.NetworkAddress)
}
Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ func (apil *RestChainListener) Serve(ctx context.Context) {

query := "?" + string(fiberCtx.Request().URI().QueryString())
path := "/" + fiberCtx.Params("*")
if path == apil.endpoint.HealthCheckPath {
fiberCtx.Status(http.StatusOK)
return fiberCtx.SendString("Health status OK")
}
dappID := extractDappIDFromFiberContext(fiberCtx)
analytics := metrics.NewRelayAnalytics(dappID, chainID, apiInterface)

Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ func (apil *TendermintRpcChainListener) Serve(ctx context.Context) {
startTime := time.Now()
query := "?" + string(fiberCtx.Request().URI().QueryString())
path := fiberCtx.Params("*")
if "/"+path == apil.endpoint.HealthCheckPath {
fiberCtx.Status(http.StatusOK)
return fiberCtx.SendString("Health status OK")
}
dappID := extractDappIDFromFiberContext(fiberCtx)
ctx, cancel := context.WithCancel(context.Background())
guid := utils.GenerateUniqueIdentifier()
Expand Down
2 changes: 2 additions & 0 deletions protocol/common/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
BLOCK_PROVIDERS_ADDRESSES_HEADER_NAME = "lava-providers-block"
RELAY_TIMEOUT_HEADER_NAME = "lava-relay-timeout"
EXTENSION_OVERRIDE_HEADER_NAME = "lava-extension"
// send http request to /lava/health to see if the process is up - (ret code 200)
DEFAULT_HEALTH_PATH = "/lava/health"
)

type NodeUrl struct {
Expand Down
17 changes: 12 additions & 5 deletions protocol/lavasession/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ func GetCaCertificate(serverCertPath, serverKeyPath string) (*tls.Config, error)
}, nil
}

func GetSelfSignedConfig() (*tls.Config, error) {
cert, err := GenerateSelfSignedCertificate()
if err != nil {
return nil, utils.LavaFormatError("failed to generate TLS certificate", err)
}
return &tls.Config{
Certificates: []tls.Certificate{cert},
}, nil
}

func GetTlsConfig(networkAddress NetworkAddressData) *tls.Config {
var tlsConfig *tls.Config
var err error
Expand All @@ -122,12 +132,9 @@ func GetTlsConfig(networkAddress NetworkAddressData) *tls.Config {
utils.LavaFormatFatal("failed to generate TLS certificate", err)
}
} else {
cert, err := GenerateSelfSignedCertificate()
tlsConfig, err = GetSelfSignedConfig()
if err != nil {
utils.LavaFormatFatal("failed to generate TLS certificate", err)
}
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
utils.LavaFormatFatal("failed GetSelfSignedConfig", err)
}
}
return tlsConfig
Expand Down
2 changes: 1 addition & 1 deletion protocol/lavasession/consumer_session_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CreateConsumerSessionManager() *ConsumerSessionManager {
AllowInsecureConnectionToProviders = true // set to allow insecure for tests purposes
rand.InitRandomSeed()
baseLatency := common.AverageWorldLatency / 2 // we want performance to be half our timeout or better
return NewConsumerSessionManager(&RPCEndpoint{"stub", "stub", "stub", 0}, provideroptimizer.NewProviderOptimizer(provideroptimizer.STRATEGY_BALANCED, 0, baseLatency, 1), nil)
return NewConsumerSessionManager(&RPCEndpoint{"stub", "stub", "stub", false, "/", 0}, provideroptimizer.NewProviderOptimizer(provideroptimizer.STRATEGY_BALANCED, 0, baseLatency, 1), nil)
}

var grpcServer *grpc.Server
Expand Down
10 changes: 6 additions & 4 deletions protocol/lavasession/consumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ type SessionWithProvider struct {
type SessionWithProviderMap map[string]*SessionWithProvider

type RPCEndpoint struct {
NetworkAddress string `yaml:"network-address,omitempty" json:"network-address,omitempty" mapstructure:"network-address"` // HOST:PORT
ChainID string `yaml:"chain-id,omitempty" json:"chain-id,omitempty" mapstructure:"chain-id"` // spec chain identifier
ApiInterface string `yaml:"api-interface,omitempty" json:"api-interface,omitempty" mapstructure:"api-interface"`
Geolocation uint64 `yaml:"geolocation,omitempty" json:"geolocation,omitempty" mapstructure:"geolocation"`
NetworkAddress string `yaml:"network-address,omitempty" json:"network-address,omitempty" mapstructure:"network-address"` // HOST:PORT
ChainID string `yaml:"chain-id,omitempty" json:"chain-id,omitempty" mapstructure:"chain-id"` // spec chain identifier
ApiInterface string `yaml:"api-interface,omitempty" json:"api-interface,omitempty" mapstructure:"api-interface"`
TLSEnabled bool `yaml:"tls-enabled,omitempty" json:"tls-enabled,omitempty" mapstructure:"tls-enabled"`
HealthCheckPath string `yaml:"health-check-path,omitempty" json:"health-check-path,omitempty" mapstructure:"health-check-path"` // health check status code 200 path, default is "/"
Geolocation uint64 `yaml:"geolocation,omitempty" json:"geolocation,omitempty" mapstructure:"geolocation"`
}

func (endpoint *RPCEndpoint) String() (retStr string) {
Expand Down
3 changes: 3 additions & 0 deletions protocol/rpcconsumer/rpcconsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ func ParseEndpoints(viper_endpoints *viper.Viper, geolocation uint64) (endpoints
}
for _, endpoint := range endpoints {
endpoint.Geolocation = geolocation
if endpoint.HealthCheckPath == "" {
endpoint.HealthCheckPath = common.DEFAULT_HEALTH_PATH
}
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/rpcconsumer/rpcconsumer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (rpccs *RPCConsumerServer) SendRelay(
if len(relayResults) == 0 {
rpccs.appendHeadersToRelayResult(ctx, errorRelayResult, retries)
// suggest the user to add the timeout flag
if uint64(timeouts) == retries {
if uint64(timeouts) == retries && retries > 0 {
utils.LavaFormatDebug("all relays timeout", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "errors", Value: relayErrors.relayErrors})
return errorRelayResult, utils.LavaFormatError("Failed all relay retries due to timeout consider adding 'lava-relay-timeout' header to extend the allowed timeout duration", nil, utils.Attribute{Key: "GUID", Value: ctx})
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/rpcprovider/provider_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewProviderListener(ctx context.Context, networkAddress lavasession.Network

var serveExecutor func() error
if networkAddress.DisableTLS {
utils.LavaFormatWarning("Running with disabled TLS configuration", nil)
utils.LavaFormatInfo("Running with disabled TLS configuration")
serveExecutor = func() error { return pl.httpServer.Serve(lis) }
} else {
pl.httpServer.TLSConfig = lavasession.GetTlsConfig(networkAddress)
Expand Down
Loading

0 comments on commit c41d5cb

Please sign in to comment.