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

[BREAKING CHANGE] fix: unify the fields name in rpc #441

Merged
merged 4 commits into from
Jan 3, 2025
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
22 changes: 11 additions & 11 deletions src/fiber/gen/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,7 @@ impl ::core::fmt::Display for NodeAnnouncement {
write!(f, ", {}: {}", "features", self.features())?;
write!(f, ", {}: {}", "timestamp", self.timestamp())?;
write!(f, ", {}: {}", "node_id", self.node_id())?;
write!(f, ", {}: {}", "alias", self.alias())?;
write!(f, ", {}: {}", "node_name", self.node_name())?;
write!(f, ", {}: {}", "address", self.address())?;
write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
write!(
Expand Down Expand Up @@ -3158,7 +3158,7 @@ impl NodeAnnouncement {
let end = molecule::unpack_number(&slice[20..]) as usize;
Pubkey::new_unchecked(self.0.slice(start..end))
}
pub fn alias(&self) -> Byte32 {
pub fn node_name(&self) -> Byte32 {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[20..]) as usize;
let end = molecule::unpack_number(&slice[24..]) as usize;
Expand Down Expand Up @@ -3223,7 +3223,7 @@ impl molecule::prelude::Entity for NodeAnnouncement {
.features(self.features())
.timestamp(self.timestamp())
.node_id(self.node_id())
.alias(self.alias())
.node_name(self.node_name())
.address(self.address())
.chain_hash(self.chain_hash())
.auto_accept_min_ckb_funding_amount(self.auto_accept_min_ckb_funding_amount())
Expand Down Expand Up @@ -3253,7 +3253,7 @@ impl<'r> ::core::fmt::Display for NodeAnnouncementReader<'r> {
write!(f, ", {}: {}", "features", self.features())?;
write!(f, ", {}: {}", "timestamp", self.timestamp())?;
write!(f, ", {}: {}", "node_id", self.node_id())?;
write!(f, ", {}: {}", "alias", self.alias())?;
write!(f, ", {}: {}", "node_name", self.node_name())?;
write!(f, ", {}: {}", "address", self.address())?;
write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
write!(
Expand Down Expand Up @@ -3312,7 +3312,7 @@ impl<'r> NodeAnnouncementReader<'r> {
let end = molecule::unpack_number(&slice[20..]) as usize;
PubkeyReader::new_unchecked(&self.as_slice()[start..end])
}
pub fn alias(&self) -> Byte32Reader<'r> {
pub fn node_name(&self) -> Byte32Reader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[20..]) as usize;
let end = molecule::unpack_number(&slice[24..]) as usize;
Expand Down Expand Up @@ -3411,7 +3411,7 @@ pub struct NodeAnnouncementBuilder {
pub(crate) features: Uint64,
pub(crate) timestamp: Uint64,
pub(crate) node_id: Pubkey,
pub(crate) alias: Byte32,
pub(crate) node_name: Byte32,
pub(crate) address: BytesVec,
pub(crate) chain_hash: Byte32,
pub(crate) auto_accept_min_ckb_funding_amount: Uint64,
Expand All @@ -3435,8 +3435,8 @@ impl NodeAnnouncementBuilder {
self.node_id = v;
self
}
pub fn alias(mut self, v: Byte32) -> Self {
self.alias = v;
pub fn node_name(mut self, v: Byte32) -> Self {
self.node_name = v;
self
}
pub fn address(mut self, v: BytesVec) -> Self {
Expand Down Expand Up @@ -3465,7 +3465,7 @@ impl molecule::prelude::Builder for NodeAnnouncementBuilder {
+ self.features.as_slice().len()
+ self.timestamp.as_slice().len()
+ self.node_id.as_slice().len()
+ self.alias.as_slice().len()
+ self.node_name.as_slice().len()
+ self.address.as_slice().len()
+ self.chain_hash.as_slice().len()
+ self.auto_accept_min_ckb_funding_amount.as_slice().len()
Expand All @@ -3483,7 +3483,7 @@ impl molecule::prelude::Builder for NodeAnnouncementBuilder {
offsets.push(total_size);
total_size += self.node_id.as_slice().len();
offsets.push(total_size);
total_size += self.alias.as_slice().len();
total_size += self.node_name.as_slice().len();
offsets.push(total_size);
total_size += self.address.as_slice().len();
offsets.push(total_size);
Expand All @@ -3500,7 +3500,7 @@ impl molecule::prelude::Builder for NodeAnnouncementBuilder {
writer.write_all(self.features.as_slice())?;
writer.write_all(self.timestamp.as_slice())?;
writer.write_all(self.node_id.as_slice())?;
writer.write_all(self.alias.as_slice())?;
writer.write_all(self.node_name.as_slice())?;
writer.write_all(self.address.as_slice())?;
writer.write_all(self.chain_hash.as_slice())?;
writer.write_all(self.auto_accept_min_ckb_funding_amount.as_slice())?;
Expand Down
6 changes: 3 additions & 3 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct NodeInfo {
// Tentatively using 64 bits for features. May change the type later while developing.
// rust-lightning uses a Vec<u8> here.
pub features: u64,
// The alias of the node. This is a human-readable string that is meant to be used for labelling nodes in the UI.
pub alias: AnnouncedNodeName,
// The name of the node. This is a human-readable string that is meant to be used for labelling nodes in the UI.
pub node_name: AnnouncedNodeName,
// All the reachable addresses.
pub addresses: Vec<MultiAddr>,
// If the other party funding more than this amount, we will automatically accept the channel.
Expand All @@ -64,7 +64,7 @@ impl From<NodeAnnouncement> for NodeInfo {
node_id: value.node_id,
timestamp: value.timestamp,
features: value.features,
alias: value.alias,
node_name: value.node_name,
addresses: value.addresses,
auto_accept_min_ckb_funding_amount: value.auto_accept_min_ckb_funding_amount,
udt_cfg_infos: value.udt_cfg_infos,
Expand Down
10 changes: 4 additions & 6 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ pub enum LocalInfoKind {
#[derive(Debug, Clone)]
pub struct NodeInfoResponse {
pub node_name: Option<AnnouncedNodeName>,
pub peer_id: PeerId,
pub public_key: Pubkey,
pub node_id: Pubkey,
pub addresses: Vec<MultiAddr>,
pub chain_hash: Hash256,
pub open_channel_auto_accept_min_ckb_funding_amount: u64,
Expand Down Expand Up @@ -1318,8 +1317,7 @@ where
NetworkActorCommand::NodeInfo(_, rpc) => {
let response = NodeInfoResponse {
node_name: state.node_name.clone(),
peer_id: state.peer_id.clone(),
public_key: state.get_public_key().clone(),
node_id: state.get_public_key().clone(),
addresses: state.announced_addrs.clone(),
chain_hash: get_chain_hash(),
open_channel_auto_accept_min_ckb_funding_amount: state
Expand Down Expand Up @@ -1905,10 +1903,10 @@ where
debug!("Returning old node announcement message as it is still valid");
}
_ => {
let alias = self.node_name.unwrap_or_default();
let node_name = self.node_name.unwrap_or_default();
let addresses = self.announced_addrs.clone();
let announcement = NodeAnnouncement::new(
alias,
node_name,
addresses,
&self.private_key,
now,
Expand Down
2 changes: 1 addition & 1 deletion src/fiber/schema/gossip.mol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ table NodeAnnouncement {
timestamp: Uint64,
node_id: Pubkey,
// Must be a valid utf-8 string of length maximal length 32 bytes.
alias: Byte32,
node_name: Byte32,
// All the reachable addresses.
address: BytesVec,
// Chain hash
Expand Down
18 changes: 9 additions & 9 deletions src/fiber/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ pub struct NodeAnnouncement {
// Must be a valid utf-8 string of length maximal length 32 bytes.
// If the length is less than 32 bytes, it will be padded with 0.
// If the length is more than 32 bytes, it should be truncated.
pub alias: AnnouncedNodeName,
pub node_name: AnnouncedNodeName,
// All the reachable addresses.
pub addresses: Vec<MultiAddr>,
// chain_hash
Expand All @@ -1666,7 +1666,7 @@ pub struct NodeAnnouncement {

impl NodeAnnouncement {
pub fn new_unsigned(
alias: AnnouncedNodeName,
node_name: AnnouncedNodeName,
addresses: Vec<MultiAddr>,
node_id: Pubkey,
timestamp: u64,
Expand All @@ -1677,7 +1677,7 @@ impl NodeAnnouncement {
features: Default::default(),
timestamp,
node_id,
alias,
node_name,
chain_hash: get_chain_hash(),
addresses,
auto_accept_min_ckb_funding_amount,
Expand All @@ -1686,14 +1686,14 @@ impl NodeAnnouncement {
}

pub fn new(
alias: AnnouncedNodeName,
node_name: AnnouncedNodeName,
addresses: Vec<MultiAddr>,
private_key: &Privkey,
timestamp: u64,
auto_accept_min_ckb_funding_amount: u64,
) -> NodeAnnouncement {
let mut unsigned = NodeAnnouncement::new_unsigned(
alias,
node_name,
addresses,
private_key.pubkey(),
timestamp,
Expand All @@ -1709,7 +1709,7 @@ impl NodeAnnouncement {
features: self.features,
timestamp: self.timestamp,
node_id: self.node_id,
alias: self.alias,
node_name: self.node_name,
chain_hash: self.chain_hash,
addresses: self.addresses.clone(),
auto_accept_min_ckb_funding_amount: self.auto_accept_min_ckb_funding_amount,
Expand Down Expand Up @@ -1852,7 +1852,7 @@ impl From<NodeAnnouncement> for molecule_gossip::NodeAnnouncement {
.features(node_announcement.features.pack())
.timestamp(node_announcement.timestamp.pack())
.node_id(node_announcement.node_id.into())
.alias(u8_32_as_byte_32(&node_announcement.alias.0))
.node_name(u8_32_as_byte_32(&node_announcement.node_name.0))
.chain_hash(node_announcement.chain_hash.into())
.auto_accept_min_ckb_funding_amount(
node_announcement.auto_accept_min_ckb_funding_amount.pack(),
Expand Down Expand Up @@ -1893,8 +1893,8 @@ impl TryFrom<molecule_gossip::NodeAnnouncement> for NodeAnnouncement {
auto_accept_min_ckb_funding_amount: node_announcement
.auto_accept_min_ckb_funding_amount()
.unpack(),
alias: AnnouncedNodeName::from_slice(node_announcement.alias().as_slice())
.map_err(|e| Error::AnyHow(anyhow!("Invalid alias: {}", e)))?,
node_name: AnnouncedNodeName::from_slice(node_announcement.node_name().as_slice())
.map_err(|e| Error::AnyHow(anyhow!("Invalid node_name: {}", e)))?,
udt_cfg_infos: node_announcement.udt_cfg_infos().into(),
addresses: node_announcement
.address()
Expand Down
13 changes: 6 additions & 7 deletions src/rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Attempts to open a channel with a peer.

##### Params

* `peer_id` - PeerId, The peer ID to open a channel with.
* `peer_id` - PeerId, The peer ID to open a channel with, the peer must be connected through the [connect_peer](#peer-connect_peer) rpc first.
* `funding_amount` - u128, The amount of CKB or UDT to fund the channel with.
* `public` - `Option<bool>`, Whether this is a public channel (will be broadcasted to network, and can be used to forward TLCs), an optional parameter, default value is true.
* `funding_udt_type_script` - `Option<Script>`, The type script of the UDT to fund the channel with, an optional parameter.
Expand Down Expand Up @@ -433,9 +433,8 @@ Get the node information.

* `version` - String, The version of the node software.
* `commit_hash` - String, The commit hash of the node software.
* `public_key` - Pubkey, The public key of the node.
* `node_id` - Pubkey, The identity public key of the node.
* `node_name` - `Option<String>`, The optional name of the node.
* `peer_id` - PeerId, The peer ID of the node, serialized as a string.
* `addresses` - `Vec<MultiAddr>`, A list of multi-addresses associated with the node.
* `chain_hash` - Hash256, The hash of the blockchain that the node is connected to.
* `open_channel_auto_accept_min_ckb_funding_amount` - u64, The minimum CKB funding amount for automatically accepting open channel requests, serialized as a hexadecimal string.
Expand Down Expand Up @@ -670,9 +669,9 @@ The Node information.

#### Fields

* `alias` - String, The alias of the node.
* `node_name` - String, The name of the node.
* `addresses` - `Vec<MultiAddr>`, The addresses of the node.
* `node_id` - Pubkey, The node ID.
* `node_id` - Pubkey, The identity public key of the node.
* `timestamp` - u64, The timestamp of the node.
* `chain_hash` - Hash256, The chain hash of the node.
* `auto_accept_min_ckb_funding_amount` - u64, The minimum CKB funding amount for automatically accepting open channel requests.
Expand All @@ -687,8 +686,8 @@ The Channel information.
#### Fields

* `channel_outpoint` - OutPoint, The outpoint of the channel.
* `node1` - Pubkey, The node ID of the first node.
* `node2` - Pubkey, The node ID of the second node.
* `node1` - Pubkey, The identity public key of the first node.
* `node2` - Pubkey, The identity public key of the second node.
* `created_timestamp` - u64, The created timestamp of the channel, which is the block header timestamp of the block
that contains the channel funding transaction.
* `last_updated_timestamp_of_node1` - `Option<u64>`, The timestamp of the last update to channel by node 1 (e.g. updating fee rate).
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use tentacle::secio::PeerId;
#[serde_as]
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct OpenChannelParams {
/// The peer ID to open a channel with.
/// The peer ID to open a channel with, the peer must be connected through the [connect_peer](#peer-connect_peer) rpc first.
#[serde_as(as = "DisplayFromStr")]
peer_id: PeerId,

Expand Down
12 changes: 6 additions & 6 deletions src/rpc/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ impl From<ConfigUdtCfgInfos> for UdtCfgInfos {
#[serde_as]
#[derive(Serialize, Deserialize, Clone)]
struct NodeInfo {
/// The alias of the node.
alias: String,
/// The name of the node.
node_name: String,
/// The addresses of the node.
addresses: Vec<MultiAddr>,
/// The node ID.
/// The identity public key of the node.
node_id: Pubkey,
#[serde_as(as = "U64Hex")]
/// The timestamp of the node.
Expand All @@ -126,7 +126,7 @@ struct NodeInfo {
impl From<super::super::fiber::graph::NodeInfo> for NodeInfo {
fn from(value: super::super::fiber::graph::NodeInfo) -> Self {
NodeInfo {
alias: value.alias.to_string(),
node_name: value.node_name.to_string(),
addresses: value.addresses,
node_id: value.node_id,
timestamp: value.timestamp,
Expand Down Expand Up @@ -162,9 +162,9 @@ struct ChannelInfo {
/// The outpoint of the channel.
#[serde_as(as = "EntityHex")]
channel_outpoint: OutPoint,
/// The node ID of the first node.
/// The identity public key of the first node.
node1: Pubkey,
/// The node ID of the second node.
/// The identity public key of the second node.
node2: Pubkey,
/// The created timestamp of the channel, which is the block header timestamp of the block
/// that contains the channel funding transaction.
Expand Down
15 changes: 5 additions & 10 deletions src/rpc/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use jsonrpsee::{
};
use ractor::{call, ActorRef};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use tentacle::{multiaddr::MultiAddr, secio::PeerId};
use serde_with::serde_as;
use tentacle::multiaddr::MultiAddr;

#[serde_as]
#[derive(Clone, Serialize, Deserialize)]
Expand All @@ -26,16 +26,12 @@ pub(crate) struct NodeInfoResult {
/// The commit hash of the node software.
commit_hash: String,

/// The public key of the node.
public_key: Pubkey,
/// The identity public key of the node.
node_id: Pubkey,

/// The optional name of the node.
node_name: Option<String>,

/// The peer ID of the node, serialized as a string.
#[serde_as(as = "DisplayFromStr")]
peer_id: PeerId,

/// A list of multi-addresses associated with the node.
addresses: Vec<MultiAddr>,

Expand Down Expand Up @@ -116,9 +112,8 @@ where
handle_actor_call!(self.actor, message, ()).map(|response| NodeInfoResult {
version,
commit_hash,
public_key: response.public_key,
node_id: response.node_id,
node_name: response.node_name.map(|name| name.to_string()),
peer_id: response.peer_id,
addresses: response.addresses,
chain_hash: response.chain_hash,
open_channel_auto_accept_min_ckb_funding_amount: response
Expand Down
Loading