Skip to content

Commit

Permalink
Add SDK_GIT_HASH compile time env variable, include SDK version and g…
Browse files Browse the repository at this point in the history
…it hash info in payment failure report
  • Loading branch information
dangeross committed Nov 21, 2023
1 parent 8d724fe commit 57a82d0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
13 changes: 13 additions & 0 deletions libs/sdk-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("src/grpc/proto/breez.proto")?;
set_git_revision_hash();
Ok(())
}

fn set_git_revision_hash() {
use std::process::Command;

let args = &["rev-parse", "--short=10", "HEAD"];
let Ok(output) = Command::new("git").args(args).output() else { return };
let rev = String::from_utf8_lossy(&output.stdout).trim().to_string();
if rev.is_empty() {
return;
}
println!("cargo:rustc-env=SDK_GIT_HASH={}", rev);
}
3 changes: 2 additions & 1 deletion libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,10 @@ impl BreezServices {
.ok_or(SdkError::Generic {
err: "Payment not found".into(),
})?;
let lsp_id = self.persister.get_lsp_id()?;

self.support_api
.report_payment_failure(node_state, payment, data.comment)
.report_payment_failure(node_state, payment, lsp_id, data.comment)
.await
}
},
Expand Down
14 changes: 10 additions & 4 deletions libs/sdk-core/src/grpc/proto/breez.proto
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,20 @@ message GetReverseRoutingNodeRequest {}
message GetReverseRoutingNodeReply { bytes node_id = 1; }

message ReportPaymentFailureRequest {
// The sdk build version
string sdk_version = 1;
// The sdk build git hash
string sdk_git_hash = 2;
// The node pubkey reporting the failure
string node_id = 1;
string node_id = 3;
// The currently used lsp id
string lsp_id = 4;
// The ISO 8601 timestamp
string timestamp = 2;
string timestamp = 5;
// The optional comment/error response text
string comment = 3;
string comment = 6;
// The JSON encoded report payload
string report = 4;
string report = 7;
}
message ReportPaymentFailureReply {}

Expand Down
1 change: 1 addition & 0 deletions libs/sdk-core/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ pub trait SupportAPI: Send + Sync {
&self,
node_state: NodeState,
payment: Payment,
lsp_id: Option<String>,
comment: Option<String>,
) -> SdkResult<()>;
}
Expand Down
6 changes: 6 additions & 0 deletions libs/sdk-core/src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl SupportAPI for BreezServer {
&self,
node_state: NodeState,
payment: Payment,
lsp_id: Option<String>,
comment: Option<String>,
) -> SdkResult<()> {
let mut client = self.get_support_client().await?;
Expand All @@ -30,7 +31,12 @@ impl SupportAPI for BreezServer {
};

let request = Request::new(ReportPaymentFailureRequest {
sdk_version: option_env!("CARGO_PKG_VERSION")
.unwrap_or_default()
.to_string(),
sdk_git_hash: option_env!("SDK_GIT_HASH").unwrap_or_default().to_string(),
node_id: node_state.id,
lsp_id: lsp_id.unwrap_or_default(),
timestamp: timestamp.to_rfc3339(),
comment: comment.unwrap_or_default(),
report: serde_json::to_string(&report)?,
Expand Down

0 comments on commit 57a82d0

Please sign in to comment.