Skip to content

Commit

Permalink
Update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Jan 29, 2025
1 parent 957a767 commit 1e50e0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
32 changes: 16 additions & 16 deletions multinode/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type Adapter[HEAD Head] struct {

chainInfoLock sync.RWMutex
// intercepted values seen by callers of the Adapter excluding health check calls. Need to ensure MultiNode provides repeatable read guarantee
highestUserObservations ChainInfo
chainInfoHighestUserObservations ChainInfo
// most recent chain info observed during current lifecycle
latestChainInfo ChainInfo
chainInfoLatest ChainInfo
}

func NewAdapter[HEAD Head](
Expand Down Expand Up @@ -101,7 +101,7 @@ func (m *Adapter[HEAD]) SubscribeToHeads(ctx context.Context) (<-chan HEAD, Subs
}
timeout := pollInterval
poller, channel := NewPoller[HEAD](pollInterval, func(pollRequestCtx context.Context) (HEAD, error) {
if CtxIsHeathCheckRequest(ctx) {
if CtxIsHealthCheckRequest(ctx) {
pollRequestCtx = CtxAddHealthCheckFlag(pollRequestCtx)
}
return m.LatestBlock(pollRequestCtx)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (m *Adapter[HEAD]) SubscribeToFinalizedHeads(ctx context.Context) (<-chan H
}
timeout := finalizedBlockPollInterval
poller, channel := NewPoller[HEAD](finalizedBlockPollInterval, func(pollRequestCtx context.Context) (HEAD, error) {
if CtxIsHeathCheckRequest(ctx) {
if CtxIsHealthCheckRequest(ctx) {
pollRequestCtx = CtxAddHealthCheckFlag(pollRequestCtx)
}
return m.LatestFinalizedBlock(pollRequestCtx)
Expand Down Expand Up @@ -190,16 +190,16 @@ func (m *Adapter[HEAD]) OnNewHead(ctx context.Context, requestCh <-chan struct{}
defer m.chainInfoLock.Unlock()
blockNumber := head.BlockNumber()
totalDifficulty := head.GetTotalDifficulty()
if !CtxIsHeathCheckRequest(ctx) {
m.highestUserObservations.BlockNumber = max(m.highestUserObservations.BlockNumber, blockNumber)
m.highestUserObservations.TotalDifficulty = MaxTotalDifficulty(m.highestUserObservations.TotalDifficulty, totalDifficulty)
if !CtxIsHealthCheckRequest(ctx) {
m.chainInfoHighestUserObservations.BlockNumber = max(m.chainInfoHighestUserObservations.BlockNumber, blockNumber)
m.chainInfoHighestUserObservations.TotalDifficulty = MaxTotalDifficulty(m.chainInfoHighestUserObservations.TotalDifficulty, totalDifficulty)
}
select {
case <-requestCh: // no need to update latestChainInfo, as rpcMultiNodeAdapter already started new life cycle
case <-requestCh: // no need to update chainInfoLatest, as rpcMultiNodeAdapter already started new life cycle
return
default:
m.latestChainInfo.BlockNumber = blockNumber
m.latestChainInfo.TotalDifficulty = totalDifficulty
m.chainInfoLatest.BlockNumber = blockNumber
m.chainInfoLatest.TotalDifficulty = totalDifficulty
}
}

Expand All @@ -210,14 +210,14 @@ func (m *Adapter[HEAD]) OnNewFinalizedHead(ctx context.Context, requestCh <-chan

m.chainInfoLock.Lock()
defer m.chainInfoLock.Unlock()
if !CtxIsHeathCheckRequest(ctx) {
m.highestUserObservations.FinalizedBlockNumber = max(m.highestUserObservations.FinalizedBlockNumber, head.BlockNumber())
if !CtxIsHealthCheckRequest(ctx) {
m.chainInfoHighestUserObservations.FinalizedBlockNumber = max(m.chainInfoHighestUserObservations.FinalizedBlockNumber, head.BlockNumber())
}
select {
case <-requestCh: // no need to update latestChainInfo, as rpcMultiNodeAdapter already started new life cycle
case <-requestCh: // no need to update chainInfoLatest, as rpcMultiNodeAdapter already started new life cycle
return
default:
m.latestChainInfo.FinalizedBlockNumber = head.BlockNumber()
m.chainInfoLatest.FinalizedBlockNumber = head.BlockNumber()
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ func (m *Adapter[HEAD]) CancelLifeCycle() {

func (m *Adapter[HEAD]) resetLatestChainInfo() {
m.chainInfoLock.Lock()
m.latestChainInfo = ChainInfo{}
m.chainInfoLatest = ChainInfo{}
m.chainInfoLock.Unlock()
}

Expand All @@ -289,5 +289,5 @@ func (m *Adapter[HEAD]) Close() {
func (m *Adapter[HEAD]) GetInterceptedChainInfo() (latest, highestUserObservations ChainInfo) {
m.chainInfoLock.RLock()
defer m.chainInfoLock.RUnlock()
return m.latestChainInfo, m.highestUserObservations
return m.chainInfoLatest, m.chainInfoHighestUserObservations
}
2 changes: 1 addition & 1 deletion multinode/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ func CtxAddHealthCheckFlag(ctx context.Context) context.Context {
return context.WithValue(ctx, contextKeyHeathCheckRequest, struct{}{})
}

func CtxIsHeathCheckRequest(ctx context.Context) bool {
func CtxIsHealthCheckRequest(ctx context.Context) bool {
return ctx.Value(contextKeyHeathCheckRequest) != nil
}
4 changes: 2 additions & 2 deletions multinode/ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestContext(t *testing.T) {
ctx := tests.Context(t)
assert.False(t, CtxIsHeathCheckRequest(ctx), "expected false for test context")
assert.False(t, CtxIsHealthCheckRequest(ctx), "expected false for test context")
ctx = CtxAddHealthCheckFlag(ctx)
assert.True(t, CtxIsHeathCheckRequest(ctx), "expected context to contain the healthcheck flag")
assert.True(t, CtxIsHealthCheckRequest(ctx), "expected context to contain the healthcheck flag")
}
4 changes: 2 additions & 2 deletions multinode/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type RPCClient[
// Close - closes all subscriptions and aborts all RPC calls
Close()
// GetInterceptedChainInfo - returns latest and highest observed by application layer ChainInfo.
// latest ChainInfo is the most recent value received within a NodeClient's current lifecycle between Dial and DisconnectAll.
// highestUserObservations ChainInfo is the highest ChainInfo observed excluding health checks calls.
// chainInfoLatest is the most recent value received within a NodeClient's current lifecycle between Dial and DisconnectAll.
// chainInfoHighestUserObservations is the highest ChainInfo observed excluding health checks calls.
// Its values must not be reset.
// The results of corresponding calls, to get the most recent head and the latest finalized head, must be
// intercepted and reflected in ChainInfo before being returned to a caller. Otherwise, MultiNode is not able to
Expand Down

0 comments on commit 1e50e0b

Please sign in to comment.