Add safe mode check (#1108)

Change-Id: Ida10e1ab0c056b4ed1ce2317800235843763a7ac
This commit is contained in:
bruce-riley 2022-04-26 07:51:10 -05:00 committed by GitHub
parent 05d84b4d6f
commit 87b36399d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -141,6 +141,10 @@ func NewEthWatcher(
func (e *Watcher) Run(ctx context.Context) error {
logger := supervisor.Logger(ctx)
if err := e.checkForSafeMode(ctx); err != nil {
return err
}
// Initialize gossip metrics (we want to broadcast the address even if we're not yet syncing)
p2p.DefaultRegistry.SetNetworkStats(e.chainID, &gossipv1.Heartbeat_Network{
ContractAddress: e.contract.Hex(),
@ -579,3 +583,24 @@ func fetchCurrentGuardianSet(ctx context.Context, caller *abi.AbiCaller) (uint32
return currentIndex, &gs, nil
}
func (e *Watcher) checkForSafeMode(ctx context.Context) error {
if e.chainID == vaa.ChainIDKarura || e.chainID == vaa.ChainIDAcala {
c, err := rpc.DialContext(ctx, e.url)
if err != nil {
return fmt.Errorf("failed to connect to url %s to check for safe mode: %w", e.url, err)
}
var safe bool
err = c.CallContext(ctx, &safe, "net_isSafeMode")
if err != nil {
return fmt.Errorf("check for safe mode for url %s failed: %w", e.url, err)
}
if !safe {
return fmt.Errorf("url %s is not using safe mode", e.url)
}
}
return nil
}