From 705a698190584ac8bc932a31033424e9a4648ad4 Mon Sep 17 00:00:00 2001 From: Dylan Tinianov Date: Thu, 16 Jan 2025 13:38:13 -0500 Subject: [PATCH] GetTotalDifficulty --- multinode/adaptor.go | 10 ++++++---- multinode/types.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/multinode/adaptor.go b/multinode/adaptor.go index f871b7c..f17dc1c 100644 --- a/multinode/adaptor.go +++ b/multinode/adaptor.go @@ -187,16 +187,18 @@ func (m *Adapter[RPC, HEAD]) OnNewHead(ctx context.Context, requestCh <-chan str m.chainInfoLock.Lock() defer m.chainInfoLock.Unlock() + blockNumber := head.BlockNumber() + totalDifficulty := head.GetTotalDifficulty() if !CtxIsHeathCheckRequest(ctx) { - m.highestUserObservations.BlockNumber = max(m.highestUserObservations.BlockNumber, head.BlockNumber()) - m.highestUserObservations.TotalDifficulty = MaxTotalDifficulty(m.highestUserObservations.TotalDifficulty, head.TotalDifficulty()) + m.highestUserObservations.BlockNumber = max(m.highestUserObservations.BlockNumber, blockNumber) + m.highestUserObservations.TotalDifficulty = MaxTotalDifficulty(m.highestUserObservations.TotalDifficulty, totalDifficulty) } select { case <-requestCh: // no need to update latestChainInfo, as rpcMultiNodeAdapter already started new life cycle return default: - m.latestChainInfo.BlockNumber = head.BlockNumber() - m.latestChainInfo.TotalDifficulty = head.TotalDifficulty() + m.latestChainInfo.BlockNumber = blockNumber + m.latestChainInfo.TotalDifficulty = totalDifficulty } } diff --git a/multinode/types.go b/multinode/types.go index e959b76..fc0ccc0 100644 --- a/multinode/types.go +++ b/multinode/types.go @@ -83,7 +83,7 @@ type RPCClient[ type Head interface { BlockNumber() int64 BlockDifficulty() *big.Int - TotalDifficulty() *big.Int + GetTotalDifficulty() *big.Int IsValid() bool }