Node/Watcher/EVM: Fix TimeOfBlockByHash (#2517)
* Node/Watcher/EVM: Fix TimeOfBlockByHash * Tweak log messages * Remove obsolete source file
This commit is contained in:
parent
c07cba2836
commit
9802f9cf2b
|
@ -86,12 +86,12 @@ func (e *EthereumConnector) TransactionReceipt(ctx context.Context, txHash ethCo
|
|||
}
|
||||
|
||||
func (e *EthereumConnector) TimeOfBlockByHash(ctx context.Context, hash ethCommon.Hash) (uint64, error) {
|
||||
block, err := e.client.BlockByHash(ctx, hash)
|
||||
block, err := e.client.HeaderByHash(ctx, hash)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return block.Time(), err
|
||||
return block.Time, err
|
||||
}
|
||||
|
||||
func (e *EthereumConnector) ParseLogMessagePublished(log ethTypes.Log) (*ethAbi.AbiLogMessagePublished, error) {
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package connectors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// ConnectorWithGetTimeOfBlockOverride is used to override the implementation of TimeOfBlockByHash() as defined in
|
||||
// the go-ethereum library because on some chains it fails with "transaction type not supported". Calling the underlying
|
||||
// eth_getBlockByHash directly works, so the sole function of this connector is to implement TimeOfBlockByHash() using the raw connection.
|
||||
type ConnectorWithGetTimeOfBlockOverride struct {
|
||||
Connector
|
||||
}
|
||||
|
||||
func NewConnectorWithGetTimeOfBlockOverride(ctx context.Context, baseConnector Connector) (*ConnectorWithGetTimeOfBlockOverride, error) {
|
||||
connector := &ConnectorWithGetTimeOfBlockOverride{Connector: baseConnector}
|
||||
return connector, nil
|
||||
}
|
||||
|
||||
func (a *ConnectorWithGetTimeOfBlockOverride) 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
|
||||
}
|
|
@ -266,14 +266,7 @@ func (w *Watcher) Run(ctx context.Context) error {
|
|||
return fmt.Errorf("dialing eth client failed: %w", err)
|
||||
}
|
||||
finalizer := finalizers.NewArbitrumFinalizer(logger, w.l1Finalizer)
|
||||
pollConnector, err := connectors.NewBlockPollConnector(ctx, baseConnector, finalizer, 250*time.Millisecond, false, 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)
|
||||
}
|
||||
// The standard geth BlockByHash() does not work on Arbitrum.
|
||||
w.ethConn, err = connectors.NewConnectorWithGetTimeOfBlockOverride(ctx, pollConnector)
|
||||
w.ethConn, err = connectors.NewBlockPollConnector(ctx, baseConnector, finalizer, 250*time.Millisecond, false, false)
|
||||
if err != nil {
|
||||
ethConnectionErrors.WithLabelValues(w.networkName, "dial_error").Inc()
|
||||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
|
@ -313,14 +306,7 @@ func (w *Watcher) Run(ctx context.Context) error {
|
|||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
return fmt.Errorf("dialing eth client failed: %w", err)
|
||||
}
|
||||
pollConnector, err := connectors.NewBlockPollConnector(ctx, baseConnector, finalizers.NewDefaultFinalizer(), 250*time.Millisecond, useFinalizedBlocks, safeBlocksSupported)
|
||||
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)
|
||||
}
|
||||
// The standard geth BlockByHash() does not work on Optimism Bedrock.
|
||||
w.ethConn, err = connectors.NewConnectorWithGetTimeOfBlockOverride(ctx, pollConnector)
|
||||
w.ethConn, err = connectors.NewBlockPollConnector(ctx, baseConnector, finalizers.NewDefaultFinalizer(), 250*time.Millisecond, useFinalizedBlocks, safeBlocksSupported)
|
||||
if err != nil {
|
||||
ethConnectionErrors.WithLabelValues(w.networkName, "dial_error").Inc()
|
||||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
|
@ -351,14 +337,7 @@ func (w *Watcher) Run(ctx context.Context) error {
|
|||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
return fmt.Errorf("dialing eth client failed: %w", err)
|
||||
}
|
||||
pollConnector, err := connectors.NewBlockPollConnector(ctx, baseConnector, finalizers.NewDefaultFinalizer(), 250*time.Millisecond, true, true)
|
||||
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)
|
||||
}
|
||||
// The standard geth BlockByHash() does not work on Base.
|
||||
w.ethConn, err = connectors.NewConnectorWithGetTimeOfBlockOverride(ctx, pollConnector)
|
||||
w.ethConn, err = connectors.NewBlockPollConnector(ctx, baseConnector, finalizers.NewDefaultFinalizer(), 250*time.Millisecond, true, true)
|
||||
if err != nil {
|
||||
ethConnectionErrors.WithLabelValues(w.networkName, "dial_error").Inc()
|
||||
p2p.DefaultRegistry.AddErrorCount(w.chainID, 1)
|
||||
|
@ -586,6 +565,7 @@ func (w *Watcher) Run(ctx context.Context) error {
|
|||
zap.Stringer("tx", ev.Raw.TxHash),
|
||||
zap.Uint64("block", ev.Raw.BlockNumber),
|
||||
zap.Stringer("blockhash", ev.Raw.BlockHash),
|
||||
zap.Uint64("blockTime", blockTime),
|
||||
zap.Uint64("Sequence", ev.Sequence),
|
||||
zap.Uint32("Nonce", ev.Nonce),
|
||||
zap.Uint8("ConsistencyLevel", ev.ConsistencyLevel),
|
||||
|
@ -600,6 +580,7 @@ func (w *Watcher) Run(ctx context.Context) error {
|
|||
zap.Stringer("tx", ev.Raw.TxHash),
|
||||
zap.Uint64("block", ev.Raw.BlockNumber),
|
||||
zap.Stringer("blockhash", ev.Raw.BlockHash),
|
||||
zap.Uint64("blockTime", blockTime),
|
||||
zap.Uint64("Sequence", ev.Sequence),
|
||||
zap.Uint32("Nonce", ev.Nonce),
|
||||
zap.Uint8("ConsistencyLevel", ev.ConsistencyLevel),
|
||||
|
|
Loading…
Reference in New Issue