Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

### Fixed

- [#7018](https://github.com/ChainSafe/forest/issues/7018): Fixed `forest-wallet set-default` failing when the keystore has no `default` entry.

## Forest v0.33.4 "Stray"

Mandatory release for mainnet node operators. It includes support for the _NV28 FireHorse_ network upgrade on mainnet, which is set to activate at epoch `6052800` (2026-05-27T14:00:00Z). It also includes a few improvements and fixes for the JSON-RPC server.
Expand Down
20 changes: 11 additions & 9 deletions src/key_management/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,7 @@ impl Wallet {

/// Set a default `KeyInfo` to the wallet
pub fn set_default(&mut self, addr: Address) -> anyhow::Result<()> {
let addr_string = format!("wallet-{addr}");
let key_info = self.keystore.get(&addr_string)?;
if self.keystore.get("default").is_ok() {
self.keystore.remove("default")?; // This line should
// unregister current
// default key then
// continue
}
self.keystore.put("default", key_info)?;
set_default(&addr, &mut self.keystore)?;
Ok(())
}

Expand Down Expand Up @@ -227,6 +219,16 @@ pub fn try_find_key(addr: &Address, keystore: &KeyStore) -> Result<Key, Error> {
ki.try_into()
}

/// Set the default key to the key identified by `addr`.
pub fn set_default(addr: &Address, keystore: &mut KeyStore) -> Result<(), Error> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be a free function?

Copy link
Copy Markdown
Contributor Author

@sudo-shashank sudo-shashank May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matches other methods in this module like get_default, list_addrs, remove_key etc

let key_info = try_find(addr, keystore)?;
if keystore.get("default").is_ok() {
keystore.remove("default")?;
}
keystore.put("default", key_info)?;
Ok(())
}

/// Return `KeyInfo` for given address in `KeyStore`
pub fn export_key_info(addr: &Address, keystore: &KeyStore) -> Result<KeyInfo, Error> {
let key = try_find_key(addr, keystore)?;
Expand Down
6 changes: 1 addition & 5 deletions src/rpc/methods/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,7 @@ impl RpcMethod<1> for WalletSetDefault {
(address,): Self::Params,
_: &http::Extensions,
) -> Result<Self::Ok, ServerError> {
let mut keystore = ctx.keystore.write();
let addr_string = format!("wallet-{address}");
let key_info = keystore.get(&addr_string)?;
keystore.remove("default")?; // This line should unregister current default key then continue
keystore.put("default", key_info)?;
crate::key_management::set_default(&address, &mut ctx.keystore.write())?;
Ok(())
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/wallet/subcommands/wallet_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ impl WalletBackend {

async fn wallet_set_default(&mut self, address: Address) -> anyhow::Result<()> {
if let Some(keystore) = &mut self.local {
let addr_string = format!("wallet-{address}");
let key_info = keystore.get(&addr_string)?;
keystore.remove("default")?; // This line should unregister current default key then continue
keystore.put("default", key_info)?;
crate::key_management::set_default(&address, keystore)?;
Ok(())
} else {
Ok(WalletSetDefault::call(&self.remote, (address,)).await?)
Expand Down
Loading