2.0.0-main-f70869ed • Published 2 years ago

@latticexyz/services v2.0.0-main-f70869ed

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Services

This package contains MUD services -- complimentary software components for enhanced interactions with on-chain state when building with MUD. Services work out-of-the-box with any project built with MUD.

V2 Services

📄 Docs

The following services are available for use with MUD V2. For more details on each service, see the linked docs page.

ServiceDescriptionProto / SpecDefault Port
modeA node for MUD. PostgresDB-based indexer of MUD V2 events across chains + MUD worlds.mode.proto50091

🏃 Quickstart

Running MODE with Docker Compose

(Only tested on MacOS for now.)

  1. Install Docker for Mac (https://docs.docker.com/docker-for-mac/install/)
  2. Install Docker Compose (https://docs.docker.com/compose/install/)
  3. Run docker-compose -f docker-compose.mode.yaml up. This will start services for both MODE and PostgresDB.
  4. By default it will connect to a local anvil node at localhost:8545. If you want to connect to a different node, you can change the rpc.http and rpc.ws fields in the config.mode-docker.yaml file.

Running the MODE service

  1. Install Go
  2. Install Postgres
  3. Deside which database you want to use, e.g. mode and create the database
  4. Set up logical replication on the database of your choice, e.g. mode. Logical replication is used to enable fast MUD state change streaming using the WAL (Write-Ahead Log) of the database. For more infromation on logical replication, see the Postgres documentation. For this you need to
    1. Modify the DB config to use logical replication. This is done by adding the following to the postgresql.conf file:
      wal_level = logical
      max_replication_slots = 1
      max_wal_senders = 1
      alternatively you can use the following SQL commands:
      ALTER SYSTEM SET wal_level = logical;
      ALTER SYSTEM SET max_replication_slots = 1;
      ALTER SYSTEM SET max_wal_senders = 1;
    2. Restart the DB
  5. Build the source. This will build the MODE service
make mode
  1. Modify config.mode.yaml MODE config file to match your preferences. MODE can be configured either with a config file or via command line arguments (both will do the same thing). In this step you should probably change the dsn section to match your database name created in step (3): this is what MODE uses to connect to Postgres. Additionally change the chains section in case you'd like to connect and have MODE index a different chain other than a local node. You can also change the ports to match your preferences. Example config file:
chains:
  - name: "localhost"
    id: "31337"
    rpc:
      http: "http://localhost:8545"
      ws: "ws://localhost:8545"
db:
  dsn: "postgresql://localhost:5432/mode_ephemeral?sslmode=disable&replication=database"
  wipe: false
sync:
  enabled: true
  startBlock: 0
  blockBatchCount: 10000
ql:
  port: 50091
metrics:
  port: 6060
  1. If you're running with the default localhost / 31337 chain, make sure there is a local node running for the chain you want to connect to. For example, a hardhat node or an anvil node.
  2. Run the MODE service
./bin/mode -config config.mode.yaml

or

make run-mode
  1. Optionally, install grpcurl to interact with the MODE service API from the command line. For example, on MacOS you can use brew to install grpcurl:
brew install grpcurl
  1. MODE exposes a QueryLayer gRPC server on port 50091 by default. You can use a gRPC client to interact with the service API. For example, to query for the current state of an indexed MUD world deployed at address 0xff738496c8cd898dC31b670D067162200C5c20A1 and on local chain with ID 31337, you can use the GetState RPC endpoint:
grpcurl -plaintext -d '{"chainTables": [], "worldTables": [], "namespace": {"chainId":"31337", "worldAddress": "0xff738496c8cd898dC31b670D067162200C5c20A1"}}' localhost:50091 mode.QueryLayer/GetState

After the initial setup, to quickly re-build and run the MODE service, you can use

make mode run-mode

MODE and MUD

Certain parts of MODE depend on MUD, specifically the storecore package of MODE which allows us to work with data coming from MUD and perfom encoding/decodings between MUD SchemaTypes, Go types, and Postgres types when the data is store in the DB. If modifications are made to MUD StoreCore, MODE storecore.go needs to be re-generated. To do this, perform these steps:

  1. Get the latest MUD StoreCore abi and save it to a file, e.g. storecore.json or storecore.abi. It should look something like this
[
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "bytes32",
        "name": "tableId",
        "type": "bytes32"
      },
      {
        "indexed": false,
        "internalType": "bytes32[]",
        "name": "key",
        "type": "bytes32[]"
      }
    ],
    "name": "StoreDeleteRecord",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "bytes32",
        "name": "tableId",
        "type": "bytes32"
      },
      {
        "indexed": false,
        "internalType": "bytes32[]",
        "name": "key",
        "type": "bytes32[]"
      },
      {
        "indexed": false,
        "internalType": "uint8",
        "name": "schemaIndex",
        "type": "uint8"
      },
      {
        "indexed": false,
        "internalType": "bytes",
        "name": "data",
        "type": "bytes"
      }
    ],
    "name": "StoreSetField",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "bytes32",
        "name": "tableId",
        "type": "bytes32"
      },
      {
        "indexed": false,
        "internalType": "bytes32[]",
        "name": "key",
        "type": "bytes32[]"
      },
      {
        "indexed": false,
        "internalType": "bytes",
        "name": "data",
        "type": "bytes"
      }
    ],
    "name": "StoreSetRecord",
    "type": "event"
  }
]
  1. Run the following command to generate the MODE storecore.go file:
abigen --abi storecore.abi --pkg storecore --out storecore.go
  1. Copy the generated storecore.go file to the MODE storecore package. Alternatively, run the command in the storecore package directory and the file will overwrite the existing one.

V1 Services

📄 Docs

The following services are available for use with MUD V1. For more details on each service, see the linked docs page.

ServiceDescriptionProto / SpecDefault Port
ecs-snapshotIndexer reducing ECS events into a single "current" state for fast snapshot client syncsecs-snapshot.proto50061
ecs-streamMultiplexer for subscriptions to receive current block data, ECS events per block, and transaction origination dataecs-stream.proto50051
ecs-relayGeneric message relayer, supporting signed messages, service-side signature verification, relay conditions for DDoS prevention, and moreecs-relay.proto50071
faucetFaucet supporting custom drip amounts, global limits, twitter verification, and integrations with MUD componentsfaucet.proto50081

🏃 Quickstart

Running the ECS Snapshot, Stream, Relay, and Faucet services

  1. Install Go
  2. Build the source. This will build all the services
make build

or to build only specific services

make ecs-snapshot ecs-stream ecs-relay faucet
  1. If you're running with the default chain, make sure there is a local node running for the chain you want to connect to. For example, a hardhat node or an anvil node.
  2. Run whichever binary via Makefile. For example, to run the snapshot service
make run-ecs-snapshot

Protobuf

MUD services use Protocol Buffers to define the data structures and message schemas. The .proto files are available in the /proto directory at the root of this repo. For more details about .proto files and a language guide, see the Language Guide (proto3). The package has the protobuf files checked in, but in case you want to regenerate those (based on an updated .proto file for instance), run

make protoc
2.0.0-next.16

2 years ago

2.0.0-next.15

2 years ago

2.0.0-next.8

2 years ago

2.0.0-next.9

2 years ago

2.0.0-next.6

2 years ago

2.0.0-next.7

2 years ago

2.0.0-next.4

2 years ago

2.0.0-next.5

2 years ago

2.0.0-next.10

2 years ago

2.0.0-next.11

2 years ago

2.0.0-next.12

2 years ago

2.0.0-next.13

2 years ago

2.0.0-next.14

2 years ago

2.0.0-next.2

2 years ago

2.0.0-next.3

2 years ago

2.0.0-next.0

2 years ago

2.0.0-next.1

2 years ago

2.0.0-alpha.1.99

2 years ago

2.0.0-alpha.1.97

2 years ago

2.0.0-alpha.1.98

2 years ago

2.0.0-alpha.1.95

2 years ago

2.0.0-alpha.1.96

2 years ago

2.0.0-alpha.1.59

2 years ago

2.0.0-alpha.1.57

2 years ago

2.0.0-alpha.1.58

2 years ago

2.0.0-alpha.1.55

2 years ago

2.0.0-alpha.1.56

2 years ago

2.0.0-alpha.1.53

2 years ago

2.0.0-alpha.1.54

2 years ago

2.0.0-alpha.1.51

2 years ago

2.0.0-alpha.1.52

2 years ago

2.0.0-alpha.1.60

2 years ago

2.0.0-alpha.1.61

2 years ago

2.0.0-alpha.1.68

2 years ago

2.0.0-alpha.1.69

2 years ago

2.0.0-alpha.1.66

2 years ago

2.0.0-alpha.1.67

2 years ago

2.0.0-alpha.1.64

2 years ago

2.0.0-alpha.1.65

2 years ago

2.0.0-alpha.1.62

2 years ago

2.0.0-alpha.1.63

2 years ago

2.0.0-alpha.1.71

2 years ago

2.0.0-alpha.1.72

2 years ago

2.0.0-alpha.1.70

2 years ago

2.0.0-alpha.1.79

2 years ago

2.0.0-alpha.1.77

2 years ago

2.0.0-alpha.1.78

2 years ago

2.0.0-alpha.1.75

2 years ago

2.0.0-alpha.1.76

2 years ago

2.0.0-alpha.1.73

2 years ago

2.0.0-alpha.1.74

2 years ago

2.0.0-alpha.1.82

2 years ago

2.0.0-alpha.1.83

2 years ago

2.0.0-alpha.1.80

2 years ago

2.0.0-alpha.1.81

2 years ago

2.0.0-alpha.1.88

2 years ago

2.0.0-alpha.1.89

2 years ago

2.0.0-alpha.1.86

2 years ago

2.0.0-alpha.1.87

2 years ago

2.0.0-alpha.1.84

2 years ago

2.0.0-alpha.1.85

2 years ago

2.0.0-alpha.1.93

2 years ago

2.0.0-alpha.1.94

2 years ago

2.0.0-alpha.1.91

2 years ago

2.0.0-alpha.1.92

2 years ago

2.0.0-alpha.1.90

2 years ago

2.0.0-alpha.1.39

3 years ago

2.0.0-alpha.1.37

3 years ago

2.0.0-alpha.1.38

3 years ago

2.0.0-alpha.1.35

3 years ago

2.0.0-alpha.1.36

3 years ago

2.0.0-alpha.1.34

3 years ago

2.0.0-alpha.1.48

2 years ago

2.0.0-alpha.1.49

2 years ago

2.0.0-alpha.1.46

2 years ago

2.0.0-alpha.1.47

2 years ago

2.0.0-alpha.1.44

2 years ago

2.0.0-alpha.1.45

2 years ago

2.0.0-alpha.1.42

2 years ago

2.0.0-alpha.1.43

2 years ago

2.0.0-alpha.1.41

2 years ago

2.0.0-alpha.1.50

2 years ago

2.0.0-alpha.1.19

3 years ago

2.0.0-alpha.1.17

3 years ago

2.0.0-alpha.1.18

3 years ago

2.0.0-alpha.1.15

3 years ago

2.0.0-alpha.1.16

3 years ago

2.0.0-alpha.1.13

3 years ago

2.0.0-alpha.1.11

3 years ago

2.0.0-alpha.1.12

3 years ago

2.0.0-alpha.7

3 years ago

2.0.0-alpha.1.10

3 years ago

2.0.0-alpha.8

3 years ago

2.0.0-alpha.9

3 years ago

2.0.0-alpha.3

3 years ago

2.0.0-alpha.4

3 years ago

2.0.0-alpha.5

3 years ago

1.41.1-alpha.0

3 years ago

2.0.0-alpha.6

3 years ago

2.0.0-alpha.94

3 years ago

2.0.0-alpha.0

3 years ago

2.0.0-alpha.1

3 years ago

2.0.0-alpha.93

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0-alpha.92

3 years ago

1.40.0

3 years ago

2.0.0-alpha.1.28

3 years ago

2.0.0-alpha.1.29

3 years ago

2.0.0-alpha.1.26

3 years ago

2.0.0-alpha.1.27

3 years ago

2.0.0-alpha.91

3 years ago

2.0.0-alpha.90

3 years ago

2.0.0-alpha.1.22

3 years ago

2.0.0-alpha.1.23

3 years ago

2.0.0-alpha.1.20

3 years ago

2.0.0-alpha.1.21

3 years ago

2.0.0-alpha.88

3 years ago

2.0.0-alpha.87

3 years ago

2.0.0-alpha.86

3 years ago

2.0.0-alpha.85

3 years ago

2.0.0-alpha.84

3 years ago

2.0.0-alpha.83

3 years ago

2.0.0-alpha.82

3 years ago

2.0.0-alpha.81

3 years ago

2.0.0-alpha.89

3 years ago

2.0.0-alpha.80

3 years ago

2.0.0-alpha.1.33

3 years ago

2.0.0-alpha.1.31

3 years ago

2.0.0-alpha.1.32

3 years ago

2.0.0-alpha.1.30

3 years ago

2.0.0-alpha.76

3 years ago

2.0.0-alpha.75

3 years ago

2.0.0-alpha.74

3 years ago

2.0.0-alpha.73

3 years ago

2.0.0-alpha.72

3 years ago

1.41.0

3 years ago

2.0.0-alpha.79

3 years ago

2.0.0-alpha.78

3 years ago

2.0.0-alpha.66

3 years ago

2.0.0-alpha.65

3 years ago

2.0.0-alpha.64

3 years ago

2.0.0-alpha.63

3 years ago

2.0.0-alpha.62

3 years ago

2.0.0-alpha.61

3 years ago

2.0.0-alpha.60

3 years ago

2.0.0-alpha.69

3 years ago

2.0.0-alpha.68

3 years ago

2.0.0-alpha.67

3 years ago

2.0.0-alpha.55

3 years ago

2.0.0-alpha.54

3 years ago

2.0.0-alpha.53

3 years ago

2.0.0-alpha.52

3 years ago

2.0.0-alpha.51

3 years ago

2.0.0-alpha.50

3 years ago

1.42.0

3 years ago

2.0.0-alpha.59

3 years ago

2.0.0-alpha.58

3 years ago

2.0.0-alpha.57

3 years ago

2.0.0-alpha.56

3 years ago

2.0.0-alpha.44

3 years ago

2.0.0-alpha.43

3 years ago

2.0.0-alpha.41

3 years ago

2.0.0-alpha.40

3 years ago

2.0.0-alpha.49

3 years ago

2.0.0-alpha.48

3 years ago

2.0.0-alpha.47

3 years ago

2.0.0-alpha.46

3 years ago

2.0.0-alpha.45

3 years ago

2.0.0-alpha.39

3 years ago

2.0.0-alpha.38

3 years ago

2.0.0-alpha.37

3 years ago

2.0.0-alpha.36

3 years ago

1.43.0

3 years ago

1.41.1-alpha.41

3 years ago

1.37.0

3 years ago

1.35.0

3 years ago

1.37.1

3 years ago

1.39.0

3 years ago

1.36.1

3 years ago

1.34.0

3 years ago

1.38.0

3 years ago

1.33.1

3 years ago

1.31.3

3 years ago

1.29.0

3 years ago

1.27.1

3 years ago

1.32.0

3 years ago

1.30.1

3 years ago

1.26.0

3 years ago

1.28.1

3 years ago

1.28.0

3 years ago

1.31.1

3 years ago

1.31.2

3 years ago

1.31.0

3 years ago

1.15.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.13.0

3 years ago

1.0.0

3 years ago

1.12.0

3 years ago

1.19.0

3 years ago

1.18.0

3 years ago

1.17.0

3 years ago

1.16.0

3 years ago

1.14.2

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

0.16.3

3 years ago

0.16.4

3 years ago

1.21.0

3 years ago

1.22.0

3 years ago

1.20.0

3 years ago

1.24.1

3 years ago

1.25.1

3 years ago

1.23.0

3 years ago

1.24.0

3 years ago

1.23.1

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

0.16.2

3 years ago

0.16.1

3 years ago

0.16.0

3 years ago

0.15.1

3 years ago

0.15.0

3 years ago

0.14.2

3 years ago

0.14.1

3 years ago

0.14.0

3 years ago

0.13.0

3 years ago

0.12.0

3 years ago

0.11.1

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago