Skip to content

Commit ee4570d

Browse files
chore: update gno version (#41)
* Update gno version * Swap to context.Background()
1 parent 27290c6 commit ee4570d

File tree

9 files changed

+121
-184
lines changed

9 files changed

+121
-184
lines changed

client/batch.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package client
22

33
import (
4+
"context"
45
"fmt"
56

67
rpcClient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
78
)
89

910
// Batch is the wrapper for HTTP batch requests
1011
type Batch struct {
11-
batch *rpcClient.BatchHTTP
12+
batch *rpcClient.RPCBatch
1213
}
1314

1415
// AddBlockRequest adds a new block request (block fetch) to the batch
1516
func (b *Batch) AddBlockRequest(blockNum uint64) error {
1617
bn := int64(blockNum)
17-
if _, err := b.batch.Block(&bn); err != nil {
18+
if err := b.batch.Block(&bn); err != nil {
1819
return fmt.Errorf("unable to add block request, %w", err)
1920
}
2021

@@ -24,16 +25,16 @@ func (b *Batch) AddBlockRequest(blockNum uint64) error {
2425
// AddBlockResultsRequest adds a new block results request (block results fetch) to the batch
2526
func (b *Batch) AddBlockResultsRequest(blockNum uint64) error {
2627
bn := int64(blockNum)
27-
if _, err := b.batch.BlockResults(&bn); err != nil {
28+
if err := b.batch.BlockResults(&bn); err != nil {
2829
return fmt.Errorf("unable to add block results request, %w", err)
2930
}
3031

3132
return nil
3233
}
3334

3435
// Execute sends the batch off for processing by the node
35-
func (b *Batch) Execute() ([]any, error) {
36-
return b.batch.Send()
36+
func (b *Batch) Execute(ctx context.Context) ([]any, error) {
37+
return b.batch.Send(ctx)
3738
}
3839

3940
// Count returns the number of requests in the batch

client/http.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ import (
1111

1212
// Client is the TM2 HTTP client
1313
type Client struct {
14-
client *rpcClient.HTTP
14+
client *rpcClient.RPCClient
1515
}
1616

1717
// NewClient creates a new TM2 HTTP client
18-
func NewClient(remote string) *Client {
19-
return &Client{
20-
client: rpcClient.NewHTTP(remote, ""),
18+
func NewClient(remote string) (*Client, error) {
19+
client, err := rpcClient.NewHTTPClient(remote)
20+
if err != nil {
21+
return nil, fmt.Errorf("unable to create HTTP client, %w", err)
2122
}
23+
24+
return &Client{
25+
client: client,
26+
}, nil
2227
}
2328

2429
// CreateBatch creates a new request batch

client/types/types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package types
22

3+
import "context"
4+
35
// Batch defines the interface for the client batch
46
type Batch interface {
57
// AddBlockRequest adds a new block request (block fetch) to the batch
@@ -9,7 +11,7 @@ type Batch interface {
911
AddBlockResultsRequest(uint64) error
1012

1113
// Execute sends the batch off for processing by the node
12-
Execute() ([]any, error)
14+
Execute(context.Context) ([]any, error)
1315

1416
// Count returns the number of requests in the batch
1517
Count() int

cmd/start.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,24 @@ func (c *startCfg) exec(ctx context.Context) error {
133133
}
134134

135135
defer func() {
136-
if err := db.Close(); err != nil {
137-
logger.Error("unable to gracefully close DB", zap.Error(err))
136+
if closeErr := db.Close(); closeErr != nil {
137+
logger.Error("unable to gracefully close DB", zap.Error(closeErr))
138138
}
139139
}()
140140

141141
// Create an Event Manager instance
142142
em := events.NewManager()
143143

144+
// Create a TM2 client
145+
tm2Client, err := client.NewClient(c.remote)
146+
if err != nil {
147+
return fmt.Errorf("unable to create client, %w", err)
148+
}
149+
144150
// Create the fetcher service
145151
f := fetch.New(
146152
db,
147-
client.NewClient(c.remote),
153+
tm2Client,
148154
em,
149155
fetch.WithLogger(
150156
logger.Named("fetcher"),

fetch/fetch_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestFetcher_FetchTransactions_Valid_FullBlocks(t *testing.T) {
122122
mockClient = &mockClient{
123123
createBatchFn: func() clientTypes.Batch {
124124
return &mockBatch{
125-
executeFn: func() ([]any, error) {
125+
executeFn: func(_ context.Context) ([]any, error) {
126126
// Force an error
127127
return nil, errors.New("something is flaky")
128128
},
@@ -279,7 +279,7 @@ func TestFetcher_FetchTransactions_Valid_FullBlocks(t *testing.T) {
279279
mockClient = &mockClient{
280280
createBatchFn: func() clientTypes.Batch {
281281
return &mockBatch{
282-
executeFn: func() ([]any, error) {
282+
executeFn: func(_ context.Context) ([]any, error) {
283283
results := make([]any, len(batch))
284284
copy(results, batch)
285285

@@ -445,7 +445,7 @@ func TestFetcher_FetchTransactions_Valid_EmptyBlocks(t *testing.T) {
445445
mockClient = &mockClient{
446446
createBatchFn: func() clientTypes.Batch {
447447
return &mockBatch{
448-
executeFn: func() ([]any, error) {
448+
executeFn: func(_ context.Context) ([]any, error) {
449449
// Force an error
450450
return nil, errors.New("something is flaky")
451451
},
@@ -553,7 +553,7 @@ func TestFetcher_FetchTransactions_Valid_EmptyBlocks(t *testing.T) {
553553
mockClient = &mockClient{
554554
createBatchFn: func() clientTypes.Batch {
555555
return &mockBatch{
556-
executeFn: func() ([]any, error) {
556+
executeFn: func(_ context.Context) ([]any, error) {
557557
results := make([]any, len(batch))
558558
copy(results, batch)
559559

@@ -671,7 +671,7 @@ func TestFetcher_InvalidBlocks(t *testing.T) {
671671
mockClient = &mockClient{
672672
createBatchFn: func() clientTypes.Batch {
673673
return &mockBatch{
674-
executeFn: func() ([]any, error) {
674+
executeFn: func(_ context.Context) ([]any, error) {
675675
// Force an error
676676
return nil, errors.New("something is flaky")
677677
},

fetch/mocks_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fetch
22

33
import (
4+
"context"
5+
46
core_types "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
57

68
clientTypes "github.com/gnolang/tx-indexer/client/types"
@@ -58,7 +60,7 @@ func (m *mockClient) CreateBatch() clientTypes.Batch {
5860
type (
5961
addBlockRequestDelegate func(uint64) error
6062
addBlockResultsRequestDelegate func(uint64) error
61-
executeDelegate func() ([]any, error)
63+
executeDelegate func(context.Context) ([]any, error)
6264
countDelegate func() int
6365
)
6466

@@ -85,9 +87,9 @@ func (m *mockBatch) AddBlockResultsRequest(num uint64) error {
8587
return nil
8688
}
8789

88-
func (m *mockBatch) Execute() ([]any, error) {
90+
func (m *mockBatch) Execute(ctx context.Context) ([]any, error) {
8991
if m.executeFn != nil {
90-
return m.executeFn()
92+
return m.executeFn(ctx)
9193
}
9294

9395
return nil, nil

fetch/worker.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func getBlocksFromBatch(chunkRange chunkRange, client Client) ([]*types.Block, e
7979
}
8080

8181
// Get the block results
82-
blocksRaw, err := batch.Execute()
82+
blocksRaw, err := batch.Execute(context.Background())
8383
if err != nil {
8484
// Try to fetch sequentially
8585
return getBlocksSequentially(chunkRange, client)
@@ -155,7 +155,7 @@ func getTxResultFromBatch(blocks []*types.Block, client Client) ([][]*types.TxRe
155155
}
156156

157157
// Get the block results
158-
blockResultsRaw, err := batch.Execute()
158+
blockResultsRaw, err := batch.Execute(context.Background())
159159
if err != nil {
160160
// Try to fetch sequentially
161161
return getTxResultsSequentially(blocks, client)

go.mod

+25-28
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ go 1.21
55
require (
66
github.com/99designs/gqlgen v0.17.45
77
github.com/cockroachdb/pebble v1.1.0
8+
github.com/gnolang/gno v0.0.0-20240429120125-3832b1312d7d
89
github.com/go-chi/chi/v5 v5.0.12
10+
github.com/go-chi/httprate v0.9.0
911
github.com/google/uuid v1.6.0
1012
github.com/madz-lab/insertion-queue v0.0.0-20230520191346-295d3348f63a
1113
github.com/olahol/melody v1.2.0
@@ -22,7 +24,9 @@ require (
2224
github.com/DataDog/zstd v1.5.5 // indirect
2325
github.com/agnivade/levenshtein v1.1.1 // indirect
2426
github.com/beorn7/perks v1.0.1 // indirect
25-
github.com/cespare/xxhash v1.1.0 // indirect
27+
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
28+
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
29+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2630
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2731
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
2832
github.com/cockroachdb/errors v1.11.1 // indirect
@@ -31,57 +35,50 @@ require (
3135
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
3236
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
3337
github.com/davecgh/go-spew v1.1.1 // indirect
34-
github.com/dgraph-io/badger/v3 v3.2103.4 // indirect
35-
github.com/dgraph-io/ristretto v0.1.1 // indirect
36-
github.com/dustin/go-humanize v1.0.0 // indirect
38+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
3739
github.com/getsentry/sentry-go v0.27.0 // indirect
38-
github.com/gnolang/goleveldb v0.0.9 // indirect
40+
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect
41+
github.com/go-logr/logr v1.4.1 // indirect
42+
github.com/go-logr/stdr v1.2.2 // indirect
3943
github.com/gogo/protobuf v1.3.2 // indirect
40-
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
41-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
42-
github.com/golang/protobuf v1.5.3 // indirect
4344
github.com/golang/snappy v0.0.4 // indirect
44-
github.com/google/flatbuffers v1.12.1 // indirect
4545
github.com/gorilla/websocket v1.5.1 // indirect
46+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
4647
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
47-
github.com/jmhodges/levigo v1.0.0 // indirect
4848
github.com/klauspost/compress v1.17.6 // indirect
4949
github.com/kr/pretty v0.3.1 // indirect
5050
github.com/kr/text v0.2.0 // indirect
5151
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
5252
github.com/linxGnu/grocksdb v1.8.5 // indirect
5353
github.com/mitchellh/mapstructure v1.5.0 // indirect
54-
github.com/pelletier/go-toml v1.9.5 // indirect
5554
github.com/pmezard/go-difflib v1.0.0 // indirect
5655
github.com/prometheus/client_golang v1.18.0 // indirect
5756
github.com/prometheus/client_model v0.5.0 // indirect
5857
github.com/prometheus/common v0.46.0 // indirect
5958
github.com/prometheus/procfs v0.12.0 // indirect
6059
github.com/rogpeppe/go-internal v1.12.0 // indirect
61-
github.com/rs/cors v1.10.1 // indirect
60+
github.com/rs/xid v1.5.0 // indirect
6261
github.com/russross/blackfriday/v2 v2.1.0 // indirect
6362
github.com/sosodev/duration v1.2.0 // indirect
64-
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
6563
github.com/urfave/cli/v2 v2.27.1 // indirect
6664
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
67-
go.etcd.io/bbolt v1.3.8 // indirect
68-
go.opencensus.io v0.22.5 // indirect
69-
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
65+
go.opentelemetry.io/otel v1.25.0 // indirect
66+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0 // indirect
67+
go.opentelemetry.io/otel/metric v1.25.0 // indirect
68+
go.opentelemetry.io/otel/sdk v1.25.0 // indirect
69+
go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect
70+
go.opentelemetry.io/otel/trace v1.25.0 // indirect
71+
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
72+
golang.org/x/crypto v0.21.0 // indirect
73+
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
7074
golang.org/x/mod v0.16.0 // indirect
71-
golang.org/x/net v0.22.0 // indirect
75+
golang.org/x/net v0.23.0 // indirect
7276
golang.org/x/sys v0.18.0 // indirect
7377
golang.org/x/text v0.14.0 // indirect
7478
golang.org/x/tools v0.19.0 // indirect
75-
gopkg.in/yaml.v3 v3.0.1 // indirect
76-
)
77-
78-
require (
79-
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
80-
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
81-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
82-
github.com/gnolang/gno v0.0.0-20231215125729-9262c1a8f949
83-
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect
84-
github.com/go-chi/httprate v0.9.0
85-
golang.org/x/crypto v0.21.0 // indirect
79+
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
80+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
81+
google.golang.org/grpc v1.63.0 // indirect
8682
google.golang.org/protobuf v1.33.0 // indirect
83+
gopkg.in/yaml.v3 v3.0.1 // indirect
8784
)

0 commit comments

Comments
 (0)