Skip to content

Commit

Permalink
Settlement changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ejMina226 committed Dec 4, 2024
1 parent 7671c79 commit 1e7d420
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
4 changes: 3 additions & 1 deletion packages/common/src/trees/LinkedMerkleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export interface AbstractLinkedMerkleTree {
getWitness(path: bigint): LinkedLeafAndMerkleWitness;

dummyWitness(): LinkedMerkleTreeWitness;

dummy(): LinkedLeafAndMerkleWitness;
}

export interface AbstractLinkedMerkleTreeClass {
Expand Down Expand Up @@ -447,7 +449,7 @@ export function createLinkedMerkleTree(
});
}

private dummy(): LinkedLeafAndMerkleWitness {
public dummy(): LinkedLeafAndMerkleWitness {
return new LinkedLeafAndMerkleWitness({
merkleWitness: new RollupMerkleTreeWitness({
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class SettlementSmartContract
// Check witness
const path = Path.fromKey(mapPath, Field, counter);

args.witness
args.witness.merkleWitness
.checkMembership(
stateRoot,
path,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Bool, Provable, Struct } from "o1js";
import { RollupMerkleTreeWitness } from "@proto-kit/common";
import {
InMemoryLinkedMerkleLeafStore,
LinkedLeafAndMerkleWitness,
LinkedMerkleTree,
} from "@proto-kit/common";

import { Withdrawal } from "./Withdrawal";

export const OUTGOING_MESSAGE_BATCH_SIZE = 1;

export class OutgoingMessageArgument extends Struct({
witness: RollupMerkleTreeWitness,
witness: LinkedLeafAndMerkleWitness,
value: Withdrawal,
}) {
public static dummy(): OutgoingMessageArgument {
return new OutgoingMessageArgument({
witness: RollupMerkleTreeWitness.dummy(),
witness: new LinkedMerkleTree(
new InMemoryLinkedMerkleLeafStore()
).dummy(),
value: Withdrawal.dummy(),
});
}
Expand Down
14 changes: 8 additions & 6 deletions packages/sequencer/src/settlement/SettlementModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
EventEmittingComponent,
log,
noop,
RollupMerkleTree,
AreProofsEnabled,
LinkedMerkleTree,
} from "@proto-kit/common";
import { Runtime, RuntimeModulesRecord } from "@proto-kit/module";

Expand All @@ -43,11 +43,11 @@ import { SettlementStorage } from "../storage/repositories/SettlementStorage";
import { MessageStorage } from "../storage/repositories/MessageStorage";
import type { MinaBaseLayer } from "../protocol/baselayer/MinaBaseLayer";
import { Batch, SettleableBatch } from "../storage/model/Batch";
import { AsyncMerkleTreeStore } from "../state/async/AsyncMerkleTreeStore";
import { CachedMerkleTreeStore } from "../state/merkle/CachedMerkleTreeStore";
import { BlockProofSerializer } from "../protocol/production/helpers/BlockProofSerializer";
import { Settlement } from "../storage/model/Settlement";
import { FeeStrategy } from "../protocol/baselayer/fees/FeeStrategy";
import { AsyncLinkedMerkleTreeStore } from "../state/async/AsyncLinkedMerkleTreeStore";
import { CachedLinkedMerkleTreeStore } from "../state/merkle/CachedLinkedMerkleTreeStore";

import { IncomingMessageAdapter } from "./messages/IncomingMessageAdapter";
import type { OutgoingMessageQueue } from "./messages/WithdrawalQueue";
Expand Down Expand Up @@ -105,7 +105,7 @@ export class SettlementModule
@inject("OutgoingMessageQueue")
private readonly outgoingMessageQueue: OutgoingMessageQueue,
@inject("AsyncMerkleStore")
private readonly merkleTreeStore: AsyncMerkleTreeStore,
private readonly merkleTreeStore: AsyncLinkedMerkleTreeStore,
private readonly blockProofSerializer: BlockProofSerializer,
@inject("TransactionSender")
private readonly transactionSender: MinaTransactionSender,
Expand Down Expand Up @@ -206,8 +206,10 @@ export class SettlementModule

const { settlement } = this.getContracts();

const cachedStore = new CachedMerkleTreeStore(this.merkleTreeStore);
const tree = new RollupMerkleTree(cachedStore);
const cachedStore = await CachedLinkedMerkleTreeStore.new(
this.merkleTreeStore
);
const tree = new LinkedMerkleTree(cachedStore);

const [withdrawalModule, withdrawalStateName] =
this.getSettlementModuleConfig().withdrawalStatePath.split(".");
Expand Down
4 changes: 2 additions & 2 deletions packages/sequencer/test/settlement/Settlement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-inner-declarations */
import { log, mapSequential, RollupMerkleTree } from "@proto-kit/common";
import { LinkedMerkleTree, log, mapSequential } from "@proto-kit/common";
import { VanillaProtocolModules } from "@proto-kit/library";
import { Runtime } from "@proto-kit/module";
import {
Expand Down Expand Up @@ -274,7 +274,7 @@ export const settlementTestFn = (
batch!.proof.publicInput.map((x) => Field(x))
);
expect(input.stateRoot.toBigInt()).toStrictEqual(
RollupMerkleTree.EMPTY_ROOT
LinkedMerkleTree.EMPTY_ROOT
);

const lastBlock = await blockQueue.getLatestBlock();
Expand Down

0 comments on commit 1e7d420

Please sign in to comment.