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

Port latest changes from go-nitro till commit 64c4ee9 on November 15 #138

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 54 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Development

## Skipped go-nitro Commits / Features

* Usage of bearer auth tokens
* <https://github.com/statechannels/go-nitro/pull/1351> | <https://github.com/cerc-io/go-nitro/commit/903239959d2ffce936060932fca5476f50430668>
* Kademlia-dht peer discovery
* <https://github.com/statechannels/go-nitro/pull/1462>
* Use libp2p notifications
* <https://github.com/statechannels/go-nitro/pull/1488/files>
* Skipping `libp2p.NATPortMap()`
* Implement a basic reverse payment proxy
* <https://github.com/statechannels/go-nitro/pull/1483>

## Known issues (ts-nitro)

* Metamask caching issue after chain restart
* Error occurs during direct fund transfer in mobymask-ui when the Nitro Node makes an eth_call to the Nitro Adjudicator contract

```bash
Received invalid block tag 1270. Latest block number is 99
```

* <https://ethereum.stackexchange.com/questions/109625/received-invalid-block-tag-87-latest-block-number-is-0>

* To resolve this issue, attempt changing the network in Metamask and then switch back to the network you're using to connect to the local node

## Known issues (go-nitro)

* Error is thrown when trying to fund virtual channels with amounts more than their ledger channel supports

```bash
panic: error updating ledger funding: error proposing ledger update: propose could not add new state vars: insufficient funds
goroutine 88 [running]:
github.com/statechannels/go-nitro/node/engine.(*Engine).checkError(0x748a4ac48e62a6aa?, {0x1e60900, 0xc00048c940})
go-nitro/node/engine/engine.go:867 +0x139
github.com/statechannels/go-nitro/node/engine.(*Engine).run(0xc000306500, {0x1e6f948, 0xc0006a09b0})
go-nitro/node/engine/engine.go:211 +0x852
created by github.com/statechannels/go-nitro/node/engine.New in goroutine 1
go-nitro/node/engine/engine.go:164 +0x54b
```

* Error is thrown when conducting direct defund while virtual channel is running

```bash
panic: handleAPIEvent: Could not create directdefund objective for {ChannelId:0xecb0d8f2cdd9222b56dc24daa6b10fc2143f7b8861695071e260417d4ad289f6 objectiveStarted:0xc000743da0}: ledger channel has running guarantees
goroutine 200 [running]:
github.com/statechannels/go-nitro/node/engine.(*Engine).checkError(0x0?, {0x1e60900, 0xc000b8a240})
go-nitro/node/engine/engine.go:867 +0x139
github.com/statechannels/go-nitro/node/engine.(*Engine).run(0xc0009800a0, {0x1e6f948, 0xc000984000})
go-nitro/node/engine/engine.go:211 +0x852
created by github.com/statechannels/go-nitro/node/engine.New in goroutine 1
go-nitro/node/engine/engine.go:164 +0x54b
```
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
8 changes: 4 additions & 4 deletions packages/nitro-node/src/channel/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Buffer } from 'buffer';
import { ethers } from 'ethers';

import {
fromJSON, toJSON, FieldDescription, Uint, Uint64, NitroSigner,
fromJSON, toJSON, FieldDescription, Uint, Uint64, NitroSigner, WrappedError,
} from '@cerc-io/nitro-util';
import { Bytes32 } from '@statechannels/nitro-protocol';

Expand Down Expand Up @@ -124,7 +124,7 @@ export class Channel extends FixedPart {
try {
props = fromJSON(this.jsonEncodingMap, data);
} catch (err) {
throw new Error(`error unmarshaling channel data: ${err}`);
throw new WrappedError('error unmarshaling channel data', err as Error);
}

return new Channel(props);
Expand Down Expand Up @@ -389,14 +389,14 @@ export class Channel extends FixedPart {
try {
sig = await s.sign(signer);
} catch (err) {
throw new Error(`Could not sign prefund ${err}`);
throw new WrappedError('Could not sign prefund', err as Error);
}

const ss = SignedState.newSignedState(s);
try {
ss.addSignature(sig);
} catch (err) {
throw new Error(`could not add own signature ${err}`);
throw new WrappedError('could not add own signature', err as Error);
}

const ok = this.addSignedState(ss);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Buffer } from 'buffer';
import { ethers } from 'ethers';

import {
FieldDescription, NitroSigner, Uint, Uint64, fromJSON, toJSON,
FieldDescription, NitroSigner, Uint, Uint64, fromJSON, toJSON, WrappedError,
} from '@cerc-io/nitro-util';
import { Bytes32 } from '@statechannels/nitro-protocol';

Expand Down Expand Up @@ -979,7 +979,7 @@ export class ConsensusChannel {
throw new Error(`Follower did not sign initial state: ${followerAddr}, ${fp.participants![Number(Follower)]}`);
}
} catch (err) {
throw new Error(`could not verify sig: ${err}`);
throw new WrappedError('could not verify sig', err as Error);
}

const current = new SignedVars({
Expand Down Expand Up @@ -1266,7 +1266,7 @@ export class ConsensusChannel {
try {
signer = consensusCandidate.asState(this.fp).recoverSigner(countersigned.signature);
} catch (err) {
throw new Error(`unable to recover signer: ${err}`);
throw new WrappedError('unable to recover signer', err as Error);
}

if (signer !== this.fp.participants![Number(Follower)]) {
Expand Down Expand Up @@ -1303,28 +1303,28 @@ export class ConsensusChannel {
try {
vars = this.latestProposedVars();
} catch (err) {
throw new Error(`unable to construct latest proposed vars: ${err}`);
throw new WrappedError('unable to construct latest proposed vars', err as Error);
}

try {
vars.handleProposal(proposal);
} catch (err) {
throw new Error(`propose could not add new state vars: ${err}`);
throw new WrappedError('propose could not add new state vars', err as Error);
}

let signature: Signature;
try {
signature = await this.sign(vars, signer);
} catch (err) {
throw new Error(`unable to sign state update: ${err}`);
throw new Error('unable to sign state update');
}

const signed = new SignedProposal({ proposal, signature, turnNum: vars.turnNum });

try {
this.appendToProposalQueue(signed);
} catch (err) {
throw new Error(`could not append to proposal queue: ${err}`);
throw new WrappedError('could not append to proposal queue', err as Error);
}

return signed;
Expand Down Expand Up @@ -1358,7 +1358,7 @@ export class ConsensusChannel {
// Get the latest proposal vars we have
vars = this.latestProposedVars();
} catch (err) {
throw new Error(`could not generate the current proposal: ${err}`);
throw new WrappedError('could not generate the current proposal', err as Error);
}

if (p.turnNum !== vars.turnNum + BigInt(1)) {
Expand All @@ -1369,15 +1369,15 @@ export class ConsensusChannel {
try {
vars.handleProposal(p.proposal);
} catch (err) {
throw new Error(`receive could not add new state vars: ${err}`);
throw new WrappedError('receive could not add new state vars', err as Error);
}

// Validate the signature
let signer: Address;
try {
signer = this.recoverSigner(vars, p.signature);
} catch (err) {
throw new Error(`receive could not recover signature: ${err}`);
throw new WrappedError('receive could not recover signature', err as Error);
}

if (signer !== this.leader()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/nitro-node/src/channel/state/signedstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import { Buffer } from 'buffer';

import {
FieldDescription, Uint, Uint64, fromJSON, toJSON,
FieldDescription, Uint, Uint64, fromJSON, toJSON, WrappedError,
} from '@cerc-io/nitro-util';

import { Signature } from '../../crypto/signatures';
Expand Down Expand Up @@ -55,7 +55,7 @@ export class SignedState {
try {
signer = this.state().recoverSigner(sig);
} catch (err) {
throw new Error('AddSignature failed to recover signer');
throw new WrappedError('AddSignature failed to recover signer', err as Error);
}

for (let i = 0; i < (this.state().participants ?? []).length; i += 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class EthChainService implements ChainService {
newBlockUnsubscribe = this.chain.subscribeNewHead(newBlockChan);
} catch (subErr) {
errorChan.push(new WrappedError(
`subscribeNewHead failed to resubscribe: ${subErr}`,
'subscribeNewHead failed to resubscribe',
subErr as Error,
));

Expand Down Expand Up @@ -389,7 +389,7 @@ export class EthChainService implements ChainService {
// eslint-disable-next-line no-await-in-loop
await this.checkForMissedEvents(latestBlockNum);
} catch (checkErr) {
errorChan.push(new Error(`subscribeFilterLogs failed during checkForMissedEvents: ${checkErr}`));
errorChan.push(new WrappedError('subscribeFilterLogs failed during checkForMissedEvents', checkErr as Error));
return;
}

Expand Down Expand Up @@ -532,7 +532,7 @@ export class EthChainService implements ChainService {
);
await this.out.push(event);
} catch (err) {
throw new Error(`error in ParseDeposited: ${err}`);
throw new WrappedError('error in ParseDeposited', err as Error);
}
break;
}
Expand All @@ -542,7 +542,7 @@ export class EthChainService implements ChainService {
try {
au = this.na.interface.parseLog(l).args as unknown as AllocationUpdatedEventObject;
} catch (err) {
throw new Error(`error in ParseAllocationUpdated: ${err}`);
throw new WrappedError('error in ParseAllocationUpdated', err as Error);
}

let tx;
Expand All @@ -553,7 +553,7 @@ export class EthChainService implements ChainService {
throw new Error('Expected transaction to be part of the chain, but the transaction is pending');
}
} catch (err) {
throw new Error(`error in TransactionByHash: ${err}`);
throw new WrappedError('error in TransactionByHash', err as Error);
}

assert(tx !== undefined);
Expand All @@ -563,7 +563,7 @@ export class EthChainService implements ChainService {
assetAddress = assetAddressForIndex(this.na, tx, au.assetIndex.toBigInt());
} catch (err) {
throw new WrappedError(
`error in assetAddressForIndex: ${err}`,
'error in assetAddressForIndex',
err as Error,
);
}
Expand All @@ -590,7 +590,7 @@ export class EthChainService implements ChainService {
const event = new ConcludedEvent({ _channelID: new Destination(ce.channelId), _blockNum: BigInt(l.blockNumber) });
await this.out.push(event);
} catch (err) {
throw new Error(`error in ParseConcluded: ${err}`);
throw new WrappedError('error in ParseConcluded', err as Error);
}
break;
}
Expand All @@ -613,7 +613,7 @@ export class EthChainService implements ChainService {

this.out.push(event);
} catch (err) {
throw new Error(`error in ParseChallengeRegistered: ${err}`);
throw new WrappedError('error in ParseChallengeRegistered', err as Error);
}
break;
}
Expand Down Expand Up @@ -772,7 +772,7 @@ export class EthChainService implements ChainService {
await this.dispatchChainEvents(eventsToDispatch);
} catch (err) {
await errorChan.push(new WrappedError(
`failed dispatchChainEvents: ${err}`,
'failed dispatchChainEvents',
err as Error,
));
}
Expand All @@ -798,7 +798,7 @@ export class EthChainService implements ChainService {
try {
eventUnsubscribe = this.chain.subscribeFilterLogs(eventQuery, eventChan);
} catch (err) {
throw new WrappedError(`subscribeFilterLogs failed: ${err}`, err as Error);
throw new WrappedError('subscribeFilterLogs failed', err as Error);
}
this.eventUnsubscribe = eventUnsubscribe.bind(this.chain);

Expand All @@ -810,7 +810,7 @@ export class EthChainService implements ChainService {
try {
newBlockUnsubscribe = this.chain.subscribeNewHead(newBlockChan);
} catch (err) {
throw new WrappedError(`subscribeNewHead failed: ${err}`, err as Error);
throw new WrappedError('subscribeNewHead failed', err as Error);
}
this.newBlockUnsubscribe = newBlockUnsubscribe.bind(this.chain);

Expand Down
Loading
Loading