Skip to content

Commit

Permalink
Merge branch 'main' into relayer_gas_if_contract_not_deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerLamTd authored May 16, 2023
2 parents 1c76768 + 59ed335 commit 55a9eaf
Show file tree
Hide file tree
Showing 10 changed files with 5,262 additions and 4,912 deletions.
798 changes: 475 additions & 323 deletions packages/eventindexer/TaikoL1.json

Large diffs are not rendered by default.

615 changes: 304 additions & 311 deletions packages/eventindexer/contracts/taikol1/TaikoL1.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions packages/eventindexer/indexer/save_block_proposed_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func (svc *Service) saveBlockProposedEvents(
log.Infof("blockProposed by: %v", sender.Hex())

if err := svc.saveBlockProposedEvent(ctx, chainID, event, sender); err != nil {
eventindexer.BlockProposedEventsProcessedError.Inc()

return errors.Wrap(err, "svc.saveBlockProposedEvent")
}

Expand Down Expand Up @@ -73,5 +75,7 @@ func (svc *Service) saveBlockProposedEvent(
return errors.Wrap(err, "svc.eventRepo.Save")
}

eventindexer.BlockProposedEventsProcessed.Inc()

return nil
}
4 changes: 4 additions & 0 deletions packages/eventindexer/indexer/save_block_proven_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (svc *Service) saveBlockProvenEvents(
log.Infof("blockProven by: %v", event.Prover.Hex())

if err := svc.saveBlockProvenEvent(ctx, chainID, event); err != nil {
eventindexer.BlockProvenEventsProcessedError.Inc()

return errors.Wrap(err, "svc.saveBlockProvenEvent")
}

Expand Down Expand Up @@ -61,5 +63,7 @@ func (svc *Service) saveBlockProvenEvent(
return errors.Wrap(err, "svc.eventRepo.Save")
}

eventindexer.BlockProvenEventsProcessed.Inc()

return nil
}
69 changes: 69 additions & 0 deletions packages/eventindexer/indexer/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (svc *Service) subscribe(ctx context.Context, chainID *big.Int) error {
errChan := make(chan error)

go svc.subscribeBlockProven(ctx, chainID, errChan)
go svc.subscribeBlockProposed(ctx, chainID, errChan)

// nolint: gosimple
for {
Expand Down Expand Up @@ -61,6 +62,8 @@ func (svc *Service) subscribeBlockProven(ctx context.Context, chainID *big.Int,
log.Infof("blockProvenEvent from subscription for prover %v", event.Prover.Hex())

if err := svc.saveBlockProvenEvent(ctx, chainID, event); err != nil {
eventindexer.BlockProvenEventsProcessedError.Inc()

log.Errorf("svc.subscribe, svc.saveBlockProvenEvent: %v", err)
}

Expand All @@ -85,3 +88,69 @@ func (svc *Service) subscribeBlockProven(ctx context.Context, chainID *big.Int,
}
}
}

func (svc *Service) subscribeBlockProposed(ctx context.Context, chainID *big.Int, errChan chan error) {
sink := make(chan *taikol1.TaikoL1BlockProposed)

sub := event.ResubscribeErr(svc.subscriptionBackoff, func(ctx context.Context, err error) (event.Subscription, error) {
if err != nil {
log.Errorf("svc.taikoL1.WatchBlockProposed: %v", err)
}
log.Info("resubscribing to BlockProposed events")

return svc.taikol1.WatchBlockProposed(&bind.WatchOpts{
Context: ctx,
}, sink, nil)
})

defer sub.Unsubscribe()

for {
select {
case <-ctx.Done():
log.Info("context finished")
return
case err := <-sub.Err():
errChan <- errors.Wrap(err, "sub.Err()")
case event := <-sink:
log.Infof("blockProposedEvent from subscription")

tx, _, err := svc.ethClient.TransactionByHash(ctx, event.Raw.TxHash)
if err != nil {
log.Errorf("svc.ethClient.TransactionByHash: %v", err)
}

sender, err := svc.ethClient.TransactionSender(ctx, tx, event.Raw.BlockHash, event.Raw.TxIndex)
if err != nil {
log.Errorf("svc.ethClient.TransactionSender: %v", err)
}

log.Infof("blockProposed by: %v", sender.Hex())

if err := svc.saveBlockProposedEvent(ctx, chainID, event, sender); err != nil {
eventindexer.BlockProposedEventsProcessedError.Inc()

log.Errorf("svc.subscribe, svc.saveBlockProposedEvent: %v", err)
}

block, err := svc.blockRepo.GetLatestBlockProcessed(chainID)
if err != nil {
log.Errorf("svc.subscribe, blockRepo.GetLatestBlockProcessed: %v", err)
continue
}

if block.Height < event.Raw.BlockNumber {
err = svc.blockRepo.Save(eventindexer.SaveBlockOpts{
Height: event.Raw.BlockNumber,
Hash: event.Raw.BlockHash,
ChainID: chainID,
})
if err != nil {
log.Errorf("svc.subscribe, svc.blockRepo.Save: %v", err)
}

eventindexer.BlocksProcessed.Inc()
}
}
}
}
22 changes: 15 additions & 7 deletions packages/eventindexer/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import (
)

var (
EventsProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "events_processed_ops_total",
Help: "The total number of processed events",
BlockProposedEventsProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "block_proposed_events_processed_ops_total",
Help: "The total number of processed BlockProposed events",
})
BlockProposedEventsProcessedError = promauto.NewCounter(prometheus.CounterOpts{
Name: "block_proposed_events_processed_error_ops_total",
Help: "The total number of processed BlockProposed event errors encountered",
})
BlockProvenEventsProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "block_proven_events_processed_ops_total",
Help: "The total number of processed BlockProven events",
})
BlockProvenEventsProcessedError = promauto.NewCounter(prometheus.CounterOpts{
Name: "block_proven_events_processed_error_ops_total",
Help: "The total number of processed BlockProven event errors encountered",
})
BlocksProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "blocks_processed_ops_total",
Help: "The total number of processed blocks",
})
BlocksScannedError = promauto.NewCounter(prometheus.CounterOpts{
Name: "blocks_scanned_error_ops_total",
Help: "The total number of scanned block errors.",
})
ErrorsEncounteredDuringSubscription = promauto.NewCounter(prometheus.CounterOpts{
Name: "errors_encountered_during_subscription_opts_total",
Help: "The total number of errors that occurred during active subscription",
Expand Down
1 change: 0 additions & 1 deletion packages/status-page/src/utils/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ export const getConfig = async (
) => {
const contract: Contract = new Contract(contractAddress, TaikoL1, provider);
const config = await contract.getConfig();
console.log(config);
return config;
};
2 changes: 1 addition & 1 deletion packages/status-page/src/utils/getEthDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const getEthDeposits = async (
contractAddress: string
): Promise<number> => {
const stateVariables = await getStateVariables(provider, contractAddress);
return stateVariables.numEthDeposits;
return stateVariables.numEthDeposits.toNumber();
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const getNextEthDepositToProcess = async (
): Promise<number> => {
const contract: Contract = new Contract(contractAddress, TaikoL1, provider);
const stateVariables = await contract.getStateVariables();
return stateVariables.nextEthDepositToProcess;
return stateVariables.nextEthDepositToProcess.toNumber();
};
Loading

0 comments on commit 55a9eaf

Please sign in to comment.