-
Notifications
You must be signed in to change notification settings - Fork 151
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
fix(ParasService): adjust endpoint to use historicApi, fix endingOffset bug #735
Changes from 1 commit
0592f95
85377b6
6302683
47d48f6
dca40f8
c408b4c
202036b
bb569dc
0022526
24148e0
18ae042
5f1109c
7415f9f
af7e704
dfa5f0f
f632e6a
c51ea90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,11 +151,13 @@ export class ParasService extends AbstractService { | |
const currentLeasePeriodIndex = this.leasePeriodIndexAt( | ||
historicApi, | ||
blockNumber | ||
).toNumber(); | ||
); | ||
|
||
leasesFormatted = leases.reduce((acc, curLeaseOpt, idx) => { | ||
if (curLeaseOpt.isSome) { | ||
const leasePeriodIndex = currentLeasePeriodIndex + idx; | ||
const leasePeriodIndex = currentLeasePeriodIndex | ||
? currentLeasePeriodIndex.toNumber() + idx | ||
: 0; | ||
const lease = curLeaseOpt.unwrap(); | ||
acc.push({ | ||
leasePeriodIndex, | ||
|
@@ -330,14 +332,16 @@ export class ParasService extends AbstractService { | |
|
||
const leasePeriod = historicApi.consts.slots.leasePeriod as BlockNumber; | ||
const leasePeriodIndex = this.leasePeriodIndexAt(historicApi, blockNumber); | ||
const endOfLeasePeriod = leasePeriodIndex.mul(leasePeriod).add(leasePeriod); | ||
const endOfLeasePeriod = leasePeriodIndex | ||
? leasePeriodIndex.mul(leasePeriod).add(leasePeriod) | ||
: BN_ZERO; | ||
|
||
return { | ||
at: { | ||
hash, | ||
height: blockNumber.toString(10), | ||
}, | ||
leasePeriodIndex, | ||
leasePeriodIndex: leasePeriodIndex ? leasePeriodIndex : BN_ZERO, | ||
TarikGul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endOfLeasePeriod, | ||
currentLeaseHolders, | ||
}; | ||
|
@@ -399,11 +403,16 @@ export class ParasService extends AbstractService { | |
private leasePeriodIndexAt( | ||
historicApi: ApiDecoration<'promise'>, | ||
now: BN | ||
): BN { | ||
): IOption<BN> { | ||
const leasePeriod = historicApi.consts.slots.leasePeriod as BlockNumber; | ||
const offset = | ||
(historicApi.consts.slots.leaseOffset as BlockNumber) || BN_ZERO; | ||
|
||
// Edge case, see https://github.com/paritytech/polkadot/commit/3668966dc02ac793c799d8c8667e8c396d891734 | ||
if (now.toNumber() - offset.toNumber() < 0) { | ||
return null; | ||
} | ||
|
||
return now.sub(offset).div(leasePeriod); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be updated slightly. There is an edge case where offset > now and we decided to consider this has have no lease period index. In the substrate code this is represented by None. Here is the line paritytech/polkadot@3668966#diff-3e19d8a242311f202d80bcf9998ffdc22ddd933ed340f308276f353f137e2304R444 So basically it says "if now - offset is less than 0, return None". So we need a update for the logic that uses this function to basically say there is no lease period at (This logic which got added to the substrate PR a bit late). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (You can see the changes for this in substrate commit paritytech/polkadot@3668966) |
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this should be returning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be null