Skip to content

Commit a47b8a6

Browse files
committed
gRPC support ready
- Might have to fix some naming conventons - This will also greatly benefit from general type clean up - benchmarking incoming
1 parent 1b4df7e commit a47b8a6

File tree

16 files changed

+505
-27
lines changed

16 files changed

+505
-27
lines changed

cmd/blindbit-oracle/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/setavenger/blindbit-oracle/internal/dataexport"
1818
"github.com/setavenger/blindbit-oracle/internal/dblevel"
1919
"github.com/setavenger/blindbit-oracle/internal/server"
20+
v2 "github.com/setavenger/blindbit-oracle/internal/server/v2"
2021
)
2122

2223
var (
@@ -143,6 +144,11 @@ func main() {
143144
// so we can start fetching data while not fully synced. Requires headers to be synced to avoid grave errors.
144145
go server.RunServer(&server.ApiHandler{})
145146

147+
// keep it optional for now
148+
if config.GRPCHost != "" {
149+
go v2.RunGRPCServer()
150+
}
151+
146152
// todo buggy for sync catchup from 0, needs to be 1 or higher
147153
err = core.SyncChain()
148154
if err != nil {

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ require (
1212
github.com/rs/zerolog v1.34.0
1313
github.com/setavenger/blindbit-lib v0.0.0-20250807130019-f9642edb8c97
1414
github.com/setavenger/go-bip352 v0.1.8-0.20250807125845-136879952399
15-
github.com/setavenger/go-libsecp256k1 v0.0.0
15+
github.com/setavenger/go-libsecp256k1 v0.0.0-20250601142217-61f26e074fd5
1616
github.com/spf13/viper v1.19.0
1717
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
18+
google.golang.org/grpc v1.62.1
19+
google.golang.org/protobuf v1.36.2
1820
)
1921

22+
replace github.com/setavenger/blindbit-lib => ../blindbit-lib
23+
2024
require (
2125
github.com/aead/siphash v1.0.1 // indirect
2226
github.com/btcsuite/btcd v0.24.2 // indirect
@@ -35,6 +39,7 @@ require (
3539
github.com/go-playground/universal-translator v0.18.1 // indirect
3640
github.com/go-playground/validator/v10 v10.24.0 // indirect
3741
github.com/goccy/go-json v0.10.4 // indirect
42+
github.com/golang/protobuf v1.5.3 // indirect
3843
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
3944
github.com/hashicorp/hcl v1.0.0 // indirect
4045
github.com/json-iterator/go v1.1.12 // indirect
@@ -69,7 +74,7 @@ require (
6974
golang.org/x/net v0.34.0 // indirect
7075
golang.org/x/sys v0.31.0 // indirect
7176
golang.org/x/text v0.23.0 // indirect
72-
google.golang.org/protobuf v1.36.2 // indirect
77+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
7378
gopkg.in/ini.v1 v1.67.0 // indirect
7479
gopkg.in/yaml.v2 v2.4.0 // indirect
7580
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
8484
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
8585
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
8686
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
87+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
88+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
89+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
8790
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
8891
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
8992
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
9093
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
9194
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
9295
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
96+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9397
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
9498
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9599
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -156,12 +160,10 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
156160
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
157161
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
158162
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
159-
github.com/setavenger/blindbit-lib v0.0.0-20250807130019-f9642edb8c97 h1:qP//UQueTVKlu1I6/F8zkdYtZ02WiRI8Jic4LdYocPQ=
160-
github.com/setavenger/blindbit-lib v0.0.0-20250807130019-f9642edb8c97/go.mod h1:xyaSsYjsrkizd98pohR1HNEJcHrAMnzRbSTxPEDlgmk=
161163
github.com/setavenger/go-bip352 v0.1.8-0.20250807125845-136879952399 h1:SZtpspHUg1VOm8YWDK2mSfyOukxE3xHgtlNT/dOs+4k=
162164
github.com/setavenger/go-bip352 v0.1.8-0.20250807125845-136879952399/go.mod h1:j+5v4nI/7n9IBEnvr6LagRpe6whTAHjIBRtqJKyJKG4=
163-
github.com/setavenger/go-libsecp256k1 v0.0.0 h1:34iPJFpHMalo0/zz3seJqpwW5UXr6CdakTaM10KXAoI=
164-
github.com/setavenger/go-libsecp256k1 v0.0.0/go.mod h1:TOguhOrbK0FoBk466b3CjYHbaYrZcB6CJteeq/K5w/4=
165+
github.com/setavenger/go-libsecp256k1 v0.0.0-20250601142217-61f26e074fd5 h1:KKpLemBDPEQxNmTz2+5M8bWhlArls9ZkhkCHPPVh3RY=
166+
github.com/setavenger/go-libsecp256k1 v0.0.0-20250601142217-61f26e074fd5/go.mod h1:TOguhOrbK0FoBk466b3CjYHbaYrZcB6CJteeq/K5w/4=
165167
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
166168
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
167169
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
@@ -241,12 +243,18 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
241243
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
242244
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
243245
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
246+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c h1:lfpJ/2rWPa/kJgxyyXM8PrNnfCzcmxJ265mADgwmvLI=
247+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
248+
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
249+
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
244250
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
245251
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
246252
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
247253
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
248254
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
249255
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
256+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
257+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
250258
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
251259
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
252260
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/config/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ func LoadConfigs(pathToConfig string) {
2020
/* set defaults */
2121
// network
2222
viper.SetDefault("max_parallel_requests", MaxParallelRequests)
23-
viper.SetDefault("host", Host)
23+
viper.SetDefault("http_host", HTTPHost)
24+
viper.SetDefault("grpc_host", GRPCHost)
2425
viper.SetDefault("chain", "signet")
2526

2627
// RPC endpoint only. Fails if others are not set
@@ -34,7 +35,8 @@ func LoadConfigs(pathToConfig string) {
3435
viper.SetDefault("log_level", "info")
3536
// Bind viper keys to environment variables (optional, for backup)
3637
viper.AutomaticEnv()
37-
viper.BindEnv("host", "HOST")
38+
viper.BindEnv("http_host", "HTTP_HOST")
39+
viper.BindEnv("grpc_host", "GRPC_HOST")
3840
viper.BindEnv("chain", "CHAIN")
3941
viper.BindEnv("rpc_endpoint", "RPC_ENDPOINT")
4042
viper.BindEnv("cookie_path", "COOKIE_PATH")
@@ -52,7 +54,8 @@ func LoadConfigs(pathToConfig string) {
5254
/* read and set config variables */
5355
// General
5456
SyncStartHeight = viper.GetUint32("sync_start_height")
55-
Host = viper.GetString("host")
57+
HTTPHost = viper.GetString("http_host")
58+
GRPCHost = viper.GetString("grpc_host")
5659
LogLevel = viper.GetString("log_level")
5760
// Performance
5861
MaxParallelRequests = viper.GetUint16("max_parallel_requests")

internal/config/vars.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ var (
3737
DBPath = ""
3838
LogsPath = ""
3939

40-
Host = "127.0.0.1:8000"
40+
HTTPHost = "127.0.0.1:8000"
41+
GRPCHost = "127.0.0.1:50051"
4142
)
4243

4344
type chain int

internal/dblevel/blockheaderinv.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func InsertBatchBlockHeaderInv(headersInv []types.BlockHeaderInv) error {
4040
return nil
4141
}
4242

43+
// FetchByBlockHeightBlockHeaderInv change height 32 to (u)int64
4344
func FetchByBlockHeightBlockHeaderInv(height uint32) (types.BlockHeaderInv, error) {
4445
var pair types.BlockHeaderInv
4546
err := retrieveByBlockHeight(HeadersInvDB, height, &pair)
@@ -76,7 +77,7 @@ func FetchHighestBlockHeaderInv() (*types.BlockHeaderInv, error) {
7677
}
7778
if result.Hash == [32]byte{} {
7879
logging.L.Warn().Msg("no entry found")
79-
return nil, NoEntryErr{}
80+
return nil, nil
8081
}
8182
return &result, err
8283
}
@@ -90,7 +91,7 @@ func FetchHighestBlockHeaderInvByFlag(flag bool) (*types.BlockHeaderInv, error)
9091

9192
ok := iter.Last()
9293
if !ok {
93-
return nil, NoEntryErr{}
94+
return nil, nil
9495
}
9596

9697
// Process the last element first, then continue with previous elements.
@@ -331,7 +332,7 @@ func FetchAllHeadersInv() ([]types.BlockHeaderInv, error) {
331332
}
332333
if len(pairs) == 0 {
333334
logging.L.Warn().Msg("Nothing returned")
334-
return nil, NoEntryErr{}
335+
return nil, nil
335336
}
336337

337338
result := make([]types.BlockHeaderInv, len(pairs))

internal/dblevel/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func retrieveManyByBlockHashAndTxid(db *leveldb.DB, blockHash, txid [32]byte, fa
249249
return nil, err
250250
}
251251
if results == nil {
252-
return nil, NoEntryErr{}
252+
return nil, nil
253253
}
254254
return results, err
255255
}

internal/dblevel/spentoutpointsfilter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func FetchByBlockHashSpentOutpointsFilter(blockHash [32]byte) (types.Filter, err
2525
return pair, nil
2626
}
2727

28-
// FetchAllFilters returns all types.Filter in the DB
28+
// FetchAllSpentOutpointsFilters returns all types.Filter in the DB
2929
func FetchAllSpentOutpointsFilters() ([]types.Filter, error) {
3030
pairs, err := retrieveAll(SpentOutpointsFilterDB, types.PairFactoryFilter)
3131
if err != nil {
@@ -34,7 +34,7 @@ func FetchAllSpentOutpointsFilters() ([]types.Filter, error) {
3434
}
3535
if len(pairs) == 0 {
3636
logging.L.Warn().Msg("Nothing returned")
37-
return nil, NoEntryErr{}
37+
return nil, nil
3838
}
3939

4040
result := make([]types.Filter, len(pairs))

internal/dblevel/spentoutpointsindex.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func FetchByBlockHashSpentOutpointIndex(blockHash [32]byte) (*types.SpentOutpoin
3030
return &pair, nil
3131
}
3232

33-
// FetchAllTweakIndices returns all types.TweakIndex in the DB
33+
// FetchAllSpenOutpointsIndices returns all types.TweakIndex in the DB
3434
func FetchAllSpenOutpointsIndices() ([]types.SpentOutpointsIndex, error) {
3535
pairs, err := retrieveAll(SpentOutpointsIndexDB, types.PairFactorySpentOutpointsIndex)
3636
if err != nil {
@@ -39,7 +39,7 @@ func FetchAllSpenOutpointsIndices() ([]types.SpentOutpointsIndex, error) {
3939
}
4040
if len(pairs) == 0 {
4141
logging.L.Warn().Msg("Nothing returned")
42-
return nil, NoEntryErr{}
42+
return nil, nil
4343
}
4444

4545
result := make([]types.SpentOutpointsIndex, len(pairs))

internal/dblevel/tweak.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func FetchByBlockHashTweaks(blockHash [32]byte) ([]types.Tweak, error) {
8282
return nil, err
8383
}
8484
if len(pairs) == 0 {
85-
return nil, NoEntryErr{}
85+
return nil, nil
8686
}
8787

8888
result := make([]types.Tweak, len(pairs))
@@ -132,7 +132,7 @@ func FetchAllTweaks() ([]types.Tweak, error) {
132132
}
133133
if len(pairs) == 0 {
134134
logging.L.Warn().Msg("nothing returned")
135-
return nil, NoEntryErr{}
135+
return nil, nil
136136
}
137137

138138
result := make([]types.Tweak, len(pairs))

0 commit comments

Comments
 (0)