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 880c8b50 on October 12 #3

Merged
merged 2 commits into from
Apr 17, 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
63 changes: 63 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Porting go-nitro latest commits

## 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
* Implement and use `WaitForLedgerChannelStatus` and `WaitForPaymentChannelStatus` methods in Nitro class
* https://github.com/statechannels/go-nitro/pull/1829
* Implement and use `onPaymentChannelUpdated` method in Nitro class
* https://github.com/statechannels/go-nitro/pull/1801

## Tests pending

* Removed try/catch in run method of Engine, check present implementation handles all the error
* https://github.com/cerc-io/ts-nitro/pull/98
* Check all the error are returned from engine handler without throwing
* Create error in engine handlers and test it
* Test JsonRpcError
* https://github.com/cerc-io/ts-nitro/pull/101
* Create error in getPaymentChannelInfo by providing invalid payment channel id.
* Check errorChan in eth chain service is working properly.
* https://github.com/cerc-io/ts-nitro/pull/105
* Create error in eth chain service and check how errorChan handles it.
* Test nonFatalErrors in engine
* https://github.com/cerc-io/ts-nitro/pull/104
* https://github.com/statechannels/go-nitro/pull/1380/files
* Test wrapped error
* Test failed engine events
* Test the context class implementation
* https://github.com/cerc-io/ts-nitro/pull/105
* Test it behaves like Go context
* Test the signature serialisation and deserialisation
* https://github.com/cerc-io/ts-nitro/pull/107
* Conducting direct defund when virtual channel is running, error is thrown and no commands work.
* Debug this problem.
* Check this problem exists in go-nitro.
* Channel id in chain event after direct-defund is not matching actual ledger channel while conducting mobymask-ui <-> mobymask-v3-watcher-ts test.
* Logs with mismatched channel ids
```
ts-nitro:engine Sending chain transaction for channel 0x47b39e54746a42402921182dfb512917f78f358b991c05cabfdcebde870656b5 +0ms
common.js:113 ts-nitro:engine handling chain event: Channel 0x6add310cbde988eb3e10f45325b40041bd2d5c389faef0c5a3bc5b32f69fbdc5 concluded at Block 6 +22s
```
* Steps to reproduce:
* Run Hardhat in [auto mining mode ](https://hardhat.org/hardhat-network/docs/explanation/mining-modes), mobymask-ui and mobymask-v3-watcher-ts.
* Conduct test till direct-defund command (in the initial set up the bug will not appear).
* Stop all the services, restart chain, clear store and run above set up repeatedly.
* Funding more virtual channels than their ledger channel supports.
* Not able to create virtual channels if they exceed ledger channel capacity.
* Check whether go-nitro also get below error.
```bash
Error: error updating ledger funding: Error: error proposing ledger update: Error: propose could not add new state vars: Error: insufficient funds at be.crank
(http://localhost:3000/static/js/bundle.js:138464:19) at async Ge.attemptProgress
(http://localhost:3000/static/js/bundle.js:139637:25) at async Ge.handleMessage
(http://localhost:3000/static/js/bundle.js:139379:28) at async Ge.run
(http://localhost:3000/static/js/bundle.js:139302:24) +0ms
```
6 changes: 3 additions & 3 deletions packages/nitro-node/src/node/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class Engine {
e.paymentRequestsFromAPI = Channel<PaymentRequest>();

e.fromChain = chain.eventFeed();
e.fromMsg = msg.out();
e.fromMsg = msg.p2pMessages();

e.chain = chain;
e.msg = msg;
Expand Down Expand Up @@ -398,7 +398,7 @@ export class Engine {

if (obj.getStatus() === ObjectiveStatus.Completed) {
this.logger(JSON.stringify({
msg: 'Ignoring proposal for complected objective',
msg: 'Ignoring proposal for completed objective',
...withObjectiveIdAttribute(id),
}));
return [new EngineEvent({}), null];
Expand Down Expand Up @@ -484,7 +484,7 @@ export class Engine {

if (objective.getStatus() === ObjectiveStatus.Completed) {
this.logger(JSON.stringify({
msg: 'Ignoring payload for complected objective',
msg: 'Ignoring payload for completed objective',
...withObjectiveIdAttribute(objective.id()),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Message } from '../../../protocols/messages';
// TODO: Add tests
export interface MessageService {

// Out returns a chan for receiving messages from the message service
out (): ReadChannel<Message>;
// P2PMessages returns a chan for receiving messages from the message service
p2pMessages (): ReadChannel<Message>;

// Send is for sending messages with the message service
send (msg: Message): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import type { ReadChannel, ReadWriteChannel } from '@cerc-io/ts-channel';
// @ts-expect-error
import type { Libp2p } from '@cerc-io/libp2p';
// @ts-expect-error
import type { PrivateKey } from '@libp2p/interface-keys';
// @ts-expect-error
import type { Stream, Connection } from '@libp2p/interface-connection';
// @ts-expect-error
import type { IncomingStreamData } from '@libp2p/interface-registrar';
Expand Down Expand Up @@ -67,7 +65,6 @@ interface ConstructorOptions {
scAddr: Address;
newPeerInfo: ReadWriteChannel<BasicPeerInfo>;
logger: debug.Debugger;
key?: PrivateKey;
p2pHost?: Libp2p;
}

Expand All @@ -80,8 +77,6 @@ export class P2PMessageService implements MessageService {

private scAddr: Address = ethers.constants.AddressZero;

private privateKey?: PrivateKey;

private p2pHost?: Libp2p;

private newPeerInfo?: ReadWriteChannel<BasicPeerInfo>;
Expand Down Expand Up @@ -110,19 +105,6 @@ export class P2PMessageService implements MessageService {
});

ms.peer = opts.peer;
assert(ms.peer.peerId);
const { unmarshalPrivateKey } = await import('@libp2p/crypto/keys');

let messageKey;
try {
messageKey = await unmarshalPrivateKey(ms.peer.peerId.privateKey!);
} catch (err) {
ms.checkError(err as Error);
}

assert(messageKey);
ms.privateKey = messageKey;

assert(ms.peer.node);
ms.p2pHost = ms.peer.node;
assert(ms.p2pHost);
Expand All @@ -139,10 +121,7 @@ export class P2PMessageService implements MessageService {

// id returns the libp2p peer ID of the message service.
async id(): Promise<PeerId> {
const PeerIdFactory = await import('@libp2p/peer-id-factory');

assert(this.privateKey);
return PeerIdFactory.createFromPrivKey(this.privateKey);
return this.p2pHost.peerId;
}

// Custom Method to exchange info with already connected peers
Expand Down Expand Up @@ -452,8 +431,8 @@ export class P2PMessageService implements MessageService {
throw err;
}

// out returns a channel that can be used to receive messages from the message service
out(): ReadChannel<Message> {
// p2pMessages returns a channel that can be used to receive messages from the message service
p2pMessages(): ReadChannel<Message> {
return this.toEngine!.readOnly();
}

Expand Down
Loading