Skip to content

Commit

Permalink
fix a bug of division by 0 when deleting entries
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlavanet committed Mar 24, 2022
1 parent f1f188b commit d1eef0f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 55 deletions.
40 changes: 20 additions & 20 deletions vue/src/store/generated/lavanet/lava/lavanet.lava.servicer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,23 +432,6 @@ export default {
throw new SpVuexError('QueryClient:QuerySessionStorageForSpecAll', 'API Node Unavailable. Could not perform query: ' + e.message);
}
},
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProofOfWork(value);
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee,
gas: "200000" }, memo });
return result;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: ' + e.message);
}
}
},
async sendMsgStakeServicer({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
Expand Down Expand Up @@ -483,18 +466,20 @@ export default {
}
}
},
async MsgProofOfWork({ rootGetters }, { value }) {
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProofOfWork(value);
return msg;
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee,
gas: "200000" }, memo });
return result;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message);
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: ' + e.message);
}
}
},
Expand Down Expand Up @@ -528,5 +513,20 @@ export default {
}
}
},
async MsgProofOfWork({ rootGetters }, { value }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProofOfWork(value);
return msg;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message);
}
}
},
}
};
40 changes: 20 additions & 20 deletions vue/src/store/generated/lavanet/lava/lavanet.lava.servicer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,21 +556,6 @@ export default {
},


async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProofOfWork(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: '+ e.message)
}
}
},
async sendMsgStakeServicer({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
Expand Down Expand Up @@ -601,21 +586,22 @@ export default {
}
}
},

async MsgProofOfWork({ rootGetters }, { value }) {
async sendMsgProofOfWork({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProofOfWork(value)
return msg
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message)

throw new SpVuexError('TxClient:MsgProofOfWork:Send', 'Could not broadcast Tx: '+ e.message)
}
}
},

async MsgStakeServicer({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
Expand Down Expand Up @@ -644,6 +630,20 @@ export default {
}
}
},
async MsgProofOfWork({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProofOfWork(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProofOfWork:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProofOfWork:Create', 'Could not create message: ' + e.message)

}
}
},

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StdFee } from "@cosmjs/launchpad";
import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgProofOfWork } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgUnstakeServicer } from "./types/servicer/tx";
import { MsgProofOfWork } from "./types/servicer/tx";
export declare const MissingWalletError: Error;
export declare const registry: Registry;
interface TxClientOptions {
Expand All @@ -15,9 +15,9 @@ interface SignAndBroadcastOptions {
}
declare const txClient: (wallet: OfflineSigner, { addr: addr }?: TxClientOptions) => Promise<{
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }?: SignAndBroadcastOptions) => any;
msgProofOfWork: (data: MsgProofOfWork) => EncodeObject;
msgStakeServicer: (data: MsgStakeServicer) => EncodeObject;
msgUnstakeServicer: (data: MsgUnstakeServicer) => EncodeObject;
msgProofOfWork: (data: MsgProofOfWork) => EncodeObject;
}>;
interface QueryClientOptions {
addr: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgProofOfWork } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgUnstakeServicer } from "./types/servicer/tx";
import { MsgProofOfWork } from "./types/servicer/tx";
const types = [
["/lavanet.lava.servicer.MsgProofOfWork", MsgProofOfWork],
["/lavanet.lava.servicer.MsgStakeServicer", MsgStakeServicer],
["/lavanet.lava.servicer.MsgUnstakeServicer", MsgUnstakeServicer],
["/lavanet.lava.servicer.MsgProofOfWork", MsgProofOfWork],
];
export const MissingWalletError = new Error("wallet is required");
export const registry = new Registry(types);
Expand All @@ -29,9 +29,9 @@ const txClient = async (wallet, { addr: addr } = { addr: "http://localhost:26657
const { address } = (await wallet.getAccounts())[0];
return {
signAndBroadcast: (msgs, { fee, memo } = { fee: defaultFee, memo: "" }) => client.signAndBroadcast(address, msgs, fee, memo),
msgProofOfWork: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgProofOfWork", value: MsgProofOfWork.fromPartial(data) }),
msgStakeServicer: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgStakeServicer", value: MsgStakeServicer.fromPartial(data) }),
msgUnstakeServicer: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgUnstakeServicer", value: MsgUnstakeServicer.fromPartial(data) }),
msgProofOfWork: (data) => ({ typeUrl: "/lavanet.lava.servicer.MsgProofOfWork", value: MsgProofOfWork.fromPartial(data) }),
};
};
const queryClient = async ({ addr: addr } = { addr: "http://localhost:1317" }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { StdFee } from "@cosmjs/launchpad";
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgProofOfWork } from "./types/servicer/tx";
import { MsgStakeServicer } from "./types/servicer/tx";
import { MsgUnstakeServicer } from "./types/servicer/tx";
import { MsgProofOfWork } from "./types/servicer/tx";


const types = [
["/lavanet.lava.servicer.MsgProofOfWork", MsgProofOfWork],
["/lavanet.lava.servicer.MsgStakeServicer", MsgStakeServicer],
["/lavanet.lava.servicer.MsgUnstakeServicer", MsgUnstakeServicer],
["/lavanet.lava.servicer.MsgProofOfWork", MsgProofOfWork],

];
export const MissingWalletError = new Error("wallet is required");
Expand Down Expand Up @@ -45,9 +45,9 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =

return {
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
msgProofOfWork: (data: MsgProofOfWork): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgProofOfWork", value: MsgProofOfWork.fromPartial( data ) }),
msgStakeServicer: (data: MsgStakeServicer): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgStakeServicer", value: MsgStakeServicer.fromPartial( data ) }),
msgUnstakeServicer: (data: MsgUnstakeServicer): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgUnstakeServicer", value: MsgUnstakeServicer.fromPartial( data ) }),
msgProofOfWork: (data: MsgProofOfWork): EncodeObject => ({ typeUrl: "/lavanet.lava.servicer.MsgProofOfWork", value: MsgProofOfWork.fromPartial( data ) }),

};
};
Expand Down
5 changes: 4 additions & 1 deletion x/servicer/keeper/previous_session_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ func (k Keeper) GetSessionStartForBlock(ctx sdk.Context, block types.BlockNum) (
}
blockCycleToUse := k.SessionBlocks(ctx)
overlapBlocks := k.SessionBlocksOverlap(ctx)
if previousSessionsBlocks.ChangeBlock.Num >= block.Num {
if previousSessionsBlocks.ChangeBlock.Num > block.Num {
blockCycleToUse = previousSessionsBlocks.BlocksNum
overlapBlocks = previousSessionsBlocks.OverlapBlocks
}
if blockCycleToUse == 0 {
panic(fmt.Sprintf("blockCycleToUse is 0: previous session block: %d, block num:%d", previousSessionsBlocks.ChangeBlock.Num, block.Num))
}
blocksInTargetSession := block.Num % blockCycleToUse
targetBlockStart := block.Num - blocksInTargetSession
overlappingPreviousSession = nil
Expand Down
15 changes: 9 additions & 6 deletions x/servicer/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ var (
)

var (
KeySessionBlocks = []byte("SessionBlocks")
DefaultSessionBlocks uint64 = 200
KeySessionBlocks = []byte("SessionBlocks")
// DefaultSessionBlocks uint64 = 200
DefaultSessionBlocks uint64 = 20
)

var (
KeySessionsToSave = []byte("SessionsToSave")
DefaultSessionsToSave uint64 = 100
KeySessionsToSave = []byte("SessionsToSave")
// DefaultSessionsToSave uint64 = 100
DefaultSessionsToSave uint64 = 10
)

var (
KeySessionBlocksOverlap = []byte("SessionBlocksOverlap")
DefaultSessionBlocksOverlap uint64 = 20
KeySessionBlocksOverlap = []byte("SessionBlocksOverlap")
// DefaultSessionBlocksOverlap uint64 = 20
DefaultSessionBlocksOverlap uint64 = 5
)

// ParamKeyTable the param key table for launch module
Expand Down

0 comments on commit d1eef0f

Please sign in to comment.