Skip to content

Commit

Permalink
Port latest changes from go-nitro till commit ff84d606 on November 1 (
Browse files Browse the repository at this point in the history
#4)

* Upgrade state channel nitro protocol version

* Generate latest contract bindings

* Add steps to generate bindings

* Update DEVELOPMENT.md

* Use wrapped error in handle objective request

* Update README and DEVELOPMENT.md
  • Loading branch information
neerajvijay1997 authored Apr 23, 2024
1 parent f98bc7e commit 88c0191
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Porting go-nitro latest commits
# Development

## Skipped go-nitro Commits / Features

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,7 @@ Run relay node using v2 watcher
```bash
clearNodeStorage()
```

### Development

* [README](./DEVELOPMENT.md)
2 changes: 1 addition & 1 deletion packages/nitro-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@libp2p/crypto": "^1.0.4",
"@libp2p/tcp": "^6.0.0",
"@multiformats/multiaddr": "^11.1.4",
"@statechannels/nitro-protocol": "^2.0.1-alpha.5",
"@statechannels/nitro-protocol": "^2.0.1-alpha.6",
"assert": "^2.0.0",
"async-mutex": "^0.4.0",
"debug": "^4.3.4",
Expand Down
23 changes: 16 additions & 7 deletions packages/nitro-node/src/node/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ export class Engine {
try {
chainId = await this.chain.getChainId();
} catch (err) {
return [new EngineEvent({}), new Error(`could not get chain id from chain service: ${err}`)];
return [new EngineEvent({}), new WrappedError(`could not get chain id from chain service: ${err}`, err as Error)];
}

const objectiveId = or.id(myAddress, chainId);
Expand All @@ -746,7 +746,7 @@ export class Engine {
this.store.getConsensusChannel.bind(this.store),
);
} catch (err) {
return [failedEngineEvent, new Error(`handleAPIEvent: Could not create virtualfund objective for ${or}: ${err}`)];
return [failedEngineEvent, new WrappedError(`handleAPIEvent: Could not create virtualfund objective for ${or}: ${err}`, err as Error)];
}

if (METRICS_ENABLED) {
Expand Down Expand Up @@ -784,7 +784,10 @@ export class Engine {
} catch (err) {
return [
failedEngineEvent,
new Error(`handleAPIEvent: Could not create virtualdefund objective for ${JSONbigNative.stringify(request)}: ${err}`),
new WrappedError(
`handleAPIEvent: Could not create virtualdefund objective for ${JSONbigNative.stringify(request)}: ${err}`,
err as Error,
),
];
}
}
Expand All @@ -806,7 +809,10 @@ export class Engine {
} catch (err) {
return [
failedEngineEvent,
new Error(`handleAPIEvent: Could not create virtualdefund objective for ${JSONbigNative.stringify(request)}: ${err}`),
new WrappedError(
`handleAPIEvent: Could not create virtualdefund objective for ${JSONbigNative.stringify(request)}: ${err}`,
err as Error,
),
];
}

Expand All @@ -831,7 +837,7 @@ export class Engine {
} catch (err) {
return [
failedEngineEvent,
new Error(`handleAPIEvent: Could not create directfund objective for ${JSONbigNative.stringify(or)}: ${err}`),
new WrappedError(`handleAPIEvent: Could not create directfund objective for ${JSONbigNative.stringify(or)}: ${err}`, err as Error),
];
}

Expand All @@ -850,7 +856,10 @@ export class Engine {
} catch (err) {
return [
failedEngineEvent,
new Error(`handleAPIEvent: Could not create directdefund objective for ${JSONbigNative.stringify(request)}: ${err}`),
new WrappedError(
`handleAPIEvent: Could not create directdefund objective for ${JSONbigNative.stringify(request)}: ${err}`,
err as Error,
),
];
}

Expand All @@ -863,7 +872,7 @@ export class Engine {
} catch (err) {
return [
failedEngineEvent,
new Error(`handleAPIEvent: Could not destroy consensus channel for ${JSONbigNative.stringify(request)}: ${err}`),
new WrappedError(`handleAPIEvent: Could not destroy consensus channel for ${JSONbigNative.stringify(request)}: ${err}`, err as Error),
];
}

Expand Down
28 changes: 28 additions & 0 deletions packages/nitro-util/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Development

## Generate contract bindings

* Clone the go-nitro repo (<https://github.com/statechannels/go-nitro>) and run `yarn` in root of repo.

* Move to `go-nitro/packages/nitro-protocol/` and run `yarn hardhat compile` to compile the contract

```bash
$ yarn hardhat compile
Generating typings for: 43 artifacts in dir: typechain-types for target: ethers-v5
Successfully generated 67 typings!
Compiled 42 Solidity files successfully
```

* Copy files `ConsensusApp.json` `NitroAdjudicator.json` `VirtualPaymentApp.json` from go-nitro `packages/nitro-protocol/artifacts` to ts-nitro `packages/nitro-util/contracts`

* In ts-nitro `packages/nitro-util` run `yarn generate-bindings` to generate the contract bindings

```bash
$ yarn generate-bindings

yarn run v1.22.19
$ ./scripts/generate-bindings.sh
$ /ts-nitro/node_modules/.bin/typechain --target ethers-v5 --out-dir ./src/contract-bindings ./contracts/NitroAdjudicator.json ./contracts/ConsensusApp.json ./contracts/VirtualPaymentApp.json ./contracts/Token.json
Successfully generated 11 typings!
Done in 1.27s.
```
5 changes: 5 additions & 0 deletions packages/nitro-util/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# nitro-util

## Development

* [README](./DEVELOPMENT.md)
19 changes: 19 additions & 0 deletions packages/nitro-util/contracts/NitroAdjudicator.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,25 @@
"name": "ChallengeRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "channelId",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "uint48",
"name": "newTurnNumRecord",
"type": "uint48"
}
],
"name": "Checkpointed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@cerc-io/ts-channel": "1.0.3-ts-nitro-0.1.1",
"@statechannels/nitro-protocol": "^2.0.1-alpha.5",
"@statechannels/nitro-protocol": "^2.0.1-alpha.6",
"assert": "^2.0.0",
"debug": "^4.3.4",
"ethers": "^5.7.2",
Expand Down
22 changes: 22 additions & 0 deletions packages/nitro-util/src/contract-bindings/NitroAdjudicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export interface NitroAdjudicatorInterface extends utils.Interface {
"AllocationUpdated(bytes32,uint256,uint256,uint256)": EventFragment;
"ChallengeCleared(bytes32,uint48)": EventFragment;
"ChallengeRegistered(bytes32,uint48,tuple[],tuple)": EventFragment;
"Checkpointed(bytes32,uint48)": EventFragment;
"Concluded(bytes32,uint48)": EventFragment;
"Deposited(bytes32,address,uint256)": EventFragment;
"Reclaimed(bytes32,uint256)": EventFragment;
Expand All @@ -310,6 +311,7 @@ export interface NitroAdjudicatorInterface extends utils.Interface {
getEvent(nameOrSignatureOrTopic: "AllocationUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ChallengeCleared"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ChallengeRegistered"): EventFragment;
getEvent(nameOrSignatureOrTopic: "Checkpointed"): EventFragment;
getEvent(nameOrSignatureOrTopic: "Concluded"): EventFragment;
getEvent(nameOrSignatureOrTopic: "Deposited"): EventFragment;
getEvent(nameOrSignatureOrTopic: "Reclaimed"): EventFragment;
Expand Down Expand Up @@ -360,6 +362,17 @@ export type ChallengeRegisteredEvent = TypedEvent<
export type ChallengeRegisteredEventFilter =
TypedEventFilter<ChallengeRegisteredEvent>;

export interface CheckpointedEventObject {
channelId: string;
newTurnNumRecord: number;
}
export type CheckpointedEvent = TypedEvent<
[string, number],
CheckpointedEventObject
>;

export type CheckpointedEventFilter = TypedEventFilter<CheckpointedEvent>;

export interface ConcludedEventObject {
channelId: string;
finalizesAt: number;
Expand Down Expand Up @@ -781,6 +794,15 @@ export interface NitroAdjudicator extends BaseContract {
candidate?: null
): ChallengeRegisteredEventFilter;

"Checkpointed(bytes32,uint48)"(
channelId?: BytesLike | null,
newTurnNumRecord?: null
): CheckpointedEventFilter;
Checkpointed(
channelId?: BytesLike | null,
newTurnNumRecord?: null
): CheckpointedEventFilter;

"Concluded(bytes32,uint48)"(
channelId?: BytesLike | null,
finalizesAt?: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@ const _abi = [
name: "ChallengeRegistered",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "bytes32",
name: "channelId",
type: "bytes32",
},
{
indexed: false,
internalType: "uint48",
name: "newTurnNumRecord",
type: "uint48",
},
],
name: "Checkpointed",
type: "event",
},
{
anonymous: false,
inputs: [
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ const main = async () => {
await new Promise<void>((resolve) => { setTimeout(() => resolve(), 1000); });

await nitro.close();

process.exit(0);
}
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3949,10 +3949,10 @@
ethers "^5.1.4"
lodash "^4.17.21"

"@statechannels/nitro-protocol@^2.0.1-alpha.5":
version "2.0.1-alpha.5"
resolved "https://registry.yarnpkg.com/@statechannels/nitro-protocol/-/nitro-protocol-2.0.1-alpha.5.tgz#3aa09dacf6780a47ff415de23123f9aafe2534ec"
integrity sha512-CT32i5ZlZ0Jz8mAOmywALCnS/+Cl7ntrRlJr2r3jGBkkzNBWxHWR4qXg6HTUh7xxm5tY/g/TSmsGH8/z54K/Sw==
"@statechannels/nitro-protocol@^2.0.1-alpha.6":
version "2.0.1-alpha.6"
resolved "https://registry.yarnpkg.com/@statechannels/nitro-protocol/-/nitro-protocol-2.0.1-alpha.6.tgz#1bb59365eb78489eef2dfa73733bc1cad9890685"
integrity sha512-VehCgq3AOVTGCvGGIoF23YyQX+x1IbLzByFWbqPovucsm9vW0udR7r8Okw9hC0ZHanHOjQH5KxJL6aKUnrXinw==
dependencies:
"@openzeppelin/contracts" "^4.7.3"
"@statechannels/exit-format" "^0.2.0"
Expand Down

0 comments on commit 88c0191

Please sign in to comment.