Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DRY_RUN option #73

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions client/duneapi/client.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I was a little lazy in the client here by using this flag rather than just having a separate dry-run client implementation instead. Could refactor this.

Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ func (c *client) sendRequest(ctx context.Context, request BlockchainIngestReques
}()

url := fmt.Sprintf("%s/api/beta/blockchain/%s/ingest", c.cfg.URL, c.cfg.BlockchainName)
if c.cfg.DryRun {
url = fmt.Sprintf("%s/api/beta/blockchain/%s/ingest/dry-run", c.cfg.URL, c.cfg.BlockchainName)
}
c.log.Debug("Sending request", "url", url)
req, err := retryablehttp.NewRequestWithContext(ctx, "POST", url, bytes.NewReader(request.Payload))
if err != nil {
Expand Down Expand Up @@ -224,6 +227,10 @@ func (c *client) Close() error {
}

func (c *client) PostProgressReport(ctx context.Context, progress models.BlockchainIndexProgress) error {
if c.cfg.DryRun {
return nil
}

var request PostBlockchainProgressRequest
var err error
var responseStatus string
Expand Down Expand Up @@ -300,6 +307,15 @@ func (c *client) PostProgressReport(ctx context.Context, progress models.Blockch
}

func (c *client) GetProgressReport(ctx context.Context) (*models.BlockchainIndexProgress, error) {
if c.cfg.DryRun {
return &models.BlockchainIndexProgress{
BlockchainName: c.cfg.BlockchainName,
EVMStack: c.cfg.Stack.String(),
LastIngestedBlockNumber: -1, // no block ingested
LatestBlockNumber: 0,
}, nil
}

var response GetBlockchainProgressResponse
var err error
var responseStatus string
Expand Down Expand Up @@ -372,6 +388,10 @@ func (c *client) GetProgressReport(ctx context.Context) (*models.BlockchainIndex
}

func (c *client) GetBlockGaps(ctx context.Context) (*models.BlockchainGaps, error) {
if c.cfg.DryRun {
return &models.BlockchainGaps{}, nil
}

var response BlockchainGapsResponse
var err error
var responseStatus string
Expand Down
2 changes: 2 additions & 0 deletions client/duneapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Config struct {
// - reduces bandwidth
DisableCompression bool

DryRun bool

DisableBatchHeader bool // for testing/backwards compatibility
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
Stack: cfg.RPCStack,
DisableCompression: cfg.DisableCompression,
DisableBatchHeader: cfg.Dune.DisableBatchHeader,
DryRun: cfg.DryRun,
})
if err != nil {
stdlog.Fatal(err)
Expand All @@ -71,6 +72,7 @@ func main() {
BlockchainName: cfg.BlockchainName,
Stack: cfg.RPCStack,
DisableCompression: cfg.DisableCompression,
DryRun: cfg.DryRun,
})
if err != nil {
stdlog.Fatal(err)
Expand Down
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ func (r RPCClient) HasError() error {
}

type Config struct {
BlockHeight int64 `long:"block-height" env:"BLOCK_HEIGHT" description:"block height to start from" default:"-1"` // nolint:lll
BlockchainName string `long:"blockchain-name" env:"BLOCKCHAIN_NAME" description:"name of the blockchain" required:"true"` // nolint:lll
DisableCompression bool `long:"disable-compression" env:"DISABLE_COMPRESSION" description:"disable compression when sending data to Dune"` // nolint:lll
DisableGapsQuery bool `long:"disable-gaps-query" env:"DISABLE_GAPS_QUERY" description:"disable gaps query used to populate the initial DLQ"` // nolint:lll
DLQOnly bool `long:"dlq-only" env:"DLQ_ONLY" description:"Runs just the DLQ processing on its own"` // nolint:lll
BlockHeight int64 `long:"block-height" env:"BLOCK_HEIGHT" description:"block height to start from" default:"-1"` // nolint:lll
BlockchainName string `long:"blockchain-name" env:"BLOCKCHAIN_NAME" description:"name of the blockchain" required:"true"` // nolint:lll
DisableCompression bool `long:"disable-compression" env:"DISABLE_COMPRESSION" description:"disable compression when sending data to Dune"` // nolint:lll
DisableGapsQuery bool `long:"disable-gaps-query" env:"DISABLE_GAPS_QUERY" description:"disable gaps query used to populate the initial DLQ"` // nolint:lll
DLQOnly bool `long:"dlq-only" env:"DLQ_ONLY" description:"Runs just the DLQ processing on its own"` // nolint:lll
DryRun bool `long:"dry-run" env:"DRY_RUN" description:"When enabled, data is sent to Dune for validation but is not written to Dune tables"` // nolint:lll
Dune DuneClient
PollInterval time.Duration `long:"rpc-poll-interval" env:"RPC_POLL_INTERVAL" description:"Interval to poll the blockchain node" default:"300ms"` // nolint:lll
PollDLQInterval time.Duration `long:"dlq-poll-interval" env:"DLQ_POLL_INTERVAL" description:"Interval to poll the dlq" default:"300ms"` // nolint:lll
Expand Down
Loading