Skip to content

Commit b482e94

Browse files
authored
Merge pull request #418 from proto-kit/feature/tx-hook-config-validation
Added static config validation for transaction fee hook
2 parents 3c424db + f5415a4 commit b482e94

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

.github/workflows/pull-request-develop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
image: redis:6.2-alpine
114114
ports:
115115
- 6379:6379
116-
lighnet:
116+
lightnet:
117117
image: o1labs/mina-local-network:compatible-latest-lightnet
118118
env:
119119
RUN_ARCHIVE_NODE: true
@@ -151,4 +151,4 @@ jobs:
151151
polling-interval-ms: 5000
152152

153153
- name: "Integration tests"
154-
run: npm run test:integration
154+
run: npm run test:integration

packages/library/src/hooks/TransactionFeeHook.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export class TransactionFeeHook extends ProvableTransactionHook<TransactionFeeHo
6767
// check if the fee config is compatible with the current runtime
6868
// we couldn't resolve this purely on the type level, so we have to do it here
6969
public verifyConfig() {
70-
Object.keys(super.config.methods).forEach((combinedMethodName) => {
70+
const { config } = this;
71+
72+
Object.keys(config.methods).forEach((combinedMethodName) => {
7173
const [runtimeModule, runtimeMethod] = combinedMethodName.split(".");
7274
const resolvedRuntimeModule = this.runtime.resolve(runtimeModule);
7375

@@ -79,8 +81,26 @@ export class TransactionFeeHook extends ProvableTransactionHook<TransactionFeeHo
7981
throw errors.invalidMethod(combinedMethodName);
8082
}
8183
});
84+
85+
const properties = [
86+
"feeRecipient",
87+
"tokenId",
88+
"baseFee",
89+
"perWeightUnitFee",
90+
] as const;
91+
const missing = properties
92+
.filter((property) => {
93+
return config[property] === undefined;
94+
})
95+
.join(", ");
96+
97+
if (missing.length > 0) {
98+
throw new Error(`TransactionFeeHook is missing config values ${missing}`);
99+
}
82100
}
83101

102+
private async checkConfig() {}
103+
84104
public async start() {
85105
this.persistedFeeAnalyzer = new RuntimeFeeAnalyzerService(this.runtime);
86106
this.verifyConfig();

packages/sequencer/src/protocol/baselayer/MinaBaseLayer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { BaseLayer, StaticBaseLayer } from "./BaseLayer";
1919
import { LocalBlockchainUtils } from "./network-utils/LocalBlockchainUtils";
2020
import { LightnetUtils } from "./network-utils/LightnetUtils";
2121
import { RemoteNetworkUtils } from "./network-utils/RemoteNetworkUtils";
22+
import { MinaNetworkUtils } from "./network-utils/MinaNetworkUtils";
2223

2324
export type LocalMinaBaseLayerConfig = {
2425
type: "local";
@@ -96,7 +97,9 @@ export class MinaBaseLayer
9697
if (this.config.network.type === "remote") {
9798
throw new Error("NetworkUtils not available for remote networks");
9899
}
99-
return this.sequencer.dependencyContainer.resolve("NetworkUtils");
100+
return this.sequencer.dependencyContainer.resolve<MinaNetworkUtils>(
101+
"NetworkUtils"
102+
);
100103
}
101104

102105
public isLocalBlockChain(): boolean {

packages/sequencer/src/settlement/MinaSigner.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Field, PrivateKey, PublicKey, Signature, Transaction } from "o1js";
2-
import { noop } from "@proto-kit/common";
3-
import { injectable } from "tsyringe";
42

5-
import { SequencerModule } from "../sequencer/builder/SequencerModule";
3+
import {
4+
sequencerModule,
5+
SequencerModule,
6+
} from "../sequencer/builder/SequencerModule";
67

78
/**
89
* Options for signing transactions.
@@ -117,7 +118,7 @@ export interface InMemorySignerConfig {
117118
* for the Mina blockchain protocol. This implementation is suitable for
118119
* server-side sequencer operations where keys can be securely stored in memory.
119120
*/
120-
@injectable()
121+
@sequencerModule()
121122
export class InMemoryMinaSigner
122123
extends SequencerModule<InMemorySignerConfig>
123124
implements MinaSigner
@@ -330,6 +331,5 @@ export class InMemoryMinaSigner
330331
*/
331332
public async start() {
332333
this.initializeKeyMap();
333-
noop();
334334
}
335335
}

0 commit comments

Comments
 (0)