Skip to content

Commit 51524b7

Browse files
committed
prerelease fixes
1 parent 3c1cbf3 commit 51524b7

File tree

7 files changed

+54
-72
lines changed

7 files changed

+54
-72
lines changed

packages/cli/src/LocalhostAppChain.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
StateServiceQueryModule,
2828
BlockStorageNetworkStateModule,
2929
AppChainModulesRecord,
30+
InMemoryTransactionSender,
3031
} from "@proto-kit/sdk";
3132

3233
export class LocalhostAppChain<
@@ -67,6 +68,9 @@ export class LocalhostAppChain<
6768
}),
6869
}),
6970
modules: {
71+
// TODO: remove in favour of a real tx sender for the SettlementModule
72+
// temporary dependency to make the SettlementModule work
73+
TransactionSender: InMemoryTransactionSender,
7074
QueryTransportModule: StateServiceQueryModule,
7175
NetworkStateTransportModule: BlockStorageNetworkStateModule,
7276
},

packages/library/src/hooks/TransactionFeeHook.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
BlockProverExecutionData,
1212
PublicKeyOption,
1313
} from "@proto-kit/protocol";
14-
import { Field, Provable, PublicKey, UInt64 as O1JSUInt64 } from "o1js";
14+
import { Field, Provable, PublicKey } from "o1js";
1515

1616
import { UInt64 } from "../math/UInt64";
1717

@@ -137,12 +137,12 @@ export class TransactionFeeHook extends ProvableTransactionHook<TransactionFeeHo
137137
errors.invalidFeeConfigMethodId()
138138
);
139139

140-
const fee = O1JSUInt64.from(feeConfig.baseFee.value).add(
141-
O1JSUInt64.from(feeConfig.weight.value).mul(
142-
O1JSUInt64.from(feeConfig.perWeightUnitFee.value)
140+
const fee = UInt64.from(feeConfig.baseFee.value).add(
141+
UInt64.from(feeConfig.weight.value).mul(
142+
UInt64.from(feeConfig.perWeightUnitFee.value)
143143
)
144144
);
145145

146-
this.transferFee(executionData.transaction.sender, new UInt64(fee.value));
146+
this.transferFee(executionData.transaction.sender, UInt64.from(fee.value));
147147
}
148148
}

packages/library/src/runtime/Balances.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
runtimeModule,
1414
} from "@proto-kit/module";
1515
import { StateMap, assert } from "@proto-kit/protocol";
16-
import { Field, Provable, PublicKey, Struct, UInt64 } from "o1js";
16+
import { Field, PublicKey, Struct } from "o1js";
17+
import { UInt64 } from "../math/UInt64";
1718

1819
export const errors = {
1920
senderNotFrom: () => "Sender does not match 'from'",
@@ -25,8 +26,9 @@ export class BalancesKey extends Struct({
2526
tokenId: TokenId,
2627
address: PublicKey,
2728
}) {
28-
// eslint-disable-next-line @typescript-eslint/no-empty-function
29-
public test() {}
29+
public static from(tokenId: TokenId, address: PublicKey) {
30+
return new BalancesKey({ tokenId, address });
31+
}
3032
}
3133

3234
export class Balance extends UInt64 {}
@@ -58,13 +60,8 @@ export class Balances<Config = NoConfig>
5860
public getBalance(tokenId: TokenId, address: PublicKey): Balance {
5961
const key = new BalancesKey({ tokenId, address });
6062
const balanceOption = this.balances.get(key);
61-
62-
return Provable.if<Balance>(
63-
balanceOption.isSome,
64-
Balance,
65-
balanceOption.value,
66-
Balance.from(0)
67-
);
63+
const balance = Balance.from(balanceOption.value.value);
64+
return balance;
6865
}
6966

7067
public setBalance(tokenId: TokenId, address: PublicKey, amount: Balance) {
@@ -85,16 +82,7 @@ export class Balances<Config = NoConfig>
8582

8683
assert(fromBalanceIsSufficient, errors.fromBalanceInsufficient());
8784

88-
// used to prevent field underflow during subtraction
89-
const paddedFrombalance = fromBalance.add(amount);
90-
const safeFromBalance = Provable.if<Balance>(
91-
fromBalanceIsSufficient,
92-
Balance,
93-
fromBalance,
94-
paddedFrombalance
95-
);
96-
97-
const newFromBalance = safeFromBalance.sub(amount);
85+
const newFromBalance = fromBalance.sub(amount);
9886
const newToBalance = toBalance.add(amount);
9987

10088
this.setBalance(tokenId, from, newFromBalance);
@@ -109,14 +97,7 @@ export class Balances<Config = NoConfig>
10997

11098
public burn(tokenId: TokenId, address: PublicKey, amount: Balance) {
11199
const balance = this.getBalance(tokenId, address);
112-
// replace with library/uint64
113-
const paddedBalance = Provable.if<Balance>(
114-
balance.greaterThanOrEqual(amount),
115-
Balance,
116-
balance,
117-
balance.add(amount)
118-
);
119-
const newBalance = paddedBalance.sub(amount);
100+
const newBalance = balance.sub(amount);
120101
this.setBalance(tokenId, address, newBalance);
121102
}
122103

packages/sdk/src/appChain/ClientAppChain.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class ClientAppChain<
6060
});
6161

6262
appChain.configurePartial({
63+
Sequencer: {},
6364
Protocol: {
6465
BlockProver: {},
6566
StateTransitionProver: {},

packages/sdk/test/fees.test.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import "reflect-metadata";
2-
import {
3-
Balances,
4-
BalancesKey,
5-
TokenId,
6-
VanillaProtocolModulesRecord,
7-
} from "@proto-kit/library";
2+
import { Balance, Balances, BalancesKey, TokenId } from "@proto-kit/library";
83
import {
94
runtimeMethod,
105
runtimeModule,
116
RuntimeModule,
127
RuntimeModulesRecord,
13-
state,
148
} from "@proto-kit/module";
15-
import { SequencerModulesRecord } from "@proto-kit/sequencer";
16-
import { Field, PrivateKey, PublicKey, State, UInt64 } from "o1js";
9+
import { PrivateKey } from "o1js";
1710
import { inject } from "tsyringe";
1811
import { TestingAppChain } from "../src";
1912

@@ -28,7 +21,7 @@ class Faucet extends RuntimeModule<unknown> {
2821
this.balances.mint(
2922
new TokenId(0),
3023
this.transaction.sender.value,
31-
UInt64.from(1000)
24+
Balance.from(1000)
3225
);
3326
}
3427
}
@@ -40,8 +33,8 @@ class Pit extends RuntimeModule<unknown> {
4033
}
4134

4235
@runtimeMethod()
43-
public burn(amount: UInt64) {
44-
this.balances.burn(new TokenId(0), this.transaction.sender.value, amount);
36+
public burn(amount: Balance) {
37+
this.balances.burn(TokenId.from(0), this.transaction.sender.value, amount);
4538
}
4639
}
4740

@@ -119,7 +112,7 @@ describe("fees", () => {
119112
const pit = appChain.runtime.resolve("Pit");
120113

121114
const tx = await appChain.transaction(senderKey.toPublicKey(), () => {
122-
pit.burn(UInt64.from(100));
115+
pit.burn(Balance.from(100));
123116
});
124117

125118
await tx.sign();

packages/sequencer/src/settlement/transactions/MinaTransactionSender.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { inject, injectable } from "tsyringe";
33

44
import type { MinaBaseLayer } from "../../protocol/baselayer/MinaBaseLayer";
55
import { FlowCreator } from "../../worker/flow/Flow";
6-
import {
7-
SettlementProvingTask,
8-
TransactionTaskResult,
9-
} from "../tasks/SettlementProvingTask";
6+
// TODO: bring back once SettlementProvingTask doesnt rely on the Pickles import
7+
// import {
8+
// SettlementProvingTask,
9+
// TransactionTaskResult,
10+
// } from "../tasks/SettlementProvingTask";
1011

1112
import { MinaTransactionSimulator } from "./MinaTransactionSimulator";
1213

@@ -21,7 +22,9 @@ export class MinaTransactionSender {
2122

2223
public constructor(
2324
private readonly creator: FlowCreator,
24-
private readonly provingTask: SettlementProvingTask,
25+
// TODO: bring back once SettlementProvingTask doesnt rely on the Pickles import
26+
27+
// private readonly provingTask: SettlementProvingTask,
2528
private readonly simulator: MinaTransactionSimulator,
2629
@inject("BaseLayer") private readonly baseLayer: MinaBaseLayer
2730
) {}
@@ -82,25 +85,26 @@ export class MinaTransactionSender {
8285

8386
await this.simulator.applyTransaction(transaction);
8487

85-
const resultPromise = flow.withFlow<TransactionTaskResult>(
86-
async (resolve, reject) => {
87-
await flow.pushTask(
88-
this.provingTask,
89-
{
90-
transaction,
91-
chainState: {
92-
graphql: this.baseLayer.config.network.graphql,
93-
accounts,
94-
},
95-
},
96-
async (result) => {
97-
resolve(result);
98-
}
99-
);
100-
}
101-
);
102-
103-
const result = await resultPromise;
104-
await this.sendOrQueue(result.transaction);
88+
// TODO: bring back once SettlementProvingTask doesnt rely on the Pickles import
89+
// const resultPromise = flow.withFlow<TransactionTaskResult>(
90+
// async (resolve, reject) => {
91+
// await flow.pushTask(
92+
// this.provingTask,
93+
// {
94+
// transaction,
95+
// chainState: {
96+
// graphql: this.baseLayer.config.network.graphql,
97+
// accounts,
98+
// },
99+
// },
100+
// async (result) => {
101+
// resolve(result);
102+
// }
103+
// );
104+
// }
105+
// );
106+
107+
// const result = await resultPromise;
108+
// await this.sendOrQueue(result.transaction);
105109
}
106110
}

packages/sequencer/src/worker/worker/LocalTaskWorkerModule.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
sequencerModule,
1111
SequencerModule,
1212
} from "../../sequencer/builder/SequencerModule";
13-
import { SettlementProvingTask } from "../../settlement/tasks/SettlementProvingTask";
1413
import { TaskQueue } from "../queue/TaskQueue";
1514
import {
1615
BlockProvingTask,

0 commit comments

Comments
 (0)