-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the main loop logic, it connects the: - rpc node client that is getting blocks - dune api client, that is sending blocks to dune. it has a few responsabilities: - track errors on either side (and later do something about it) - track if it is behind or up to date - try to go fast. - produce good logs of what's going on
- Loading branch information
Showing
8 changed files
with
341 additions
and
79 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ingester | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"sync" | ||
"time" | ||
|
||
"github.com/duneanalytics/blockchain-ingester/client/duneapi" | ||
"github.com/duneanalytics/blockchain-ingester/client/jsonrpc" | ||
"github.com/duneanalytics/blockchain-ingester/models" | ||
) | ||
|
||
type Ingester interface { | ||
Run(ctx context.Context, wg *sync.WaitGroup) error | ||
|
||
// ConsumeBlocks sends blocks from startBlockNumber to endBlockNumber to outChan, inclusive. | ||
// If endBlockNumber is -1, it sends blocks from startBlockNumber to the tip of the chain | ||
// it will run continuously until the context is cancelled | ||
ConsumeBlocks(ctx context.Context, outChan chan models.RPCBlock, startBlockNumber, endBlockNumber int64) error | ||
|
||
// SendBlocks pushes to DuneAPI the RPCBlock Payloads as they are received in an endless loop | ||
// it will block until: | ||
// - the context is cancelled | ||
// - channel is closed | ||
// - a fatal error occurs | ||
SendBlocks(ctx context.Context, blocksCh <-chan models.RPCBlock) error | ||
|
||
// This is just a placeholder for now | ||
Info() Info | ||
} | ||
|
||
const defaultMaxBatchSize = 1 | ||
|
||
type Config struct { | ||
MaxBatchSize int | ||
StartBlockHeight int64 | ||
PollInterval time.Duration | ||
} | ||
|
||
type Info struct { | ||
LatestBlockNumber int64 | ||
IngestedBlockNumber int64 | ||
ConsumedBlockNumber int64 | ||
RPCErrors []ErrorInfo | ||
DuneErrors []ErrorInfo | ||
} | ||
|
||
type ErrorInfo struct { | ||
Timestamp time.Time | ||
BlockNumber int64 | ||
Error error | ||
} | ||
|
||
type ingester struct { | ||
log *slog.Logger | ||
node jsonrpc.BlockchainClient | ||
dune duneapi.BlockchainIngester | ||
cfg Config | ||
info Info | ||
} | ||
|
||
func New(log *slog.Logger, node jsonrpc.BlockchainClient, dune duneapi.BlockchainIngester, cfg Config) Ingester { | ||
ing := &ingester{ | ||
log: log, | ||
node: node, | ||
dune: dune, | ||
cfg: cfg, | ||
info: Info{ | ||
RPCErrors: []ErrorInfo{}, | ||
DuneErrors: []ErrorInfo{}, | ||
}, | ||
} | ||
if ing.cfg.MaxBatchSize == 0 { | ||
ing.cfg.MaxBatchSize = defaultMaxBatchSize | ||
} | ||
return ing | ||
} | ||
|
||
func (i *ingester) Info() Info { | ||
return Info{} | ||
} |
Oops, something went wrong.