Skip to content

Commit 5c4bead

Browse files
authored
feat: return proxy map (#118)
* feat: publish bins * update get pubkeys return * update api * fix * clippy * comments
1 parent 10cf952 commit 5c4bead

File tree

10 files changed

+97
-43
lines changed

10 files changed

+97
-43
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ jobs:
3636
os: macos-latest
3737
- target: aarch64-apple-darwin
3838
os: macos-latest
39+
names:
40+
- binary: commit-boost
41+
publish: commit-boost-cli
42+
- binary: default-pbs
43+
publish: commit-boost-pbs
44+
- binary: signer-module
45+
publish: commit-boost-signer
3946

4047
runs-on: ${{ matrix.os }}
4148
steps:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ struct Datagram {
4646
#[tokio::main]
4747
async fn main() {
4848
let config = load_commit_module_config::<()>().unwrap();
49-
let pubkeys = config.signer_client.get_pubkeys().await.unwrap();
49+
let pubkeys = config.signer_client.get_pubkeys().await.unwrap().keys;
5050

51-
let pubkey = *pubkeys.consensus.first().unwrap();
51+
let pubkey = *pubkeys.consensus.first().unwrap().consensus;
5252

5353
let datagram = Datagram { data: 42 };
5454
let request = SignConsensusRequest::builder(pubkey).with_msg(&datagram);

api/signer-api.yml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ paths:
2121
schema:
2222
type: object
2323
properties:
24-
consensus:
25-
description: Consensus validator pubkeys
24+
keys:
25+
description: List of mappings between consensus pubkeys and their proxies
2626
type: array
2727
items:
28-
$ref: '#/components/schemas/BlsPubkey'
29-
proxy_bls:
30-
description: BLS proxy validator pubkeys
31-
type: array
32-
items:
33-
$ref: '#/components/schemas/BlsPubkey'
34-
proxy_ecdsa:
35-
description: ECDSA proxy validator pubkeys
36-
type: array
37-
items:
38-
$ref: '#/components/schemas/EcdsaPubkey'
28+
type: object
29+
properties:
30+
consensus:
31+
description: Consensus validator pubkey
32+
$ref: "#/components/schemas/BlsPubkey"
33+
proxy_bls:
34+
description: BLS proxy validator pubkeys
35+
type: array
36+
items:
37+
$ref: "#/components/schemas/BlsPubkey"
38+
proxy_ecdsa:
39+
description: ECDSA proxy validator pubkeys
40+
type: array
41+
items:
42+
$ref: "#/components/schemas/EcdsaPubkey"
3943
"500":
4044
description: Internal error
4145
content:
@@ -75,8 +79,8 @@ paths:
7579
pubkey:
7680
description: Public key of the validator
7781
oneOf:
78-
- $ref: '#/components/schemas/BlsPubkey'
79-
- $ref: '#/components/schemas/EcdsaPubkey'
82+
- $ref: "#/components/schemas/BlsPubkey"
83+
- $ref: "#/components/schemas/EcdsaPubkey"
8084
object_root:
8185
description: The root of the object to be signed
8286
type: string
@@ -106,8 +110,8 @@ paths:
106110
application/json:
107111
schema:
108112
oneOf:
109-
- $ref: '#/components/schemas/BlsSignature'
110-
- $ref: '#/components/schemas/EcdsaSignature'
113+
- $ref: "#/components/schemas/BlsSignature"
114+
- $ref: "#/components/schemas/EcdsaSignature"
111115
examples:
112116
Consensus:
113117
value: "0xa3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989a3ffa9241f78279f1af04644cb8c79c2d8f02bcf0e28e2f186f6dcccac0a869c2be441fda50f0dea895cfce2e53f0989"
@@ -166,7 +170,7 @@ paths:
166170
pubkey:
167171
description: a validator BLS public key for which to generate a proxy key
168172
allOf:
169-
- $ref: '#/components/schemas/BlsPubkey'
173+
- $ref: "#/components/schemas/BlsPubkey"
170174
scheme:
171175
description: signature scheme to generate proxy keypair for
172176
type: string
@@ -194,16 +198,16 @@ paths:
194198
delegator:
195199
description: the validator BLS public key for which the proxy key was generated (the same one as requested)
196200
allOf:
197-
- $ref: '#/components/schemas/BlsPubkey'
201+
- $ref: "#/components/schemas/BlsPubkey"
198202
proxy:
199203
description: the generated proxy public key
200204
oneOf:
201-
- $ref: '#/components/schemas/BlsPubkey'
202-
- $ref: '#/components/schemas/EcdsaPubkey'
205+
- $ref: "#/components/schemas/BlsPubkey"
206+
- $ref: "#/components/schemas/EcdsaPubkey"
203207
signature:
204208
description: The signature of the proxy delegation
205209
allOf:
206-
- $ref: '#/components/schemas/BlsSignature'
210+
- $ref: "#/components/schemas/BlsSignature"
207211
examples:
208212
Bls:
209213
value:

crates/common/src/commit/request.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,19 @@ impl GenerateProxyRequest {
153153

154154
#[derive(Debug, Clone, Deserialize, Serialize)]
155155
pub struct GetPubkeysResponse {
156-
pub consensus: Vec<BlsPublicKey>,
156+
pub keys: Vec<ConsensusProxyMap>,
157+
}
158+
159+
/// Map of consensus pubkeys to proxies
160+
#[derive(Debug, Clone, Deserialize, Serialize)]
161+
pub struct ConsensusProxyMap {
162+
pub consensus: BlsPublicKey,
157163
pub proxy_bls: Vec<BlsPublicKey>,
158164
pub proxy_ecdsa: Vec<EcdsaPublicKey>,
159165
}
166+
167+
impl ConsensusProxyMap {
168+
pub fn new(consensus: BlsPublicKey) -> Self {
169+
Self { consensus, proxy_bls: vec![], proxy_ecdsa: vec![] }
170+
}
171+
}

crates/signer/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub enum SignerModuleError {
1515

1616
#[error("unknown proxy signer: 0x{}", hex::encode(.0))]
1717
UnknownProxySigner(Vec<u8>),
18+
19+
#[error("internal error {0}")]
20+
Internal(String),
1821
}
1922

2023
impl IntoResponse for SignerModuleError {
@@ -23,6 +26,7 @@ impl IntoResponse for SignerModuleError {
2326
SignerModuleError::Unauthorized => StatusCode::UNAUTHORIZED,
2427
SignerModuleError::UnknownConsensusSigner(_) => StatusCode::NOT_FOUND,
2528
SignerModuleError::UnknownProxySigner(_) => StatusCode::NOT_FOUND,
29+
SignerModuleError::Internal(_) => StatusCode::INTERNAL_SERVER_ERROR,
2630
};
2731

2832
(status, self.to_string()).into_response()

crates/signer/src/manager.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use alloy::rpc::types::beacon::BlsSignature;
44
use cb_common::{
55
commit::request::{
6-
ProxyDelegationBls, ProxyDelegationEcdsa, SignedProxyDelegationBls,
6+
ConsensusProxyMap, ProxyDelegationBls, ProxyDelegationEcdsa, SignedProxyDelegationBls,
77
SignedProxyDelegationEcdsa,
88
},
99
signer::{
@@ -16,6 +16,7 @@ use cb_common::{
1616
types::{Chain, ModuleId},
1717
};
1818
use derive_more::derive::Deref;
19+
use eyre::OptionExt;
1920
use tree_hash::TreeHash;
2021

2122
use crate::error::SignerModuleError;
@@ -209,6 +210,39 @@ impl SigningManager {
209210
.map(|x| x.delegation)
210211
.ok_or(SignerModuleError::UnknownProxySigner(pubkey.as_ref().to_vec()))
211212
}
213+
214+
pub fn get_consensus_proxy_maps(
215+
&self,
216+
module_id: &ModuleId,
217+
) -> eyre::Result<Vec<ConsensusProxyMap>> {
218+
let consensus = self.consensus_pubkeys();
219+
let proxy_bls = self.proxy_pubkeys_bls.get(module_id).cloned().unwrap_or_default();
220+
let proxy_ecdsa = self.proxy_pubkeys_ecdsa.get(module_id).cloned().unwrap_or_default();
221+
222+
let mut keys: Vec<_> = consensus.into_iter().map(ConsensusProxyMap::new).collect();
223+
224+
for bls in proxy_bls {
225+
let delegator = self.get_delegation_bls(&bls)?.message.delegator;
226+
let entry = keys
227+
.iter_mut()
228+
.find(|x| x.consensus == delegator)
229+
.ok_or_eyre("missing consensus")?;
230+
231+
entry.proxy_bls.push(bls);
232+
}
233+
234+
for ecdsa in proxy_ecdsa {
235+
let delegator = self.get_delegation_ecdsa(&ecdsa)?.message.delegator;
236+
let entry = keys
237+
.iter_mut()
238+
.find(|x| x.consensus == delegator)
239+
.ok_or_eyre("missing consensus")?;
240+
241+
entry.proxy_ecdsa.push(ecdsa);
242+
}
243+
244+
Ok(keys)
245+
}
212246
}
213247

214248
#[cfg(test)]

crates/signer/src/service.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ async fn handle_get_pubkeys(
108108
debug!(event = "get_pubkeys", ?req_id, "New request");
109109

110110
let signing_manager = state.manager.read().await;
111+
let map = signing_manager
112+
.get_consensus_proxy_maps(&module_id)
113+
.map_err(|err| SignerModuleError::Internal(err.to_string()))?;
111114

112-
let consensus = signing_manager.consensus_pubkeys();
113-
let proxy_bls =
114-
signing_manager.proxy_pubkeys_bls().get(&module_id).cloned().unwrap_or_default();
115-
let proxy_ecdsa =
116-
signing_manager.proxy_pubkeys_ecdsa().get(&module_id).cloned().unwrap_or_default();
117-
118-
let res = GetPubkeysResponse { consensus, proxy_bls, proxy_ecdsa };
115+
let res = GetPubkeysResponse { keys: map };
119116

120117
Ok((StatusCode::OK, Json(res)).into_response())
121118
}

docs/docs/developing/commit-module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Furthermore, in order to request a signature, we'd need a public key of the vali
6161
let pubkeys = config.signer_client.get_pubkeys().await.unwrap();
6262
```
6363

64-
Which will essentially call the `get_pubkeys` endpoint of the [SignerAPI](/api).
64+
Which will call the `get_pubkeys` endpoint of the [SignerAPI](/api), returning all the consensus pubkeys and the corresponding proxy keys, of your module.
6565

6666
Then, we can request a signature either with a consensus key or with a proxy key:
6767

examples/da_commit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tokio.workspace = true
1515

1616
# serialization
1717
serde.workspace = true
18+
serde_json.workspace = true
1819

1920
# telemetry
2021
tracing.workspace = true

examples/da_commit/src/main.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ impl DaCommitService {
3939
pub async fn run(self) -> Result<()> {
4040
// the config has the signer_client already setup, we can use it to interact
4141
// with the Signer API
42-
let pubkeys = self.config.signer_client.get_pubkeys().await?;
43-
info!(
44-
consensus = pubkeys.consensus.len(),
45-
proxy_bls = pubkeys.proxy_bls.len(),
46-
proxy_ecdsa = pubkeys.proxy_ecdsa.len(),
47-
"Received pubkeys"
48-
);
49-
50-
let pubkey = *pubkeys.consensus.first().ok_or_eyre("no key available")?;
42+
let pubkeys = self.config.signer_client.get_pubkeys().await?.keys;
43+
info!(pubkeys = %serde_json::to_string_pretty(&pubkeys).unwrap(), "Received pubkeys");
44+
45+
let pubkey = pubkeys.first().ok_or_eyre("no key available")?.consensus;
5146
info!("Registered validator {pubkey}");
5247

5348
let proxy_delegation_bls = self.config.signer_client.generate_proxy_key_bls(pubkey).await?;

0 commit comments

Comments
 (0)