-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use batches instead of single requests for the fetcher
- Loading branch information
1 parent
977917d
commit 34b9f9d
Showing
9 changed files
with
320 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
rpcClient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client" | ||
) | ||
|
||
// Batch is the wrapper for HTTP batch requests | ||
type Batch struct { | ||
batch *rpcClient.BatchHTTP | ||
} | ||
|
||
// AddBlockRequest adds a new block request (block fetch) to the batch | ||
func (b *Batch) AddBlockRequest(blockNum int64) error { | ||
if _, err := b.batch.Block(&blockNum); err != nil { | ||
return fmt.Errorf("unable to add block request, %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// AddBlockResultsRequest adds a new block results request (block results fetch) to the batch | ||
func (b *Batch) AddBlockResultsRequest(blockNum int64) error { | ||
if _, err := b.batch.BlockResults(&blockNum); err != nil { | ||
return fmt.Errorf("unable to add block results request, %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Execute sends the batch off for processing by the node | ||
func (b *Batch) Execute() ([]any, error) { | ||
return b.batch.Send() | ||
} | ||
|
||
// Count returns the number of requests in the batch | ||
func (b *Batch) Count() int { | ||
return b.batch.Count() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package types | ||
|
||
// Batch defines the interface for the client batch | ||
type Batch interface { | ||
// AddBlockRequest adds a new block request (block fetch) to the batch | ||
AddBlockRequest(int64) error | ||
|
||
// AddBlockResultsRequest adds a new block results request (block results fetch) to the batch | ||
AddBlockResultsRequest(blockNum int64) error | ||
|
||
// Execute sends the batch off for processing by the node | ||
Execute() ([]any, error) | ||
|
||
// Count returns the number of requests in the batch | ||
Count() int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.