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

merging qchain to main #9

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions .github/workflows/push-docker-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy dev images to GHCR

on:
push:
branches:
- 'dev'

jobs:
push-store-image:
runs-on: ubuntu-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@main

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build Inventory Image'
run: |
docker build . --tag ghcr.io/qubic/qubic-archiver:dev
docker push ghcr.io/qubic/qubic-archiver:dev
2 changes: 1 addition & 1 deletion .github/workflows/push-docker.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy Images to GHCR
name: Deploy prod images to GHCR

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
go-version: [1.20.x]
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (p *Processor) processOneByOne() error {
}

val := validator.New(client, p.ps)
err = val.ValidateTick(ctx, nextTick)
err = val.ValidateTick(ctx, uint64(tickInfo.InitialTick), nextTick)
if err != nil {
return errors.Wrapf(err, "validating tick %d", nextTick)
}
Expand Down
340 changes: 238 additions & 102 deletions protobuff/archive.pb.go

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions protobuff/archive.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions protobuff/archive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ message GetTransferTransactionsPerTickResponse {
TransferTransactionsPerTick transfer_transactions_per_tick = 1;
}

message GetQChainHashRequest {
uint32 tick_number = 1;
}

message GetQChainHashResponse {
string hex_digest = 1;
}

service ArchiveService {
rpc GetTickData(GetTickDataRequest) returns (GetTickDataResponse);
rpc GetTickTransactions(GetTickTransactionsRequest) returns (GetTickTransactionsResponse);
Expand All @@ -192,4 +200,5 @@ service ArchiveService {
rpc GetSkippedTicks(GetSkippedTicksRequest) returns (GetSkippedTicksResponse);
rpc GetTransferTransactions(GetTransferTransactionsRequest) returns (GetTransferTransactionsResponse);
rpc GetTransferTransactionsPerTick(GetTransferTransactionsPerTickRequest) returns (GetTransferTransactionsPerTickResponse);
rpc GetQChainHash(GetQChainHashRequest) returns (GetQChainHashResponse);
}
37 changes: 37 additions & 0 deletions protobuff/archive_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions rpc/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ func (s *Server) GetTransferTransactionsPerTick(ctx context.Context, req *protob
return &protobuff.GetTransferTransactionsPerTickResponse{TransferTransactionsPerTick: txs}, nil
}

func (s *Server) GetQChainHash(ctx context.Context, req *protobuff.GetQChainHashRequest) (*protobuff.GetQChainHashResponse, error) {
hash, err := s.store.GetQChainDigest(ctx, uint64(req.TickNumber))
if err != nil {
if errors.Cause(err) == store.ErrNotFound {
return nil, status.Errorf(codes.NotFound, "qChain hash for specified tick not found")
}
return nil, status.Errorf(codes.Internal, "getting qChain hash: %v", err)
}

return &protobuff.GetQChainHashResponse{HexDigest: hex.EncodeToString(hash[:])}, nil
}

func (s *Server) Start() error {
srv := grpc.NewServer(
grpc.MaxRecvMsgSize(600*1024*1024),
Expand Down
8 changes: 8 additions & 0 deletions store/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
LastProcessedTickPerEpoch = 0x05
SkippedTicksInterval = 0x06
IdentityTransferTransactions = 0x07
QChainDigest = 0x08
)

func tickDataKey(tickNumber uint64) []byte {
Expand Down Expand Up @@ -72,3 +73,10 @@ func identityTransferTransactions(identity string) []byte {

return key
}

func qChainDigestKey(tickNumber uint64) []byte {
key := []byte{QChainDigest}
key = binary.BigEndian.AppendUint64(key, tickNumber)

return key
}
26 changes: 26 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,29 @@ func (s *PebbleStore) GetTransferTransactionsPerTick(ctx context.Context, identi

return &perTick, nil
}

func (s *PebbleStore) PutQChainDigest(ctx context.Context, tickNumber uint64, digest []byte) error {
key := qChainDigestKey(tickNumber)

err := s.db.Set(key, digest, pebble.Sync)
if err != nil {
return errors.Wrap(err, "setting qChain digest")
}

return nil
}

func (s *PebbleStore) GetQChainDigest(ctx context.Context, tickNumber uint64) ([]byte, error) {
key := qChainDigestKey(tickNumber)
value, closer, err := s.db.Get(key)
if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return nil, ErrNotFound
}

return nil, errors.Wrap(err, "getting qChain digest")
}
defer closer.Close()

return value, nil
}
34 changes: 34 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,37 @@ func TestPebbleStore_TransferTransactions(t *testing.T) {
_, err = store.GetTransferTransactionsPerTick(ctx, idOne, 14)
require.EqualError(t, err, ErrNotFound.Error())
}

func TestPebbleStore_QChainHash(t *testing.T) {
ctx := context.Background()

// Setup test environment
dbDir, err := os.MkdirTemp("", "pebble_test")
require.NoError(t, err)
defer os.RemoveAll(dbDir)

db, err := pebble.Open(filepath.Join(dbDir, "testdb"), &pebble.Options{})
require.NoError(t, err)
defer db.Close()

logger, _ := zap.NewDevelopment()
store := NewPebbleStore(db, logger)

// Sample QChainHash for testing
tickNumber := uint64(12795005)
qChainHash := []byte("qChainHash")

// Set QChainHash
err = store.PutQChainDigest(ctx, tickNumber, qChainHash)
require.NoError(t, err)

// Get QChainHash
retrievedQChainHash, err := store.GetQChainDigest(ctx, tickNumber)
require.NoError(t, err)
require.Equal(t, qChainHash, retrievedQChainHash)

// Test retrieval of non-existent QChainHash
_, err = store.GetQChainDigest(ctx, 999) // Assuming 999 is a tick number that wasn't stored
require.Error(t, err)
require.Equal(t, ErrNotFound, err)
}
Loading
Loading