Skip to content

Commit

Permalink
node: fix finalized only for eth (not moonbeam)
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Sep 14, 2022
1 parent 58186b8 commit 8ad0cf0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions node/pkg/ethereum/pollimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type PollFinalizer interface {
}

type PollImpl struct {
BaseEth EthImpl
Finalizer PollFinalizer
DelayInMs int
IsEthPoS bool
hasEthSwitched bool
logger *zap.Logger
rawClient *ethRpc.Client
BaseEth EthImpl
Finalizer PollFinalizer
DelayInMs int
IsEthPoS bool
hasEthSwitchedToPoS bool
logger *zap.Logger
rawClient *ethRpc.Client
}

func (e *PollImpl) SetLogger(l *zap.Logger) {
Expand All @@ -50,7 +50,7 @@ func (e *PollImpl) SetLogger(l *zap.Logger) {
}

func (e *PollImpl) SetEthSwitched() {
e.hasEthSwitched = true
e.hasEthSwitchedToPoS = true
e.logger.Info("switching from latest to finalized", zap.String("eth_network", e.BaseEth.NetworkName), zap.Int("delay_in_ms", e.DelayInMs))
}

Expand Down Expand Up @@ -235,7 +235,7 @@ 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 {
} else if e.hasEthSwitchedToPoS {
numStr = "finalized"
} else {
numStr = "latest"
Expand All @@ -261,7 +261,7 @@ 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 {
if e.IsEthPoS && !e.hasEthSwitchedToPoS && d.Cmp(big.NewInt(0)) == 0 {
e.SetEthSwitched()
return e.getBlock(ctx, number)
}
Expand Down

0 comments on commit 8ad0cf0

Please sign in to comment.