Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNS-137: implement new jailing design #238

Merged
merged 44 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4b9dfc8
CNS-137: added check that consumer is paired with reported provider
oren-lava Jan 10, 2023
f30dee1
CNS-137: changed proto of provider payment storage
oren-lava Jan 10, 2023
d7f055c
CNS-137: update complainer CU in provider payment storage (according …
oren-lava Jan 11, 2023
c3829b7
CNS-137: implemented new unresponsive punishment mechanism
oren-lava Jan 11, 2023
316f84d
CNS-137: small fixes
oren-lava Jan 12, 2023
8b4e2ba
CNS-137: moved unresponsive unit test to seperate file + rename
oren-lava Jan 12, 2023
481e2cd
CNS-137: finished implementing the new jailing mechanism
oren-lava Jan 15, 2023
3b7b508
CNS-137: fix small bug - epoch payments saved providerPaymentStorage …
oren-lava Jan 15, 2023
f9b8474
CNS-137: created new pairing param RecommendedEpochNumToCollectPayment
oren-lava Jan 15, 2023
dd435f0
CNS-137: fixed minor bugs in unresponsive code
oren-lava Jan 16, 2023
5087d0e
CNS-137: fixed unresponsive unit tests
oren-lava Jan 16, 2023
ecd0c94
CNS-137: checking only payments of staked providers (instead of all p…
oren-lava Jan 16, 2023
400de41
CNS-137: added stress test
oren-lava Jan 16, 2023
b0c5dc0
CNS-137: rename test file (typo)
oren-lava Jan 16, 2023
fd177c0
CNS-137: lowered the providers/clients amount in the stress test (so …
oren-lava Jan 16, 2023
3f31066
CNS-137: fix PR issues
oren-lava Jan 18, 2023
382ad08
CNS-137: fix typo
oren-lava Jan 18, 2023
84e1a63
CNS-137: in sentry replaced StaleEpochDistance with recommendedEpochN…
oren-lava Jan 19, 2023
645be2b
CNS-137: fix additional PR issues
oren-lava Jan 19, 2023
bae645c
CNS-137: fix more PR issues
oren-lava Jan 19, 2023
3bc9cb1
CNS-137: revert sentry.go change for testing
oren-lava Jan 22, 2023
b6e4b93
CNS-137: fix small PR issue (unresponsive list check)
oren-lava Jan 22, 2023
ebc575b
CNS-137: revert sentry.go changes
oren-lava Jan 29, 2023
de591e3
CNS-137: moved servicersToPair CU division to relay payment
oren-lava Jan 29, 2023
16eb24b
CNS-137: changed proto to camelCase
oren-lava Jan 29, 2023
c814dd7
CNS-137: moved epoch start funcs in each module to a designated func
oren-lava Jan 29, 2023
2d5cb6e
CNS-137: rename ClientPayments to ProviderPaymentStorages in epochPay…
oren-lava Jan 29, 2023
bf93de5
CNS-137: fix PR issues
oren-lava Jan 30, 2023
0fccd13
CNS-137: merge branch 'main' into CNS-137
oren-lava Feb 1, 2023
816f651
CNS-137: another merge of branch 'main' into CNS-137
oren-lava Feb 1, 2023
787e9ab
CNS-137: added RecommendedEpochNumToCollectPayment param
oren-lava Feb 1, 2023
49cebea
CNS-137: fixed unresponsive provider to work with new payment objects…
oren-lava Feb 1, 2023
e4085b7
CNS-137: fix minor PR issues
oren-lava Feb 2, 2023
04db712
Merge branch 'main' into CNS-137-implement
oren-lava Feb 2, 2023
8cc05aa
CNS-137: changed providerPaymentStorage proto field nums
oren-lava Feb 2, 2023
61cf4d1
Merge branch 'CNS-137-implement' of github.com:lavanet/lava into CNS-…
oren-lava Feb 2, 2023
27690c0
CNS-137: added upgrade v0.5.1 which inits the RecommendedEpochNumToCo…
oren-lava Feb 5, 2023
884b1fa
Merge branch 'main' into CNS-137-implement
oren-lava Feb 5, 2023
2a556f4
CNS-137: fix unit tests PR issues
oren-lava Feb 6, 2023
eae380f
CNS-137: changed upgrade tag to v0.5.2 to avoid conflicts
oren-lava Feb 6, 2023
7223b24
Merge branch 'main' into CNS-137-implement
oren-lava Feb 6, 2023
42d71b1
CNS-137: fix lint issues
oren-lava Feb 6, 2023
c18c030
Merge branch 'CNS-137-implement' of github.com:lavanet/lava into CNS-…
oren-lava Feb 6, 2023
24a3def
CNS-137: fix more lint issues
oren-lava Feb 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ jobs:

# Install Ignite
- name: ignite install
uses: nick-fields/retry@v2
with:
max_attempts: 3
retry_on: error
timeout_minutes: 20
command: git clone --depth 1 --branch v0.22.2 https://github.com/ignite/cli && cd cli && make install

run: git clone --depth 1 --branch v0.22.2 https://github.com/ignite/cli && cd cli && make install
# run: curl https://get.ignite.com/cli! | bash
- name: ignite version
run: ignite version
# - name: starport install
# run: curl https://get.starport.network/starport@v0.19.2! | bash
# - name: starport version
# run: starport version

# Setup Paths
- name: home
Expand Down Expand Up @@ -188,4 +187,5 @@ jobs:
- name: GRPC Gateway Error Only Logs
if: always()
continue-on-error: true

run: cat testutil/e2e/logs/11_grpcGateway_errors.log
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import (
"github.com/lavanet/lava/app/keepers"
"github.com/lavanet/lava/app/upgrades"
"github.com/lavanet/lava/app/upgrades/v0_5_0"
"github.com/lavanet/lava/app/upgrades/v0_5_1"
"github.com/lavanet/lava/docs"
conflictmodule "github.com/lavanet/lava/x/conflict"
conflictmodulekeeper "github.com/lavanet/lava/x/conflict/keeper"
Expand Down Expand Up @@ -116,7 +117,7 @@ const (
)

// Upgrades add here future upgrades (upgrades.Upgrade)
var Upgrades = []upgrades.Upgrade{upgrades.Upgrade_0_4_0, upgrades.Upgrade_0_4_3, upgrades.Upgrade_0_4_4, upgrades.Upgrade_0_4_5, v0_5_0.Upgrade}
var Upgrades = []upgrades.Upgrade{upgrades.Upgrade_0_4_0, upgrades.Upgrade_0_4_3, upgrades.Upgrade_0_4_4, upgrades.Upgrade_0_4_5, v0_5_0.Upgrade, v0_5_1.Upgrade}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

Expand Down
39 changes: 39 additions & 0 deletions app/upgrades/v0_5_1/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v0_5_1

import (
"log"

store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/lavanet/lava/app/keepers"
"github.com/lavanet/lava/app/upgrades"
pairingtypes "github.com/lavanet/lava/x/pairing/types"
)

const UpgradeName = "v0.5.1"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName, // upgrade name defined few lines above
CreateUpgradeHandler: CreateUpgradeHandler, // create CreateUpgradeHandler in upgrades.go below
StoreUpgrades: store.StoreUpgrades{}, // StoreUpgrades has 3 fields: Added/Renamed/Deleted any module that fits these description should be added in the way below
}

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.LavaKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
log.Println("########################")
log.Println("# STARTING UPGRADE #")
log.Println("########################")

// we use a dedicated SET since the upgrade package doesn't have access to the paramstore, thus can't set a parameter directly
keepers.PairingKeeper.SetRecommendedEpochNumToCollectPayment(ctx, pairingtypes.DefaultRecommendedEpochNumToCollectPayment)

return mm.RunMigrations(ctx, configurator, vm)
}
}
1 change: 1 addition & 0 deletions proto/pairing/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 recommendedEpochNumToCollectPayment = 14 [(gogoproto.moretags) = "yaml:\"recommended_epoch_num_to_collect_payment\""];
}
4 changes: 3 additions & 1 deletion proto/pairing/provider_payment_storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ option go_package = "github.com/lavanet/lava/x/pairing/types";
import "pairing/unique_payment_storage_client_provider.proto";

message ProviderPaymentStorage {

string index = 1;
reserved 2;
uint64 epoch = 3;
repeated string unresponsiveness_complaints = 4;
reserved 4;
repeated string uniquePaymentStorageClientProviderKeys = 5;
uint64 complainersTotalCu = 6; // total CU that were supposed to be served by the provider but didn't because he was unavailable (so consumers complained about him)
}
// change Client -> consumer

Expand Down
20 changes: 6 additions & 14 deletions testutil/keeper/keepers_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
conflicttypes "github.com/lavanet/lava/x/conflict/types"
epochstoragekeeper "github.com/lavanet/lava/x/epochstorage/keeper"
epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types"
"github.com/lavanet/lava/x/pairing"
pairingkeeper "github.com/lavanet/lava/x/pairing/keeper"
pairingtypes "github.com/lavanet/lava/x/pairing/types"
"github.com/lavanet/lava/x/spec"
Expand All @@ -31,7 +32,9 @@ import (
tmdb "github.com/tendermint/tm-db"
)

const BLOCK_TIME = 30 * time.Second
const (
BLOCK_TIME = 30 * time.Second
)

const BLOCK_HEADER_LEN = 32

Expand Down Expand Up @@ -214,20 +217,9 @@ func AdvanceEpoch(ctx context.Context, ks *Keepers, customBlockTime ...time.Dura
// Make sure you save the new context
func NewBlock(ctx context.Context, ks *Keepers, customTime ...time.Duration) {
unwrapedCtx := sdk.UnwrapSDKContext(ctx)
block := uint64(unwrapedCtx.BlockHeight())
if ks.Epochstorage.IsEpochStart(sdk.UnwrapSDKContext(ctx)) {
ks.Epochstorage.FixateParams(unwrapedCtx, block)
// begin block
ks.Epochstorage.SetEpochDetailsStart(unwrapedCtx, block)
ks.Epochstorage.StoreCurrentEpochStakeStorage(unwrapedCtx, block, epochstoragetypes.ProviderKey)
ks.Epochstorage.StoreCurrentEpochStakeStorage(unwrapedCtx, block, epochstoragetypes.ClientKey)

ks.Epochstorage.UpdateEarliestEpochstart(unwrapedCtx)
ks.Epochstorage.RemoveOldEpochData(unwrapedCtx, epochstoragetypes.ProviderKey)
ks.Epochstorage.RemoveOldEpochData(unwrapedCtx, epochstoragetypes.ClientKey)

ks.Pairing.RemoveOldEpochPayment(unwrapedCtx)
ks.Pairing.CheckUnstakingForCommit(unwrapedCtx)
ks.Epochstorage.EpochStart(unwrapedCtx)
ks.Pairing.EpochStart(unwrapedCtx, pairing.EPOCHS_NUM_TO_CHECK_CU_FOR_UNRESPONSIVE_PROVIDER, pairing.EPOCHS_NUM_TO_CHECK_FOR_COMPLAINERS)
}

ks.Conflict.CheckAndHandleAllVotes(unwrapedCtx)
Expand Down
32 changes: 32 additions & 0 deletions x/epochstorage/keeper/epoch_start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/x/epochstorage/types"
)

// Function that calls all the functions that are supposed to run in epoch start
func (k Keeper) EpochStart(ctx sdk.Context) {
block := uint64(ctx.BlockHeight())

// save params for this epoch
k.FixateParams(ctx, block)

// on Epoch start we need to do:
// 1. update Epoch start
// 2. update the StakeStorage
// on epoch start block end: (because other modules need this info) to clear their storages
// 3. remove old StakeStorage
// 4. update earliest epoch start

k.SetEpochDetailsStart(ctx, block)

k.StoreCurrentEpochStakeStorage(ctx, block, types.ProviderKey)

k.StoreCurrentEpochStakeStorage(ctx, block, types.ClientKey)

k.UpdateEarliestEpochstart(ctx)

k.RemoveOldEpochData(ctx, types.ProviderKey)
k.RemoveOldEpochData(ctx, types.ClientKey)
}
24 changes: 2 additions & 22 deletions x/epochstorage/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,8 @@ func (AppModule) ConsensusVersion() uint64 { return 2 }
// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
if am.keeper.IsEpochStart(ctx) {
block := uint64(ctx.BlockHeight())

// save params for this epoch
am.keeper.FixateParams(ctx, block)

// on Epoch start we need to do:
// 1. update Epoch start
// 2. update the StakeStorage
// on epoch start block end: (because other modules need this info) to clear their storages
// 3. remove old StakeStorage
// 4. update earliest epoch start

am.keeper.SetEpochDetailsStart(ctx, block)

am.keeper.StoreCurrentEpochStakeStorage(ctx, block, types.ProviderKey)

am.keeper.StoreCurrentEpochStakeStorage(ctx, block, types.ClientKey)

am.keeper.UpdateEarliestEpochstart(ctx)

am.keeper.RemoveOldEpochData(ctx, types.ProviderKey)
am.keeper.RemoveOldEpochData(ctx, types.ClientKey)
// run functions that are supposed to run in epoch start
am.keeper.EpochStart(ctx)

// Notify world we have a new session

Expand Down
34 changes: 34 additions & 0 deletions x/pairing/keeper/epoch_start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/utils"
)

// Function that calls all the functions that are supposed to run in epoch start
func (k Keeper) EpochStart(ctx sdk.Context, epochsNumToCheckCuForUnresponsiveProvider uint64, epochsNumToCheckForComplainers uint64) {
logger := k.Logger(ctx)
logOnErr := func(err error, failingFunc string) {
if err != nil {
attrs := map[string]string{"error": err.Error()}
utils.LavaError(ctx, logger, "new_epoch", attrs, failingFunc)
}
}
// on session start we need to do:
// 1. remove old session payments
// 2. unstake any unstaking providers
// 3. unstake any unstaking users
// 4. unstake/jail unresponsive providers

// 1.
err := k.RemoveOldEpochPayment(ctx)
logOnErr(err, "RemoveOldEpochPayment")

// 2+3.
err = k.CheckUnstakingForCommit(ctx)
logOnErr(err, "CheckUnstakingForCommit")

// 4. unstake unresponsive providers
err = k.UnstakeUnresponsiveProviders(ctx, epochsNumToCheckCuForUnresponsiveProvider, epochsNumToCheckForComplainers)
logOnErr(err, "UnstakeUnresponsiveProviders")
}
Loading