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

POC for /block #6

Merged
merged 44 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0667986
inital database schema for block storage (#4)
andynog May 12, 2023
8f9817e
add uint64 domain (#4)
andynog May 12, 2023
955e38a
minor fixes and renames (#4)
andynog May 12, 2023
eb6f6db
More info README (#4)
andynog May 12, 2023
6ea65de
update and fix sql scripts, add sequence number (#4)
andynog May 12, 2023
3701cdd
refactoring some fields (#4)
andynog May 15, 2023
cf130ff
initial logic to insert some blocks (#1)
andynog May 15, 2023
119418d
added more block data, refactoring schema (#1)
andynog May 17, 2023
39065f9
initial logic for rpc service (#3)
andynog May 18, 2023
9c95bec
initial logic to return block data (#3)
andynog May 18, 2023
0b712fe
started to add block data (#1)
andynog May 23, 2023
b5bfdd7
added logic to insert block transactions (#1)
andynog May 23, 2023
482e2cd
added last_block_id information (#1)
andynog May 24, 2023
a22ff7f
added header_version information (#1)
andynog May 24, 2023
b92accb
added remaining block header fields (#1)
andynog May 24, 2023
e683a6b
rename last_block_id columns to match header (#4)
andynog May 24, 2023
97c4bb8
Added block last commit info (#1)
andynog May 24, 2023
a73131d
update postgres docker image version (#4)
andynog May 24, 2023
49e1291
added block_id info (#1)
andynog May 25, 2023
8a007b5
remove private key (no need) from block_data table (#4)
andynog May 25, 2023
4db94a0
make endpoint configurable and retrieve last height (#1)
andynog May 25, 2023
5ec97d4
added last_commit_signature info (#4)
andynog May 25, 2023
ed63d1c
added last_commit_signatures info (#1)
andynog May 25, 2023
6b8a428
initial schema for evidence (#4)
andynog May 31, 2023
db032e7
adding duplicate_vote_evidence table (#4)
andynog May 31, 2023
e96f3c2
added logic to insert duplicate vote evidence (#1)
andynog Jun 1, 2023
55960fa
initial logic to return a duplicate vote evidence (#3)
andynog Jun 2, 2023
c493351
fully implemented the duplicate vote evidence response (#3)
andynog Jun 2, 2023
cc3ed26
Initial schema for light client attack evidence (#4)
andynog Jun 2, 2023
f29ba7d
reshuffle sequence (#4)
andynog Jun 5, 2023
0d7791d
some clean up (#1)
andynog Jun 5, 2023
78beb10
adding initial schema for light client attack evidence (#4)
andynog Jun 7, 2023
1414d95
initial logic to insert light client attack evidence (#1)
andynog Jun 7, 2023
14838e9
refactoring some schema names (#4)
andynog Jun 7, 2023
778f632
initial logic to return light client attack evidence (#3)
andynog Jun 7, 2023
4834d83
simplified schema creation merged into one file (#4)
andynog Jun 19, 2023
f1c4876
initial service commands implementation #1 #3
andynog Jun 19, 2023
90f7890
refactoring logic into services, initial ingest service implementatio…
andynog Jun 20, 2023
3c9a97a
implemented RPC as a service (#3)
andynog Jun 20, 2023
4a8c39b
fixed logic to return proper json using CometBFT libs/json (#3)
andynog Jun 21, 2023
eefe263
minor refactoring (#3)
andynog Jun 22, 2023
757e142
adding logic to store validator struct (#4)
andynog Jun 23, 2023
eb8d65c
added logic to add normalized byzantine validator for lca evidence (#…
andynog Jun 26, 2023
56c676a
added byzantine validators return in light client attack evidence (#3)
andynog Jun 27, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# RPC Companion

### WIP (Work In Progress)
# RPC Companion (Work In Progress)

This is the repository for the RPC Companion solution based on the Data Companion ADR

## Starting the Postgres Database

Access the Docker folder:

`cd ./database/docker`

Run the services

`docker-compose -f docker-compose.yml up`

## Accessing the database with pgAdmin

Open a browser and navigate to
http://127.0.0.1:5050

Use the following credentials:

```
User: [email protected]
Password: pgadmin123
```
21 changes: 21 additions & 0 deletions commands/ingest/ingest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ingest

import (
"github.com/spf13/cobra"
)

// IngestCmd ingest service commands
var IngestCmd = &cobra.Command{
Use: "ingest",
Short: "Ingest Service commands",
Long: `The Ingest Service pulls data from a CometBFT full node and store the information in a database.

There should be just one running instance of the Ingest Service targeting a full node.`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
IngestCmd.AddCommand(StartCmd)
}
52 changes: 52 additions & 0 deletions commands/ingest/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ingest

import (
"fmt"
"github.com/cometbft/rpc-companion/ingest"
"github.com/spf13/cobra"
"log"
"os"
"strconv"
)

// TODO: make this configurable via a config or parameter
const connString = "postgres://postgres:[email protected]:15432/postgres?sslmode=disable"

// StartCmd start ingest service
var StartCmd = &cobra.Command{
Use: "start",
Short: "Start Ingest Service",
Long: `The start command runs an instance of the Ingest Service`,
Run: func(cmd *cobra.Command, args []string) {

//Instantiate a new Ingest Service
ingestSvc := ingest.NewService(connString)

//Insert some blocks
numberHeights := int64(10)
initialHeightParameter := os.Getenv("COMPANION_INITIAL_HEIGHT")
initialHeight, err := strconv.ParseInt(initialHeightParameter, 10, 64)
if err != nil {
fmt.Printf("Invalid initial height %s: %s\n", initialHeightParameter, err)
}

for height := initialHeight; height <= initialHeight+numberHeights; height++ {

blockFetched, err := ingestSvc.Fetcher.FetchBlock(int64(height))
if err != nil {
log.Fatalf("Error fetching block at height %d: %s\n", height, err)
}

inserted, err := ingestSvc.Storage.InsertBlock(*blockFetched)
if err != nil {
fmt.Printf("Error inserting block at height %d: %s\n", height, err)
}
if inserted {
fmt.Printf("Inserted height %d\n", height)
}
}
},
}

func init() {
}
39 changes: 39 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package commands

import (
ingest "github.com/cometbft/rpc-companion/commands/ingest"
rpc "github.com/cometbft/rpc-companion/commands/rpc"
"github.com/spf13/cobra"
)

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "rpc-companion",
Short: "RPC Companion - CometBFT",
Long: `RPC Companion is an implementation of a Data Companion for CometBFT based chains`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cobra.CheckErr(RootCmd.Execute())
}

func init() {

options := cobra.CompletionOptions{
DisableDefaultCmd: true,
DisableNoDescFlag: true,
DisableDescriptions: false,
}
RootCmd.CompletionOptions = options

cobra.EnableCommandSorting = true

RootCmd.AddCommand(ingest.IngestCmd)
RootCmd.AddCommand(rpc.RpcCmd)
}

func initConfig() {

}
19 changes: 19 additions & 0 deletions commands/rpc/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package rpc

import (
"github.com/spf13/cobra"
)

// RpcCmd RPC service commands
var RpcCmd = &cobra.Command{
Use: "rpc",
Short: "RPC Service commands",
Long: `The RPC Service expose a RPC endpoint compatible with the CometBFT RPC endpoint.`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func init() {
RpcCmd.AddCommand(StartCmd)
}
27 changes: 27 additions & 0 deletions commands/rpc/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package rpc

import (
"github.com/cometbft/rpc-companion/rpc"
"github.com/spf13/cobra"
)

// TODO: make this configurable via a config or parameter
const connString = "postgres://postgres:[email protected]:15432/postgres?sslmode=disable"

// StartCmd start RPC service
var StartCmd = &cobra.Command{
Use: "start",
Short: "Start RPC Service",
Long: `The start command runs an instance of the RPC Service`,
Run: func(cmd *cobra.Command, args []string) {

//Instantiate a new Ingest Service
rpcSvc := rpc.NewService(connString)

//Start the service
rpcSvc.Serve()
},
}

func init() {
}
2 changes: 1 addition & 1 deletion database/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.9'
services:
docker_postgres:
image: postgres:15.2-alpine
image: postgres:15.3-alpine
restart: always
environment:
- POSTGRES_DB=postgres
Expand Down
Loading