Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional sign_extensions field to [[chain]] config #882

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct Chain {
/// ID of a particular chain
pub id: Id,

/// Should extensions for this chain be signed?
pub sign_extensions: bool,

/// Signing keyring for this chain
pub keyring: KeyRing,

Expand Down Expand Up @@ -56,6 +59,7 @@ impl Chain {

Ok(Self {
id: config.id.clone(),
sign_extensions: config.sign_extensions,
keyring: KeyRing::new(config.key_format.clone()),
state: Mutex::new(state),
})
Expand Down
10 changes: 10 additions & 0 deletions src/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ pub struct ChainConfig {
/// Key serialization format configuration for this chain
pub key_format: keyring::Format,

/// Should vote extensions on this chain be signed? (default: false)
///
/// CometBFT v0.38 and newer supports an `ExtendedCommitSig` which requires computing an
/// additional signature over an extension using the consensus key beyond simply signing a vote.
///
/// Note: in the future this can be autodetected via the `signExtension` field on `SignVote`.
/// See cometbft/cometbft#2439.
#[serde(default)]
pub sign_extensions: bool,

/// Path to chain-specific `priv_validator_state.json` file
pub state_file: Option<PathBuf>,

Expand Down
24 changes: 13 additions & 11 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@ impl Session {
self.log_signing_request(&signable_msg, started_at).unwrap();

// Add extension signature if the message is a precommit for a non-empty block ID.
if let Some(extension_msg) = signable_msg.extension_bytes(chain_id)? {
let started_at = Instant::now();
let extension_sig = chain.keyring.sign(public_key, &extension_msg)?;
signable_msg.add_extension_signature(extension_sig)?;

info!(
"[{}@{}] signed vote extension ({} ms)",
&self.config.chain_id,
&self.config.addr,
started_at.elapsed().as_millis(),
);
if chain.sign_extensions {
if let Some(extension_msg) = signable_msg.extension_bytes(chain_id)? {
let started_at = Instant::now();
let extension_sig = chain.keyring.sign(public_key, &extension_msg)?;
signable_msg.add_extension_signature(extension_sig)?;

info!(
"[{}@{}] signed vote extension ({} ms)",
&self.config.chain_id,
&self.config.addr,
started_at.elapsed().as_millis(),
);
}
}

Ok(signable_msg.into())
Expand Down
1 change: 1 addition & 0 deletions tmkms.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[[chain]]
id = "cosmoshub-3"
key_format = { type = "bech32", account_key_prefix = "cosmospub", consensus_key_prefix = "cosmosvalconspub" }
sign_extensions = false # Should vote extensions for this chain be signed? (default: false)
# state_file = "/path/to/cosmoshub_priv_validator_state.json"
# state_hook = { cmd = ["/path/to/block/height_script", "--example-arg", "cosmoshub"] }

Expand Down
Loading