Skip to content
Closed
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
19 changes: 18 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will build, vet, and format a golang project
# This workflow will build, vet, format a golang project, and install protoc with necessary plugins
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go
Expand All @@ -8,6 +8,21 @@ on:
pull_request:

jobs:
protobuf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2

- name: Generate protobuf files
run: ./core/nakamoto/protobufs/build.sh

format:
runs-on: ubuntu-latest
steps:
Expand All @@ -27,6 +42,7 @@ jobs:

vet:
runs-on: ubuntu-latest
needs: protobuf
steps:
- uses: actions/checkout@v4

Expand All @@ -40,6 +56,7 @@ jobs:

build:
runs-on: ubuntu-latest
needs: protobuf
steps:
- uses: actions/checkout@v4

Expand Down
27 changes: 27 additions & 0 deletions core/nakamoto/netpeer_proto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package nakamoto

import (
"fmt"
"log"
"net"

"google.golang.org/grpc"

pb "github.com/liamzebedee/tinychain-go/core/nakamoto/protobufs"
)

type ProtoNetPeer struct {
pb.UnimplementedPeerServiceServer
}

func (p *ProtoNetPeer) Start() {
port := 10000
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
pb.RegisterPeerServiceServer(grpcServer, p)
grpcServer.Serve(lis)
}
1 change: 1 addition & 0 deletions core/nakamoto/protobufs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.go
5 changes: 5 additions & 0 deletions core/nakamoto/protobufs/SETUP.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

```
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
```
12 changes: 12 additions & 0 deletions core/nakamoto/protobufs/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set -ex


# protoc -I=. --go_out=. --go_opt=paths=source_relative core/nakamoto/proto/*.proto
# protoc -I=core/nakamoto/proto/ --go_out=core/nakamoto/proto --go_opt=paths=source_relative core/nakamoto/proto/*.proto

# export PATH=$PATH:$(pwd)
export PATH="$PATH:$(go env GOPATH)/bin:$(pwd)"

SRCDIR=core/nakamoto/protobufs
cd $SRCDIR
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative services.proto
120 changes: 120 additions & 0 deletions core/nakamoto/protobufs/services.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
syntax = "proto3";
option go_package = "github.com/tinychainorg/tinychain/core/nakamoto/protobufs";


//
// Types.
//

message Transaction {
bytes sig = 1;
bytes from = 2;
bytes to = 3;
uint64 amount = 4;
uint64 fee = 5;
uint64 nonce = 6;
}

message Block {
BlockHeader header = 1;
BlockBody body = 2;
}

message BlockHeader {
bytes parentHash = 1;
bytes parentTotalWork = 2;
bytes difficulty = 3;
uint64 timestamp = 4;
uint64 numTransactions = 5;
bytes transactionsMerkleRoot = 6;
bytes nonce = 7;
bytes graffiti = 8;
}

message BlockBody {
repeated Transaction transactions = 1;
}

message TipInfo {
bytes hash = 1;
uint64 height = 2;
}

//
// Bidirectional streaming messages.
//

message HeartbeatMessage {
TipInfo fullTip = 1;
TipInfo headersTip = 2;
string clientVersion = 3;
uint32 wireProtocolVersion = 4;
string clientAddress = 5;
uint64 time = 6;
}

message GossipPeersMessage {
repeated string addresses = 1;
}

message GossipBlockMessage {
Block block = 1;
}

message GossipTransactionMessage {
Transaction transaction = 1;
}

//
// Request-response RPC's.
//

message HaveBlockRequest {
bytes hash = 1;
}
message HaveBlockResponse {
bool hasBlock = 1;
}

message GetTipRequest {}
message GetTipResponse {
BlockHeader full = 1;
BlockHeader headers = 2;
}

message SyncGetDataRequest {
bytes fromBlock = 1;
bytes heights = 2;
bool headers = 3;
bool bodies = 4;
}
message SyncGetDataResponse {
repeated BlockHeader headers = 1;
repeated BlockBody bodies = 2;
}

message SyncGetTipAtDepthRequest {
bytes fromBlock = 1;
uint64 depth = 2;
}
message SyncGetTipAtDepthResponse {
BlockHeader tip = 1;
}


//
// Peer RPC service.
//

service PeerService {
rpc Heartbeat(stream HeartbeatMessage) returns (stream HeartbeatMessage);
rpc GossipPeers(stream GossipPeersMessage) returns (stream GossipPeersMessage);
rpc GossipNewBlock(stream GossipBlockMessage) returns (stream GossipBlockMessage);
rpc GossipNewTransaction(stream GossipTransactionMessage) returns (stream GossipTransactionMessage);

rpc GetTip(GetTipRequest) returns (GetTipResponse);
rpc HaveBlock(HaveBlockRequest) returns (HaveBlockResponse);

rpc SyncGetData(SyncGetDataRequest) returns (SyncGetDataResponse);
rpc SyncGetTipAtDepth(SyncGetTipAtDepthRequest) returns (SyncGetTipAtDepthResponse);
}
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ require (
github.com/triplewz/poseidon v0.0.1 // indirect
github.com/vocdoni/go-snark v0.0.0-20210614184457-1c2a880c9322 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98y
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -202,6 +203,8 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -226,6 +229,8 @@ golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand All @@ -249,6 +254,12 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Binary file added protoc
Binary file not shown.