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: Websocket & mempool archieve & userop status method #175

Merged
merged 12 commits into from
Apr 29, 2024
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports = {
allowAny: true,
},
],
"@typescript-eslint/no-explicit-any": "off",
"import/no-extraneous-dependencies": [
"error",
{
Expand Down Expand Up @@ -161,8 +162,8 @@ module.exports = {
},
{
files: ["**/test/**/*.test.ts"],
plugins: ["mocha", "chai-expect"],
extends: ["plugin:mocha/recommended", "plugin:chai-expect/recommended"],
plugins: ["mocha"],
extends: ["plugin:mocha/recommended"],
rules: {
// We observed that having multiple top level "describe" save valuable indentation
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/max-top-level-suites.md
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ For a video tutorial on the above, you can [view this here.](https://www.youtube
- [x] Unsafe mode - bypass opcode & stake validation
- [x] Redirect RPC - Redirect ETH rpc calls to the underlying execution client. This is needed if you use UserOp.js
- [x] P2P - Exchange of UserOps between all the nodes in the network. Heavily inspired by the Lodestar's implementation of p2p (https://github.com/ChainSafe/lodestar/)
- [x] Websockets event - to listen to pending and submitted userops

### ⚡️ CLI Options
- `--unsafeMode` - enables unsafeMode
- `--redirectRpc` - enables redirecting eth rpc calls
- `--executor.bundlingMode manual|auto` - sets bundling mode to `manual` or `auto` on start. Default value is `auto`
- `--api.ws true|false` - enables / disables websocket server. Default is `true`
- `--api.wsPort number` - sets websocket service port. Default is the same as `api.port`

## 🔑 Relayer Configuration

Expand Down Expand Up @@ -124,6 +127,7 @@ For a video tutorial on the above, you can [view this here.](https://www.youtube
"skipBundleValidation": false, # # optional, skips bundle validation
"userOpGasLimit": 25000000, # optional, gas limit of a userop
"bundleGasLimit": 25000000, # optional, gas limit of a bundle
"archiveDuration": 5184000 # optional, keeps submitted, reverted and cancelled userops in the mempool for this many seconds
}
```
## 💬 Contact
Expand Down
136 changes: 68 additions & 68 deletions P2P.md → docs/p2p.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
# How to test p2p
### Run geth-dev
`cd test`
`docker-compose up -d geth-dev`
### Deploy EP and Factory from EF account-abstraction repo
1. clone the https://github.com/eth-infinitism/account-abstraction repo `git clone https://github.com/eth-infinitism/account-abstraction.git`
2. run `yarn deploy --network localhost`
We should have deployments in the following addresses.
- Entrypoint addr: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
- SimpleAccountFactory addr: 0x9406Cc6185a346906296840746125a0E44976454
- SimpleAccount addr: 0xbba97eC4fFF328d485382DfD5A9bf9653c6018Af // sample address, deployed address could be different
### Top up account
go to docker console
```
> geth attach http://127.0.0.1:8545
```
Inside geth terminal
```
> eth.sendTransaction({ from: eth.accounts[0], to: "0xbba97eC4fFF328d485382DfD5A9bf9653c6018Af", value: 1000000000000000000 })
```
### Modify the
### Generate userop from erc4337 examples
`yarn simpleAccount transfer --to 0x9406Cc6185a346906296840746125a0E44976454 --amount 0`
Example:
```
{
"sender":"0xbba97eC4fFF328d485382DfD5A9bf9653c6018Af",
"nonce":"0x0",
"initCode":"0x9406cc6185a346906296840746125a0e449764545fbfb9cf00000000000000000000000005449b55b91e9ebdd099ed584cb6357234f2ab3b0000000000000000000000000000000000000000000000000000000000000000",
"callData":"0xb61d27f60000000000000000000000009406cc6185a346906296840746125a0e4497645400000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit":"0x5568",
"verificationGasLimit":"0x5ea0c",
"preVerificationGas":"0xb820",
"maxFeePerGas":"0x4ac312de",
"maxPriorityFeePerGas":"0xed2ba9a",
"paymasterAndData":"0x",
"signature":"0xecdc2665d72b04bf133e39a3849d3eedc4913550d17f839eda442db2ea175e906750b860ba0e3ac1d3de068c2e16183a1e430f77fae2ec94e44298083576033e1c"
}
```
### Run the bootnode
```
./skandha node --redirectRpc --executor.bundlingMode manual
```
### Run a regular node
```
./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db --api.port 14338 --p2p.port 4338 --p2p.enrPort 4338 --p2p.bootEnrs [enr]
```
### Run the second regular node
```
./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db2 --api.port 14339 --p2p.port 4339 --p2p.enrPort 4339 --p2p.bootEnrs [enr]
```
## How to test p2p

### Run geth-dev

`cd test`
`docker-compose up -d geth-dev`

### Deploy EP and Factory from EF account-abstraction repo

1. clone the https://github.com/eth-infinitism/account-abstraction repo `git clone https://github.com/eth-infinitism/account-abstraction.git`
2. run `yarn deploy --network localhost`

We should have deployments in the following addresses.
- Entrypoint addr: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
- SimpleAccountFactory addr: 0x9406Cc6185a346906296840746125a0E44976454
- SimpleAccount addr: 0xbba97eC4fFF328d485382DfD5A9bf9653c6018Af // sample address, deployed address could be different

### Top up account

go to docker console
```
> geth attach http://127.0.0.1:8545
```
Inside geth terminal
```
> eth.sendTransaction({ from: eth.accounts[0], to: "0xbba97eC4fFF328d485382DfD5A9bf9653c6018Af", value: 1000000000000000000 })
```

### Modify the

### Generate userop from erc4337 examples

`yarn simpleAccount transfer --to 0x9406Cc6185a346906296840746125a0E44976454 --amount 0`

Example:
```
{
"sender":"0xbba97eC4fFF328d485382DfD5A9bf9653c6018Af",
"nonce":"0x0",
"initCode":"0x9406cc6185a346906296840746125a0e449764545fbfb9cf00000000000000000000000005449b55b91e9ebdd099ed584cb6357234f2ab3b0000000000000000000000000000000000000000000000000000000000000000",
"callData":"0xb61d27f60000000000000000000000009406cc6185a346906296840746125a0e4497645400000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit":"0x5568",
"verificationGasLimit":"0x5ea0c",
"preVerificationGas":"0xb820",
"maxFeePerGas":"0x4ac312de",
"maxPriorityFeePerGas":"0xed2ba9a",
"paymasterAndData":"0x",
"signature":"0xecdc2665d72b04bf133e39a3849d3eedc4913550d17f839eda442db2ea175e906750b860ba0e3ac1d3de068c2e16183a1e430f77fae2ec94e44298083576033e1c"
}
```

### Run the bootnode

```
./skandha node --redirectRpc --executor.bundlingMode manual
```

### Run a regular node

```
./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db --api.port 14338 --p2p.port 4338 --p2p.enrPort 4338 --p2p.bootEnrs [enr]
```

### Run the second regular node

```
./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db2 --api.port 14339 --p2p.port 4339 --p2p.enrPort 4339 --p2p.bootEnrs [enr]
```
184 changes: 184 additions & 0 deletions docs/skandha_subscribe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
## skandha_subscribe

Creates a new subscription for desired events. Sends data as soon as it occurs.

### Event Types

- pendingUserOps - user ops validated and put in the mempool
- submittedUserOps - user ops that are submitted on chain, reverted or deleted from mempool
- onChainUserOps - user ops successfully submitted on chain

### Examples:

### Pending UserOps

```json
{
"method": "skandha_subscribe",
"params": [
"pendingUserOps"
],
"id": 1,
"jsonrpc": "2.0"
}
```

#### Response

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x106eb9867751ff1bf61bad4a80b8b486"
}
```


#### Event

```json
{
"jsonrpc": "2.0",
"method": "skandha_subscription",
"params": {
"subscription": "0x106eb9867751ff1bf61bad4a80b8b486",
"result": {
"userOp": {
"sender": "0xb582979C2136189475326c648732F76677B16B98",
"nonce": "0x5",
"initCode": "0x",
"callData": "0x47e1da2a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000009fd4f6088f2025427ab1e89257a44747081ed590000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0xb957",
"verificationGasLimit": "0x9b32",
"maxFeePerGas": "0x171ab3b64",
"maxPriorityFeePerGas": "0x59682f00",
"paymasterAndData": "0x",
"preVerificationGas": "0xae70",
"signature": "0x260dfe374ec4d662fae1ac99384abc50b0490d9a087877580f585e739be368e424576440db1d2fa8950b32207d023126a48749f86c35192d872b04eed22c4f2d1b"
},
"userOpHash": "0xf8a549671473d0ee532ca235b4629b239823b426b9a898d20c58ca5212a64c9e",
"entryPoint": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"prefund": "0x2e7a15ccb8c44",
"submittedTime": "0x18f2990121c",
"status": "pending"
}
}
}
```

---

### Submitted, Reverted, Cancelled User Ops

```json
{
"method": "skandha_subscribe",
"params": [
"submittedUserOps"
],
"id": 1,
"jsonrpc": "2.0"
}
```

#### Event

```json
{
"jsonrpc": "2.0",
"method": "skandha_subscription",
"params": {
"subscription": "0x80e0632d2300aa2e1bcdb1e84329963f",
"result": {
"userOp": {
"sender": "0xb582979C2136189475326c648732F76677B16B98",
"nonce": "0x5",
"initCode": "0x",
"callData": "0x47e1da2a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000009fd4f6088f2025427ab1e89257a44747081ed590000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0xb957",
"verificationGasLimit": "0x9b32",
"maxFeePerGas": "0x171ab3b64",
"maxPriorityFeePerGas": "0x59682f00",
"paymasterAndData": "0x",
"preVerificationGas": "0xae70",
"signature": "0x260dfe374ec4d662fae1ac99384abc50b0490d9a087877580f585e739be368e424576440db1d2fa8950b32207d023126a48749f86c35192d872b04eed22c4f2d1b"
},
"userOpHash": "0xf8a549671473d0ee532ca235b4629b239823b426b9a898d20c58ca5212a64c9e",
"entryPoint": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"transaction": "0x3612daa69ec6d4804065e107e9055c9ec25c9c801d199886524e884e98179656",
"status": "Submitted"
}
}
}
```

### Onchain UserOps

#### Request

```json
{
"method": "skandha_subscribe",
"params": [
"onChainUserOps"
],
"id": 1,
"jsonrpc": "2.0"
}
```

#### Event

```json
{
"jsonrpc": "2.0",
"method": "skandha_subscription",
"params": {
"subscription": "0x2e8cf00cbe014abca180c1b6eae51173",
"result": {
"userOp": {
"sender": "0xb582979C2136189475326c648732F76677B16B98",
"nonce": "0x6",
"initCode": "0x",
"callData": "0x47e1da2a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000009fd4f6088f2025427ab1e89257a44747081ed590000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0xb957",
"verificationGasLimit": "0x9b32",
"maxFeePerGas": "0x1420c636e",
"maxPriorityFeePerGas": "0x59682f00",
"paymasterAndData": "0x",
"preVerificationGas": "0xae70",
"signature": "0xbe055319adb23a465cf7439b7d4c2ab6e86383a100459c9c34942bd9a7fd016273a159b9239fca414633b6163353faa648dc3a41857075cde2cdd1813eb92fbc1c"
},
"userOpHash": "0xefafb37d346ccfaf183f0474015aacefe178707e78d56d95e19de8950c033393",
"entryPoint": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"transaction": "0x8adba5c0463bd2cce16585871190972f49f00ead733b7005f43bf62c93296233",
"status": "onChain"
}
}
}
```

### Unsubscribe

#### Request

```json
{
"method": "skandha_unsubscribe",
"params": [
"0xcf47424b5f492abfaa97ca5d4aed1f1d"
],
"id": 1,
"jsonrpc": "2.0"
}
```

#### Response

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "ok"
}
```
Loading
Loading