Skip to content

Commit

Permalink
add new env vars & tidy existing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sledro committed Nov 1, 2024
1 parent 2c46a78 commit 5fd2841
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 24 deletions.
66 changes: 53 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,79 @@ func main() {
Logger.Warn(".env file not found, will attempt to use environment variables from system")
}

llDefaultStartBlock, err := strconv.ParseUint(os.Getenv("LL_DEFAULT_START_BLOCK"), 10, 64)
// L1

l1DefaultStartBlock, err := strconv.ParseUint(os.Getenv("L1_DEFAULT_START_BLOCK"), 10, 64)
if err != nil {
log.Fatalf("failed to parse L1_DEFAULT_START_BLOCK: %v", err)
}

l1MaxBatchSize, err := strconv.ParseUint(os.Getenv("L1_MAX_BATCH_SIZE"), 10, 64)
if err != nil {
log.Fatalf("failed to parse L1_MAX_BATCH_SIZE: %v", err)
}

l1MinBatchSize, err := strconv.ParseUint(os.Getenv("L1_MIN_BATCH_SIZE"), 10, 64)
if err != nil {
log.Fatalf("failed to parse L1_MIN_BATCH_SIZE: %v", err)
}

l1StatusCheckInterval, err := strconv.ParseUint(os.Getenv("L1_STATUS_CHECK_INTERVAL"), 10, 64)
if err != nil {
log.Fatalf("failed to parse L1_STATUS_CHECK_INTERVAL: %v", err)
}

l1FetchInterval, err := strconv.ParseUint(os.Getenv("L1_FETCH_INTERVAL"), 10, 64)
if err != nil {
log.Fatalf("failed to parse L1_FETCH_INTERVAL: %v", err)
}

// L2

l2DefaultStartBlock, err := strconv.ParseUint(os.Getenv("L2_DEFAULT_START_BLOCK"), 10, 64)
if err != nil {
log.Fatalf("failed to parse L2_DEFAULT_START_BLOCK: %v", err)
}

l2MaxBatchSize, err := strconv.ParseUint(os.Getenv("L2_MAX_BATCH_SIZE"), 10, 64)
if err != nil {
log.Fatalf("failed to parse LL_DEFAULT_START_BLOCK: %v", err)
log.Fatalf("failed to parse L2_MAX_BATCH_SIZE: %v", err)
}

ethDefaultStartBlock, err := strconv.ParseUint(os.Getenv("ETH_DEFAULT_START_BLOCK"), 10, 64)
l2MinBatchSize, err := strconv.ParseUint(os.Getenv("L2_MIN_BATCH_SIZE"), 10, 64)
if err != nil {
log.Fatalf("failed to parse ETH_DEFAULT_START_BLOCK: %v", err)
log.Fatalf("failed to parse L2_MIN_BATCH_SIZE: %v", err)
}

ethStatusCheckInterval, err := strconv.ParseUint(os.Getenv("ETH_STATUS_CHECK_INTERVAL"), 10, 64)
l2FetchInterval, err := strconv.ParseUint(os.Getenv("L2_FETCH_INTERVAL"), 10, 64)
if err != nil {
log.Fatalf("failed to parse ETH_STATUS_CHECK_INTERVAL: %v", err)
log.Fatalf("failed to parse L2_FETCH_INTERVAL: %v", err)
}

indexer, err := indexer.NewIndexer(indexer.IndexerOpts{
Lightlink: &lightlink.ClientOpts{
Endpoint: os.Getenv("LL_RPC_URL"),
Endpoint: os.Getenv("L2_RPC_URL"),
L2StandardBridgeAddress: common.HexToAddress(os.Getenv("L2_STANDARD_BRIDGE_ADDRESS")),
L2CrossDomainMessengerAddress: common.HexToAddress(os.Getenv("L2_CROSS_DOMAIN_MESSENGER_ADDRESS")),
L2ToL1MessagePasserAddress: common.HexToAddress(os.Getenv("L2_TO_L1_MESSAGE_PASSER_ADDRESS")),
Logger: Logger.With("component", "lightlink-indexer"),
DefaultStartBlock: llDefaultStartBlock,
DefaultStartBlock: l2DefaultStartBlock,
MaxBatchSize: l2MaxBatchSize,
MinBatchSize: l2MinBatchSize,
FetchInterval: l2FetchInterval,
},
Ethereum: &ethereum.ClientOpts{
Endpoint: os.Getenv("ETHEREUM_RPC_URL"),
Endpoint: os.Getenv("L1_RPC_URL"),
L1StandardBridgeAddress: common.HexToAddress(os.Getenv("L1_STANDARD_BRIDGE_ADDRESS")),
L1CrossDomainMessengerAddress: common.HexToAddress(os.Getenv("L1_CROSS_DOMAIN_MESSENGER_ADDRESS")),
LightLinkPortalAddress: common.HexToAddress(os.Getenv("LIGHTLINK_PORTAL_ADDRESS")),
CanonicalStateChainAddress: common.HexToAddress(os.Getenv("CANONICAL_STATE_CHAIN_ADDRESS")),
LightLinkPortalAddress: common.HexToAddress(os.Getenv("L1_LIGHTLINK_PORTAL_ADDRESS")),
CanonicalStateChainAddress: common.HexToAddress(os.Getenv("L1_CANONICAL_STATE_CHAIN_ADDRESS")),
Logger: Logger.With("component", "ethereum-indexer"),
DefaultStartBlock: ethDefaultStartBlock,
StatusCheckInterval: ethStatusCheckInterval,
DefaultStartBlock: l1DefaultStartBlock,
StatusCheckInterval: l1StatusCheckInterval,
MaxBatchSize: l1MaxBatchSize,
MinBatchSize: l1MinBatchSize,
FetchInterval: l1FetchInterval,
},
Database: &database.DatabaseOpts{
URI: os.Getenv("DATABASE_URI"),
Expand Down
3 changes: 3 additions & 0 deletions ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type ClientOpts struct {
Timeout time.Duration
DefaultStartBlock uint64
StatusCheckInterval uint64
MaxBatchSize uint64
MinBatchSize uint64
FetchInterval uint64
}

// NewEthereumRPC returns a new EthereumRPC client over HTTP.
Expand Down
17 changes: 12 additions & 5 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
LL_RPC_URL=
L2_RPC_URL=
L2_STANDARD_BRIDGE_ADDRESS=
L2_CROSS_DOMAIN_MESSENGER_ADDRESS=
L2_TO_L1_MESSAGE_PASSER_ADDRESS=
LL_DEFAULT_START_BLOCK=
L2_DEFAULT_START_BLOCK=
L2_MAX_BATCH_SIZE=
L2_MIN_BATCH_SIZE=
L2_FETCH_INTERVAL=

ETHEREUM_RPC_URL=
L1_RPC_URL=
L1_STANDARD_BRIDGE_ADDRESS=
L1_CROSS_DOMAIN_MESSENGER_ADDRESS=
LIGHTLINK_PORTAL_ADDRESS=
CANONICAL_STATE_CHAIN_ADDRESS=
L1_LIGHTLINK_PORTAL_ADDRESS=
L1_CANONICAL_STATE_CHAIN_ADDRESS=
L1_MAX_BATCH_SIZE=
L1_MIN_BATCH_SIZE=
L1_FETCH_INTERVAL=

DATABASE_URI=
DATABASE_NAME=

API_PORT=
6 changes: 3 additions & 3 deletions indexer/indexer_ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

func (i *Indexer) indexEthereum(ctx context.Context) error {
minBatchSize := uint64(1)
maxBatchSize := uint64(5000)
minBatchSize := i.ethereum.Opts.MinBatchSize
maxBatchSize := i.ethereum.Opts.MaxBatchSize
start := i.ethereum.Opts.DefaultStartBlock

// Get last indexed block
Expand Down Expand Up @@ -49,7 +49,7 @@ func (i *Indexer) indexEthereum(ctx context.Context) error {
"chainHead", lastBlock,
"nextBatchStart", start,
"minBatchSize", minBatchSize)
time.Sleep(time.Second * 10)
time.Sleep(time.Duration(i.ethereum.Opts.FetchInterval) * time.Second)
continue
}

Expand Down
6 changes: 3 additions & 3 deletions indexer/indexer_lightlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

func (i *Indexer) indexLightLink(ctx context.Context) error {
minBatchSize := uint64(50)
maxBatchSize := uint64(2000)
minBatchSize := i.lightlink.Opts.MinBatchSize
maxBatchSize := i.lightlink.Opts.MaxBatchSize
start := i.lightlink.Opts.DefaultStartBlock

// Get last indexed block
Expand Down Expand Up @@ -43,7 +43,7 @@ func (i *Indexer) indexLightLink(ctx context.Context) error {
"chainHead", lastBlock,
"nextBatchStart", start)

time.Sleep(time.Second * 10)
time.Sleep(time.Duration(i.lightlink.Opts.FetchInterval) * time.Second)
continue
}

Expand Down
3 changes: 3 additions & 0 deletions lightlink/lightlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type ClientOpts struct {
Logger *slog.Logger
Timeout time.Duration
DefaultStartBlock uint64
MaxBatchSize uint64
MinBatchSize uint64
FetchInterval uint64
}

// NewEthereumRPC returns a new EthereumRPC client over HTTP.
Expand Down

0 comments on commit 5fd2841

Please sign in to comment.