Skip to content

Commit

Permalink
fix(p2p): download messages from higher round (#261)
Browse files Browse the repository at this point in the history
* Download messages if round is higher

* Check download messages

* Check our header

* Signatures count in header

* Fix higher round handling

* Remove RoundState from header

* Use readonly

* Set downloads by round

* Round state returns prevotes and precommits

* Return array

* Return latest round with minority

* Extract check message

* Extract check response

* Split check response

* Support full download

* Cleanup

* Don't decrease below requested round

* Fixes

* Fix getMessages

* Check messages have same round and height

* REmove console.log

* Typo

* Move can download check to downloader

* Calculate round

* Remove TODOS

* Move method

* Extract method

* Calculate round

* Cleanup

* Rename methods

* Determine reponse check based on response

* Ensure that round is higher for full download

* Add round and height to DownloadJob

* Move can downloadProposal inside proposal downloader

* Rename field

* Add round and height to job

* Set proposal on header

* Move download check

* Allow 2 sequential proposals

* Fix minority check
  • Loading branch information
sebastijankuzner authored Oct 4, 2023
1 parent d18d3d8 commit 9af1ac1
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 172 deletions.
12 changes: 10 additions & 2 deletions packages/consensus/source/round-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,23 @@ export class RoundState implements Contracts.Consensus.IRoundState {
return this.#prevotes.get(validatorIndex);
}

public getPrevotes(): Contracts.Crypto.IPrevote[] {
return [...this.#prevotes.values()];
}

public getPrecommit(validatorIndex: number): Contracts.Crypto.IPrecommit | undefined {
return this.#precommits.get(validatorIndex);
}

public getValidatorsSignedPrevote(): boolean[] {
public getPrecommits(): Contracts.Crypto.IPrecommit[] {
return [...this.#precommits.values()];
}

public getValidatorsSignedPrevote(): readonly boolean[] {
return this.#validatorsSignedPrevote;
}

public getValidatorsSignedPrecommit(): boolean[] {
public getValidatorsSignedPrecommit(): readonly boolean[] {
return this.#validatorsSignedPrecommit;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/contracts/source/contracts/consensus/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export interface IRoundState extends IProcessableUnit {
hasMinorityPrevotesOrPrecommits(): boolean;
getPrevote(validatorIndex: number): IPrevote | undefined;
getPrecommit(validatorIndex: number): IPrecommit | undefined;
getPrevotes(): IPrevote[];
getPrecommits(): IPrecommit[];
getValidator(consensusPublicKey: string): IValidatorWallet;
getValidatorsSignedPrevote(): boolean[];
getValidatorsSignedPrecommit(): boolean[];
getValidatorsSignedPrevote(): readonly boolean[];
getValidatorsSignedPrecommit(): readonly boolean[];
aggregatePrevotes(): Promise<IAggregatedSignature>;
aggregatePrecommits(): Promise<IAggregatedSignature>;
logPrevotes(): void;
Expand Down
14 changes: 8 additions & 6 deletions packages/contracts/source/contracts/p2p/header.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { IRoundState } from "../consensus/consensus";
import { Contracts } from "../..";

export type IHeaderData = {
version: string;
height: number;
round: number;
step: number;
proposedBlockId?: string;
validatorsSignedPrevote: boolean[];
validatorsSignedPrecommit: boolean[];
validatorsSignedPrevote: readonly boolean[];
validatorsSignedPrecommit: readonly boolean[];
};

export interface IHeader {
height: number;
round: number;
roundState: IRoundState;
proposal?: Contracts.Crypto.IProposal;
validatorsSignedPrecommit: readonly boolean[];
validatorsSignedPrevote: readonly boolean[];

toData(): IHeaderData;
canDownloadProposal(headerData: IHeaderData): boolean;
canDownloadMessages(headerData: IHeaderData): boolean;
getValidatorsSignedPrecommitCount(): number;
getValidatorsSignedPrevoteCount(): number;
}

export type HeaderFactory = () => IHeader;
Loading

0 comments on commit 9af1ac1

Please sign in to comment.