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

Merge master into develop #1540

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
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
62 changes: 33 additions & 29 deletions src/semibook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,48 +703,52 @@ class Semibook
public async stateInitialize(
block: BlockManager.BlockWithoutParentHash
): Promise<LogSubscriber.ErrorOrState<Semibook.State>> {
const localConfig = await this.getConfig(block.number); // TODO: make this reorg resistant too, but it's HIGHLY unlikely that we encounter an issue here
this.#offer_gasbase = localConfig.offer_gasbase;
try {
const localConfig = await this.getConfig(block.number); // TODO: make this reorg resistant too, but it's HIGHLY unlikely that we encounter an issue here
this.#offer_gasbase = localConfig.offer_gasbase;

/**
* To ensure consistency in this cache, everything is initially fetched from a specific block,
* we expect $fetchOfferListPrefix to return error if reorg is detected
*/
const result = await this.#fetchOfferListPrefix(block);

if (result.error) {
return { error: result.error, ok: undefined };
}

/**
* To ensure consistency in this cache, everything is initially fetched from a specific block,
* we expect $fetchOfferListPrefix to return error if reorg is detected
*/
const result = await this.#fetchOfferListPrefix(block);
const offers = result.ok;

if (result.error) {
return { error: result.error, ok: undefined };
}
if (offers.length > 0) {
const state: Semibook.State = {
bestInCache: offers[0].id,
worstInCache: offers[offers.length - 1].id,
offerCache: new Map(),
};

const offers = result.ok;
for (const offer of offers) {
this.#insertOffer(state, offer);
}

return {
error: undefined,
ok: state,
};
}

if (offers.length > 0) {
const state: Semibook.State = {
bestInCache: offers[0].id,
worstInCache: offers[offers.length - 1].id,
bestInCache: undefined,
worstInCache: undefined,
offerCache: new Map(),
};

for (const offer of offers) {
this.#insertOffer(state, offer);
}

return {
error: undefined,
ok: state,
};
} catch (e) {
return { error: "FailedInitialize", ok: undefined };
}

const state: Semibook.State = {
bestInCache: undefined,
worstInCache: undefined,
offerCache: new Map(),
};

return {
error: undefined,
ok: state,
};
}

public stateHandleLog(
Expand Down
Loading