-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
366 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# External Signer | ||
|
||
Lodestar supports connecting an external signing server like [Web3Signer](https://docs.web3signer.consensys.io/), [Diva](https://docs.shamirlabs.org/), | ||
or any other service implementing the [remote signing specification](https://github.com/ethereum/remote-signing-api). This allows the validator client | ||
to operate without storing any validator private keys locally by delegating the signing of messages (e.g. attestations, beacon blocks) to the external signer | ||
which is accessed through a [REST API](https://ethereum.github.io/remote-signing-api/) via HTTP(S). This API should not be exposed directly to the public | ||
Internet and appropriate firewall rules should be in place to restrict access only from the validator client. | ||
|
||
## Configuration | ||
|
||
Lodestar provides [CLI options](./validator-cli.md#--externalsignerurl) to connect an external signer. | ||
|
||
```sh | ||
./lodestar validator --externalSigner.url "http://localhost:9000" --externalSigner.fetch | ||
``` | ||
|
||
The validator client will fetch the list of public keys from the external signer and automatically keep them in sync with signers in local validator store | ||
by adding newly discovered public keys and removing no longer present public keys on external signer. | ||
|
||
By default, the list of public keys will be fetched from the external signer once per epoch (6.4 minutes). This interval can be configured by setting [`--externalSigner.fetchInterval`](./validator-cli.md#--externalsignerfetchinterval) flag which takes a number in milliseconds. | ||
|
||
Alternatively, if it is not desired to use all public keys imported on the external signer, it is also possible to explicitly specify a list of public keys to use | ||
by setting the [`--externalSigner.pubkeys`](./validator-cli.md#--externalsignerpubkeys) flag instead of [`--externalSigner.fetch`](./validator-cli.md#--externalsignerfetch). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import bls from "@chainsafe/bls"; | ||
import {CoordType} from "@chainsafe/bls/types"; | ||
import {fromHexString} from "@chainsafe/ssz"; | ||
import {ChainForkConfig} from "@lodestar/config"; | ||
import {SLOTS_PER_EPOCH} from "@lodestar/params"; | ||
import {toSafePrintableUrl} from "@lodestar/utils"; | ||
|
||
import {LoggerVc} from "../util/index.js"; | ||
import {externalSignerGetKeys} from "../util/externalSignerClient.js"; | ||
import {SignerType, ValidatorStore} from "./validatorStore.js"; | ||
|
||
export type ExternalSignerOptions = { | ||
url?: string; | ||
fetch?: boolean; | ||
fetchInterval?: number; | ||
}; | ||
|
||
/** | ||
* This service is responsible for keeping the keys managed by the connected | ||
* external signer and the validator client in sync by adding newly discovered keys | ||
* and removing no longer present keys on external signer from the validator store. | ||
*/ | ||
export function pollExternalSignerPubkeys( | ||
config: ChainForkConfig, | ||
logger: LoggerVc, | ||
signal: AbortSignal, | ||
validatorStore: ValidatorStore, | ||
opts?: ExternalSignerOptions | ||
): void { | ||
const externalSigner = opts ?? {}; | ||
|
||
if (!externalSigner.url || !externalSigner.fetch) { | ||
return; // Disabled | ||
} | ||
|
||
async function fetchExternalSignerPubkeys(): Promise<void> { | ||
// External signer URL is already validated earlier | ||
const externalSignerUrl = externalSigner.url as string; | ||
const printableUrl = toSafePrintableUrl(externalSignerUrl); | ||
|
||
try { | ||
logger.debug("Fetching public keys from external signer", {url: printableUrl}); | ||
const externalPubkeys = await externalSignerGetKeys(externalSignerUrl); | ||
assertValidPubkeysHex(externalPubkeys); | ||
logger.debug("Received public keys from external signer", {url: printableUrl, count: externalPubkeys.length}); | ||
|
||
const localPubkeys = validatorStore.getRemoteSignerPubkeys(externalSignerUrl); | ||
logger.debug("Local public keys stored for external signer", {url: printableUrl, count: localPubkeys.length}); | ||
|
||
const localPubkeysSet = new Set(localPubkeys); | ||
for (const pubkey of externalPubkeys) { | ||
if (!localPubkeysSet.has(pubkey)) { | ||
await validatorStore.addSigner({type: SignerType.Remote, pubkey, url: externalSignerUrl}); | ||
logger.info("Added remote signer", {pubkey, url: printableUrl}); | ||
} | ||
} | ||
|
||
const externalPubkeysSet = new Set(externalPubkeys); | ||
for (const pubkey of localPubkeys) { | ||
if (!externalPubkeysSet.has(pubkey)) { | ||
validatorStore.removeSigner(pubkey); | ||
logger.info("Removed remote signer", {pubkey, url: printableUrl}); | ||
} | ||
} | ||
} catch (e) { | ||
logger.error("Failed to fetch public keys from external signer", {url: printableUrl}, e as Error); | ||
} | ||
} | ||
|
||
const interval = setInterval( | ||
fetchExternalSignerPubkeys, | ||
externalSigner.fetchInterval ?? | ||
// Once per epoch by default | ||
SLOTS_PER_EPOCH * config.SECONDS_PER_SLOT * 1000 | ||
); | ||
signal.addEventListener("abort", () => clearInterval(interval), {once: true}); | ||
} | ||
|
||
function assertValidPubkeysHex(pubkeysHex: string[]): void { | ||
for (const pubkeyHex of pubkeysHex) { | ||
const pubkeyBytes = fromHexString(pubkeyHex); | ||
bls.PublicKey.fromBytes(pubkeyBytes, CoordType.jacobian, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.