Skip to content

Commit

Permalink
added docker usage documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xluk committed Feb 19, 2024
1 parent f24d6ce commit a787430
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 239 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ COPY fourq_verify /app/fourq_verify
RUN chmod +x /app/go-archiver
RUN chmod +x /app/fourq_verify

EXPOSE 21841
EXPOSE 21842
EXPOSE 8000
EXPOSE 8001

WORKDIR /app

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# go-archiver
# docker run -v /root/store:/app/store --name qubic-archiver --restart=always -d ghcr.io/qubic/qubic-archiver

## Docker usage:
When running the docker container, you need to specify the following environment variables:
- `QUBIC_ARCHIVER_QUBIC_NODE_IP` - the IP address of the Qubic node that archiver will connect to
- `QUBIC_ARCHIVER_QUBIC_FALLBACK_TICK` - the start tick for the archiver to start archiving from (needs to be from current epoch)
```bash
$ docker run -p 8000:8000 -p 8001:8001 -e QUBIC_ARCHIVER_QUBIC_NODE_IP="212.51.150.253" -e QUBIC_ARCHIVER_QUBIC_FALLBACK_TICK=12543674 -v /root/store:/app/store --name qubic-archiver -d ghcr.io/qubic/qubic-archiver
```

## Querying the archiver
```bash
$ curl -sX POST http://127.0.0.1:8000/qubic.archiver.archive.pb.ArchiveService/GetTickTransactions -d '{"tickNumber": 12570631}'
$ curl -sX POST http://127.0.0.1:8000/qubic.archiver.archive.pb.ArchiveService/GetTickData -d '{"tickNumber": 12570631}'
$ curl -sX POST http://127.0.0.1:8000/qubic.archiver.archive.pb.ArchiveService/GetTransaction -d '{"txId": "qbizhhehgiijddcgbzdxqtkqcwuedcvgnrorvovdkavytqsukxlucyjhjxeg"}'
```
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ func main() {
func run() error {
var cfg struct {
Server struct {
GrpcHost string `conf:"default:0.0.0.0:21841"`
HttpHost string `conf:"default:0.0.0.0:21842"`
ReadTimeout time.Duration `conf:"default:5s"`
WriteTimeout time.Duration `conf:"default:5s"`
ShutdownTimeout time.Duration `conf:"default:5s"`
Expand All @@ -39,7 +37,7 @@ func run() error {
NodeIp string `conf:"default:212.51.150.253"`
NodePort string `conf:"default:21841"`
FallbackTick uint64 `conf:"default:12543674"`
BatchSize uint64 `conf:"default:500"`
BatchSize uint64 `conf:"default:500"`
}
}

Expand Down Expand Up @@ -69,15 +67,15 @@ func run() error {
}
log.Printf("main: Config :\n%v\n", out)

db, err := pebble.Open("demo", &pebble.Options{})
db, err := pebble.Open("store", &pebble.Options{})
if err != nil {
log.Fatalf("err opening pebble: %s", err.Error())
}
defer db.Close()

ps := store.NewPebbleStore(db, nil)

rpcServer := rpc.NewServer("0.0.0.0:21841", "0.0.0.0:21842", ps, nil)
rpcServer := rpc.NewServer("0.0.0.0:80001", "0.0.0.0:8000", ps, nil)
rpcServer.Start()

shutdown := make(chan os.Signal, 1)
Expand Down
443 changes: 221 additions & 222 deletions protobuff/archive.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion protobuff/archive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message Transaction {
}

message GetTransactionRequest {
string digest_hex = 1;
string tx_id = 1;
}

message GetTransactionResponse{
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *Server) GetTickTransactions(ctx context.Context, req *protobuff.GetTick
return &protobuff.GetTickTransactionsResponse{Transactions: txs.Transactions}, nil
}
func (s *Server) GetTransaction(ctx context.Context, req *protobuff.GetTransactionRequest) (*protobuff.GetTransactionResponse, error) {
id := types.Identity(req.DigestHex)
id := types.Identity(req.TxId)
digest, err := id.ToPubKey(true)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid tx id: %v", err)
Expand Down
22 changes: 15 additions & 7 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type Validator struct {
qu *qubic.Connection
qu *qubic.Connection
store *store.PebbleStore
}

Expand All @@ -24,18 +24,20 @@ func NewValidator(qu *qubic.Connection, store *store.PebbleStore) *Validator {
}

func (v *Validator) ValidateTick(ctx context.Context, tickNumber uint64) error {
ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

quorumVotes, err := v.qu.GetQuorumVotes(ctx, uint32(tickNumber))
if err != nil {
return errors.Wrap(err, "getting quorum tick data")
}

//
if len(quorumVotes) == 0 {
return errors.New("not quorum votes fetched")
}

//getting computors from storage, otherwise get it from a node
epoch := quorumVotes[0].Epoch
var comps types.Computors
comps, err = computors.Get(ctx, v.store, uint64(epoch))
Expand All @@ -48,24 +50,29 @@ func (v *Validator) ValidateTick(ctx context.Context, tickNumber uint64) error {
if err != nil {
return errors.Wrap(err, "getting computors from qubic")
}

err = computors.Store(ctx, v.store, comps)
if err != nil {
return errors.Wrap(err, "storing computors")
}
}

err = computors.Validate(ctx, comps)
if err != nil {
return errors.Wrap(err, "validating comps")
}
//log.Println("Computors validated")
err = computors.Store(ctx, v.store, comps)
if err != nil {
return errors.Wrap(err, "storing computors")
}

err = quorum.Validate(ctx, quorumVotes, comps)
if err != nil {
return errors.Wrap(err, "validating quorum")
}

// if the quorum votes have an empty tick data, it means that POTENTIALLY there is no tick data, it doesn't for
// validation, but we may need to fetch it in the future ?!
if quorumVotes[0].TxDigest == [32]byte{} {
return nil
}

log.Println("Quorum validated")

tickData, err := v.qu.GetTickData(ctx, uint32(tickNumber))
Expand Down Expand Up @@ -95,6 +102,7 @@ func (v *Validator) ValidateTick(ctx context.Context, tickNumber uint64) error {

log.Printf("Validated %d transactions\n", len(validTxs))

// proceed to storing tick information
err = quorum.Store(ctx, v.store, quorumVotes)
if err != nil {
return errors.Wrap(err, "storing quorum votes")
Expand Down

0 comments on commit a787430

Please sign in to comment.