node: eth finalized check
This commit is contained in:
parent
e0843bf2bc
commit
58186b8d75
|
@ -32,11 +32,13 @@ type PollFinalizer interface {
|
|||
}
|
||||
|
||||
type PollImpl struct {
|
||||
BaseEth EthImpl
|
||||
Finalizer PollFinalizer
|
||||
DelayInMs int
|
||||
logger *zap.Logger
|
||||
rawClient *ethRpc.Client
|
||||
BaseEth EthImpl
|
||||
Finalizer PollFinalizer
|
||||
DelayInMs int
|
||||
IsEthPoS bool
|
||||
hasEthSwitched bool
|
||||
logger *zap.Logger
|
||||
rawClient *ethRpc.Client
|
||||
}
|
||||
|
||||
func (e *PollImpl) SetLogger(l *zap.Logger) {
|
||||
|
@ -47,6 +49,11 @@ func (e *PollImpl) SetLogger(l *zap.Logger) {
|
|||
}
|
||||
}
|
||||
|
||||
func (e *PollImpl) SetEthSwitched() {
|
||||
e.hasEthSwitched = true
|
||||
e.logger.Info("switching from latest to finalized", zap.String("eth_network", e.BaseEth.NetworkName), zap.Int("delay_in_ms", e.DelayInMs))
|
||||
}
|
||||
|
||||
func (e *PollImpl) DialContext(ctx context.Context, rawurl string) (err error) {
|
||||
timeout, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
defer cancel()
|
||||
|
@ -228,13 +235,16 @@ func (e *PollImpl) getBlock(ctx context.Context, number *big.Int) (*common.NewBl
|
|||
var numStr string
|
||||
if number != nil {
|
||||
numStr = ethHexUtils.EncodeBig(number)
|
||||
} else if e.hasEthSwitched {
|
||||
numStr = "finalized"
|
||||
} else {
|
||||
numStr = "latest"
|
||||
}
|
||||
|
||||
type Marshaller struct {
|
||||
Number *ethHexUtils.Big
|
||||
Hash ethCommon.Hash `json:"hash"`
|
||||
Number *ethHexUtils.Big
|
||||
Hash ethCommon.Hash `json:"hash"`
|
||||
Difficulty *ethHexUtils.Big
|
||||
}
|
||||
|
||||
var m Marshaller
|
||||
|
@ -250,6 +260,11 @@ func (e *PollImpl) getBlock(ctx context.Context, number *big.Int) (*common.NewBl
|
|||
)
|
||||
return nil, fmt.Errorf("failed to unmarshal block: Number is nil")
|
||||
}
|
||||
d := big.Int(*m.Difficulty)
|
||||
if !e.hasEthSwitched && d.Cmp(big.NewInt(0)) == 0 {
|
||||
e.SetEthSwitched()
|
||||
return e.getBlock(ctx, number)
|
||||
}
|
||||
n := big.Int(*m.Number)
|
||||
return &common.NewBlock{
|
||||
Number: &n,
|
||||
|
|
|
@ -134,6 +134,8 @@ func NewEthWatcher(
|
|||
// When we are running in mainnet or testnet, we need to use the Celo ethereum library rather than go-ethereum.
|
||||
// However, in devnet, we currently run the standard ETH node for Celo, so we need to use the standard go-ethereum.
|
||||
ethIntf = &celo.CeloImpl{NetworkName: networkName}
|
||||
} else if chainID == vaa.ChainIDEthereum && !unsafeDevMode {
|
||||
ethIntf = &PollImpl{BaseEth: EthImpl{NetworkName: networkName}, DelayInMs: 250, IsEthPoS: true}
|
||||
} else if chainID == vaa.ChainIDMoonbeam && !unsafeDevMode {
|
||||
ethIntf = &PollImpl{BaseEth: EthImpl{NetworkName: networkName}, Finalizer: &MoonbeamFinalizer{}, DelayInMs: 250}
|
||||
} else if chainID == vaa.ChainIDNeon {
|
||||
|
|
Loading…
Reference in New Issue