Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:primevprotocol/mev-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kant committed Oct 16, 2023
2 parents 55b3d99 + c7f9284 commit 535a5b6
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 85 deletions.
72 changes: 20 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ log_level: debug
# Bootnodes used for bootstrapping the network.
bootnodes:
- /ip4/35.91.118.20/tcp/13522/p2p/16Uiu2HAmAG5z3E8p7o19tEcLdGvYrJYdD1NabRDc6jmizDva5BL3

# The default is set to false for development reasons. Change it to true if you wish to accept bids on your builder instance
expose_builder_api: false
```
- After the config file is ready, run `mev-commit start` with the config option.
Expand All @@ -58,66 +61,25 @@ OPTIONS:
```
- After the node is started, users can check the status of the peers connected to the node using the `/topology` endpoint on the HTTP port.
```
```json
{
self: {
Addresses: [
"self": {
"Addresses": [
"/ip4/127.0.0.1/tcp/13526",
"/ip4/192.168.1.103/tcp/13526",
"/ip4/192.168.100.5/tcp/18625"
],
Ethereum Address: "0x55B3B672DEB14178615F648911e76b7FE1B23e5D",
Peer Type: "builder",
Underlay: "16Uiu2HAmBykfyf9A5DnRguHNS1mvSaprzYEkjRf6uafLU4javG4L"
"Ethereum Address": "0x55B3B672DEB14178615F648911e76b7FE1B23e5D",
"Peer Type": "builder",
"Underlay": "16Uiu2HAmBykfyf9A5DnRguHNS1mvSaprzYEkjRf6uafLU4javG4L"
},
connected_peers: {
builders: [
{
"0xca61596ccef983eb7cae42340ec553dd89881403"
}
"connected_peers": {
"builders": [
"0xca61596ccef983eb7cae42340ec553dd89881403"
]
}
}
```
## Sending bids as a Searcher
To send bids, you can use an [gRPC api](https://github.com/primevprotocol/mev-commit/blob/main/rpc/searcherapi/v1/searcherapi.proto) that is availible to searcher nodes.
Upon running this service, searcher nodes will have access to the following:
```protobuf
service Searcher {
rpc SendBid(Bid) returns (stream Commitment) {}
}
message Bid {
string tx_hash = 1;
int64 amount = 2;
int64 block_number = 3;
};
```

By default, the docker setup exposes port `13524`, which is the standard port on which the searcher api is running. By hitting `SendBid` with the bid structure in the following format:
```
{
"tx_hash": "<tx-hash>",
"amount": <number>,
"block_number": <block-number>
}
```


## Commitments from Builders
To gather commitments from builders, the builder mev-node must maintain an active service that interfaces with the [GRPC API](https://github.com/primevprotocol/mev-commit/blob/main/rpc/builderapi/v1/builderapi.proto) and interacts with the following functions:

```protobuf
// ReceiveBids is called by the builder to receive bids from the mev-commit node.
// The mev-commit node will stream bids to the builder.
rpc ReceiveBids(EmptyMessage) returns (stream Bid) {}
// SendProcessedBids is called by the builder to send processed bids to the mev-commit node.
// The builder will stream processed bids to the mev-commit node.
rpc SendProcessedBids(stream BidResponse) returns (EmptyMessage) {}
```


## Building Docker Image

Expand All @@ -132,11 +94,17 @@ To simplify the deployment process, you may utilize Docker to create an isolated
- Running with Docker Compose:

```
docker-compose up --build
docker-compose up --build
```

- Stopping the Service:

```
docker-compose down
docker-compose down
```

## APIs for Searcher & Builder
[Link to Documentation on Searcher and Builder API](./pkg/rpc/README.md)
- This includes:
- the payload for the searcher API
- The required setup for builders to process bids into commitments in their personal infra.
36 changes: 19 additions & 17 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ func createKey(c *cli.Context) error {
}

type config struct {
PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"`
Secret string `yaml:"secret" json:"secret"`
PeerType string `yaml:"peer_type" json:"peer_type"`
P2PPort int `yaml:"p2p_port" json:"p2p_port"`
HTTPPort int `yaml:"http_port" json:"http_port"`
RPCPort int `yaml:"rpc_port" json:"rpc_port"`
LogFmt string `yaml:"log_fmt" json:"log_fmt"`
LogLevel string `yaml:"log_level" json:"log_level"`
Bootnodes []string `yaml:"bootnodes" json:"bootnodes"`
PrivKeyFile string `yaml:"priv_key_file" json:"priv_key_file"`
Secret string `yaml:"secret" json:"secret"`
PeerType string `yaml:"peer_type" json:"peer_type"`
P2PPort int `yaml:"p2p_port" json:"p2p_port"`
HTTPPort int `yaml:"http_port" json:"http_port"`
RPCPort int `yaml:"rpc_port" json:"rpc_port"`
LogFmt string `yaml:"log_fmt" json:"log_fmt"`
LogLevel string `yaml:"log_level" json:"log_level"`
Bootnodes []string `yaml:"bootnodes" json:"bootnodes"`
ExposeBuilderAPI bool `yaml:"expose_builder_api" json:"expose_builder_api"`
}

func checkConfig(cfg *config) error {
Expand Down Expand Up @@ -176,14 +177,15 @@ func start(c *cli.Context) error {
}

nd, err := node.NewNode(&node.Options{
PrivKey: privKey,
Secret: cfg.Secret,
PeerType: cfg.PeerType,
P2PPort: cfg.P2PPort,
HTTPPort: cfg.HTTPPort,
RPCPort: cfg.RPCPort,
Logger: logger,
Bootnodes: cfg.Bootnodes,
PrivKey: privKey,
Secret: cfg.Secret,
PeerType: cfg.PeerType,
P2PPort: cfg.P2PPort,
HTTPPort: cfg.HTTPPort,
RPCPort: cfg.RPCPort,
Logger: logger,
Bootnodes: cfg.Bootnodes,
ExposeBuilderAPI: cfg.ExposeBuilderAPI,
})
if err != nil {
return fmt.Errorf("failed starting node: %w", err)
Expand Down
1 change: 1 addition & 0 deletions config/builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ rpc_port: 13524
secret: hello
log_fmt: text
log_level: debug
expose_builder_api: false
bootnodes:
- /ip4/<localhost>/tcp/13522/p2p/<p2p_ID>
30 changes: 17 additions & 13 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ import (
)

type Options struct {
Version string
PrivKey *ecdsa.PrivateKey
Secret string
PeerType string
Logger *slog.Logger
P2PPort int
HTTPPort int
RPCPort int
Bootnodes []string
Version string
PrivKey *ecdsa.PrivateKey
Secret string
PeerType string
Logger *slog.Logger
P2PPort int
HTTPPort int
RPCPort int
Bootnodes []string
ExposeBuilderAPI bool
}

type Node struct {
Expand Down Expand Up @@ -108,16 +109,19 @@ func NewNode(opts *Options) (*Node, error) {

switch opts.PeerType {
case p2p.PeerTypeBuilder.String():
builderAPI := builderapi.NewService(opts.Logger.With("component", "builderapi"))
builderapiv1.RegisterBuilderServer(grpcServer, builderAPI)

var bidProcessor preconfirmation.BidProcessor = noOpBidProcessor{}
if opts.ExposeBuilderAPI {
builderAPI := builderapi.NewService(opts.Logger.With("component", "builderapi"))
builderapiv1.RegisterBuilderServer(grpcServer, builderAPI)
bidProcessor = builderAPI
}
// TODO(@ckartik): Update noOpBidProcessor to be selected as default in a flag paramater.
preconfProto := preconfirmation.New(
topo,
p2pSvc,
preconfSigner,
noOpUserStore{},
noOpBidProcessor{},
bidProcessor,
opts.Logger.With("component", "preconfirmation_protocol"),
)
// Only register handler for builder
Expand Down
6 changes: 3 additions & 3 deletions pkg/preconfirmation/preconfirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Preconfirmation struct {
topo Topology
streamer p2p.Streamer
us UserStore
processer BidProcesser
processer BidProcessor
logger *slog.Logger
}

Expand All @@ -37,7 +37,7 @@ type UserStore interface {
CheckUserRegistred(*common.Address) bool
}

type BidProcesser interface {
type BidProcessor interface {
ProcessBid(context.Context, *preconfsigner.Bid) (chan builderapiv1.BidResponse_Status, error)
}

Expand All @@ -46,7 +46,7 @@ func New(
streamer p2p.Streamer,
signer preconfsigner.Signer,
us UserStore,
processor BidProcesser,
processor BidProcessor,
logger *slog.Logger,
) *Preconfirmation {
return &Preconfirmation{
Expand Down
62 changes: 62 additions & 0 deletions pkg/rpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# RPC APIs

## Overview

There's two key RPC APIs this software provides:
- Searcher API
- Builder Internal Operations API

## Searcher API
- This is the api that takes bids into the mev-commit node that is emulating a searcher.
- The SendBid RPC endpoint will subseqently propegate the Bid after it is signed, to the primev P2P network.

The format for the request payload is as follows:

```protobuf
message Bid {
string tx_hash = 1;
int64 amount = 2;
int64 block_number = 3;
};
```

Which is the following in JSON Format:
```javascript
{
"tx_hash": "<string transaction hash>",
"amount": <integer amount of bid in wei>,
"block_number": <the block number formated as a base 10 integer>
}
```

The response to the searcher API is a stream of commitments, an example response is shown below:
```javascript
{
"tx_hash": "transaction_hash15",
"amount": "1000",
"block_number": "12345",
"bid_digest": "fb77987f64d8efaa93c659e4365e60ba7b1b3013ee12b4c988e3dbd87b76109d",
"bid_signature": "65cb64450be1c83e48a3de5565c07d10b69a75c6c463af01ffb20849e777861a3fd07e1415c83f31f1e05cc7b430b4073faf988b3b0a469148e02ccba9fd6d9901",
"pre_confirmation_digest": "0f25c2d8adc489d2db535865c70a47ab7eccbbc89ca95b705547c38811712111",
"pre_confirmation_signature": "4838b53968be8a4cd4bceee9a8299885546b7d184cfe6390dcb8afd37fec3c1b08f0ce03935afce5b11b9f425434a4b22d01cb4d4dd5f4e5894c699302dbb3ad01"
}
```


## Commitments from Builders | Builder API
To gather commitments from builders, the builder mev-node must maintain an active service that interfaces with the [GRPC API](https://github.com/primevprotocol/mev-commit/blob/main/rpc/builderapi/v1/builderapi.proto) and interacts with the following functions:

```protobuf
// ReceiveBids is called by the builder to receive bids from the mev-commit node.
// The mev-commit node will stream bids to the builder.
rpc ReceiveBids(EmptyMessage) returns (stream Bid) {}
// SendProcessedBids is called by the builder to send processed bids to the mev-commit node.
// The builder will stream processed bids to the mev-commit node.
rpc SendProcessedBids(stream BidResponse) returns (EmptyMessage) {}
```

**By default this service is disabled**, and must be enabled by setting the BuilderAPIEmabled flag in the config file to true.

The file is located at [./config/builder.yaml](../../config/builder.yml) form the top level of the project and the variable is set to `expose_builder_api: false` by default.

0 comments on commit 535a5b6

Please sign in to comment.