node: arbitrum watcher fix (#1699)
This commit is contained in:
parent
3ac55339c9
commit
2fe56754d2
|
@ -0,0 +1,42 @@
|
|||
// On Arbitrum we are unable to get blocks by transaction hash using the go-ethereum library
|
||||
// because it fails with "transaction type not supported". However, calling the underlying
|
||||
// eth_getBlockByHash directly works. The sole function of this connector is to implement
|
||||
// TimeOfBlockByHash using the raw connection.
|
||||
|
||||
package connectors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
type ArbitrumConnector struct {
|
||||
Connector
|
||||
}
|
||||
|
||||
func NewArbitrumConnector(ctx context.Context, baseConnector Connector) (*ArbitrumConnector, error) {
|
||||
connector := &ArbitrumConnector{Connector: baseConnector}
|
||||
return connector, nil
|
||||
}
|
||||
|
||||
func (a *ArbitrumConnector) TimeOfBlockByHash(ctx context.Context, hash ethCommon.Hash) (uint64, error) {
|
||||
type Marshaller struct {
|
||||
Time string `json:"timestamp" gencodec:"required"`
|
||||
}
|
||||
|
||||
var m *Marshaller
|
||||
err := a.RawCallContext(ctx, &m, "eth_getBlockByHash", hash, false)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get block %s: %w", hash.String(), err)
|
||||
}
|
||||
|
||||
num, err := strconv.ParseUint(m.Time[2:], 16, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to parse time %s: %w", m.Time, err)
|
||||
}
|
||||
|
||||
return num, nil
|
||||
}
|
|
@ -229,12 +229,18 @@ func (w *Watcher) Run(ctx context.Context) error {
|
|||
return fmt.Errorf("dialing eth client failed: %w", err)
|
||||
}
|
||||
finalizer := finalizers.NewArbitrumFinalizer(logger, baseConnector, baseConnector.Client())
|
||||
w.ethConn, err = connectors.NewBlockPollConnector(ctx, baseConnector, finalizer, 250*time.Millisecond, false)
|
||||
pollConnector, err := connectors.NewBlockPollConnector(ctx, baseConnector, finalizer, 250*time.Millisecond, false)
|
||||
if err != nil {
|
||||
ethConnectionErrors.WithLabelValues(w.networkName, "dial_error").Inc()
|
||||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
return fmt.Errorf("creating block poll connector failed: %w", err)
|
||||
}
|
||||
w.ethConn, err = connectors.NewArbitrumConnector(ctx, pollConnector)
|
||||
if err != nil {
|
||||
ethConnectionErrors.WithLabelValues(w.networkName, "dial_error").Inc()
|
||||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
return fmt.Errorf("creating arbitrum connector failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
w.ethConn, err = connectors.NewEthereumConnector(timeout, w.networkName, w.url, w.contract, logger)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue