Skip to content

Commit

Permalink
server/asset/eth: compile-time block poll interval
Browse files Browse the repository at this point in the history
One second is blazing fast for an RPC provider unless it's a local node.
  • Loading branch information
chappjc committed Jan 26, 2023
1 parent 1352f92 commit e538e9f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions server/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,19 @@ func init() {

registerToken(testTokenID, 0)
registerToken(usdcID, 0)

if blockPollIntervalStr != "" {
blockPollInterval, _ = time.ParseDuration(blockPollIntervalStr)
if blockPollInterval < time.Second {
panic(fmt.Sprintf("invalid value for blockPollIntervalStr: %q", blockPollIntervalStr))
}
}
}

const (
BipID = 60
ethContractVersion = 0
version = 0
// The blockPollInterval is the delay between calls to bestBlockHash to
// check for new blocks.
blockPollInterval = time.Second
)

var (
Expand All @@ -103,6 +107,12 @@ var (

testTokenID, _ = dex.BipSymbolID("dextt.eth")
usdcID, _ = dex.BipSymbolID("usdc.eth")

// blockPollInterval is the delay between calls to bestBlockHash to check
// for new blocks. Modify at compile time via blockPollIntervalStr:
// go build -tags lgpl -ldflags "-X 'decred.org/dcrdex/server/asset/eth.blockPollIntervalStr=10s'"
blockPollInterval = time.Second
blockPollIntervalStr string
)

type driverBase struct {
Expand Down Expand Up @@ -734,6 +744,8 @@ func (eth *ETHBackend) run(ctx context.Context) {
// Shut down the RPC client on ctx.Done().
defer eth.shutdown()

eth.baseLogger.Infof("Starting ETH block polling with interval of %v",
blockPollInterval)
blockPoll := time.NewTicker(blockPollInterval)
defer blockPoll.Stop()

Expand Down

0 comments on commit e538e9f

Please sign in to comment.