Skip to content

Commit cdd0433

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 5fae0f9 commit cdd0433

File tree

15 files changed

+507
-28
lines changed

15 files changed

+507
-28
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.sum

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,18 @@ 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=
93-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
96+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
97+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
98+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9499
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
95100
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
96101
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
@@ -143,10 +148,12 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
143148
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
144149
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
145150
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
146-
github.com/setavenger/go-bip352 v0.1.6 h1:7D1/RMLa+1XaP1ccdseGwgUUfUY20jVf5unAY679x3Y=
147-
github.com/setavenger/go-bip352 v0.1.6/go.mod h1:ajjkB64QrjbF0+MEUjeeBlBxDaJk7VmYUN8XbOK+EKo=
148-
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
149-
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
151+
github.com/setavenger/go-bip352 v0.1.8-0.20250807125845-136879952399 h1:SZtpspHUg1VOm8YWDK2mSfyOukxE3xHgtlNT/dOs+4k=
152+
github.com/setavenger/go-bip352 v0.1.8-0.20250807125845-136879952399/go.mod h1:j+5v4nI/7n9IBEnvr6LagRpe6whTAHjIBRtqJKyJKG4=
153+
github.com/setavenger/go-libsecp256k1 v0.0.0-20250601142217-61f26e074fd5 h1:KKpLemBDPEQxNmTz2+5M8bWhlArls9ZkhkCHPPVh3RY=
154+
github.com/setavenger/go-libsecp256k1 v0.0.0-20250601142217-61f26e074fd5/go.mod h1:TOguhOrbK0FoBk466b3CjYHbaYrZcB6CJteeq/K5w/4=
155+
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
156+
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
150157
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
151158
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
152159
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
@@ -221,14 +228,21 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
221228
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
222229
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
223230
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
231+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
232+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c h1:lfpJ/2rWPa/kJgxyyXM8PrNnfCzcmxJ265mADgwmvLI=
233+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
234+
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
235+
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
224236
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
225237
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
226238
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
227239
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
228240
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
229241
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
230-
google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4=
231-
google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
242+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
243+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
244+
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
245+
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
232246
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
233247
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
234248
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=

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))

internal/dblevel/tweakindex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func FetchAllTweakIndices() ([]types.TweakIndex, error) {
4040
}
4141
if len(pairs) == 0 {
4242
logging.L.Warn().Msg("Nothing returned")
43-
return nil, NoEntryErr{}
43+
return nil, nil
4444
}
4545

4646
result := make([]types.TweakIndex, len(pairs))

0 commit comments

Comments
 (0)