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

feat: add node config builder #55

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
enable das params
spsjvc committed Mar 19, 2024

Verified

This commit was signed with the committer’s verified signature.
commit e07dde0f50459e03caf47591fb6961db58005fed
42 changes: 30 additions & 12 deletions src/nodeConfigBuilder.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,22 @@ export type NodeConfigBuilderEnableStakerParams = {
privateKey: string;
};

export type RpcAggregatorBackendsItem = {
url: string;
pubkey: string;
signermask: number;
};

export type NodeConfigBuilderEnableDataAvailabilityServiceParams = {
restAggregator: {
urls: string[];
};
rpcAggregator: {
assumedHonest?: undefined;
backends: RpcAggregatorBackendsItem[];
};
};

export class NodeConfigBuilder {
private nodeConfig: NodeConfig;
private isInitialized: boolean;
@@ -104,24 +120,26 @@ export class NodeConfigBuilder {
return this;
}

public enableDataAvailabilityService(): NodeConfigBuilder {
const backendsJson = stringifyJson<NodeConfigDataAvailabilityRpcAggregatorBackendsJson>([
{
url: 'http://localhost:9876',
pubkey:
'YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==',
signermask: 1,
},
]);
public enableDataAvailabilityService(
params: NodeConfigBuilderEnableDataAvailabilityServiceParams,
): NodeConfigBuilder {
const backends = params.rpcAggregator.backends.map((backend, index) => ({
...backend,
signermask: 1 << index, // 2^n
}));

const rpcAggregatorAssumedHonest = params.rpcAggregator.assumedHonest ?? 1;
const rpcAggregatorBackendsJson =
stringifyJson<NodeConfigDataAvailabilityRpcAggregatorBackendsJson>(backends);

this.set('node.data-availability.enable', true);

this.set('node.data-availability.rest-aggregator.enable', true);
this.set('node.data-availability.rest-aggregator.urls', ['http://localhost:9877']);
this.set('node.data-availability.rest-aggregator.urls', params.restAggregator.urls);

this.set('node.data-availability.rpc-aggregator.enable', true);
this.set('node.data-availability.rpc-aggregator.assumed-honest', 1);
this.set('node.data-availability.rpc-aggregator.backends', backendsJson);
this.set('node.data-availability.rpc-aggregator.assumed-honest', rpcAggregatorAssumedHonest);
this.set('node.data-availability.rpc-aggregator.backends', rpcAggregatorBackendsJson);

return this;
}
16 changes: 15 additions & 1 deletion src/nodeConfigBuilder.unit.test.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,21 @@ it('creates node config without defaults', () => {
it('creates node config with data availability service', () => {
const nodeConfig = createNodeConfigBuilder()
.initialize(initializeParams)
.enableDataAvailabilityService()
.enableDataAvailabilityService({
restAggregator: {
urls: ['http://localhost:9877'],
},
rpcAggregator: {
backends: [
{
url: 'http://localhost:9876',
pubkey:
'YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==',
signermask: 1,
},
],
},
})
.build();

expect(nodeConfig).toMatchSnapshot();
12 changes: 5 additions & 7 deletions src/types/NodeConfig.ts
Original file line number Diff line number Diff line change
@@ -19,10 +19,8 @@ export type NodeConfigChainInfoJson = [
},
];

export type NodeConfigDataAvailabilityRpcAggregatorBackendsJson = [
{
url: string;
pubkey: string;
signermask: number;
},
];
export type NodeConfigDataAvailabilityRpcAggregatorBackendsJson = {
url: string;
pubkey: string;
signermask: number;
}[];

Unchanged files with check annotations Beta

nitroTestnodeL3,
} from './chains';
export function parentChainIsArbitrum(parentChainId: ParentChainId): boolean {

Check failure on line 13 in src/nodeConfigBuilderUtils.ts

GitHub Actions / Test (Unit)

Function lacks ending return statement and return type does not include 'undefined'.

Check failure on line 13 in src/nodeConfigBuilderUtils.ts

GitHub Actions / Test (Integration)

Function lacks ending return statement and return type does not include 'undefined'.
// doing switch here to make sure it's exhaustive when checking against `ParentChainId`
switch (parentChainId) {
case mainnet.id: