Skip to content

Commit

Permalink
Disabling optimistic mode for complex transfers and withdrawals (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenKor authored Sep 9, 2024
1 parent e074115 commit 7d5d428
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,13 @@ export class ZkBobClient extends ZkBobProvider {
let jobs: SequencerJob[] = [];
let optimisticState = ZERO_OPTIMISTIC_STATE;
for (let index = 0; index < txParts.length; index++) {

// TODO: remove it
// disabling optimistic mode
if (index > 0) {
await this.waitReadyToTransact();
}

const onePart = txParts[index];
const outputs = onePart.outNotes.map((aNote) => { return {to: aNote.destination, amount: `${aNote.amountGwei}`} });
const oneTx: ITransferData = {
Expand Down Expand Up @@ -1091,7 +1098,8 @@ export class ZkBobClient extends ZkBobProvider {
// if there are few additional tx, we should collect the optimistic state before processing them
await this.waitJobTxHash(aJob);

optimisticState = await this.zpState().getNewState(this.sequencer(), this.account?.birthindex ?? 0);
// TODO: come back to optimistic transactions [they were temporary disabled due to decentralized sequencer specific]
//optimisticState = await this.zpState().getNewState(this.sequencer(), this.account?.birthindex ?? 0);
}
}

Expand Down Expand Up @@ -1147,6 +1155,12 @@ export class ZkBobClient extends ZkBobProvider {
let optimisticState = ZERO_OPTIMISTIC_STATE;
for (let index = 0; index < txParts.length; index++) {
const onePart = txParts[index];

// TODO: remove it
// disabling optimistic mode
if (index > 0) {
await this.waitReadyToTransact();
}

let oneTxData: any;
let txType: RegularTxType;
Expand All @@ -1159,6 +1173,7 @@ export class ZkBobClient extends ZkBobProvider {
prover_fee: onePart.fee.proverPart.toString(),
data: [],
};

oneTxData = await state.createTransferOptimistic(oneTx, optimisticState);
txType = RegularTxType.Transfer;
} else if (onePart.outNotes.length == 1) {
Expand All @@ -1173,6 +1188,7 @@ export class ZkBobClient extends ZkBobProvider {
prover_fee: onePart.fee.proverPart.toString(),
data: [],
};

oneTxData = await state.createWithdrawalOptimistic(oneTx, optimisticState);
txType = RegularTxType.Withdraw;
} else {
Expand Down Expand Up @@ -1206,7 +1222,8 @@ export class ZkBobClient extends ZkBobProvider {
// if there are few additional tx, we should collect the optimistic state before processing them
await this.waitJobTxHash(aJob);

optimisticState = await this.zpState().getNewState(this.sequencer(), this.account?.birthindex ?? 0);
// TODO: come back to optimistic transactions [they were temporary disabled due to decentralized sequencer specific]
//optimisticState = await this.zpState().getNewState(this.sequencer(), this.account?.birthindex ?? 0);
}
}

Expand Down

0 comments on commit 7d5d428

Please sign in to comment.