Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
  • Loading branch information
joshua-kim committed Nov 4, 2024
1 parent 618375d commit a28960b
Show file tree
Hide file tree
Showing 5 changed files with 738 additions and 17 deletions.
21 changes: 7 additions & 14 deletions dsmr/node.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package dsmr

import (
"context"
"fmt"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/common"
)

func New[T Tx](client Client[T], txsPerChunk int) *Node[T] {
Expand All @@ -20,6 +15,7 @@ func New[T Tx](client Client[T], txsPerChunk int) *Node[T] {
}

type Node[T Tx] struct {
//TODO chunk handler
client Client[T]
chunkBuilder chunkBuilder[T]
chunkCertBuilder chunkCertBuilder[T]
Expand All @@ -28,14 +24,6 @@ type Node[T Tx] struct {
chunks chan Chunk[T]
}

func (Node[_]) AppGossip(context.Context, ids.NodeID, []byte) {
return
}

func (n Node[_]) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *common.AppError) {
return nil, nil
}

func (n Node[_]) Run(blks chan<- Block) error {
for {
chunk := <-n.chunks
Expand All @@ -55,7 +43,8 @@ func (n Node[_]) Run(blks chan<- Block) error {
}

// TODO why return error
// Caller is assumed to de-dup transactions
// TODO handle frozen sponsor + validator assignments
// Caller is assumed to de-dup transactions?
func (n Node[T]) AddTx(tx T) error {
chunk, err := n.chunkBuilder.Add(tx, 0)
if err != nil {
Expand All @@ -66,6 +55,10 @@ func (n Node[T]) AddTx(tx T) error {
return nil
}

func (n Node[T]) Verify(b Block) error {

}

// consumes chunks and aggregates signtures to generate chunk certs
type chunkCertBuilder[T Tx] struct{}

Expand Down
6 changes: 3 additions & 3 deletions dsmr/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ func TestNode(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)

blks := make(chan Block)
builtBlk := make(chan Block)
node := New[tx](client{}, tt.txsPerChunk)
go func() {
_ = node.Run(blks)
_ = node.Run(builtBlk)
}()

for _, tx := range tt.txs {
require.NoError(node.AddTx(tx))
}

<-blks
<-builtBlk
})
}
}
Expand Down
55 changes: 55 additions & 0 deletions dsmr/p2p.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dsmr

import (
"context"
"time"

"google.golang.org/protobuf/proto"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/hypersdk/proto/pb/dsmr"
)

var (
_ p2p.Handler = (*GetChunkHandler)(nil)
_ p2p.Handler = (*GetChunkSignatureHandler)(nil)
)

type GetChunkHandler struct{}

func (g GetChunkHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte) {
return
}

func (g GetChunkHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *common.AppError) {
return nil, nil
}

// Receives a chunk, persists it, signs it, and replies w/ a signature
// Producer sends chunks to peers for replication + collect signatures
type GetChunkSignatureHandler struct {
}

func (g GetChunkSignatureHandler) AppGossip(context.Context, ids.NodeID, []byte) {
return
}

func (g GetChunkSignatureHandler) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, appRequestBytes []byte) ([]byte, *common.AppError) {
request := &dsmr.Chunk{}
if err := proto.Unmarshal(appRequestBytes, request); err != nil {
panic(err)
}

//TODO persist + sign
//TODO conflicting?

response := &dsmr.ChunkSignature{}
responseBytes, err := proto.Marshal(response)
if err != nil {
panic(err)
}

return responseBytes, nil
}
51 changes: 51 additions & 0 deletions proto/dsmr/dsmr.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

syntax = "proto3";

package dsmr;

option go_package = "github.com/ava-labs/hypersdk/proto/pb/dsmr";

message Chunk {
bytes producer = 1;
uint64 expiry = 2;
bytes beneficiary = 3;
repeated Transaction transactions = 4;
bytes signer = 5;
bytes signature = 6;
}

message ChunkSignature {
bytes chunk_id = 1;
bytes producer = 2;
uint64 expiry = 3;
bytes signer = 4; // bls public key
bytes signature = 5;
}


message Transaction {
bytes bytes = 1;
}

message ChunkCertificate {
bytes chunk_id = 1;
bytes producer = 2;
uint64 expiry = 3;
bytes signers = 4; // bitset
bytes signature = 5;
}

message ExecutedChunk {
bytes chunk_id = 1;
bytes beneficiary = 2;
repeated Transaction transactions = 3;
bytes warp_results = 4; // bitset
}

message GetChunkRequest {
bytes chunk_id = 1;
}

//TODO chunk fault
Loading

0 comments on commit a28960b

Please sign in to comment.