Skip to content

Commit

Permalink
GetTotalDifficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Jan 16, 2025
1 parent 321938c commit 705a698
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions multinode/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion multinode/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type RPCClient[
type Head interface {
BlockNumber() int64
BlockDifficulty() *big.Int
TotalDifficulty() *big.Int
GetTotalDifficulty() *big.Int
IsValid() bool
}

Expand Down

0 comments on commit 705a698

Please sign in to comment.