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

feat: use indexer directly [JS-842] #1069

Merged
merged 41 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
771f61e
feat: refactor configs [JS-831]
shamsartem Oct 30, 2024
38455bc
fix circular dependency
shamsartem Oct 30, 2024
7a61077
Apply automatic changes
shamsartem Oct 30, 2024
2fdc977
fix
shamsartem Oct 30, 2024
7991aeb
Apply automatic changes
shamsartem Oct 30, 2024
3dc1d8d
simplify
shamsartem Oct 30, 2024
0ebac89
import only what's needed from lodash
shamsartem Oct 30, 2024
75601cf
fix?
shamsartem Oct 30, 2024
5504ab5
just in case
shamsartem Oct 30, 2024
e804ef1
Merge branch 'main' into refactor
shamsartem Oct 30, 2024
7d9c540
Merge branch 'main' into refactor
shamsartem Oct 31, 2024
da98076
make all aliases hidden from top-level of help
shamsartem Oct 31, 2024
2d4acd2
Apply automatic changes
shamsartem Oct 31, 2024
41bcde0
stop managing ocker compose config completely
shamsartem Nov 1, 2024
d49a1f9
feat: use indexer directly
shamsartem Nov 5, 2024
616479f
fix
shamsartem Nov 5, 2024
eb52c51
don't require build for linting
shamsartem Nov 5, 2024
735d792
remove irrelevant dependencies
shamsartem Nov 5, 2024
be52e49
add docker for on-each-commit
shamsartem Nov 5, 2024
8856f00
add env
shamsartem Nov 5, 2024
fba4662
change runs-on
shamsartem Nov 5, 2024
5fdd23e
add permissions?
shamsartem Nov 5, 2024
22f6ada
fix and remove stuff from docs.yml
shamsartem Nov 5, 2024
c1530c8
fix
shamsartem Nov 5, 2024
ebfeec1
add generated to prettierignore
shamsartem Nov 6, 2024
a19187e
add config promise to the Map right away to prevent possible problems…
shamsartem Nov 6, 2024
53a68b0
fix
shamsartem Nov 6, 2024
278dcad
remove rest of the clients
shamsartem Nov 12, 2024
e3401d9
Merge branch 'main' into indexer
shamsartem Nov 12, 2024
65afa0f
get cc statuses from RPC
shamsartem Nov 12, 2024
9b0c2f7
lowercase dealId
shamsartem Nov 12, 2024
43dc831
add debug log
shamsartem Nov 12, 2024
6f70f4d
try using batch read like before instead of multicall read
shamsartem Nov 12, 2024
a7ee43f
try adding timeout
shamsartem Nov 12, 2024
7f53cee
use on-chain info for cc, refactor and fix
shamsartem Nov 13, 2024
cafff89
Apply automatic changes
shamsartem Nov 13, 2024
a194ec7
take ccId from subgraph if cc from RPC is zeroHash (was removed)
shamsartem Nov 13, 2024
9be7d30
don't convert already converted peerId
shamsartem Nov 13, 2024
b7c2a47
Merge branch 'main' into indexer
shamsartem Nov 18, 2024
20cb1b5
rename left-ower Fluence Labs
shamsartem Nov 18, 2024
c354632
improve startDate and expirationDate display
shamsartem Nov 27, 2024
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
Prev Previous commit
improve startDate and expirationDate display
shamsartem committed Nov 27, 2024
commit c35463221fe5b13e9ad625931c787e4198ab0430
27 changes: 20 additions & 7 deletions packages/cli/package/src/lib/chain/commitment.ts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's split this file into smaller ones

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't mind I will think about doing that in a separate PR. I think splitting the code in multiple files doesn't solve any concrete issues, more of a matter of a taste thing, though I could be wrong and I agree this file is pretty big already. On the other hand it still seems ok to work with and as a bonus doesn't require you to jump between many files when working with commitments, which is pretty convenient

Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ import type {
CapacityCommitmentStatus,
CcDetailsQuery,
} from "../gql/gqlGenerated.js";
import { bigintSecondsToDate } from "../helpers/bigintOps.js";
import { secondsToDate } from "../helpers/bigintOps.js";
import { stringifyUnknown } from "../helpers/stringifyUnknown.js";
import { bigintToStr, numToStr } from "../helpers/typesafeStringify.js";
import { splitErrorsAndResults, commaSepStrToArr } from "../helpers/utils.js";
@@ -1041,6 +1041,23 @@ async function getDetailedCommitmentInfo({
| undefined;
ccFromChain: Awaited<ReturnType<Contracts["diamond"]["getCommitment"]>>;
}) {
const { calculateTimestamp } = await import(
"@fluencelabs/deal-ts-clients/dist/dealExplorerClient/utils.js"
);

function getStartOrExpirationDate(epoch: bigint) {
// if startEpoch is 0, then it's not yet started - no need to show anything
return ccFromChain.startEpoch === 0n
? "-"
: secondsToDate(
calculateTimestamp(
Number(epoch),
Number(initTimestamp),
Number(epochDuration),
),
).toLocaleString();
}

const totalRewardsSplit = splitRewards(
totalRewards,
ccFromChain.rewardDelegatorRate,
@@ -1081,12 +1098,8 @@ async function getDetailedCommitmentInfo({
startEpoch: bigintToStr(ccFromChain.startEpoch),
endEpoch: bigintToStr(ccFromChain.endEpoch),
currentEpoch: bigintToStr(currentEpoch),
startDate: bigintSecondsToDate(
initTimestamp + ccFromChain.startEpoch * epochDuration,
).toLocaleString(),
expirationDate: bigintSecondsToDate(
initTimestamp + ccFromChain.endEpoch * epochDuration,
).toLocaleString(),
startDate: getStartOrExpirationDate(ccFromChain.startEpoch),
expirationDate: getStartOrExpirationDate(ccFromChain.endEpoch),
totalCU: bigintToStr(ccFromChain.unitCount),
missedProofs: bigintToStr(ccFromChain.totalFailCount),
threshold: bigintToStr(maxFailedRatio * ccFromChain.unitCount),
20 changes: 4 additions & 16 deletions packages/cli/package/src/lib/deal.ts
Original file line number Diff line number Diff line change
@@ -474,6 +474,10 @@ async function getMatchedOffersByDealId(dealAddress: string) {
throw new Error(`Deal already has target number of workers matched.`);
}

const { calculateEpoch } = await import(
"@fluencelabs/deal-ts-clients/dist/dealExplorerClient/utils.js"
);

const currentEpoch = calculateEpoch(
_meta.block.timestamp,
initTimestamp,
@@ -632,22 +636,6 @@ async function getMatchedOffersByDealId(dealAddress: string) {
return matchedOffers;
}

function calculateEpoch(
timestamp: number,
epochControllerStorageInitTimestamp: number,
epochControllerStorageEpochDuration: number,
) {
dbg(
`timestamp: ${numToStr(timestamp)} epochControllerStorageInitTimestamp: ${numToStr(epochControllerStorageInitTimestamp)} epochControllerStorageEpochDuration: ${numToStr(epochControllerStorageEpochDuration)}`,
);

return Math.floor(
1 +
(timestamp - epochControllerStorageInitTimestamp) /
epochControllerStorageEpochDuration,
);
}

function prepareDealProviderAccessLists(
providersAccessType: number,
providersAccessList:
4 changes: 2 additions & 2 deletions packages/cli/package/src/lib/helpers/bigintOps.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export function bigintSecondsToDate(bigSec: bigint): Date {
return new Date(Number(bigSec * 1000n));
export function secondsToDate(bigSec: bigint | number): Date {
return new Date(Number(bigSec) * 1000);
}