Skip to content

Commit

Permalink
fix(core-state): iterate over active delegates who have ranks (#4421)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainydio authored Jun 17, 2021
1 parent 76ecfe3 commit d634a92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/unit/core-state/round-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ describe("RoundState", () => {

getDposPreviousRoundState.mockReturnValue({
getAllDelegates: jest.fn().mockReturnValue(delegates),
getActiveDelegates: jest.fn().mockReturnValue(delegates),
getRoundDelegates: jest.fn().mockReturnValue(delegates),
});

Expand Down Expand Up @@ -659,6 +660,7 @@ describe("RoundState", () => {

getDposPreviousRoundState.mockReturnValue({
getAllDelegates: jest.fn().mockReturnValue(delegates),
getActiveDelegates: jest.fn().mockReturnValue(delegates),
getRoundDelegates: jest.fn().mockReturnValue(delegates),
});

Expand Down Expand Up @@ -797,6 +799,7 @@ describe("RoundState", () => {

getDposPreviousRoundState.mockReturnValue({
getAllDelegates: jest.fn().mockReturnValue(delegates),
getActiveDelegates: jest.fn().mockReturnValue(delegates),
getRoundDelegates: jest.fn().mockReturnValue(delegates),
});

Expand Down
1 change: 1 addition & 0 deletions packages/core-kernel/src/contracts/state/dpos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface DposState {

export interface DposPreviousRoundState {
getAllDelegates(): readonly Wallet[];
getActiveDelegates(): readonly Wallet[];
getRoundDelegates(): readonly Wallet[];
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core-state/src/dpos/dpos-previous-round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class DposPreviousRoundState implements Contracts.State.DposPreviousRound
return this.dposState.getAllDelegates();
}

public getActiveDelegates(): readonly Contracts.State.Wallet[] {
return this.dposState.getActiveDelegates();
}

public getRoundDelegates(): readonly Contracts.State.Wallet[] {
return this.dposState.getRoundDelegates();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core-state/src/round-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class RoundState {
const prevRoundState = await this.getDposPreviousRoundState(blocks, roundInfo);

// TODO: Move to Dpos
for (const prevRoundDelegateWallet of prevRoundState.getAllDelegates()) {
for (const prevRoundDelegateWallet of prevRoundState.getActiveDelegates()) {
// ! name suggest that this is pure function
// ! when in fact it is manipulating current wallet repository setting delegate ranks
const username = prevRoundDelegateWallet.getAttribute("delegate.username");
Expand Down

0 comments on commit d634a92

Please sign in to comment.