Skip to content

Commit

Permalink
Introducing GetAllConfigDigests (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnogo authored Oct 22, 2024
1 parent e5f3ecb commit b169beb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
59 changes: 59 additions & 0 deletions mocks/pkg/reader/rmn_home.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions pkg/reader/rmn_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ type RMNHome interface {
GetMinObservers(configDigest cciptypes.Bytes32) (map[cciptypes.ChainSelector]int, error)
// GetOffChainConfig gets the offchain config for the given configDigest
GetOffChainConfig(configDigest cciptypes.Bytes32) (cciptypes.Bytes, error)
// GetAllConfigDigests gets the active and candidate RMNHomeConfigs
GetAllConfigDigests() (activeConfigDigest cciptypes.Bytes32, candidateConfigDigest cciptypes.Bytes32)
services.Service
}

type rmnHomeState struct {
primaryConfigDigest cciptypes.Bytes32
secondaryConfigDigest cciptypes.Bytes32
activeConfigDigest cciptypes.Bytes32
candidateConfigDigest cciptypes.Bytes32
rmnHomeConfig map[cciptypes.Bytes32]rmntypes.HomeConfig
}

Expand Down Expand Up @@ -161,15 +163,15 @@ func (r *rmnHomePoller) fetchAndSetRmnHomeConfigs(ctx context.Context) error {
}

func (r *rmnHomePoller) setRMNHomeState(
primaryConfigDigest cciptypes.Bytes32,
secondaryConfigDigest cciptypes.Bytes32,
activeConfigDigest cciptypes.Bytes32,
candidateConfigDigest cciptypes.Bytes32,
rmnHomeConfig map[cciptypes.Bytes32]rmntypes.HomeConfig) {
r.mutex.Lock()
defer r.mutex.Unlock()
s := &r.rmnHomeState

s.primaryConfigDigest = primaryConfigDigest
s.secondaryConfigDigest = secondaryConfigDigest
s.activeConfigDigest = activeConfigDigest
s.candidateConfigDigest = candidateConfigDigest
s.rmnHomeConfig = rmnHomeConfig
}

Expand Down Expand Up @@ -211,6 +213,14 @@ func (r *rmnHomePoller) GetOffChainConfig(configDigest cciptypes.Bytes32) (ccipt
return cfg.OffchainConfig, nil
}

func (r *rmnHomePoller) GetAllConfigDigests() (
activeConfigDigest cciptypes.Bytes32,
candidateConfigDigest cciptypes.Bytes32) {
r.mutex.RLock()
defer r.mutex.RUnlock()
return r.rmnHomeState.activeConfigDigest, r.rmnHomeState.candidateConfigDigest
}

func (r *rmnHomePoller) Close() error {
return r.sync.StopOnce(r.Name(), func() error {
defer r.wg.Wait()
Expand Down
5 changes: 5 additions & 0 deletions pkg/reader/rmn_home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ func Test_RMNHomePollingWorking(t *testing.T) {
require.True(t, exists)
require.Equal(t, i+1, minObs)
}

activeConfigDigest, candidateConfigDigest := configPoller.GetAllConfigDigests()
require.Equal(t, primaryConfig.ConfigDigest, activeConfigDigest)
require.Equal(t, secondaryConfig.ConfigDigest, candidateConfigDigest)

}
})
}
Expand Down

0 comments on commit b169beb

Please sign in to comment.